diff --git a/hibernate-reactive-core/src/test/java/org/hibernate/reactive/QueryTest.java b/hibernate-reactive-core/src/test/java/org/hibernate/reactive/QueryTest.java index 100c65fa12..0eca8cd78d 100644 --- a/hibernate-reactive-core/src/test/java/org/hibernate/reactive/QueryTest.java +++ b/hibernate-reactive-core/src/test/java/org/hibernate/reactive/QueryTest.java @@ -606,6 +606,70 @@ public void testSingleResultOrNullNonUniqueException(VertxTestContext context) { ); } + @Test + public void testSelectionQueryGetResultCountWithStage(VertxTestContext context) { + Author author1 = new Author( "Iain M. Banks" ); + Author author2 = new Author( "Neal Stephenson" ); + test( context, getSessionFactory() + .withTransaction( s -> s.persist( author1, author2 ) ) + .thenCompose( v -> getSessionFactory().withSession( s -> s + .createSelectionQuery( "from Author", Author.class ) + .getResultCount() ) ) + .thenAccept( count -> assertEquals( 2L, count ) ) + ); + } + + @Test + public void testQueryGetResultCountWithStage(VertxTestContext context) { + Author author1 = new Author( "Iain M. Banks" ); + Author author2 = new Author( "Neal Stephenson" ); + test( context, getSessionFactory() + .withTransaction( s -> s.persist( author1, author2 ) ) + .thenCompose( v -> getSessionFactory().withSession( s -> s + .createQuery( "from Author", Author.class ) + .getResultCount() ) ) + .thenAccept( count -> assertEquals( 2L, count ) ) + .thenCompose( v -> getSessionFactory().withSession( s -> s + .createQuery( "from Author", Author.class ) + .setMaxResults( 1 ) + .setFirstResult( 1 ) + .getResultCount() ) ) + .thenAccept( count -> assertEquals( 2L, count ) ) + ); + } + + @Test + public void testSelectionQueryGetResultCountWithMutiny(VertxTestContext context) { + Author author1 = new Author( "Iain M. Banks" ); + Author author2 = new Author( "Neal Stephenson" ); + test( context, getSessionFactory() + .withTransaction( s -> s.persist( author1, author2 ) ) + .thenCompose( v -> getSessionFactory().withSession( s -> s + .createSelectionQuery( "from Author", Author.class ) + .getResultCount() ) ) + .thenAccept( count -> assertEquals( 2L, count ) ) + ); + } + + @Test + public void testQueryGetResultCountWithMutiny(VertxTestContext context) { + Author author1 = new Author( "Iain M. Banks" ); + Author author2 = new Author( "Neal Stephenson" ); + test( context, getMutinySessionFactory() + .withTransaction( s -> s.persistAll( author1, author2 ) ) + .chain( () -> getMutinySessionFactory().withSession( s -> s + .createQuery( "from Author", Author.class ) + .getResultCount() ) ) + .invoke( count -> assertEquals( 2L, count ) ) + .chain( () -> getMutinySessionFactory().withSession( s -> s + .createQuery( "from Author", Author.class ) + .setMaxResults( 1 ) + .setFirstResult( 1 ) + .getResultCount() ) ) + .invoke( count -> assertEquals( 2L, count ) ) + ); + } + @NamedNativeQuery( name = SQL_NAMED_QUERY, resultClass = Object[].class,