Skip to content

Commit 3cd4d3a

Browse files
committed
[hibernate#1514] Add test to ReactiveStatelessProxyUpdateTest
We need to test with Mutiny and with CompletionStage because the exception is thrown by the API classes. I've also cleaned up a bit the code to avoid NullPointerException in case of failures (it should throw the correct assertion error).
1 parent dde7d5b commit 3cd4d3a

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

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

+29-7
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
import static java.util.concurrent.TimeUnit.MINUTES;
3232
import static org.hibernate.reactive.testing.ReactiveAssertions.assertThrown;
33+
import static org.hibernate.reactive.util.impl.CompletionStages.voidFuture;
3334
import static org.junit.jupiter.api.Assertions.assertEquals;
3435
import static org.junit.jupiter.api.Assertions.assertTrue;
3536

@@ -83,26 +84,47 @@ public void testUnfetchedEntityException(VertxTestContext context) {
8384
}
8485

8586
@Test
86-
public void testLazyInitializationException(VertxTestContext context) {
87+
public void testLazyInitializationExceptionWithMutiny(VertxTestContext context) {
8788
Game lol = new Game( "League of Legends" );
8889
GameCharacter ck = new GameCharacter( "Caitlyn Kiramman" );
8990
ck.setGame( lol );
9091

91-
test( context, assertThrown( LazyInitializationException.class, getMutinySessionFactory()
92+
test( context, getMutinySessionFactory()
9293
.withTransaction( s -> s.persistAll( lol, ck ) )
9394
.chain( targetId -> getMutinySessionFactory()
9495
.withStatelessSession( session -> session.get( GameCharacter.class, ck.getId() ) )
9596
)
96-
.call( charFound -> getMutinySessionFactory()
97-
.withStatelessTransaction( s -> {
97+
.call( charFound -> assertThrown(
98+
LazyInitializationException.class, getMutinySessionFactory().withStatelessTransaction( s -> {
9899
Game game = charFound.getGame();
99100
// LazyInitializationException here because we haven't fetched the entity
100101
game.setGameTitle( "League of Legends V2" );
101-
context.failNow( "We were expecting a LazyInitializationException" );
102-
return null;
102+
return Uni.createFrom().voidItem();
103103
} )
104+
) )
105+
);
106+
}
107+
108+
@Test
109+
public void testLazyInitializationExceptionWithStage(VertxTestContext context) {
110+
Game lol = new Game( "League of Legends" );
111+
GameCharacter ck = new GameCharacter( "Caitlyn Kiramman" );
112+
ck.setGame( lol );
113+
114+
test( context, getSessionFactory()
115+
.withTransaction( s -> s.persist( lol, ck ) )
116+
.thenCompose( targetId -> getSessionFactory()
117+
.withStatelessSession( session -> session.get( GameCharacter.class, ck.getId() ) )
104118
)
105-
) );
119+
.thenCompose( charFound -> assertThrown(
120+
LazyInitializationException.class, getSessionFactory().withStatelessTransaction( s -> {
121+
Game game = charFound.getGame();
122+
// LazyInitializationException here because we haven't fetched the entity
123+
game.setGameTitle( "League of Legends V2" );
124+
return voidFuture();
125+
} )
126+
) )
127+
);
106128
}
107129

108130
@Test

0 commit comments

Comments
 (0)