Skip to content

Commit c52199d

Browse files
committed
[#1893] Add test cases for fetch(getReference())
1 parent 5cb015d commit c52199d

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import jakarta.persistence.Version;
3131

3232
import static java.util.concurrent.TimeUnit.MINUTES;
33+
import static org.assertj.core.api.Assertions.assertThat;
3334
import static org.hibernate.reactive.util.impl.CompletionStages.loop;
3435
import static org.junit.jupiter.api.Assertions.assertEquals;
3536
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -231,6 +232,25 @@ public void testRefreshDetachedProxy(VertxTestContext context) {
231232
);
232233
}
233234

235+
@Test
236+
public void testFetchOfReference(VertxTestContext context) {
237+
final Book goodOmens = new Book( "Good Omens: The Nice and Accurate Prophecies of Agnes Nutter, Witch" );
238+
final Author neil = new Author( "Neil Gaiman", goodOmens );
239+
final Author terry = new Author( "Terry Pratchett", goodOmens );
240+
goodOmens.getAuthors().add( neil );
241+
goodOmens.getAuthors().add( terry );
242+
243+
test( context, getMutinySessionFactory()
244+
.withTransaction( s -> s.persistAll( goodOmens, terry, neil ) )
245+
.call( () -> getMutinySessionFactory().withSession( s -> s
246+
// Not the most common case, but should be possible
247+
.fetch( s.getReference( Book.class, goodOmens.getId() ) )
248+
.chain( reference -> s.fetch( reference.getAuthors() ) )
249+
.invoke( authors -> assertThat( authors ).containsExactlyInAnyOrder( terry, neil ) )
250+
) )
251+
);
252+
}
253+
234254
@Entity(name = "Tome")
235255
@Table(name = "TBook")
236256
public static class Book {

integration-tests/bytecode-enhancements-it/src/test/java/org/hibernate/reactive/it/ReferenceBETest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import io.vertx.junit5.VertxTestContext;
2323

2424
import static java.util.concurrent.TimeUnit.MINUTES;
25+
import static org.assertj.core.api.Assertions.assertThat;
2526
import static org.hibernate.reactive.util.impl.CompletionStages.completedFuture;
2627
import static org.hibernate.reactive.util.impl.CompletionStages.loop;
2728
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -212,4 +213,23 @@ public void testRefreshDetachedProxy(VertxTestContext context) {
212213
) )
213214
);
214215
}
216+
217+
@Test
218+
public void testFetchOfReference(VertxTestContext context) {
219+
final Book goodOmens = new Book( "Good Omens: The Nice and Accurate Prophecies of Agnes Nutter, Witch" );
220+
final Author neil = new Author( "Neil Gaiman", goodOmens );
221+
final Author terry = new Author( "Terry Pratchett", goodOmens );
222+
goodOmens.getAuthors().add( neil );
223+
goodOmens.getAuthors().add( terry );
224+
225+
test( context, getMutinySessionFactory()
226+
.withTransaction( s -> s.persistAll( goodOmens, terry, neil ) )
227+
.call( () -> getMutinySessionFactory().withSession( s -> s
228+
// Not the most common case, but should be possible
229+
.fetch( s.getReference( Book.class, goodOmens.getId() ) )
230+
.chain( reference -> s.fetch( reference.getAuthors() ) )
231+
.invoke( authors -> assertThat( authors ).containsExactlyInAnyOrder( terry, neil ) )
232+
) )
233+
);
234+
}
215235
}

0 commit comments

Comments
 (0)