Re-enable additional tests
This commit is contained in:
parent
ee07497e85
commit
8e3e119d7d
|
@ -4,12 +4,11 @@
|
|||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.ecid;
|
||||
package org.hibernate.orm.test.ecid;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Iterator;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.EmbeddedId;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
|
@ -17,31 +16,45 @@ import javax.persistence.JoinColumns;
|
|||
import javax.persistence.ManyToOne;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Gail Badner
|
||||
*/
|
||||
public class CompositeIdAssociationsWithEmbeddedCompositeIdTest extends BaseCoreFunctionalTestCase {
|
||||
@DomainModel(
|
||||
annotatedClasses = {
|
||||
CompositeIdAssociationsWithEmbeddedCompositeIdTest.Parent.class,
|
||||
CompositeIdAssociationsWithEmbeddedCompositeIdTest.Person.class
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
public class CompositeIdAssociationsWithEmbeddedCompositeIdTest {
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[] { Parent.class, Person.class };
|
||||
@AfterEach
|
||||
public void tearDown(SessionFactoryScope scope){
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
session.createQuery( "delete from Person" ).executeUpdate();
|
||||
session.createQuery( "delete from Parent" ).executeUpdate();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-13114")
|
||||
public void testQueries() {
|
||||
@TestForIssue(jiraKey = "HHH-13114")
|
||||
public void testQueries(SessionFactoryScope scope) {
|
||||
Parent parent1 = new Parent( "Jane", 0 );
|
||||
Parent parent2 = new Parent( "Jim", 1 );
|
||||
Person person = doInHibernate(
|
||||
this::sessionFactory, session -> {
|
||||
Person person = scope.fromTransaction(
|
||||
session -> {
|
||||
Person p = new Person();
|
||||
p.setParent1( parent1 );
|
||||
p.setParent2( parent2 );
|
||||
|
@ -50,27 +63,27 @@ public class CompositeIdAssociationsWithEmbeddedCompositeIdTest extends BaseCore
|
|||
session.persist( parent2 );
|
||||
session.persist( p );
|
||||
return p;
|
||||
});
|
||||
} );
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory, session -> {
|
||||
checkResult( session.get( Person.class, person ) );
|
||||
});
|
||||
scope.inTransaction(
|
||||
session ->
|
||||
checkResult( session.get( Person.class, person ) )
|
||||
);
|
||||
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory, session -> {
|
||||
checkResult( session.createQuery( "from Person p", Person.class ).getSingleResult() );
|
||||
});
|
||||
scope.inTransaction(
|
||||
session ->
|
||||
checkResult( session.createQuery( "from Person p", Person.class ).getSingleResult() )
|
||||
);
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory, session -> {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Iterator<Person> iterator = session.createQuery( "from Person p", Person.class ).list().iterator();
|
||||
assertTrue( iterator.hasNext() );
|
||||
Person p = iterator.next();
|
||||
checkResult( p );
|
||||
assertFalse( iterator.hasNext() );
|
||||
});
|
||||
} );
|
||||
}
|
||||
|
||||
private void checkResult(Person p) {
|
||||
|
@ -83,7 +96,7 @@ public class CompositeIdAssociationsWithEmbeddedCompositeIdTest extends BaseCore
|
|||
@Entity(name = "Person")
|
||||
public static class Person implements Serializable {
|
||||
@Id
|
||||
@JoinColumns( value = {
|
||||
@JoinColumns(value = {
|
||||
@JoinColumn(name = "p1Name"),
|
||||
@JoinColumn(name = "p1Index")
|
||||
})
|
||||
|
@ -91,7 +104,7 @@ public class CompositeIdAssociationsWithEmbeddedCompositeIdTest extends BaseCore
|
|||
private Parent parent1;
|
||||
|
||||
@Id
|
||||
@JoinColumns( value = {
|
||||
@JoinColumns(value = {
|
||||
@JoinColumn(name = "p2Name"),
|
||||
@JoinColumn(name = "p2Index")
|
||||
})
|
||||
|
@ -116,6 +129,7 @@ public class CompositeIdAssociationsWithEmbeddedCompositeIdTest extends BaseCore
|
|||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
@ -123,6 +137,7 @@ public class CompositeIdAssociationsWithEmbeddedCompositeIdTest extends BaseCore
|
|||
public Parent getParent1() {
|
||||
return parent1;
|
||||
}
|
||||
|
||||
public void setParent1(Parent parent1) {
|
||||
this.parent1 = parent1;
|
||||
}
|
||||
|
@ -130,6 +145,7 @@ public class CompositeIdAssociationsWithEmbeddedCompositeIdTest extends BaseCore
|
|||
public Parent getParent2() {
|
||||
return parent2;
|
||||
}
|
||||
|
||||
public void setParent2(Parent parent2) {
|
||||
this.parent2 = parent2;
|
||||
}
|
||||
|
@ -137,6 +153,7 @@ public class CompositeIdAssociationsWithEmbeddedCompositeIdTest extends BaseCore
|
|||
public int getBirthOrder() {
|
||||
return birthOrder;
|
||||
}
|
||||
|
||||
public void setBirthOrder(int birthOrder) {
|
||||
this.birthOrder = birthOrder;
|
||||
}
|
||||
|
@ -148,7 +165,7 @@ public class CompositeIdAssociationsWithEmbeddedCompositeIdTest extends BaseCore
|
|||
private String name;
|
||||
|
||||
@Id
|
||||
@Column(name="ind")
|
||||
@Column(name = "ind")
|
||||
private int index;
|
||||
|
||||
public Parent() {
|
|
@ -10,7 +10,7 @@
|
|||
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
|
||||
|
||||
<hibernate-mapping
|
||||
package="org.hibernate.test.ecid"
|
||||
package="org.hibernate.orm.test.ecid"
|
||||
default-access="field">
|
||||
|
||||
<!--
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id: Course.java 6913 2005-05-25 17:37:51Z oneovthafew $
|
||||
package org.hibernate.test.ecid;
|
||||
package org.hibernate.orm.test.ecid;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
|
@ -0,0 +1,172 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.orm.test.ecid;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.proxy.HibernateProxy;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Gavin King
|
||||
*/
|
||||
@DomainModel(
|
||||
xmlMappings = "org/hibernate/orm/test/ecid/Course.hbm.xml"
|
||||
)
|
||||
@SessionFactory
|
||||
public class EmbeddedCompositeIdTest {
|
||||
|
||||
@AfterEach
|
||||
public void tearDown(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session ->
|
||||
session.createQuery( "delete from Course" ).executeUpdate()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMerge(SessionFactoryScope scope) {
|
||||
Course uc = new UniversityCourse( "mat2000", "Monash", "second year maths", 0 );
|
||||
Course c = new Course( "eng5000", "BHS", "grade 5 english" );
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
session.persist( uc );
|
||||
session.persist( c );
|
||||
}
|
||||
);
|
||||
|
||||
c.setDescription( "Grade 5 English" );
|
||||
uc.setDescription( "Second year mathematics" );
|
||||
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
session.merge( c );
|
||||
session.merge( uc );
|
||||
}
|
||||
);
|
||||
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
session.delete( c );
|
||||
session.delete( uc );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-799")
|
||||
public void testMerging(SessionFactoryScope scope) {
|
||||
Course course = new Course( "EN-101", "BA", "preparatory english" );
|
||||
scope.inTransaction(
|
||||
session ->
|
||||
session.persist( course )
|
||||
);
|
||||
|
||||
String newDesc = "basic preparatory english";
|
||||
course.setDescription( newDesc );
|
||||
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Course c = (Course) session.merge( course );
|
||||
assertEquals( newDesc, c.getDescription(), "description not merged" );
|
||||
}
|
||||
);
|
||||
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Course cid = new Course( "EN-101", "BA", null );
|
||||
Course c = session.get( Course.class, cid );
|
||||
assertEquals( newDesc, c.getDescription(), "description not merged" );
|
||||
session.delete( c );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPolymorphism(SessionFactoryScope scope) {
|
||||
Course uc = new UniversityCourse( "mat2000", "Monash", "second year maths", 0 );
|
||||
Course c = new Course( "eng5000", "BHS", "grade 5 english" );
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
session.persist( uc );
|
||||
session.persist( c );
|
||||
}
|
||||
);
|
||||
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Course ucid = new Course( "mat2000", "Monash", null );
|
||||
Course cid = new Course( "eng5000", "BHS", null );
|
||||
Course luc = session.load( Course.class, ucid );
|
||||
Course lc = session.load( Course.class, cid );
|
||||
assertFalse( Hibernate.isInitialized( luc ) );
|
||||
assertFalse( Hibernate.isInitialized( lc ) );
|
||||
assertEquals( UniversityCourse.class, Hibernate.getClass( luc ) );
|
||||
assertEquals( Course.class, Hibernate.getClass( lc ) );
|
||||
assertSame( ( (HibernateProxy) lc ).getHibernateLazyInitializer().getImplementation(), cid );
|
||||
assertEquals( "eng5000", c.getCourseCode() );
|
||||
assertEquals( "mat2000", uc.getCourseCode() );
|
||||
}
|
||||
);
|
||||
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Course ucid = new Course( "mat2000", "Monash", null );
|
||||
Course cid = new Course( "eng5000", "BHS", null );
|
||||
Course luc = session.get( Course.class, ucid );
|
||||
Course lc = session.get( Course.class, cid );
|
||||
assertTrue( Hibernate.isInitialized( luc ) );
|
||||
assertTrue( Hibernate.isInitialized( lc ) );
|
||||
assertEquals( UniversityCourse.class, Hibernate.getClass( luc ) );
|
||||
assertEquals( Course.class, Hibernate.getClass( lc ) );
|
||||
assertSame( lc, cid );
|
||||
assertEquals( "eng5000", c.getCourseCode() );
|
||||
assertEquals( "mat2000", uc.getCourseCode() );
|
||||
}
|
||||
);
|
||||
|
||||
List<Course> courses = scope.fromTransaction(
|
||||
session -> {
|
||||
List<Course> list = session.createQuery( "from Course order by courseCode" ).list();
|
||||
assertTrue( list.get( 0 ) instanceof Course );
|
||||
assertTrue( list.get( 1 ) instanceof UniversityCourse );
|
||||
assertEquals( "eng5000", list.get( 0 ).getCourseCode() );
|
||||
assertEquals( "mat2000", list.get( 1 ).getCourseCode() );
|
||||
return list;
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
courses.get( 0 ).setDescription( "Grade 5 English" );
|
||||
courses.get( 1 ).setDescription( "Second year mathematics" );
|
||||
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
session.saveOrUpdate( courses.get( 0 ) );
|
||||
session.saveOrUpdate( courses.get( 1 ) );
|
||||
}
|
||||
);
|
||||
|
||||
scope.inTransaction(
|
||||
session ->
|
||||
courses.forEach( course -> session.delete( c ) )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id: UniversityCourse.java 6913 2005-05-25 17:37:51Z oneovthafew $
|
||||
package org.hibernate.test.ecid;
|
||||
package org.hibernate.orm.test.ecid;
|
||||
|
||||
|
||||
/**
|
|
@ -1,165 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.ecid;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.proxy.HibernateProxy;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Gavin King
|
||||
*/
|
||||
public class EmbeddedCompositeIdTest extends BaseCoreFunctionalTestCase {
|
||||
@Override
|
||||
public String[] getMappings() {
|
||||
return new String[] { "ecid/Course.hbm.xml" };
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMerge() {
|
||||
Session s = openSession();
|
||||
Transaction t = s.beginTransaction();
|
||||
Course uc = new UniversityCourse("mat2000", "Monash", "second year maths", 0);
|
||||
Course c = new Course("eng5000", "BHS", "grade 5 english");
|
||||
s.persist(uc);
|
||||
s.persist(c);
|
||||
t.commit();
|
||||
s.close();
|
||||
|
||||
c.setDescription("Grade 5 English");
|
||||
uc.setDescription("Second year mathematics");
|
||||
|
||||
s = openSession();
|
||||
t = s.beginTransaction();
|
||||
s.merge(c);
|
||||
s.merge(uc);
|
||||
t.commit();
|
||||
s.close();
|
||||
|
||||
s = openSession();
|
||||
t = s.beginTransaction();
|
||||
s.delete(c);
|
||||
s.delete(uc);
|
||||
t.commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-799" )
|
||||
public void testMerging() {
|
||||
Session s = openSession();
|
||||
Transaction t = s.beginTransaction();
|
||||
Course course = new Course( "EN-101", "BA", "preparatory english" );
|
||||
s.persist( course );
|
||||
t.commit();
|
||||
s.close();
|
||||
|
||||
String newDesc = "basic preparatory english";
|
||||
course.setDescription( newDesc );
|
||||
|
||||
s = openSession();
|
||||
t = s.beginTransaction();
|
||||
Course c = (Course) s.merge( course );
|
||||
assertEquals( "description not merged", newDesc, c.getDescription() );
|
||||
t.commit();
|
||||
s.close();
|
||||
|
||||
s = openSession();
|
||||
t = s.beginTransaction();
|
||||
Course cid = new Course( "EN-101", "BA", null );
|
||||
course = ( Course ) s.get( Course.class, cid );
|
||||
assertEquals( "description not merged", newDesc, course.getDescription() );
|
||||
s.delete( course );
|
||||
t.commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPolymorphism() {
|
||||
Session s = openSession();
|
||||
Transaction t = s.beginTransaction();
|
||||
Course uc = new UniversityCourse("mat2000", "Monash", "second year maths", 0);
|
||||
Course c = new Course("eng5000", "BHS", "grade 5 english");
|
||||
s.persist(uc);
|
||||
s.persist(c);
|
||||
t.commit();
|
||||
s.close();
|
||||
|
||||
s = openSession();
|
||||
t = s.beginTransaction();
|
||||
Course ucid = new Course("mat2000", "Monash", null);
|
||||
Course cid = new Course("eng5000", "BHS", null);
|
||||
Course luc = (Course) s.load(Course.class, ucid);
|
||||
Course lc = (Course) s.load(Course.class, cid);
|
||||
assertFalse( Hibernate.isInitialized(luc) );
|
||||
assertFalse( Hibernate.isInitialized(lc) );
|
||||
assertEquals( UniversityCourse.class, Hibernate.getClass(luc) );
|
||||
assertEquals( Course.class, Hibernate.getClass(lc) );
|
||||
assertSame( ( (HibernateProxy) lc ).getHibernateLazyInitializer().getImplementation(), cid );
|
||||
assertEquals( c.getCourseCode(), "eng5000" );
|
||||
assertEquals( uc.getCourseCode(), "mat2000" );
|
||||
t.commit();
|
||||
s.close();
|
||||
|
||||
s = openSession();
|
||||
t = s.beginTransaction();
|
||||
ucid = new Course("mat2000", "Monash", null);
|
||||
cid = new Course("eng5000", "BHS", null);
|
||||
luc = (Course) s.get(Course.class, ucid);
|
||||
lc = (Course) s.get(Course.class, cid);
|
||||
assertTrue( Hibernate.isInitialized(luc) );
|
||||
assertTrue( Hibernate.isInitialized(lc) );
|
||||
assertEquals( UniversityCourse.class, Hibernate.getClass(luc) );
|
||||
assertEquals( Course.class, Hibernate.getClass(lc) );
|
||||
assertSame( lc, cid );
|
||||
assertEquals( c.getCourseCode(), "eng5000" );
|
||||
assertEquals( uc.getCourseCode(), "mat2000" );
|
||||
t.commit();
|
||||
s.close();
|
||||
|
||||
s = openSession();
|
||||
t = s.beginTransaction();
|
||||
List list = s.createQuery("from Course order by courseCode").list();
|
||||
assertTrue( list.get(0) instanceof Course );
|
||||
assertTrue( list.get(1) instanceof UniversityCourse );
|
||||
c = (Course) list.get(0);
|
||||
uc = (UniversityCourse) list.get(1);
|
||||
assertEquals( c.getCourseCode(), "eng5000" );
|
||||
assertEquals( uc.getCourseCode(), "mat2000" );
|
||||
t.commit();
|
||||
s.close();
|
||||
|
||||
c.setDescription("Grade 5 English");
|
||||
uc.setDescription("Second year mathematics");
|
||||
|
||||
s = openSession();
|
||||
t = s.beginTransaction();
|
||||
s.saveOrUpdate(c);
|
||||
s.saveOrUpdate(uc);
|
||||
t.commit();
|
||||
s.close();
|
||||
|
||||
s = openSession();
|
||||
t = s.beginTransaction();
|
||||
s.delete(c);
|
||||
s.delete(uc);
|
||||
t.commit();
|
||||
s.close();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue