Skip to content

Commit 004d6ac

Browse files
committed
[#487] Clean tables after every test
In preparation of having a single factory per test class
1 parent 06873a7 commit 004d6ac

37 files changed

+250
-18
lines changed

hibernate-reactive-core/src/test/java/org/hibernate/reactive/BatchFetchTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import org.hibernate.LockMode;
1111
import org.hibernate.annotations.BatchSize;
1212
import org.hibernate.cfg.Configuration;
13+
14+
import org.junit.After;
1315
import org.junit.Test;
1416

1517
import javax.persistence.CascadeType;
@@ -45,6 +47,13 @@ protected Configuration constructConfiguration() {
4547
return configuration;
4648
}
4749

50+
@After
51+
public void cleanDb(TestContext context) {
52+
test( context, getSessionFactory()
53+
.withTransaction( (s, t) -> s.createQuery( "delete from Element" ).executeUpdate()
54+
.thenCompose( v -> s.createQuery( "delete from Node" ).executeUpdate() ) ) );
55+
}
56+
4857
@Test
4958
public void testQuery(TestContext context) {
5059

hibernate-reactive-core/src/test/java/org/hibernate/reactive/BatchQueryOnConnectionTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.hibernate.cfg.Configuration;
1616
import org.hibernate.reactive.pool.ReactiveConnection;
1717

18+
import org.junit.After;
1819
import org.junit.Test;
1920

2021
import io.vertx.ext.unit.TestContext;
@@ -24,6 +25,11 @@
2425
public class BatchQueryOnConnectionTest extends BaseReactiveTest {
2526
private static final int BATCH_SIZE = 20;
2627

28+
@After
29+
public void cleanDb(TestContext context) {
30+
test( context, deleteEntities( "DataPoint" ) );
31+
}
32+
2733
@Test
2834
public void testBatchInsertSizeEqMultiple(TestContext context) {
2935
final List<List<Object[]>> paramsBatches = doBatchInserts( context, 50, BATCH_SIZE );

hibernate-reactive-core/src/test/java/org/hibernate/reactive/EagerElementCollectionForBasicTypeListTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.hibernate.reactive.mutiny.Mutiny;
2121
import org.hibernate.reactive.stage.Stage;
2222

23+
import org.junit.After;
2324
import org.junit.Before;
2425
import org.junit.Test;
2526

@@ -61,6 +62,11 @@ public void populateDb(TestContext context) {
6162
test( context, session.persist( thePerson ).call( session::flush ) );
6263
}
6364

65+
@After
66+
public void cleanDb(TestContext context) {
67+
test( context, deleteEntities( "Person" ) );
68+
}
69+
6470
@Test
6571
public void persistWithMutinyAPI(TestContext context) {
6672
Mutiny.Session session = openMutinySession();

hibernate-reactive-core/src/test/java/org/hibernate/reactive/EagerElementCollectionForBasicTypeMapTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.hibernate.reactive.mutiny.Mutiny;
2121
import org.hibernate.reactive.stage.Stage;
2222

23+
import org.junit.After;
2324
import org.junit.Before;
2425
import org.junit.Test;
2526

@@ -59,6 +60,11 @@ public void populateDb(TestContext context) {
5960
test( context, session.persist( thePerson ).call( session::flush ) );
6061
}
6162

63+
@After
64+
public void cleanDb(TestContext context) {
65+
test( context, deleteEntities( "Person" ) );
66+
}
67+
6268
@Test
6369
public void persistWithMutinyAPI(TestContext context) {
6470
Mutiny.Session session = openMutinySession();

hibernate-reactive-core/src/test/java/org/hibernate/reactive/EagerElementCollectionForBasicTypeSetTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.hibernate.reactive.mutiny.Mutiny;
2424
import org.hibernate.reactive.stage.Stage;
2525

26+
import org.junit.After;
2627
import org.junit.Before;
2728
import org.junit.Test;
2829

@@ -64,6 +65,11 @@ public void populateDb(TestContext context) {
6465
test( context, session.persist( thePerson ).call( session::flush ) );
6566
}
6667

68+
@After
69+
public void cleanDb(TestContext context) {
70+
test( context, deleteEntities( "Person" ) );
71+
}
72+
6773
@Test
6874
public void persistWithMutinyAPI(TestContext context) {
6975
Mutiny.Session session = openMutinySession();

hibernate-reactive-core/src/test/java/org/hibernate/reactive/EagerElementCollectionForEmbeddableEntityTypeMapTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.hibernate.reactive.mutiny.Mutiny;
2222
import org.hibernate.reactive.stage.Stage;
2323

24+
import org.junit.After;
2425
import org.junit.Before;
2526
import org.junit.Test;
2627

@@ -47,6 +48,11 @@ public void populateDb(TestContext context) {
4748
test( context, session.persist( thePerson ).call( session::flush ) );
4849
}
4950

51+
@After
52+
public void cleanDb(TestContext context) {
53+
test( context, deleteEntities( "Person" ) );
54+
}
55+
5056
@Test
5157
public void persistWithMutinyAPI(TestContext context) {
5258
Mutiny.Session session = openMutinySession();

hibernate-reactive-core/src/test/java/org/hibernate/reactive/EagerElementCollectionForEmbeddableTypeListTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.hibernate.reactive.mutiny.Mutiny;
2121
import org.hibernate.reactive.stage.Stage;
2222

23+
import org.junit.After;
2324
import org.junit.Before;
2425
import org.junit.Test;
2526

@@ -71,6 +72,11 @@ public void populateDb(TestContext context) {
7172
);
7273
}
7374

75+
@After
76+
public void cleanDb(TestContext context) {
77+
test( context, deleteEntities( "Person" ) );
78+
}
79+
7480
@Test
7581
public void persistWithMutinyAPI(TestContext context) {
7682
Mutiny.Session session = openMutinySession();

hibernate-reactive-core/src/test/java/org/hibernate/reactive/EagerElementCollectionForEmbeddedEmbeddableMapTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.hibernate.reactive.mutiny.Mutiny;
2222
import org.hibernate.reactive.stage.Stage;
2323

24+
import org.junit.After;
2425
import org.junit.Before;
2526
import org.junit.Test;
2627

@@ -48,6 +49,11 @@ public void populateDb(TestContext context) {
4849
test( context, session.persist( thePerson ).call( session::flush ) );
4950
}
5051

52+
@After
53+
public void cleanDb(TestContext context) {
54+
test( context, deleteEntities( "Person" ) );
55+
}
56+
5157
@Test
5258
public void persistWithMutinyAPI(TestContext context) {
5359
Mutiny.Session session = openMutinySession();

hibernate-reactive-core/src/test/java/org/hibernate/reactive/EagerElementCollectionForEmbeddedEmbeddableTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.hibernate.reactive.mutiny.Mutiny;
2222
import org.hibernate.reactive.stage.Stage;
2323

24+
import org.junit.After;
2425
import org.junit.Before;
2526
import org.junit.Test;
2627

@@ -71,6 +72,11 @@ public void populateDb(TestContext context) {
7172
);
7273
}
7374

75+
@After
76+
public void cleanDb(TestContext context) {
77+
test( context, deleteEntities( "Person" ) );
78+
}
79+
7480
@Test
7581
public void persistWithMutinyAPI(TestContext context) {
7682
Mutiny.Session session = openMutinySession();

hibernate-reactive-core/src/test/java/org/hibernate/reactive/EagerManyToOneAssociationTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
import io.vertx.ext.unit.TestContext;
99
import org.hibernate.cfg.Configuration;
10+
11+
import org.junit.After;
1012
import org.junit.Test;
1113

1214
import javax.persistence.*;
@@ -25,6 +27,11 @@ protected Configuration constructConfiguration() {
2527
return configuration;
2628
}
2729

30+
@After
31+
public void cleanDb(TestContext context) {
32+
test( context, deleteEntities( Book.class, Author.class ) );
33+
}
34+
2835
@Test
2936
public void persistOneBook(TestContext context) {
3037
final Book book = new Book( 6, "The Boy, The Mole, The Fox and The Horse" );

hibernate-reactive-core/src/test/java/org/hibernate/reactive/EagerOneToManyAssociationTest.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66
package org.hibernate.reactive;
77

8-
import io.vertx.ext.unit.TestContext;
98
import org.hibernate.cfg.Configuration;
109
import org.junit.Test;
1110

@@ -14,6 +13,10 @@
1413
import java.util.List;
1514
import java.util.Objects;
1615

16+
import org.junit.After;
17+
18+
import io.vertx.ext.unit.TestContext;
19+
1720
import static org.hibernate.reactive.util.impl.CompletionStages.completedFuture;
1821
import static org.hibernate.reactive.util.impl.CompletionStages.voidFuture;
1922

@@ -25,6 +28,11 @@ protected Configuration constructConfiguration() {
2528
configuration.addAnnotatedClass( Author.class );
2629
return configuration;
2730
}
31+
32+
@After
33+
public void cleanDb(TestContext context) {
34+
test( context, deleteEntities( Author.class, Book.class ) );
35+
}
2836
//
2937
// private CompletionStage<Integer> populateDB(Book... books) {
3038
// StringBuilder authorQueryBuilder = new StringBuilder();

hibernate-reactive-core/src/test/java/org/hibernate/reactive/EagerOneToOneAssociationTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
import io.vertx.ext.unit.TestContext;
99
import org.hibernate.cfg.Configuration;
10+
11+
import org.junit.After;
1012
import org.junit.Test;
1113

1214
import javax.persistence.*;
@@ -24,6 +26,11 @@ protected Configuration constructConfiguration() {
2426
return configuration;
2527
}
2628

29+
@After
30+
public void cleanDb(TestContext context) {
31+
test( context, deleteEntities( Book.class, Author.class ) );
32+
}
33+
2734
@Test
2835
public void testPersist(TestContext context) {
2936
final Book mostPopularBook = new Book( 5, "The Boy, The Mole, The Fox and The Horse" );

hibernate-reactive-core/src/test/java/org/hibernate/reactive/EagerOrderedElementCollectionForEmbeddableTypeListTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import org.hibernate.cfg.Configuration;
1111
import org.hibernate.reactive.mutiny.Mutiny;
1212
import org.hibernate.reactive.stage.Stage;
13+
14+
import org.junit.After;
1315
import org.junit.Before;
1416
import org.junit.Test;
1517

@@ -70,6 +72,11 @@ public void populateDb(TestContext context) {
7072
);
7173
}
7274

75+
@After
76+
public void cleanDb(TestContext context) {
77+
test( context, deleteEntities( "Person" ) );
78+
}
79+
7380
@Test
7481
public void persistWithMutinyAPI(TestContext context) {
7582
Mutiny.Session session = openMutinySession();

hibernate-reactive-core/src/test/java/org/hibernate/reactive/EagerTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import org.hibernate.annotations.Fetch;
1111
import org.hibernate.annotations.FetchMode;
1212
import org.hibernate.cfg.Configuration;
13+
14+
import org.junit.After;
1315
import org.junit.Test;
1416

1517
import javax.persistence.CascadeType;
@@ -46,6 +48,13 @@ protected Configuration constructConfiguration() {
4648
return configuration;
4749
}
4850

51+
@After
52+
public void cleanDb(TestContext context) {
53+
test( context, getSessionFactory()
54+
.withTransaction( (s, t) -> s.createQuery( "delete from Element" ).executeUpdate()
55+
.thenCompose( v -> s.createQuery( "delete from Node" ).executeUpdate() ) ) );
56+
}
57+
4958
@Test
5059
public void testEagerCollectionFetch(TestContext context) {
5160

hibernate-reactive-core/src/test/java/org/hibernate/reactive/EmptyCompositeCollectionKeyTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.hibernate.reactive.stage.Stage;
2323
import org.hibernate.reactive.testing.DatabaseSelectionRule;
2424

25+
import org.junit.After;
2526
import org.junit.Rule;
2627
import org.junit.Test;
2728

@@ -40,6 +41,11 @@ protected Configuration constructConfiguration() {
4041
return configuration;
4142
}
4243

44+
@After
45+
public void cleanDb(TestContext context) {
46+
test( context, deleteEntities( "Family" ) );
47+
}
48+
4349
@Test
4450
public void testGetEntityWithEmptyChildrenCollection(TestContext context) {
4551
/* CASE 1: Family has Parent + child with null names + NULL relatives */

hibernate-reactive-core/src/test/java/org/hibernate/reactive/FetchModeSubselectEagerTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import org.hibernate.annotations.Fetch;
1111
import org.hibernate.annotations.FetchMode;
1212
import org.hibernate.cfg.Configuration;
13+
14+
import org.junit.After;
1315
import org.junit.Test;
1416

1517
import javax.persistence.*;
@@ -30,6 +32,13 @@ protected Configuration constructConfiguration() {
3032
return configuration;
3133
}
3234

35+
@After
36+
public void cleanDb(TestContext context) {
37+
test( context, getSessionFactory()
38+
.withTransaction( (s, t) -> s.createQuery( "delete from Element" ).executeUpdate()
39+
.thenCompose( v -> s.createQuery( "delete from Node" ).executeUpdate() ) ) );
40+
}
41+
3342
@Test
3443
public void testEagerCollectionFetch(TestContext context) {
3544

hibernate-reactive-core/src/test/java/org/hibernate/reactive/FilterTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import io.vertx.ext.unit.TestContext;
99
import org.hibernate.annotations.Filter;
1010
import org.hibernate.cfg.Configuration;
11+
12+
import org.junit.After;
1113
import org.junit.Test;
1214

1315
import javax.persistence.*;
@@ -30,6 +32,14 @@ protected Configuration constructConfiguration() {
3032
return configuration;
3133
}
3234

35+
@After
36+
public void cleanDb(TestContext context) {
37+
test( context, deleteEntities( "Element" )
38+
.thenCompose( v -> getSessionFactory()
39+
.withTransaction( (s, t) -> s
40+
.createQuery( "delete from Node" ).executeUpdate() ) ) );
41+
}
42+
3343
@Test
3444
public void testFilter(TestContext context) {
3545

hibernate-reactive-core/src/test/java/org/hibernate/reactive/GeneratedPropertyJoinedTableTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.hibernate.cfg.Configuration;
2424
import org.hibernate.reactive.testing.DatabaseSelectionRule;
2525

26+
import org.junit.After;
2627
import org.junit.Rule;
2728
import org.junit.Test;
2829

@@ -50,6 +51,11 @@ protected Configuration constructConfiguration() {
5051
return configuration;
5152
}
5253

54+
@After
55+
public void cleanDb(TestContext context) {
56+
test( context, deleteEntities( "GeneratedWithIdentity", "GeneratedRegular" ) );
57+
}
58+
5359
@Test
5460
public void testWithIdentity(TestContext context) {
5561
final GeneratedWithIdentity davide = new GeneratedWithIdentity( "Davide", "D'Alto" );

0 commit comments

Comments
 (0)