Skip to content

Commit 1912a5c

Browse files
committed
[#1280] tests for getCurrentSession()
1 parent 72106db commit 1912a5c

File tree

2 files changed

+70
-12
lines changed

2 files changed

+70
-12
lines changed

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

+33-6
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,7 @@
2727
import jakarta.persistence.metamodel.EntityType;
2828

2929
import static java.util.concurrent.TimeUnit.MINUTES;
30-
import static org.junit.jupiter.api.Assertions.assertEquals;
31-
import static org.junit.jupiter.api.Assertions.assertFalse;
32-
import static org.junit.jupiter.api.Assertions.assertNotEquals;
33-
import static org.junit.jupiter.api.Assertions.assertNotNull;
34-
import static org.junit.jupiter.api.Assertions.assertTrue;
35-
import static org.junit.jupiter.api.Assertions.fail;
30+
import static org.junit.jupiter.api.Assertions.*;
3631

3732
@Timeout(value = 10, timeUnit = MINUTES)
3833

@@ -668,6 +663,38 @@ public void testForceFlushWithDelete(VertxTestContext context) {
668663
);
669664
}
670665

666+
@Test
667+
public void testCurrentSession(VertxTestContext context) {
668+
test( context,
669+
getMutinySessionFactory().withSession(session ->
670+
getMutinySessionFactory().withSession(s -> {
671+
assertEquals(session, s);
672+
Mutiny.Session currentSession = getMutinySessionFactory().getCurrentSession();
673+
assertNotNull(currentSession);
674+
assertTrue(currentSession.isOpen());
675+
assertEquals(session, currentSession);
676+
return Uni.createFrom().voidItem();
677+
}).invoke(() -> assertNotNull(getMutinySessionFactory().getCurrentSession()))
678+
).invoke(() -> assertNull(getMutinySessionFactory().getCurrentSession()))
679+
);
680+
}
681+
682+
@Test
683+
public void testCurrentStatelessSession(VertxTestContext context) {
684+
test( context,
685+
getMutinySessionFactory().withStatelessSession(session ->
686+
getMutinySessionFactory().withStatelessSession(s -> {
687+
assertEquals(session, s);
688+
Mutiny.StatelessSession currentSession = getMutinySessionFactory().getCurrentStatelessSession();
689+
assertNotNull(currentSession);
690+
assertTrue(currentSession.isOpen());
691+
assertEquals(session, currentSession);
692+
return Uni.createFrom().voidItem();
693+
}).invoke(() -> assertNotNull(getMutinySessionFactory().getCurrentStatelessSession()))
694+
).invoke(() -> assertNull(getMutinySessionFactory().getCurrentStatelessSession()))
695+
);
696+
}
697+
671698
private void assertThatPigsAreEqual(GuineaPig expected, GuineaPig actual) {
672699
assertNotNull( actual );
673700
assertEquals( expected.getId(), actual.getId() );

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

+37-6
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,7 @@
3232

3333
import static java.util.concurrent.TimeUnit.MINUTES;
3434
import static org.assertj.core.api.Assertions.assertThat;
35-
import static org.junit.jupiter.api.Assertions.assertEquals;
36-
import static org.junit.jupiter.api.Assertions.assertFalse;
37-
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
38-
import static org.junit.jupiter.api.Assertions.assertNotEquals;
39-
import static org.junit.jupiter.api.Assertions.assertNotNull;
40-
import static org.junit.jupiter.api.Assertions.assertTrue;
35+
import static org.junit.jupiter.api.Assertions.*;
4136

4237
@Timeout(value = 10, timeUnit = MINUTES)
4338

@@ -969,6 +964,42 @@ context, openSession()
969964
);
970965
}
971966

967+
@Test
968+
public void testCurrentSession(VertxTestContext context) {
969+
test( context,
970+
getSessionFactory().withSession(session ->
971+
getSessionFactory().withSession(s -> {
972+
assertEquals(session, s);
973+
Stage.Session currentSession = getSessionFactory().getCurrentSession();
974+
assertNotNull(currentSession);
975+
assertTrue(currentSession.isOpen());
976+
assertEquals(session, currentSession);
977+
return CompletionStages.voidFuture();
978+
})
979+
.thenAccept(v -> assertNotNull(getSessionFactory().getCurrentSession()))
980+
)
981+
.thenAccept(v -> assertNull(getSessionFactory().getCurrentSession()))
982+
);
983+
}
984+
985+
@Test
986+
public void testCurrentStatelessSession(VertxTestContext context) {
987+
test( context,
988+
getSessionFactory().withStatelessSession(session ->
989+
getSessionFactory().withStatelessSession(s -> {
990+
assertEquals(session, s);
991+
Stage.StatelessSession currentSession = getSessionFactory().getCurrentStatelessSession();
992+
assertNotNull(currentSession);
993+
assertTrue(currentSession.isOpen());
994+
assertEquals(session, currentSession);
995+
return CompletionStages.voidFuture();
996+
})
997+
.thenAccept(v -> assertNotNull(getSessionFactory().getCurrentStatelessSession()))
998+
)
999+
.thenAccept(v -> assertNull(getSessionFactory().getCurrentStatelessSession()))
1000+
);
1001+
}
1002+
9721003
private void assertThatPigsAreEqual(GuineaPig expected, GuineaPig actual) {
9731004
assertNotNull( actual );
9741005
assertEquals( expected.getId(), actual.getId() );

0 commit comments

Comments
 (0)