11package com .infobip .spring .data .jdbc ;
22
3- import static com .infobip .spring .data .jdbc .QPerson .person ;
4- import static com .infobip .spring .data .jdbc .QPersonSettings .personSettings ;
5- import static org .assertj .core .api .BDDAssertions .then ;
3+ import static com .infobip .spring .data .jdbc .QPerson .* ;
4+ import static com .infobip .spring .data .jdbc .QPersonSettings .* ;
5+ import static org .assertj .core .api .BDDAssertions .* ;
66
77import java .time .ZoneOffset ;
88import java .util .List ;
99import java .util .TimeZone ;
1010import java .util .stream .Collectors ;
1111
12- import com .infobip .spring .data .jdbc .extension .CustomQuerydslJdbcRepository ;
13- import com .querydsl .core .types .Projections ;
14- import com .querydsl .sql .SQLQueryFactory ;
15- import lombok .AllArgsConstructor ;
1612import org .junit .jupiter .api .AfterAll ;
1713import org .junit .jupiter .api .BeforeAll ;
1814import org .junit .jupiter .api .Test ;
15+ import org .springframework .data .domain .PageRequest ;
16+ import org .springframework .data .domain .Sort ;
1917import org .springframework .transaction .annotation .Transactional ;
2018
19+ import com .infobip .spring .data .jdbc .extension .CustomQuerydslJdbcRepository ;
20+ import com .querydsl .core .types .Projections ;
21+ import com .querydsl .sql .SQLQueryFactory ;
22+
23+ import lombok .AllArgsConstructor ;
24+
2125@ AllArgsConstructor
2226public class QuerydslJdbcRepositoryTest extends TestBase {
2327
@@ -53,7 +57,8 @@ void shouldStreamAll() {
5357 actual = stream .collect (Collectors .toList ());
5458 }
5559
56- then (actual ).usingRecursiveFieldByFieldElementComparator ().containsExactlyInAnyOrder (johnDoe , johnyRoe , janeDoe );
60+ then (actual ).usingRecursiveFieldByFieldElementComparator ()
61+ .containsExactlyInAnyOrder (johnDoe , johnyRoe , janeDoe );
5762 }
5863
5964 @ Test
@@ -151,6 +156,27 @@ void shouldQueryMany() {
151156 then (actual ).containsOnly (johnDoe );
152157 }
153158
159+ @ Test
160+ void shouldQueryManyWithPageable () {
161+ // given
162+ givenSavedPerson ("John" , "Doe" );
163+ givenSavedPerson ("Johny" , "Roe" );
164+ var janeDoe = givenSavedPerson ("Jane" , "Doe" );
165+ givenSavedPerson ("John" , "Roe" );
166+ givenSavedPerson ("Janie" , "Doe" );
167+ var janeStone = givenSavedPerson ("Jane" , "Stone" );
168+
169+ var page = PageRequest .of (0 , 2 , Sort .by (Sort .Order .asc ("firstName" )));
170+
171+ var actual = repository .queryMany (sqlQuery -> sqlQuery .from (person )
172+ .where (person .firstName .in ("John" , "Jane" )), page );
173+
174+ then (actual .getSize ()).isEqualTo (2 );
175+ then (actual .getTotalElements ()).isEqualTo (4 );
176+ then (actual .getTotalPages ()).isEqualTo (2 );
177+ then (actual ).containsExactlyInAnyOrder (janeDoe , janeStone );
178+ }
179+
154180 @ Test
155181 void shouldProject () {
156182
@@ -184,8 +210,8 @@ void shouldUpdate() {
184210
185211 then (actual ).isEqualTo (1 );
186212 then (repository .findAll ()).extracting (Person ::firstName )
187- .containsExactlyInAnyOrder ("John" , "John" , "Jane" )
188- .hasSize (3 );
213+ .containsExactlyInAnyOrder ("John" , "John" , "Jane" )
214+ .hasSize (3 );
189215 }
190216
191217 @ Test
@@ -259,7 +285,7 @@ void shouldSupportMultipleConstructors() {
259285 void shouldExtendSimpleQuerydslJdbcRepository () {
260286 // then
261287 then (repository ).isInstanceOf (QuerydslJdbcRepository .class )
262- .isNotInstanceOf (CustomQuerydslJdbcRepository .class );
288+ .isNotInstanceOf (CustomQuerydslJdbcRepository .class );
263289 }
264290
265291 @ Transactional
@@ -270,9 +296,9 @@ void springDataAndQuerydslShouldHandleTimeZoneTheSameForSameTimeZone() {
270296
271297 // when
272298 sqlQueryFactory .insert (person )
273- .columns (person .firstName , person .lastName , person .createdAt )
274- .values (givenPerson .firstName (), givenPerson .lastName (), givenPerson .createdAt ())
275- .execute ();
299+ .columns (person .firstName , person .lastName , person .createdAt )
300+ .values (givenPerson .firstName (), givenPerson .lastName (), givenPerson .createdAt ())
301+ .execute ();
276302 repository .save (givenPerson );
277303
278304 // then
0 commit comments