Skip to content

Commit d3a5d0b

Browse files
committed
HHH-19871 --wip-- Envers migration to JUnit 6
- `org.hibernate.orm.test.envers.integration.hashcode` - `org.hibernate.orm.test.envers.integration.ids` - `org.hibernate.orm.test.envers.integration.interfaces`
1 parent 72e1f20 commit d3a5d0b

34 files changed

+1302
-1436
lines changed

hibernate-envers/src/test/java/org/hibernate/orm/test/envers/integration/hashcode/ChangingHashcode.java

Lines changed: 56 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -5,92 +5,87 @@
55
package org.hibernate.orm.test.envers.integration.hashcode;
66

77
import java.util.Arrays;
8-
import jakarta.persistence.EntityManager;
98

10-
import org.hibernate.orm.test.envers.BaseEnversJPAFunctionalTestCase;
11-
import org.hibernate.orm.test.envers.Priority;
9+
import org.hibernate.envers.AuditReaderFactory;
1210
import org.hibernate.orm.test.envers.tools.TestTools;
11+
import org.hibernate.testing.envers.junit.EnversTest;
12+
import org.hibernate.testing.orm.junit.BeforeClassTemplate;
13+
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
14+
import org.hibernate.testing.orm.junit.Jpa;
1315

14-
import org.junit.Test;
16+
import org.junit.jupiter.api.Test;
17+
18+
import static org.junit.jupiter.api.Assertions.assertEquals;
19+
import static org.junit.jupiter.api.Assertions.assertNull;
1520

