Skip to content

Commit 1ce7cb7

Browse files
committed
[hibernate#1932] Test getReactiveResultCount() with native queries
1 parent bade38e commit 1ce7cb7

File tree

1 file changed

+64
-0
lines changed
  • hibernate-reactive-core/src/test/java/org/hibernate/reactive

1 file changed

+64
-0
lines changed

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

+64
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,70 @@ public void testQueryGetResultCountWithMutiny(VertxTestContext context) {
670670
);
671671
}
672672

673+
@Test
674+
public void testNativeSelectionQueryGetResultCountWithStage(VertxTestContext context) {
675+
Author author1 = new Author( "Iain M. Banks" );
676+
Author author2 = new Author( "Neal Stephenson" );
677+
test( context, getSessionFactory()
678+
.withTransaction( s -> s.persist( author1, author2 ) )
679+
.thenCompose( v -> getSessionFactory().withSession( s -> s
680+
.createNativeQuery( "select * from " + AUTHOR_TABLE, Author.class )
681+
.getResultCount() ) )
682+
.thenAccept( count -> assertEquals( 2L, count ) )
683+
);
684+
}
685+
686+
@Test
687+
public void testNativeQueryGetResultCountWithStage(VertxTestContext context) {
688+
Author author1 = new Author( "Iain M. Banks" );
689+
Author author2 = new Author( "Neal Stephenson" );
690+
test( context, getSessionFactory()
691+
.withTransaction( s -> s.persist( author1, author2 ) )
692+
.thenCompose( v -> getSessionFactory().withSession( s -> s
693+
.createNativeQuery( "select * from " + AUTHOR_TABLE, Author.class )
694+
.getResultCount() ) )
695+
.thenAccept( count -> assertEquals( 2L, count ) )
696+
.thenCompose( v -> getSessionFactory().withSession( s -> s
697+
.createNativeQuery( "select * from " + AUTHOR_TABLE, Author.class )
698+
.setMaxResults( 1 )
699+
.setFirstResult( 1 )
700+
.getResultCount() ) )
701+
.thenAccept( count -> assertEquals( 2L, count ) )
702+
);
703+
}
704+
705+
@Test
706+
public void testNativeSelectionQueryGetResultCountWithMutiny(VertxTestContext context) {
707+
Author author1 = new Author( "Iain M. Banks" );
708+
Author author2 = new Author( "Neal Stephenson" );
709+
test( context, getSessionFactory()
710+
.withTransaction( s -> s.persist( author1, author2 ) )
711+
.thenCompose( v -> getSessionFactory().withSession( s -> s
712+
.createNativeQuery( "select * from " + AUTHOR_TABLE, Author.class )
713+
.getResultCount() ) )
714+
.thenAccept( count -> assertEquals( 2L, count ) )
715+
);
716+
}
717+
718+
@Test
719+
public void testNativeQueryGetResultCountWithMutiny(VertxTestContext context) {
720+
Author author1 = new Author( "Iain M. Banks" );
721+
Author author2 = new Author( "Neal Stephenson" );
722+
test( context, getMutinySessionFactory()
723+
.withTransaction( s -> s.persistAll( author1, author2 ) )
724+
.chain( () -> getMutinySessionFactory().withSession( s -> s
725+
.createNativeQuery( "select * from " + AUTHOR_TABLE, Author.class )
726+
.getResultCount() ) )
727+
.invoke( count -> assertEquals( 2L, count ) )
728+
.chain( () -> getMutinySessionFactory().withSession( s -> s
729+
.createNativeQuery( "select * from " + AUTHOR_TABLE, Author.class )
730+
.setMaxResults( 1 )
731+
.setFirstResult( 1 )
732+
.getResultCount() ) )
733+
.invoke( count -> assertEquals( 2L, count ) )
734+
);
735+
}
736+
673737
@NamedNativeQuery(
674738
name = SQL_NAMED_QUERY,
675739
resultClass = Object[].class,

0 commit comments

Comments
 (0)