Skip to content

Commit 68bc095

Browse files
committed
HHH-19846 - Drop JUnit 4 usage
Not converted... * org.hibernate.orm.test.hql.PostgreSQLFunctionSelectClauseTest - registering custom function * org.hibernate.orm.test.hql.PostgreSQLFunctionWhereClauseTest - aux-db-object * org.hibernate.orm.test.id.usertype - type registrations * org.hibernate.orm.test.idgen.enhanced.HiloOptimizerConcurrencyTest - recreation of SF during tests * org.hibernate.orm.test.type.AbstractJavaTimeTypeTest subtypes - crazy parameterization (see org.hibernate.orm.test.tm.InterceptorTransactionTest)
1 parent 24d3eee commit 68bc095

File tree

10 files changed

+660
-752
lines changed

10 files changed

+660
-752
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/unidir/BackrefPropertyRefTest.java

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,42 @@
44
*/
55
package org.hibernate.orm.test.unidir;
66

7-
import org.hibernate.testing.FailureExpected;
7+
import org.hibernate.mapping.PersistentClass;
8+
import org.hibernate.testing.orm.junit.DomainModel;
9+
import org.hibernate.testing.orm.junit.DomainModelScope;
10+
import org.hibernate.testing.orm.junit.FailureExpected;
811
import org.hibernate.testing.orm.junit.JiraKey;
12+
import org.hibernate.testing.orm.junit.SessionFactory;
13+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
14+
import org.junit.jupiter.api.Test;
15+
16+
import static org.junit.jupiter.api.Assertions.assertEquals;
917

