Skip to content

Commit 3315ec0

Browse files
committed
HHH-19871 --wip-- Envers migration to JUnit 6
- ... last `integration.*` packages
1 parent dddeaf4 commit 3315ec0

File tree

115 files changed

+7670
-7618
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+7670
-7618
lines changed

hibernate-envers/src/test/java/org/hibernate/orm/test/envers/entities/IntTestPrivSeqEntity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ public boolean equals(Object o) {
6868

6969
IntTestPrivSeqEntity that = (IntTestPrivSeqEntity) o;
7070

71-
if ( id != null ? !id.equals( that.id ) : that.id != null ) {
71+
if ( id != null ? !id.equals( that.getId() ) : that.getId() != null ) {
7272
return false;
7373
}
74-
if ( number != null ? !number.equals( that.number ) : that.number != null ) {
74+
if ( number != null ? !number.equals( that.getNumber() ) : that.getNumber() != null ) {
7575
return false;
7676
}
7777

hibernate-envers/src/test/java/org/hibernate/orm/test/envers/entities/StrIntTestEntity.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@ public boolean equals(Object o) {
7575

7676
StrIntTestEntity that = (StrIntTestEntity) o;
7777

78-
if ( id != null ? !id.equals( that.id ) : that.id != null ) {
78+
if ( id != null ? !id.equals( that.getId() ) : that.getId() != null ) {
7979
return false;
8080
}
81-
if ( number != null ? !number.equals( that.number ) : that.number != null ) {
81+
if ( number != null ? !number.equals( that.getNumber() ) : that.getNumber() != null ) {
8282
return false;
8383
}
84-
if ( str1 != null ? !str1.equals( that.str1 ) : that.str1 != null ) {
84+
if ( str1 != null ? !str1.equals( that.getStr1() ) : that.getStr1() != null ) {
8585
return false;
8686
}
8787

hibernate-envers/src/test/java/org/hibernate/orm/test/envers/entities/StrTestPrivSeqEntity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ public boolean equals(Object o) {
6868

6969
StrTestPrivSeqEntity that = (StrTestPrivSeqEntity) o;
7070

71-
if ( id != null ? !id.equals( that.id ) : that.id != null ) {
71+
if ( id != null ? !id.equals( that.getId() ) : that.getId() != null ) {
7272
return false;
7373
}
74-
if ( str != null ? !str.equals( that.str ) : that.str != null ) {
74+
if ( str != null ? !str.equals( that.getStr() ) : that.getStr() != null ) {
7575
return false;
7676
}
7777

hibernate-envers/src/test/java/org/hibernate/orm/test/envers/entities/onetomany/CollectionRefEdEntity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ public boolean equals(Object o) {
7777

7878
CollectionRefEdEntity that = (CollectionRefEdEntity) o;
7979

80-
if ( data != null ? !data.equals( that.data ) : that.data != null ) {
80+
if ( data != null ? !data.equals( that.getData() ) : that.getData() != null ) {
8181
return false;
8282
}
83-
if ( id != null ? !id.equals( that.id ) : that.id != null ) {
83+
if ( id != null ? !id.equals( that.getId() ) : that.getId() != null ) {
8484
return false;
8585
}
8686

hibernate-envers/src/test/java/org/hibernate/orm/test/envers/entities/onetomany/ListRefEdEntity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ public boolean equals(Object o) {
7474

7575
ListRefEdEntity that = (ListRefEdEntity) o;
7676

77-
if ( data != null ? !data.equals( that.data ) : that.data != null ) {
77+
if ( data != null ? !data.equals( that.getData() ) : that.getData() != null ) {
7878
return false;
7979
}
80-
if ( id != null ? !id.equals( that.id ) : that.id != null ) {
80+
if ( id != null ? !id.equals( that.getId() ) : that.getId() != null ) {
8181
return false;
8282
}
8383

hibernate-envers/src/test/java/org/hibernate/orm/test/envers/entities/onetomany/SetRefEdEntity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ public boolean equals(Object o) {
9191

9292
SetRefEdEntity that = (SetRefEdEntity) o;
9393

94-
if ( data != null ? !data.equals( that.data ) : that.data != null ) {
94+
if ( data != null ? !data.equals( that.getData() ) : that.getData() != null ) {
9595
return false;
9696
}
97-
if ( id != null ? !id.equals( that.id ) : that.id != null ) {
97+
if ( id != null ? !id.equals( that.getId() ) : that.getId() != null ) {
9898
return false;
9999
}
100100

hibernate-envers/src/test/java/org/hibernate/orm/test/envers/entities/onetomany/SetRefIngEntity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ public boolean equals(Object o) {
8181

8282
SetRefIngEntity that = (SetRefIngEntity) o;
8383

84-
if ( data != null ? !data.equals( that.data ) : that.data != null ) {
84+
if ( data != null ? !data.equals( that.getData() ) : that.getData() != null ) {
8585
return false;
8686
}
87-
if ( id != null ? !id.equals( that.id ) : that.id != null ) {
87+
if ( id != null ? !id.equals( that.getId() ) : that.getId() != null ) {
8888
return false;
8989
}
9090

hibernate-envers/src/test/java/org/hibernate/orm/test/envers/entities/onetomany/ids/SetRefEdEmbIdEntity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ public boolean equals(Object o) {
7575

7676
SetRefEdEmbIdEntity that = (SetRefEdEmbIdEntity) o;
7777

78-
if ( data != null ? !data.equals( that.data ) : that.data != null ) {
78+
if ( data != null ? !data.equals( that.getData() ) : that.getData() != null ) {
7979
return false;
8080
}
81-
if ( id != null ? !id.equals( that.id ) : that.id != null ) {
81+
if ( id != null ? !id.equals( that.getId() ) : that.getId() != null ) {
8282
return false;
8383
}
8484

hibernate-envers/src/test/java/org/hibernate/orm/test/envers/entities/onetomany/ids/SetRefEdMulIdEntity.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,13 @@ public boolean equals(Object o) {
9595

9696
SetRefEdMulIdEntity that = (SetRefEdMulIdEntity) o;
9797

98-
if ( data != null ? !data.equals( that.data ) : that.data != null ) {
98+
if ( data != null ? !data.equals( that.getData() ) : that.getData() != null ) {
9999
return false;
100100
}
101-
if ( id1 != null ? !id1.equals( that.id1 ) : that.id1 != null ) {
101+
if ( id1 != null ? !id1.equals( that.getId1() ) : that.getId1() != null ) {
102102
return false;
103103
}
104-
if ( id2 != null ? !id2.equals( that.id2 ) : that.id2 != null ) {
104+
if ( id2 != null ? !id2.equals( that.getId2() ) : that.getId2() != null ) {
105105
return false;
106106
}
107107

hibernate-envers/src/test/java/org/hibernate/orm/test/envers/integration/onetomany/BasicCollection.java

Lines changed: 107 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -8,88 +8,81 @@
88
import java.util.Collections;
99
import java.util.HashSet;
1010
import java.util.Set;
11-
import jakarta.persistence.EntityManager;
1211

13-
import org.hibernate.orm.test.envers.BaseEnversJPAFunctionalTestCase;
14-
import org.hibernate.orm.test.envers.Priority;
12+
import org.hibernate.envers.AuditReaderFactory;
1513
import org.hibernate.orm.test.envers.entities.onetomany.CollectionRefEdEntity;
1614
import org.hibernate.orm.test.envers.entities.onetomany.CollectionRefIngEntity;
15+
import org.hibernate.testing.envers.junit.EnversTest;
16+
import org.hibernate.testing.orm.junit.BeforeClassTemplate;
17+
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
18+
import org.hibernate.testing.orm.junit.Jpa;
19+
import org.junit.jupiter.api.Test;
1720

18-
import org.junit.Test;
21+
import static org.junit.jupiter.api.Assertions.assertEquals;
22+
import static org.junit.jupiter.api.Assertions.assertTrue;
1923

2024
/**
2125
* @author Adam Warski (adam at warski dot org)
2226
*/
23-
public class BasicCollection extends BaseEnversJPAFunctionalTestCase {
27+
@EnversTest
28+
@Jpa(annotatedClasses = {CollectionRefEdEntity.class, CollectionRefIngEntity.class})
29+
public class BasicCollection {
2430
private Integer ed1_id;
2531
private Integer ed2_id;
2632

2733
private Integer ing1_id;
2834
private Integer ing2_id;
2935

30-
@Override
31-
protected Class<?>[] getAnnotatedClasses() {
32-
return new Class[] {CollectionRefEdEntity.class, CollectionRefIngEntity.class};
33-
}
34-
35-
@Test
36-
@Priority(10)
37-
public void initData() {
38-
EntityManager em = getEntityManager();
39-
40-
CollectionRefEdEntity ed1 = new CollectionRefEdEntity( 1, "data_ed_1" );
41-
CollectionRefEdEntity ed2 = new CollectionRefEdEntity( 2, "data_ed_2" );
42-
43-
CollectionRefIngEntity ing1 = new CollectionRefIngEntity( 3, "data_ing_1", ed1 );
44-
CollectionRefIngEntity ing2 = new CollectionRefIngEntity( 4, "data_ing_2", ed1 );
45-
46-
// Revision 1
47-
em.getTransaction().begin();
48-
49-
em.persist( ed1 );
50-
em.persist( ed2 );
51-
52-
em.persist( ing1 );
53-
em.persist( ing2 );
54-
55-
em.getTransaction().commit();
36+
@BeforeClassTemplate
37+
public void initData(EntityManagerFactoryScope scope) {
38+
scope.inTransaction( em -> {
39+
// Revision 1
40+
CollectionRefEdEntity ed1 = new CollectionRefEdEntity( 1, "data_ed_1" );
41+
CollectionRefEdEntity ed2 = new CollectionRefEdEntity( 2, "data_ed_2" );
5642

57-
// Revision 2
58-
em.getTransaction().begin();
43+
CollectionRefIngEntity ing1 = new CollectionRefIngEntity( 3, "data_ing_1", ed1 );
44+
CollectionRefIngEntity ing2 = new CollectionRefIngEntity( 4, "data_ing_2", ed1 );
5945

60-
ing1 = em.find( CollectionRefIngEntity.class, ing1.getId() );
61-
ed2 = em.find( CollectionRefEdEntity.class, ed2.getId() );
46+
em.persist( ed1 );
47+
em.persist( ed2 );
6248

63-
ing1.setReference( ed2 );
49+
em.persist( ing1 );
50+
em.persist( ing2 );
6451

65-
em.getTransaction().commit();
52+
ed1_id = ed1.getId();
53+
ed2_id = ed2.getId();
6654

67-
// Revision 3
68-
em.getTransaction().begin();
55+
ing1_id = ing1.getId();
56+
ing2_id = ing2.getId();
57+
} );
6958

70-
ing2 = em.find( CollectionRefIngEntity.class, ing2.getId() );
71-
ed2 = em.find( CollectionRefEdEntity.class, ed2.getId() );
59+
scope.inTransaction( em -> {
60+
// Revision 2
61+
CollectionRefIngEntity ing1 = em.find( CollectionRefIngEntity.class, ing1_id );
62+
CollectionRefEdEntity ed2 = em.find( CollectionRefEdEntity.class, ed2_id );
7263

73-
ing2.setReference( ed2 );
64+
ing1.setReference( ed2 );
65+
} );
7466

75-
em.getTransaction().commit();
67+
scope.inTransaction( em -> {
68+
// Revision 3
69+
CollectionRefIngEntity ing2 = em.find( CollectionRefIngEntity.class, ing2_id );
70+
CollectionRefEdEntity ed2 = em.find( CollectionRefEdEntity.class, ed2_id );
7671

77-
//
78-
79-
ed1_id = ed1.getId();
80-
ed2_id = ed2.getId();
81-
82-
ing1_id = ing1.getId();
83-
ing2_id = ing2.getId();
72+
ing2.setReference( ed2 );
73+
} );
8474
}
8575

8676
@Test
87-
public void testRevisionsCounts() {
88-
assert Arrays.asList( 1, 2, 3 ).equals( getAuditReader().getRevisions( CollectionRefEdEntity.class, ed1_id ) );
89-
assert Arrays.asList( 1, 2, 3 ).equals( getAuditReader().getRevisions( CollectionRefEdEntity.class, ed2_id ) );
90-
91-
assert Arrays.asList( 1, 2 ).equals( getAuditReader().getRevisions( CollectionRefIngEntity.class, ing1_id ) );
92-
assert Arrays.asList( 1, 3 ).equals( getAuditReader().getRevisions( CollectionRefIngEntity.class, ing2_id ) );
77+
public void testRevisionsCounts(EntityManagerFactoryScope scope) {
78+
scope.inEntityManager( em -> {
79+
final var auditReader = AuditReaderFactory.get( em );
80+
assertEquals( Arrays.asList( 1, 2, 3 ), auditReader.getRevisions( CollectionRefEdEntity.class, ed1_id ) );
81+
assertEquals( Arrays.asList( 1, 2, 3 ), auditReader.getRevisions( CollectionRefEdEntity.class, ed2_id ) );
82+
83+
assertEquals( Arrays.asList( 1, 2 ), auditReader.getRevisions( CollectionRefIngEntity.class, ing1_id ) );
84+
assertEquals( Arrays.asList( 1, 3 ), auditReader.getRevisions( CollectionRefIngEntity.class, ing2_id ) );
85+
} );
9386
}
9487

9588
private <T> Set<T> makeSet(T... objects) {
@@ -102,69 +95,80 @@ private <T> Set<T> makeSet(T... objects) {
10295
}
10396

10497
@Test
105-
public void testHistoryOfEdId1() {
106-
CollectionRefIngEntity ing1 = getEntityManager().find( CollectionRefIngEntity.class, ing1_id );
107-
CollectionRefIngEntity ing2 = getEntityManager().find( CollectionRefIngEntity.class, ing2_id );
98+
public void testHistoryOfEdId1(EntityManagerFactoryScope scope) {
99+
scope.inEntityManager( em -> {
100+
final var auditReader = AuditReaderFactory.get( em );
101+
CollectionRefIngEntity ing1 = em.find( CollectionRefIngEntity.class, ing1_id );
102+
CollectionRefIngEntity ing2 = em.find( CollectionRefIngEntity.class, ing2_id );
108103

109-
CollectionRefEdEntity rev1 = getAuditReader().find( CollectionRefEdEntity.class, ed1_id, 1 );
110-
CollectionRefEdEntity rev2 = getAuditReader().find( CollectionRefEdEntity.class, ed1_id, 2 );
111-
CollectionRefEdEntity rev3 = getAuditReader().find( CollectionRefEdEntity.class, ed1_id, 3 );
104+
CollectionRefEdEntity rev1 = auditReader.find( CollectionRefEdEntity.class, ed1_id, 1 );
105+
CollectionRefEdEntity rev2 = auditReader.find( CollectionRefEdEntity.class, ed1_id, 2 );
106+
CollectionRefEdEntity rev3 = auditReader.find( CollectionRefEdEntity.class, ed1_id, 3 );
112107

113-
assert rev1.getReffering().containsAll( makeSet( ing1, ing2 ) );
114-
assert rev1.getReffering().size() == 2;
108+
assertTrue( rev1.getReffering().containsAll( makeSet( ing1, ing2 ) ) );
109+
assertEquals( 2, rev1.getReffering().size() );
115110

116-
assert rev2.getReffering().containsAll( makeSet( ing2 ) );
117-
assert rev2.getReffering().size() == 1;
111+
assertTrue( rev2.getReffering().containsAll( makeSet( ing2 ) ) );
112+
assertEquals( 1, rev2.getReffering().size() );
118113

119-
assert rev3.getReffering().containsAll( Collections.EMPTY_SET );
120-
assert rev3.getReffering().size() == 0;
114+
assertTrue( rev3.getReffering().containsAll( Collections.EMPTY_SET ) );
115+
assertEquals( 0, rev3.getReffering().size() );
116+
} );
121117
}
122118

123119
@Test
124-
public void testHistoryOfEdId2() {
125-
CollectionRefIngEntity ing1 = getEntityManager().find( CollectionRefIngEntity.class, ing1_id );
126-
CollectionRefIngEntity ing2 = getEntityManager().find( CollectionRefIngEntity.class, ing2_id );
127-
128-
CollectionRefEdEntity rev1 = getAuditReader().find( CollectionRefEdEntity.class, ed2_id, 1 );
129-
CollectionRefEdEntity rev2 = getAuditReader().find( CollectionRefEdEntity.class, ed2_id, 2 );
130-
CollectionRefEdEntity rev3 = getAuditReader().find( CollectionRefEdEntity.class, ed2_id, 3 );
120+
public void testHistoryOfEdId2(EntityManagerFactoryScope scope) {
121+
scope.inEntityManager( em -> {
122+
final var auditReader = AuditReaderFactory.get( em );
123+
CollectionRefIngEntity ing1 = em.find( CollectionRefIngEntity.class, ing1_id );
124+
CollectionRefIngEntity ing2 = em.find( CollectionRefIngEntity.class, ing2_id );
131125

132-
assert rev1.getReffering().containsAll( Collections.EMPTY_SET );
133-
assert rev1.getReffering().size() == 0;
126+
CollectionRefEdEntity rev1 = auditReader.find( CollectionRefEdEntity.class, ed2_id, 1 );
127+
CollectionRefEdEntity rev2 = auditReader.find( CollectionRefEdEntity.class, ed2_id, 2 );
128+
CollectionRefEdEntity rev3 = auditReader.find( CollectionRefEdEntity.class, ed2_id, 3 );
134129

135-
assert rev2.getReffering().containsAll( makeSet( ing1 ) );
136-
assert rev2.getReffering().size() == 1;
130+
assertTrue( rev1.getReffering().containsAll( Collections.EMPTY_SET ) );
131+
assertEquals( 0, rev1.getReffering().size() );
137132

138-
assert rev3.getReffering().containsAll( makeSet( ing1, ing2 ) );
139-
assert rev3.getReffering().size() == 2;
133+
assertTrue( rev2.getReffering().containsAll( makeSet( ing1 ) ) );
134+
assertEquals( 1, rev2.getReffering().size() );
140135

136+
assertTrue( rev3.getReffering().containsAll( makeSet( ing1, ing2 ) ) );
137+
assertEquals( 2, rev3.getReffering().size() );
138+
} );
141139
}
142140

143141
@Test
144-
public void testHistoryOfEdIng1() {
145-
CollectionRefEdEntity ed1 = getEntityManager().find( CollectionRefEdEntity.class, ed1_id );
146-
CollectionRefEdEntity ed2 = getEntityManager().find( CollectionRefEdEntity.class, ed2_id );
147-
148-
CollectionRefIngEntity rev1 = getAuditReader().find( CollectionRefIngEntity.class, ing1_id, 1 );
149-
CollectionRefIngEntity rev2 = getAuditReader().find( CollectionRefIngEntity.class, ing1_id, 2 );
150-
CollectionRefIngEntity rev3 = getAuditReader().find( CollectionRefIngEntity.class, ing1_id, 3 );
151-
152-
assert rev1.getReference().equals( ed1 );
153-
assert rev2.getReference().equals( ed2 );
154-
assert rev3.getReference().equals( ed2 );
142+
public void testHistoryOfEdIng1(EntityManagerFactoryScope scope) {
143+
scope.inEntityManager( em -> {
144+
final var auditReader = AuditReaderFactory.get( em );
145+
CollectionRefEdEntity ed1 = em.find( CollectionRefEdEntity.class, ed1_id );
146+
CollectionRefEdEntity ed2 = em.find( CollectionRefEdEntity.class, ed2_id );
147+
148+
CollectionRefIngEntity rev1 = auditReader.find( CollectionRefIngEntity.class, ing1_id, 1 );
149+
CollectionRefIngEntity rev2 = auditReader.find( CollectionRefIngEntity.class, ing1_id, 2 );
150+
CollectionRefIngEntity rev3 = auditReader.find( CollectionRefIngEntity.class, ing1_id, 3 );
151+
152+
assertEquals( ed1, rev1.getReference() );
153+
assertEquals( ed2, rev2.getReference() );
154+
assertEquals( ed2, rev3.getReference() );
155+
} );
155156
}
156157

157158
@Test
158-
public void testHistoryOfEdIng2() {
159-
CollectionRefEdEntity ed1 = getEntityManager().find( CollectionRefEdEntity.class, ed1_id );
160-
CollectionRefEdEntity ed2 = getEntityManager().find( CollectionRefEdEntity.class, ed2_id );
161-
162-
CollectionRefIngEntity rev1 = getAuditReader().find( CollectionRefIngEntity.class, ing2_id, 1 );
163-
CollectionRefIngEntity rev2 = getAuditReader().find( CollectionRefIngEntity.class, ing2_id, 2 );
164-
CollectionRefIngEntity rev3 = getAuditReader().find( CollectionRefIngEntity.class, ing2_id, 3 );
165-
166-
assert rev1.getReference().equals( ed1 );
167-
assert rev2.getReference().equals( ed1 );
168-
assert rev3.getReference().equals( ed2 );
159+
public void testHistoryOfEdIng2(EntityManagerFactoryScope scope) {
160+
scope.inEntityManager( em -> {
161+
final var auditReader = AuditReaderFactory.get( em );
162+
CollectionRefEdEntity ed1 = em.find( CollectionRefEdEntity.class, ed1_id );
163+
CollectionRefEdEntity ed2 = em.find( CollectionRefEdEntity.class, ed2_id );
164+
165+
CollectionRefIngEntity rev1 = auditReader.find( CollectionRefIngEntity.class, ing2_id, 1 );
166+
CollectionRefIngEntity rev2 = auditReader.find( CollectionRefIngEntity.class, ing2_id, 2 );
167+
CollectionRefIngEntity rev3 = auditReader.find( CollectionRefIngEntity.class, ing2_id, 3 );
168+
169+
assertEquals( ed1, rev1.getReference() );
170+
assertEquals( ed1, rev2.getReference() );
171+
assertEquals( ed2, rev3.getReference() );
172+
} );
169173
}
170174
}

0 commit comments

Comments
 (0)