|
30 | 30 |
|
31 | 31 | import static java.util.concurrent.TimeUnit.MINUTES;
|
32 | 32 | import static org.hibernate.reactive.testing.ReactiveAssertions.assertThrown;
|
| 33 | +import static org.hibernate.reactive.util.impl.CompletionStages.voidFuture; |
33 | 34 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
34 | 35 | import static org.junit.jupiter.api.Assertions.assertTrue;
|
35 | 36 |
|
@@ -83,26 +84,47 @@ public void testUnfetchedEntityException(VertxTestContext context) {
|
83 | 84 | }
|
84 | 85 |
|
85 | 86 | @Test
|
86 |
| - public void testLazyInitializationException(VertxTestContext context) { |
| 87 | + public void testLazyInitializationExceptionWithMutiny(VertxTestContext context) { |
87 | 88 | Game lol = new Game( "League of Legends" );
|
88 | 89 | GameCharacter ck = new GameCharacter( "Caitlyn Kiramman" );
|
89 | 90 | ck.setGame( lol );
|
90 | 91 |
|
91 |
| - test( context, assertThrown( LazyInitializationException.class, getMutinySessionFactory() |
| 92 | + test( context, getMutinySessionFactory() |
92 | 93 | .withTransaction( s -> s.persistAll( lol, ck ) )
|
93 | 94 | .chain( targetId -> getMutinySessionFactory()
|
94 | 95 | .withStatelessSession( session -> session.get( GameCharacter.class, ck.getId() ) )
|
95 | 96 | )
|
96 |
| - .call( charFound -> getMutinySessionFactory() |
97 |
| - .withStatelessTransaction( s -> { |
| 97 | + .call( charFound -> assertThrown( |
| 98 | + LazyInitializationException.class, getMutinySessionFactory().withStatelessTransaction( s -> { |
98 | 99 | Game game = charFound.getGame();
|
99 | 100 | // LazyInitializationException here because we haven't fetched the entity
|
100 | 101 | game.setGameTitle( "League of Legends V2" );
|
101 |
| - context.failNow( "We were expecting a LazyInitializationException" ); |
102 |
| - return null; |
| 102 | + return Uni.createFrom().voidItem(); |
103 | 103 | } )
|
| 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() ) ) |
104 | 118 | )
|
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 | + ); |
106 | 128 | }
|
107 | 129 |
|
108 | 130 | @Test
|
|
0 commit comments