From 091f14f5fdd311e24a0a326f51f35693bc56d0e4 Mon Sep 17 00:00:00 2001 From: Davide D'Alto Date: Tue, 11 Jun 2024 10:58:54 +0200 Subject: [PATCH] [#1932] Test for `#getReactiveResultCount` with HQL --- .../org/hibernate/reactive/QueryTest.java | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) 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 054264011b..00e42e82ed 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 @@ -607,6 +607,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,