16
16
17
17
package org .springframework .data .couchbase .repository ;
18
18
19
- import com .couchbase .client .core .error .CouchbaseException ;
20
- import com .couchbase .client .core .error .IndexExistsException ;
21
- import com .couchbase .client .java .query .QueryScanConsistency ;
19
+ import static com .couchbase .client .java .query .QueryScanConsistency .NOT_BOUNDED ;
20
+ import static com .couchbase .client .java .query .QueryScanConsistency .REQUEST_PLUS ;
21
+ import static java .util .Arrays .asList ;
22
+ import static org .assertj .core .api .Assertions .assertThat ;
23
+ import static org .junit .jupiter .api .Assertions .assertEquals ;
24
+ import static org .junit .jupiter .api .Assertions .assertFalse ;
25
+ import static org .junit .jupiter .api .Assertions .assertNotNull ;
26
+ import static org .junit .jupiter .api .Assertions .assertNull ;
27
+ import static org .junit .jupiter .api .Assertions .assertThrows ;
28
+ import static org .junit .jupiter .api .Assertions .assertTrue ;
29
+ import static org .springframework .data .couchbase .config .BeanNames .COUCHBASE_TEMPLATE ;
30
+
31
+ import java .lang .reflect .Method ;
32
+ import java .util .ArrayList ;
33
+ import java .util .Arrays ;
34
+ import java .util .List ;
35
+ import java .util .Locale ;
36
+ import java .util .Optional ;
37
+ import java .util .concurrent .Callable ;
38
+ import java .util .concurrent .ExecutorService ;
39
+ import java .util .concurrent .Executors ;
40
+ import java .util .concurrent .Future ;
41
+ import java .util .stream .Collectors ;
42
+
22
43
import org .junit .jupiter .api .BeforeEach ;
23
44
import org .junit .jupiter .api .Test ;
24
45
import org .springframework .beans .factory .annotation .Autowired ;
31
52
import org .springframework .data .auditing .DateTimeProvider ;
32
53
import org .springframework .data .couchbase .CouchbaseClientFactory ;
33
54
import org .springframework .data .couchbase .config .AbstractCouchbaseConfiguration ;
55
+ import org .springframework .data .couchbase .core .CouchbaseQueryExecutionException ;
34
56
import org .springframework .data .couchbase .core .CouchbaseTemplate ;
35
57
import org .springframework .data .couchbase .core .RemoveResult ;
36
58
import org .springframework .data .couchbase .core .query .N1QLExpression ;
37
59
import org .springframework .data .couchbase .core .query .Query ;
38
60
import org .springframework .data .couchbase .core .query .QueryCriteria ;
39
- import org .springframework .data .couchbase .domain .*;
61
+ import org .springframework .data .couchbase .domain .Address ;
62
+ import org .springframework .data .couchbase .domain .Airport ;
63
+ import org .springframework .data .couchbase .domain .AirportDefaultConsistencyRepository ;
64
+ import org .springframework .data .couchbase .domain .AirportRepository ;
65
+ import org .springframework .data .couchbase .domain .Iata ;
66
+ import org .springframework .data .couchbase .domain .NaiveAuditorAware ;
67
+ import org .springframework .data .couchbase .domain .Person ;
68
+ import org .springframework .data .couchbase .domain .PersonRepository ;
69
+ import org .springframework .data .couchbase .domain .User ;
70
+ import org .springframework .data .couchbase .domain .UserRepository ;
40
71
import org .springframework .data .couchbase .domain .time .AuditingDateTimeProvider ;
41
72
import org .springframework .data .couchbase .repository .auditing .EnableCouchbaseAuditing ;
42
73
import org .springframework .data .couchbase .repository .config .EnableCouchbaseRepositories ;
49
80
import org .springframework .data .domain .Page ;
50
81
import org .springframework .data .domain .PageRequest ;
51
82
import org .springframework .data .domain .Pageable ;
83
+ import org .springframework .data .domain .Sort ;
52
84
import org .springframework .data .projection .SpelAwareProxyProjectionFactory ;
53
85
import org .springframework .data .repository .core .support .DefaultRepositoryMetadata ;
54
86
import org .springframework .test .context .junit .jupiter .SpringJUnitConfig ;
55
87
56
- import java .lang .reflect .Method ;
57
- import java .util .ArrayList ;
58
- import java .util .Arrays ;
59
- import java .util .List ;
60
- import java .util .Locale ;
61
- import java .util .Optional ;
62
- import java .util .concurrent .Callable ;
63
- import java .util .concurrent .ExecutorService ;
64
- import java .util .concurrent .Executors ;
65
- import java .util .concurrent .Future ;
66
- import java .util .stream .Collectors ;
67
-
68
- import static com .couchbase .client .java .query .QueryScanConsistency .NOT_BOUNDED ;
69
- import static com .couchbase .client .java .query .QueryScanConsistency .REQUEST_PLUS ;
70
- import static java .util .Arrays .asList ;
71
- import static org .assertj .core .api .Assertions .assertThat ;
72
- import static org .junit .jupiter .api .Assertions .*;
73
- import static org .springframework .data .couchbase .config .BeanNames .COUCHBASE_TEMPLATE ;
88
+ import com .couchbase .client .core .error .CouchbaseException ;
89
+ import com .couchbase .client .core .error .IndexExistsException ;
90
+ import com .couchbase .client .java .query .QueryScanConsistency ;
74
91
75
92
/**
76
93
* Repository tests
@@ -88,8 +105,7 @@ public class CouchbaseRepositoryQueryIntegrationTests extends ClusterAwareIntegr
88
105
89
106
@ Autowired AirportRepository airportRepository ;
90
107
91
- @ Autowired
92
- AirportDefaultConsistencyRepository airportDefaultConsistencyRepository ;
108
+ @ Autowired AirportDefaultConsistencyRepository airportDefaultConsistencyRepository ;
93
109
94
110
@ Autowired UserRepository userRepository ;
95
111
@@ -195,6 +211,19 @@ void findBySimpleProperty() {
195
211
}
196
212
}
197
213
214
+ @ Test
215
+ void findWithPageRequest () {
216
+ Airport vie = null ;
217
+ try {
218
+ vie = new Airport ("airports::vie" , "vie" , "low6" );
219
+ vie = airportRepository .save (vie );
220
+ // The exception occurred while building the query. This query will not find anything on execution.
221
+ Page <Airport > airports = airportRepository .findAllByOrganizationIdsContains ("123" , PageRequest .of (0 , 1 ));
222
+ } finally {
223
+ // airportRepository.delete(vie);
224
+ }
225
+ }
226
+
198
227
@ Test
199
228
public void saveNotBounded () {
200
229
// save() followed by query with NOT_BOUNDED will result in not finding the document
@@ -234,7 +263,8 @@ public void saveNotBoundedRequestPlus() {
234
263
ApplicationContext ac = new AnnotationConfigApplicationContext (ConfigRequestPlus .class );
235
264
// the Config class has been modified, these need to be loaded again
236
265
CouchbaseTemplate couchbaseTemplateRP = (CouchbaseTemplate ) ac .getBean (COUCHBASE_TEMPLATE );
237
- AirportDefaultConsistencyRepository airportRepositoryRP = (AirportDefaultConsistencyRepository ) ac .getBean ("airportDefaultConsistencyRepository" );
266
+ AirportDefaultConsistencyRepository airportRepositoryRP = (AirportDefaultConsistencyRepository ) ac
267
+ .getBean ("airportDefaultConsistencyRepository" );
238
268
239
269
// save() followed by query with NOT_BOUNDED will result in not finding the document
240
270
Airport vie = new Airport ("airports::vie" , "vie" , "low9" );
@@ -272,7 +302,8 @@ public void saveNotBoundedRequestPlusWithDefaultRepository() {
272
302
ApplicationContext ac = new AnnotationConfigApplicationContext (ConfigRequestPlus .class );
273
303
// the Config class has been modified, these need to be loaded again
274
304
CouchbaseTemplate couchbaseTemplateRP = (CouchbaseTemplate ) ac .getBean (COUCHBASE_TEMPLATE );
275
- AirportDefaultConsistencyRepository airportRepositoryRP = (AirportDefaultConsistencyRepository ) ac .getBean ("airportDefaultConsistencyRepository" );
305
+ AirportDefaultConsistencyRepository airportRepositoryRP = (AirportDefaultConsistencyRepository ) ac
306
+ .getBean ("airportDefaultConsistencyRepository" );
276
307
277
308
List <Airport > sizeBeforeTest = airportRepositoryRP .findAll ();
278
309
assertEquals (0 , sizeBeforeTest .size ());
@@ -357,6 +388,7 @@ public void testStreamQuery() {
357
388
void count () {
358
389
String [] iatas = { "JFK" , "IAD" , "SFO" , "SJC" , "SEA" , "LAX" , "PHX" };
359
390
391
+ airportRepository .countOne ();
360
392
try {
361
393
362
394
airportRepository .saveAll (
@@ -366,6 +398,11 @@ void count() {
366
398
Long count = airportRepository .countFancyExpression (asList ("JFK" ), asList ("jfk" ), false );
367
399
assertEquals (1 , count );
368
400
401
+ Pageable sPageable = PageRequest .of (0 , 2 ).withSort (Sort .by ("iata" ));
402
+ Page <Airport > sPage = airportRepository .getAllByIataNot ("JFK" , sPageable );
403
+ assertEquals (iatas .length - 1 , sPage .getTotalElements ());
404
+ assertEquals (sPageable .getPageSize (), sPage .getContent ().size ());
405
+
369
406
Pageable pageable = PageRequest .of (0 , 2 );
370
407
Page <Airport > aPage = airportRepository .findAllByIataNot ("JFK" , pageable );
371
408
assertEquals (iatas .length - 1 , aPage .getTotalElements ());
@@ -392,6 +429,16 @@ void count() {
392
429
}
393
430
}
394
431
432
+ @ Test
433
+ void badCount () {
434
+ assertThrows (CouchbaseQueryExecutionException .class , () -> airportRepository .countBad ());
435
+ }
436
+
437
+ @ Test
438
+ void goodCount () {
439
+ airportRepository .countGood ();
440
+ }
441
+
395
442
@ Test
396
443
void threadSafeParametersTest () throws Exception {
397
444
String [] iatas = { "JFK" , "IAD" , "SFO" , "SJC" , "SEA" , "LAX" , "PHX" };
0 commit comments