1018
/**
1119
* @author Gail Badner
1220
*/
13-
@JiraKey( value = "HHH-9370")
14-
@FailureExpected( jiraKey = "HHH-9370")
21+
@SuppressWarnings("JUnitMalformedDeclaration")
22+
@JiraKey("HHH-9370")
23+
@DomainModel(
24+
xmlMappings = "org/hibernate/orm/test/unidir/ParentChildPropertyRef.hbm.xml"
25+
)
26+
@SessionFactory
1527
public class BackrefPropertyRefTest extends BackrefTest {
28+
@Test
29+
void verifyMapping(DomainModelScope modelScope, SessionFactoryScope factoryScope) {
30+
final PersistentClass entityBinding = modelScope.getEntityBinding( Parent.class );
31+
assertEquals( "parent_with_prop_ref", entityBinding.getRootTable().getName() );
32+
}
1633

1734
@Override
18-
protected String[] getMappings() {
19-
return new String[] { "unidir/ParentChildPropertyRef.hbm.xml" };
35+
@FailureExpected(jiraKey = "HHH-9370")
36+
public void testBackRef(SessionFactoryScope factoryScope) {
37+
super.testBackRef( factoryScope );
2038
}
2139

40+
@Override
41+
@FailureExpected(jiraKey = "HHH-9370")
42+
public void testBackRefToProxiedEntityOnMerge(SessionFactoryScope factoryScope) {
43+
super.testBackRefToProxiedEntityOnMerge( factoryScope );
44+
}
2245
}

hibernate-core/src/test/java/org/hibernate/orm/test/unidir/BackrefTest.java

Lines changed: 65 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -5,133 +5,87 @@
55
package org.hibernate.orm.test.unidir;
66

77
import org.hibernate.Hibernate;
8-
import org.hibernate.Session;
9-
import org.hibernate.Transaction;
10-
import org.hibernate.cfg.Configuration;
11-
import org.hibernate.metamodel.CollectionClassification;
12-
13-
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
14-
import org.junit.Test;
15-
16-
import static org.hibernate.cfg.AvailableSettings.DEFAULT_LIST_SEMANTICS;
17-
import static org.junit.Assert.assertEquals;
18-
import static org.junit.Assert.assertFalse;
8+
import org.hibernate.testing.orm.junit.DomainModel;
9+
import org.hibernate.testing.orm.junit.SessionFactory;
10+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
11+
import org.junit.jupiter.api.AfterEach;
12+
import org.junit.jupiter.api.Assertions;
13+
import org.junit.jupiter.api.Test;
1914

2015
/**
2116
* @author Gavin King
2217
*/
23-
public class BackrefTest extends BaseCoreFunctionalTestCase {
24-
25-
@Override
26-
protected String getBaseForMappings() {
27-
return "org/hibernate/orm/test/";
28-
}
29-
30-
@Override
31-
protected String[] getMappings() {
32-
return new String[] { "unidir/ParentChild.hbm.xml" };
33-
}
34-
35-
@Override
36-
protected Class<?>[] getAnnotatedClasses() {
37-
// No test needed at this time. This was purely to test a
38-
// validation issue from HHH-5836.
39-
return new Class<?>[] { Parent1.class, Child1.class, Child2.class };
40-
}
41-
42-
@Override
43-
protected void configure(Configuration configuration) {
44-
super.configure( configuration );
45-
configuration.setProperty( DEFAULT_LIST_SEMANTICS, CollectionClassification.BAG );
18+
@SuppressWarnings("JUnitMalformedDeclaration")
19+
@DomainModel(
20+
xmlMappings = "org/hibernate/orm/test/unidir/ParentChild.hbm.xml"
21+
// annotatedClasses = { Parent1.class, Child1.class, Child2.class }
22+
)
23+
@SessionFactory
24+
public class BackrefTest {
25+
@AfterEach
26+
void tearDown(SessionFactoryScope factoryScope) {
27+
factoryScope.dropData();
4628
}
4729

4830
@Test
49-
public void testBackRef() {
50-
Session s = openSession();
51-
Transaction t = s.beginTransaction();
52-
Parent p = new Parent("Marc", 123456789);
53-
Parent p2 = new Parent("Nathalie", 987654321 );
54-
Child c = new Child("Elvira");
55-
Child c2 = new Child("Blase");
56-
p.getChildren().add(c);
57-
p.getChildren().add(c2);
58-
s.persist(p);
59-
s.persist(p2);
60-
t.commit();
61-
s.close();
62-
63-
s = openSession();
64-
t = s.beginTransaction();
65-
c = (Child) s.get(Child.class, "Elvira");
66-
c.setAge(2);
67-
t.commit();
68-
s.close();
69-
70-
s = openSession();
71-
t = s.beginTransaction();
72-
p = (Parent) s.get(Parent.class, "Marc");
73-
c = (Child) s.get(Child.class, "Elvira");
74-
c.setAge(18);
75-
t.commit();
76-
s.close();
77-
78-
s = openSession();
79-
t = s.beginTransaction();
80-
p = (Parent) s.get(Parent.class, "Marc");
81-
p2 = (Parent) s.get(Parent.class, "Nathalie");
82-
c = (Child) s.get(Child.class, "Elvira");
83-
assertEquals( p.getChildren().indexOf(c), 0 );
84-
p.getChildren().remove(c);
85-
p2.getChildren().add(c);
86-
t.commit();
87-
88-
s.close();
89-
s = openSession();
90-
t = s.beginTransaction();
91-
Parent p3 = new Parent("Marion", 543216789);
92-
p3.getChildren().add( new Child("Gavin") );
93-
s.merge(p3);
94-
t.commit();
95-
s.close();
96-
97-
s = openSession();
98-
t = s.beginTransaction();
99-
s.createQuery( "delete from Child" ).executeUpdate();
100-
s.createQuery( "delete from Parent" ).executeUpdate();
101-
t.commit();
102-
s.close();
31+
public void testBackRef(SessionFactoryScope factoryScope) {
32+
factoryScope.inTransaction( (session) -> {
33+
Parent p = new Parent("Marc", 123456789);
34+
Parent p2 = new Parent("Nathalie", 987654321 );
35+
Child c = new Child("Elvira");
36+
Child c2 = new Child("Blase");
37+
p.getChildren().add(c);
38+
p.getChildren().add(c2);
39+
session.persist(p);
40+
session.persist(p2);
41+
} );
42+
43+
factoryScope.inTransaction( (s) -> {
44+
var c = s.find( Child.class, "Elvira" );
45+
c.setAge(2);
46+
} );
47+
48+
factoryScope.inTransaction( (s) -> {
49+
var c = s.find( Child.class, "Elvira" );
50+
c.setAge(18);
51+
} );
52+
53+
factoryScope.inTransaction( (s) -> {
54+
var p = s.find( Parent.class, "Marc" );
55+
var p2 = s.find( Parent.class, "Nathalie" );
56+
var c = s.find( Child.class, "Elvira" );
57+
Assertions.assertEquals( 0, p.getChildren().indexOf(c) );
58+
p.getChildren().remove(c);
59+
p2.getChildren().add(c);
60+
} );
61+
62+
factoryScope.inTransaction( (s) -> {
63+
var p3 = new Parent("Marion", 543216789);
64+
p3.getChildren().add( new Child("Gavin") );
65+
s.merge(p3);
66+
} );
10367
}
10468

10569
@Test
106-
public void testBackRefToProxiedEntityOnMerge() {
107-
Session s = openSession();
108-
s.beginTransaction();
109-
Parent me = new Parent( "Steve", 192837465 );
110-
me.getChildren().add( new Child( "Joe" ) );
111-
s.persist( me );
112-
s.getTransaction().commit();
113-
s.close();
70+
public void testBackRefToProxiedEntityOnMerge(SessionFactoryScope factoryScope) {
71+
var me = factoryScope.fromTransaction( (s) -> {
72+
var steve = new Parent( "Steve", 192837465 );
73+
steve.getChildren().add( new Child( "Joe" ) );
74+
s.persist( steve );
75+
return steve;
76+
} );
11477

11578
// while detached, add a new element
11679
me.getChildren().add( new Child( "Cece" ) );
11780
me.getChildren().add( new Child( "Austin" ) );
11881

119-
s = openSession();
120-
s.beginTransaction();
12182
// load 'me' to associate it with the new session as a proxy (this may have occurred as 'prior work'
12283
// to the reattachment below)...
123-
Object meProxy = s.getReference( Parent.class, me.getName() );
124-
assertFalse( Hibernate.isInitialized( meProxy ) );
125-
// now, do the reattchment...
126-
s.merge( me );
127-
s.getTransaction().commit();
128-
s.close();
129-
130-
s = openSession();
131-
s.beginTransaction();
132-
s.createQuery( "delete from Child" ).executeUpdate();
133-
s.createQuery( "delete from Parent" ).executeUpdate();
134-
s.getTransaction().commit();
135-
s.close();
84+
factoryScope.inTransaction( (s) -> {
85+
Object meProxy = s.getReference( Parent.class, me.getName() );
86+
Assertions.assertFalse( Hibernate.isInitialized( meProxy ) );
87+
// now, do the reattchment...
88+
s.merge( me );
89+
} );
13690
}
13791
}

hibernate-core/src/test/java/org/hibernate/orm/test/unidir/UnidirectionalOneToManyNonPkJoinColumnTest.java

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,49 +4,52 @@
44
*/
55
package org.hibernate.orm.test.unidir;
66

7-
import java.io.Serializable;
8-
import java.util.List;
97
import jakarta.persistence.Entity;
108
import jakarta.persistence.FetchType;
119
import jakarta.persistence.Id;
1210
import jakarta.persistence.JoinColumn;
1311
import jakarta.persistence.OneToMany;
1412
import jakarta.persistence.Table;
15-
1613
import org.hibernate.annotations.Fetch;
1714
import org.hibernate.annotations.FetchMode;
18-
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
19-
15+
import org.hibernate.testing.orm.junit.DomainModel;
2016
import org.hibernate.testing.orm.junit.JiraKey;
21-
import org.junit.Test;
17+
import org.hibernate.testing.orm.junit.SessionFactory;
18+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
19+
import org.junit.jupiter.api.AfterEach;
20+
import org.junit.jupiter.api.Test;
2221

23-
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
22+
import java.io.Serializable;
23+
import java.util.List;
2424

2525
/**
2626
* @author Vlad Mihalcea
2727
*/
28-
public class UnidirectionalOneToManyNonPkJoinColumnTest extends BaseEntityManagerFunctionalTestCase {
29-
30-
@Override
31-
protected Class<?>[] getAnnotatedClasses() {
32-
return new Class<?>[] {
33-
Customer.class,
34-
Order.class
35-
};
28+
@SuppressWarnings("JUnitMalformedDeclaration")
29+
@DomainModel(annotatedClasses = {
30+
UnidirectionalOneToManyNonPkJoinColumnTest.Customer.class,
31+
UnidirectionalOneToManyNonPkJoinColumnTest.Order.class
32+
})
33+
@SessionFactory
34+
public class UnidirectionalOneToManyNonPkJoinColumnTest {
35+
@AfterEach
36+
void tearDown(SessionFactoryScope factoryScope) {
37+
factoryScope.dropData();
3638
}
3739

3840
@Test
39-
@JiraKey( value = "HHH-12064" )
40-
public void test() {
41-
doInJPA( this::entityManagerFactory, entityManager -> {
41+
@JiraKey("HHH-12064")
42+
public void test(SessionFactoryScope factoryScope) {
43+
factoryScope.inTransaction( entityManager -> {
4244
// Save the entity on the One side
4345
Customer customer = new Customer();
4446
customer.idCode = "ABC";
4547
customer.translationId = 1L;
4648

4749
entityManager.persist(customer);
4850
} );
49-
doInJPA( this::entityManagerFactory, entityManager -> {
51+
52+
factoryScope.inTransaction( entityManager -> {
5053
// Attempt to load the entity saved in the previous session
5154
entityManager.find(Customer.class, "ABC");
5255
} );

0 commit comments

Comments
 (0)