Skip to content

Commit

Permalink
[hibernate#1932] Test getReactiveResultCount() with native queries
Browse files Browse the repository at this point in the history
  • Loading branch information
DavideD committed Jun 11, 2024
1 parent bade38e commit 1ce7cb7
Showing 1 changed file with 64 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,70 @@ public void testQueryGetResultCountWithMutiny(VertxTestContext context) {
);
}

@Test
public void testNativeSelectionQueryGetResultCountWithStage(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
.createNativeQuery( "select * from " + AUTHOR_TABLE, Author.class )
.getResultCount() ) )
.thenAccept( count -> assertEquals( 2L, count ) )
);
}

@Test
public void testNativeQueryGetResultCountWithStage(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
.createNativeQuery( "select * from " + AUTHOR_TABLE, Author.class )
.getResultCount() ) )
.thenAccept( count -> assertEquals( 2L, count ) )
.thenCompose( v -> getSessionFactory().withSession( s -> s
.createNativeQuery( "select * from " + AUTHOR_TABLE, Author.class )
.setMaxResults( 1 )
.setFirstResult( 1 )
.getResultCount() ) )
.thenAccept( count -> assertEquals( 2L, count ) )
);
}

@Test
public void testNativeSelectionQueryGetResultCountWithMutiny(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
.createNativeQuery( "select * from " + AUTHOR_TABLE, Author.class )
.getResultCount() ) )
.thenAccept( count -> assertEquals( 2L, count ) )
);
}

@Test
public void testNativeQueryGetResultCountWithMutiny(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
.createNativeQuery( "select * from " + AUTHOR_TABLE, Author.class )
.getResultCount() ) )
.invoke( count -> assertEquals( 2L, count ) )
.chain( () -> getMutinySessionFactory().withSession( s -> s
.createNativeQuery( "select * from " + AUTHOR_TABLE, 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 1ce7cb7

Please sign in to comment.