1
1
package com .infobip .spring .data .jdbc ;
2
2
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 .* ;
6
6
7
7
import java .time .ZoneOffset ;
8
8
import java .util .List ;
9
9
import java .util .TimeZone ;
10
10
import java .util .stream .Collectors ;
11
11
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 ;
16
12
import org .junit .jupiter .api .AfterAll ;
17
13
import org .junit .jupiter .api .BeforeAll ;
18
14
import org .junit .jupiter .api .Test ;
15
+ import org .springframework .data .domain .PageRequest ;
16
+ import org .springframework .data .domain .Sort ;
19
17
import org .springframework .transaction .annotation .Transactional ;
20
18
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
+
21
25
@ AllArgsConstructor
22
26
public class QuerydslJdbcRepositoryTest extends TestBase {
23
27
@@ -53,7 +57,8 @@ void shouldStreamAll() {
53
57
actual = stream .collect (Collectors .toList ());
54
58
}
55
59
56
- then (actual ).usingRecursiveFieldByFieldElementComparator ().containsExactlyInAnyOrder (johnDoe , johnyRoe , janeDoe );
60
+ then (actual ).usingRecursiveFieldByFieldElementComparator ()
61
+ .containsExactlyInAnyOrder (johnDoe , johnyRoe , janeDoe );
57
62
}
58
63
59
64
@ Test
@@ -151,6 +156,27 @@ void shouldQueryMany() {
151
156
then (actual ).containsOnly (johnDoe );
152
157
}
153
158
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
+
154
180
@ Test
155
181
void shouldProject () {
156
182
@@ -184,8 +210,8 @@ void shouldUpdate() {
184
210
185
211
then (actual ).isEqualTo (1 );
186
212
then (repository .findAll ()).extracting (Person ::firstName )
187
- .containsExactlyInAnyOrder ("John" , "John" , "Jane" )
188
- .hasSize (3 );
213
+ .containsExactlyInAnyOrder ("John" , "John" , "Jane" )
214
+ .hasSize (3 );
189
215
}
190
216
191
217
@ Test
@@ -259,7 +285,7 @@ void shouldSupportMultipleConstructors() {
259
285
void shouldExtendSimpleQuerydslJdbcRepository () {
260
286
// then
261
287
then (repository ).isInstanceOf (QuerydslJdbcRepository .class )
262
- .isNotInstanceOf (CustomQuerydslJdbcRepository .class );
288
+ .isNotInstanceOf (CustomQuerydslJdbcRepository .class );
263
289
}
264
290
265
291
@ Transactional
@@ -270,9 +296,9 @@ void springDataAndQuerydslShouldHandleTimeZoneTheSameForSameTimeZone() {
270
296
271
297
// when
272
298
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 ();
276
302
repository .save (givenPerson );
277
303
278
304
// then
0 commit comments