Skip to content

Commit 62cd92e

Browse files
committed
[#2012] Refactoring and clean up JsonTypeTest
1 parent 973f80f commit 62cd92e

File tree

1 file changed

+10
-23
lines changed

1 file changed

+10
-23
lines changed

hibernate-reactive-core/src/test/java/org/hibernate/reactive/types/JsonTypeTest.java

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import java.util.Collection;
99
import java.util.List;
1010
import java.util.Objects;
11-
import java.util.concurrent.CompletionStage;
1211
import java.util.function.Consumer;
1312

1413
import org.hibernate.reactive.BaseReactiveTest;
@@ -26,19 +25,17 @@
2625
import jakarta.persistence.Version;
2726

2827
import static java.util.concurrent.TimeUnit.MINUTES;
28+
import static org.assertj.core.api.Assertions.assertThat;
2929
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.DB2;
3030
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.MARIA;
3131
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.ORACLE;
3232
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.SQLSERVER;
33-
import static org.hibernate.reactive.util.impl.CompletionStages.loop;
3433
import static org.junit.jupiter.api.Assertions.assertEquals;
35-
import static org.junit.jupiter.api.Assertions.assertNotNull;
3634

3735
/**
3836
* Test types that we expect to work only on selected DBs.
3937
*/
4038
@Timeout(value = 10, timeUnit = MINUTES)
41-
4239
@DisabledFor(value = DB2, reason = "java.sql.SQLException: The object 'HREACT.JSONENTITY' provided is not defined, SQLCODE=-204 SQLSTATE=42704")
4340
@DisabledFor(value = SQLSERVER, reason = "java.lang.IllegalArgumentException: Unsupported value class: class io.vertx.core.json.JsonObject")
4441
@DisabledFor(value = ORACLE, reason = "java.sql.SQLException: ORA-17004: Invalid column type: https://docs.oracle.com/error-help/db/ora-17004/")
@@ -50,15 +47,6 @@ protected Collection<Class<?>> annotatedEntities() {
5047
return List.of( Basic.class );
5148
}
5249

53-
@Override
54-
public CompletionStage<Void> deleteEntities(Class<?>... types) {
55-
return getSessionFactory()
56-
.withTransaction( s -> loop( types, entityClass -> s
57-
.createSelectionQuery( "from JsonEntity", entityClass )
58-
.getResultList()
59-
.thenCompose( list -> loop( list, entity -> s.remove( entity ) ) ) ) );
60-
}
61-
6250
@Test
6351
public void testJsonType(VertxTestContext context) {
6452
Basic basic = new Basic();
@@ -79,16 +67,15 @@ public void testNullJsonType(VertxTestContext context) {
7967
* Persist the entity, find it and execute the assertions
8068
*/
8169
private void testField(VertxTestContext context, Basic original, Consumer<Basic> consumer) {
82-
test(
83-
context,
84-
getSessionFactory().withTransaction( (s, t) -> s.persist( original ) )
85-
.thenCompose( v -> openSession() )
86-
.thenCompose( s2 -> s2.find( Basic.class, original.id )
87-
.thenAccept( found -> {
88-
assertNotNull( found );
89-
assertEquals( original, found );
90-
consumer.accept( found );
91-
} ) )
70+
test( context, getSessionFactory()
71+
.withTransaction( s -> s.persist( original ) )
72+
.thenCompose( v -> getSessionFactory().withTransaction( s -> s
73+
.find( Basic.class, original.id ) )
74+
)
75+
.thenAccept( found -> {
76+
assertThat( found ).isEqualTo( original );
77+
consumer.accept( found );
78+
} )
9279
);
9380
}
9481

0 commit comments

Comments
 (0)