Skip to content

Commit 6a6f370

Browse files
committed
HHH-19846 - Remove JUnit4: org.hibernate.orm.test.jpa.graphs/*
Signed-off-by: Jan Schatteman <[email protected]>
1 parent 88dc3c7 commit 6a6f370

File tree

6 files changed

+976
-1050
lines changed

6 files changed

+976
-1050
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/jpa/graphs/CacheableEntityGraphTest.java

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import jakarta.persistence.ElementCollection;
1212
import jakarta.persistence.Entity;
1313
import jakarta.persistence.EntityGraph;
14-
import jakarta.persistence.EntityManager;
1514
import jakarta.persistence.EnumType;
1615
import jakarta.persistence.Enumerated;
1716
import jakarta.persistence.FetchType;
@@ -23,43 +22,38 @@
2322

2423
import org.hibernate.annotations.Cache;
2524
import org.hibernate.annotations.CacheConcurrencyStrategy;
26-
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
2725

26+
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
2827
import org.hibernate.testing.orm.junit.JiraKey;
29-
import org.junit.Test;
28+
import org.hibernate.testing.orm.junit.Jpa;
29+
import org.junit.jupiter.api.Test;
3030

31-
public class CacheableEntityGraphTest extends BaseEntityManagerFunctionalTestCase {
32-
33-
@Override
34-
protected Class<?>[] getAnnotatedClasses() {
35-
return new Class[] { Product.class, Color.class, Tag.class };
36-
}
31+
@Jpa(annotatedClasses = {CacheableEntityGraphTest.Product.class, CacheableEntityGraphTest.Color.class, CacheableEntityGraphTest.Tag.class})
32+
public class CacheableEntityGraphTest {
3733

3834
@Test
3935
@JiraKey(value = "HHH-15964")
40-
public void test() {
41-
EntityManager em = getOrCreateEntityManager();
42-
43-
em.getTransaction().begin();
44-
Tag tag = new Tag( Set.of( TagType.FOO ) );
45-
em.persist( tag );
46-
47-
Color color = new Color();
48-
em.persist( color );
49-
50-
Product product = new Product( tag, color );
51-
em.persist( product );
52-
em.getTransaction().commit();
53-
54-
em.clear();
55-
56-
EntityGraph<Product> entityGraph = em.createEntityGraph( Product.class );
57-
entityGraph.addAttributeNodes( "tag" );
58-
59-
em.createQuery( "select p from Product p", Product.class )
60-
.setMaxResults( 2 )
61-
.setHint( "jakarta.persistence.loadgraph", entityGraph )
62-
.getSingleResult();
36+
public void test(EntityManagerFactoryScope scope) {
37+
scope.inEntityManager( entityManager -> {
38+
entityManager.getTransaction().begin();
39+
Tag tag = new Tag( Set.of( TagType.FOO ) );
40+
entityManager.persist( tag );
41+
42+
Color color = new Color();
43+
entityManager.persist( color );
44+
45+
Product product = new Product( tag, color );
46+
entityManager.persist( product );
47+
entityManager.getTransaction().commit();
48+
49+
EntityGraph<Product> entityGraph = entityManager.createEntityGraph( Product.class );
50+
entityGraph.addAttributeNodes( "tag" );
51+
52+
entityManager.createQuery( "select p from Product p", Product.class )
53+
.setMaxResults( 2 )
54+
.setHint( "jakarta.persistence.loadgraph", entityGraph )
55+
.getSingleResult();
56+
} );
6357
}
6458

6559
@Entity(name = "Product")

hibernate-core/src/test/java/org/hibernate/orm/test/jpa/graphs/EntityGraphAttributeResolutionTest.java

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -25,81 +25,76 @@
2525
import jakarta.persistence.Table;
2626

2727
import org.hibernate.graph.GraphSemantic;
28-
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
2928

29+
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
3030
import org.hibernate.testing.orm.junit.JiraKey;
31-
import org.junit.Before;
32-
import org.junit.Test;
31+
import org.hibernate.testing.orm.junit.Jpa;
32+
import org.junit.jupiter.api.BeforeEach;
33+
import org.junit.jupiter.api.Test;
3334

3435
import static org.assertj.core.api.Assertions.assertThat;
35-
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
36-
3736

3837
/**
3938
* @author Benjamin M.
4039
* @author Nathan Xu
4140
*/
4241
@JiraKey( value = "HHH-14113" )
4342
@SuppressWarnings({ "unchecked", "rawtypes" })
44-
public class EntityGraphAttributeResolutionTest extends BaseEntityManagerFunctionalTestCase {
43+
@Jpa(annotatedClasses = {EntityGraphAttributeResolutionTest.User.class, EntityGraphAttributeResolutionTest.Group.class})
44+
public class EntityGraphAttributeResolutionTest {
4545

4646
private User u;
4747
private Group g1, g2;
4848

49-
@Override
50-
protected Class<?>[] getAnnotatedClasses() {
51-
return new Class<?>[] { User.class, Group.class };
52-
}
53-
54-
@Before
55-
public void setUp() {
56-
doInJPA( this::entityManagerFactory, em -> {
49+
@BeforeEach
50+
public void setUp(EntityManagerFactoryScope scope) {
51+
scope.inTransaction( entityManager -> {
5752
g1 = new Group();
5853
g1.addPermission( Permission.BAR );
59-
em.persist( g1 );
54+
entityManager.persist( g1 );
6055

6156
g2 = new Group();
6257
g2.addPermission( Permission.BAZ );
63-
em.persist( g2 );
58+
entityManager.persist( g2 );
6459

6560
u = new User();
66-
em.persist( u );
61+
entityManager.persist( u );
6762
u.addGroup( g1 );
6863
u.addGroup( g2 );
6964
} );
7065
}
7166

7267
@Test
73-
public void fetchAssocWithNamedFetchGraph() {
74-
doInJPA( this::entityManagerFactory, em -> {
75-
List result = em.createQuery( "SELECT u.groups FROM User u WHERE u.id = ?1" )
68+
public void fetchAssocWithNamedFetchGraph(EntityManagerFactoryScope scope) {
69+
scope.inTransaction( entityManager -> {
70+
List result = entityManager.createQuery( "SELECT u.groups FROM User u WHERE u.id = ?1" )
7671
.setParameter(1, u.getId() )
77-
.setHint( GraphSemantic.FETCH.getJpaHintName(), em.getEntityGraph( Group.ENTITY_GRAPH ) )
72+
.setHint( GraphSemantic.FETCH.getJpaHintName(), entityManager.getEntityGraph( Group.ENTITY_GRAPH ) )
7873
.getResultList();
7974

8075
assertThat( result ).containsExactlyInAnyOrder( g1, g2 );
8176
} );
8277
}
8378

8479
@Test
85-
public void fetchAssocWithNamedFetchGraphAndJoin() {
86-
doInJPA( this::entityManagerFactory, em -> {
87-
List result = em.createQuery( "SELECT g FROM User u JOIN u.groups g WHERE u.id = ?1" )
80+
public void fetchAssocWithNamedFetchGraphAndJoin(EntityManagerFactoryScope scope) {
81+
scope.inTransaction( entityManager -> {
82+
List result = entityManager.createQuery( "SELECT g FROM User u JOIN u.groups g WHERE u.id = ?1" )
8883
.setParameter( 1, u.getId() )
89-
.setHint( GraphSemantic.FETCH.getJpaHintName(), em.getEntityGraph( Group.ENTITY_GRAPH ) )
84+
.setHint( GraphSemantic.FETCH.getJpaHintName(), entityManager.getEntityGraph( Group.ENTITY_GRAPH ) )
9085
.getResultList();
9186

9287
assertThat( result ).containsExactlyInAnyOrder( g1, g2 );
9388
} );
9489
}
9590

9691
@Test
97-
public void fetchAssocWithAdhocFetchGraph() {
98-
doInJPA( this::entityManagerFactory, em -> {
99-
EntityGraph<Group> eg = em.createEntityGraph( Group.class );
92+
public void fetchAssocWithAdhocFetchGraph(EntityManagerFactoryScope scope) {
93+
scope.inTransaction( entityManager -> {
94+
EntityGraph<Group> eg = entityManager.createEntityGraph( Group.class );
10095
eg.addAttributeNodes( "permissions" );
10196

102-
List result = em.createQuery( "SELECT u.groups FROM User u WHERE u.id = ?1" )
97+
List result = entityManager.createQuery( "SELECT u.groups FROM User u WHERE u.id = ?1" )
10398
.setParameter(1, u.getId() )
10499
.setHint( GraphSemantic.FETCH.getJpaHintName(), eg )
105100
.getResultList();

0 commit comments

Comments
 (0)