Skip to content

Commit bcb81ad

Browse files
committed
[#3811] Add test for ReactiveSelectionQuery.getKeyedResultList
1 parent 1142c91 commit bcb81ad

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.util.Objects;
1010
import java.util.concurrent.CompletionStage;
1111

12+
import org.hibernate.query.Order;
1213
import org.hibernate.annotations.Filter;
1314
import org.hibernate.annotations.FilterDef;
1415
import org.hibernate.annotations.ParamDef;
@@ -163,6 +164,39 @@ public void testMaxResultsWithStage(VertxTestContext context) {
163164
);
164165
}
165166

167+
@Test
168+
public void testReactiveKeyedPagination(VertxTestContext context) {
169+
test( context, openSession()
170+
.thenCompose( session -> {
171+
var query = session.createSelectionQuery(
172+
"from FamousPerson p where p.status = :status order by p.name, p.id",
173+
FamousPerson.class
174+
);
175+
final var firstPage = first( 2 ).keyedBy( List.of(
176+
Order.asc( FamousPerson.class, "name" ),
177+
Order.asc( FamousPerson.class, "id" )
178+
) );
179+
return query.setParameter( "status", Status.LIVING )
180+
.getReactiveKeyedResultList( firstPage )
181+
.thenCompose( firstResults -> {
182+
assertThat( firstResults.getResultList() ).containsExactly( margaret, rebeccaActress );
183+
assertThat( firstResults.getKeyList() ).hasSize( 2 );
184+
assertThat( firstResults.isFirstPage() ).isTrue();
185+
assertThat( firstResults.isLastPage() ).isFalse();
186+
assertThat( firstResults.getPreviousPage() ).isNull();
187+
return query.getReactiveKeyedResultList( firstResults.getNextPage() )
188+
.thenAccept( secondResults -> {
189+
assertThat( secondResults.getResultList() ).containsExactly( rebeccaSinger );
190+
assertThat( secondResults.getKeyList() ).hasSize( 1 );
191+
assertThat( secondResults.isFirstPage() ).isFalse();
192+
assertThat( secondResults.isLastPage() ).isTrue();
193+
assertThat( secondResults.getPreviousPage() ).isNotNull();
194+
} );
195+
} );
196+
} )
197+
);
198+
}
199+
166200
@Test
167201
public void testMaxResultsWithStageAndPage(VertxTestContext context) {
168202
test( context, enableFilter( openSession(), FamousPerson.IS_ALIVE_FILTER )

0 commit comments

Comments
 (0)