1621
/**
1722
* @author Adam Warski (adam at warski dot org)
1823
*/
19-
public class ChangingHashcode extends BaseEnversJPAFunctionalTestCase {
24+
@EnversTest
25+
@Jpa(annotatedClasses = {WikiPage.class, WikiImage.class})
26+
public class ChangingHashcode {
2027
private Long pageId;
2128
private Long imageId;
2229

23-
@Override
24-
protected Class<?>[] getAnnotatedClasses() {
25-
return new Class[] {WikiPage.class, WikiImage.class};
26-
}
27-
28-
@Test
29-
@Priority(10)
30-
public void initData() {
30+
@BeforeClassTemplate
31+
public void initData(EntityManagerFactoryScope scope) {
3132
// Revision 1
32-
EntityManager em = getEntityManager();
33-
em.getTransaction().begin();
34-
35-
WikiPage page = new WikiPage( "title", "content" );
36-
em.persist( page );
37-
38-
em.getTransaction().commit();
33+
scope.inTransaction( em -> {
34+
WikiPage page = new WikiPage( "title", "content" );
35+
em.persist( page );
36+
pageId = page.getId();
37+
} );
3938

4039
// Revision 2
41-
em = getEntityManager();
42-
em.getTransaction().begin();
43-
44-
WikiImage image = new WikiImage( "name1" );
45-
em.persist( image );
40+
scope.inTransaction( em -> {
41+
WikiImage image = new WikiImage( "name1" );
42+
em.persist( image );
4643

47-
page = em.find( WikiPage.class, page.getId() );
48-
page.getImages().add( image );
44+
WikiPage page = em.find( WikiPage.class, pageId );
45+
page.getImages().add( image );
4946

50-
em.getTransaction().commit();
47+
imageId = image.getId();
48+
} );
5149

5250
// Revision 3
53-
em = getEntityManager();
54-
em.getTransaction().begin();
55-
56-
image = em.find( WikiImage.class, image.getId() );
57-
image.setName( "name2" );
58-
59-
em.getTransaction().commit();
60-
61-
pageId = page.getId();
62-
imageId = image.getId();
51+
scope.inTransaction( em -> {
52+
WikiImage image = em.find( WikiImage.class, imageId );
53+
image.setName( "name2" );
54+
} );
6355
}
6456

6557
@Test
66-
public void testRevisionsCounts() {
67-
assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( WikiPage.class, pageId ) );
68-
assert Arrays.asList( 2, 3 ).equals( getAuditReader().getRevisions( WikiImage.class, imageId ) );
58+
public void testRevisionsCounts(EntityManagerFactoryScope scope) {
59+
scope.inEntityManager( em -> {
60+
final var auditReader = AuditReaderFactory.get( em );
61+
assertEquals( Arrays.asList( 1, 2 ), auditReader.getRevisions( WikiPage.class, pageId ) );
62+
assertEquals( Arrays.asList( 2, 3 ), auditReader.getRevisions( WikiImage.class, imageId ) );
63+
} );
6964
}
7065

7166
@Test
72-
public void testHistoryOfImage() {
73-
assert getAuditReader().find( WikiImage.class, imageId, 1 ) == null;
74-
assert getAuditReader().find( WikiImage.class, imageId, 2 ).equals( new WikiImage( "name1" ) );
75-
assert getAuditReader().find( WikiImage.class, imageId, 3 ).equals( new WikiImage( "name2" ) );
67+
public void testHistoryOfImage(EntityManagerFactoryScope scope) {
68+
scope.inEntityManager( em -> {
69+
final var auditReader = AuditReaderFactory.get( em );
70+
assertNull( auditReader.find( WikiImage.class, imageId, 1 ) );
71+
assertEquals( new WikiImage( "name1" ), auditReader.find( WikiImage.class, imageId, 2 ) );
72+
assertEquals( new WikiImage( "name2" ), auditReader.find( WikiImage.class, imageId, 3 ) );
73+
} );
7674
}
7775

7876
@Test
79-
public void testHistoryOfPage() {
80-
assert getAuditReader().find( WikiPage.class, pageId, 1 ).getImages().size() == 0;
81-
assert getAuditReader().find( WikiPage.class, pageId, 2 ).getImages().equals(
82-
TestTools.makeSet(
83-
new WikiImage(
84-
"name1"
85-
)
86-
)
87-
);
88-
assert getAuditReader().find( WikiPage.class, pageId, 3 ).getImages().equals(
89-
TestTools.makeSet(
90-
new WikiImage(
91-
"name2"
92-
)
93-
)
94-
);
77+
public void testHistoryOfPage(EntityManagerFactoryScope scope) {
78+
scope.inEntityManager( em -> {
79+
final var auditReader = AuditReaderFactory.get( em );
80+
assertEquals( 0, auditReader.find( WikiPage.class, pageId, 1 ).getImages().size() );
81+
assertEquals(
82+
TestTools.makeSet( new WikiImage( "name1" ) ),
83+
auditReader.find( WikiPage.class, pageId, 2 ).getImages()
84+
);
85+
assertEquals(
86+
TestTools.makeSet( new WikiImage( "name2" ) ),
87+
auditReader.find( WikiPage.class, pageId, 3 ).getImages()
88+
);
89+
} );
9590
}
9691
}

hibernate-envers/src/test/java/org/hibernate/orm/test/envers/integration/hashcode/ComponentCollectionHashcodeChangeTest.java

Lines changed: 54 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,34 @@
1111
import jakarta.persistence.ElementCollection;
1212
import jakarta.persistence.Embeddable;
1313
import jakarta.persistence.Entity;
14-
import jakarta.persistence.EntityManager;
1514
import jakarta.persistence.GeneratedValue;
1615
import jakarta.persistence.Id;
1716

17+
import org.hibernate.envers.AuditReaderFactory;
1818
import org.hibernate.envers.Audited;
19-
import org.hibernate.orm.test.envers.BaseEnversJPAFunctionalTestCase;
20-
import org.hibernate.orm.test.envers.Priority;
2119
import org.hibernate.orm.test.envers.tools.TestTools;
20+
import org.hibernate.testing.envers.junit.EnversTest;
21+
import org.hibernate.testing.orm.junit.BeforeClassTemplate;
22+
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
2223
import org.hibernate.testing.orm.junit.JiraKey;
23-
import org.junit.Test;
24+
import org.hibernate.testing.orm.junit.Jpa;
2425

25-
import static org.junit.Assert.assertEquals;
26+
import org.junit.jupiter.api.Test;
27+
28+
import static org.junit.jupiter.api.Assertions.assertEquals;
2629

2730
/**
2831
* @author Chris Cranford
2932
*/
3033
@JiraKey(value = "HHH-11063")
31-
public class ComponentCollectionHashcodeChangeTest extends BaseEnversJPAFunctionalTestCase {
34+
@EnversTest
35+
@Jpa(annotatedClasses = {ComponentCollectionHashcodeChangeTest.ComponentEntity.class, ComponentCollectionHashcodeChangeTest.Component.class})
36+
public class ComponentCollectionHashcodeChangeTest {
3237
private Integer id;
3338

34-
@Override
35-
protected Class<?>[] getAnnotatedClasses() {
36-
return new Class<?>[] { ComponentEntity.class, Component.class };
37-
}
38-
39-
@Test
40-
@Priority(10)
41-
public void initData() {
42-
EntityManager entityManager = getEntityManager();
43-
try {
39+
@BeforeClassTemplate
40+
public void initData(EntityManagerFactoryScope scope) {
41+
scope.inEntityManager( entityManager -> {
4442
// Revision 1 - Create entity with 2 components
4543
entityManager.getTransaction().begin();
4644
Component component1 = new Component();
@@ -72,53 +70,52 @@ public void initData() {
7270
entity.getComponents().add( component3 );
7371
entityManager.merge( entity );
7472
entityManager.getTransaction().commit();
75-
}
76-
catch ( Exception e ) {
77-
if ( entityManager.getTransaction().isActive() ) {
78-
entityManager.getTransaction().rollback();
79-
}
80-
}
81-
finally {
82-
entityManager.close();
83-
}
73+
} );
8474
}
8575

8676
@Test
87-
public void testRevisionCounts() {
88-
assertEquals( Arrays.asList( 1, 2, 3 ), getAuditReader().getRevisions( ComponentEntity.class, id ) );
77+
public void testRevisionCounts(EntityManagerFactoryScope scope) {
78+
scope.inEntityManager( em -> {
79+
final var auditReader = AuditReaderFactory.get( em );
80+
assertEquals( Arrays.asList( 1, 2, 3 ), auditReader.getRevisions( ComponentEntity.class, id ) );
81+
} );
8982
}
9083

9184
@Test
92-
public void testCollectionHistory() {
93-
final ComponentEntity rev1 = getAuditReader().find( ComponentEntity.class, id, 1 );
94-
assertEquals( 2, rev1.getComponents().size() );
95-
assertEquals(
96-
TestTools.makeSet(
97-
new Component( "User1", "Test1" ),
98-
new Component( "User2", "Test2" )
99-
),
100-
rev1.getComponents()
101-
);
102-
103-
final ComponentEntity rev2 = getAuditReader().find( ComponentEntity.class, id, 2 );
104-
assertEquals( 2, rev2.getComponents().size() );
105-
assertEquals(
106-
TestTools.makeSet(
107-
new Component( "User1-Inline", "Test1" ),
108-
new Component( "User2", "Test2" )
109-
),
110-
rev2.getComponents()
111-
);
112-
113-
final ComponentEntity rev3 = getAuditReader().find( ComponentEntity.class, id, 3 );
114-
assertEquals( 2, rev3.getComponents().size() );
115-
assertEquals(
116-
TestTools.makeSet(
117-
new Component( "User1-Inline", "Test1" ),
118-
new Component( "User2", "Test3" )
119-
),
120-
rev3.getComponents()
121-
);
85+
public void testCollectionHistory(EntityManagerFactoryScope scope) {
86+
scope.inEntityManager( em -> {
87+
final var auditReader = AuditReaderFactory.get( em );
88+
89+
final ComponentEntity rev1 = auditReader.find( ComponentEntity.class, id, 1 );
90+
assertEquals( 2, rev1.getComponents().size() );
91+
assertEquals(
92+
TestTools.makeSet(
93+
new Component( "User1", "Test1" ),
94+
new Component( "User2", "Test2" )
95+
),
96+
rev1.getComponents()
97+
);
98+
99+
final ComponentEntity rev2 = auditReader.find( ComponentEntity.class, id, 2 );
100+
assertEquals( 2, rev2.getComponents().size() );
101+
assertEquals(
102+
TestTools.makeSet(
103+
new Component( "User1-Inline", "Test1" ),
104+
new Component( "User2", "Test2" )
105+
),
106+
rev2.getComponents()
107+
);
108+
109+
final ComponentEntity rev3 = auditReader.find( ComponentEntity.class, id, 3 );
110+
assertEquals( 2, rev3.getComponents().size() );
111+
assertEquals(
112+
TestTools.makeSet(
113+
new Component( "User1-Inline", "Test1" ),
114+
new Component( "User2", "Test3" )
115+
),
116+
rev3.getComponents()
117+
);
118+
} );
122119
}
123120

124121
@Entity(name = "ComponentEntity")

0 commit comments

Comments
 (0)