Skip to content

Commit

Permalink
[#1932] Test for #getReactiveResultCount with HQL
Browse files Browse the repository at this point in the history
  • Loading branch information
DavideD committed Aug 2, 2024
1 parent 503db5c commit 97adb04
Showing 1 changed file with 64 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 97adb04

Please sign in to comment.