1616
1717package org .springframework .data .couchbase .repository ;
1818
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+
2243import org .junit .jupiter .api .BeforeEach ;
2344import org .junit .jupiter .api .Test ;
2445import org .springframework .beans .factory .annotation .Autowired ;
3152import org .springframework .data .auditing .DateTimeProvider ;
3253import org .springframework .data .couchbase .CouchbaseClientFactory ;
3354import org .springframework .data .couchbase .config .AbstractCouchbaseConfiguration ;
55+ import org .springframework .data .couchbase .core .CouchbaseQueryExecutionException ;
3456import org .springframework .data .couchbase .core .CouchbaseTemplate ;
3557import org .springframework .data .couchbase .core .RemoveResult ;
3658import org .springframework .data .couchbase .core .query .N1QLExpression ;
3759import org .springframework .data .couchbase .core .query .Query ;
3860import 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 ;
4071import org .springframework .data .couchbase .domain .time .AuditingDateTimeProvider ;
4172import org .springframework .data .couchbase .repository .auditing .EnableCouchbaseAuditing ;
4273import org .springframework .data .couchbase .repository .config .EnableCouchbaseRepositories ;
4980import org .springframework .data .domain .Page ;
5081import org .springframework .data .domain .PageRequest ;
5182import org .springframework .data .domain .Pageable ;
83+ import org .springframework .data .domain .Sort ;
5284import org .springframework .data .projection .SpelAwareProxyProjectionFactory ;
5385import org .springframework .data .repository .core .support .DefaultRepositoryMetadata ;
5486import org .springframework .test .context .junit .jupiter .SpringJUnitConfig ;
5587
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 ;
7491
7592/**
7693 * Repository tests
@@ -88,8 +105,7 @@ public class CouchbaseRepositoryQueryIntegrationTests extends ClusterAwareIntegr
88105
89106 @ Autowired AirportRepository airportRepository ;
90107
91- @ Autowired
92- AirportDefaultConsistencyRepository airportDefaultConsistencyRepository ;
108+ @ Autowired AirportDefaultConsistencyRepository airportDefaultConsistencyRepository ;
93109
94110 @ Autowired UserRepository userRepository ;
95111
@@ -195,6 +211,19 @@ void findBySimpleProperty() {
195211 }
196212 }
197213
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+
198227 @ Test
199228 public void saveNotBounded () {
200229 // save() followed by query with NOT_BOUNDED will result in not finding the document
@@ -234,7 +263,8 @@ public void saveNotBoundedRequestPlus() {
234263 ApplicationContext ac = new AnnotationConfigApplicationContext (ConfigRequestPlus .class );
235264 // the Config class has been modified, these need to be loaded again
236265 CouchbaseTemplate couchbaseTemplateRP = (CouchbaseTemplate ) ac .getBean (COUCHBASE_TEMPLATE );
237- AirportDefaultConsistencyRepository airportRepositoryRP = (AirportDefaultConsistencyRepository ) ac .getBean ("airportDefaultConsistencyRepository" );
266+ AirportDefaultConsistencyRepository airportRepositoryRP = (AirportDefaultConsistencyRepository ) ac
267+ .getBean ("airportDefaultConsistencyRepository" );
238268
239269 // save() followed by query with NOT_BOUNDED will result in not finding the document
240270 Airport vie = new Airport ("airports::vie" , "vie" , "low9" );
@@ -272,7 +302,8 @@ public void saveNotBoundedRequestPlusWithDefaultRepository() {
272302 ApplicationContext ac = new AnnotationConfigApplicationContext (ConfigRequestPlus .class );
273303 // the Config class has been modified, these need to be loaded again
274304 CouchbaseTemplate couchbaseTemplateRP = (CouchbaseTemplate ) ac .getBean (COUCHBASE_TEMPLATE );
275- AirportDefaultConsistencyRepository airportRepositoryRP = (AirportDefaultConsistencyRepository ) ac .getBean ("airportDefaultConsistencyRepository" );
305+ AirportDefaultConsistencyRepository airportRepositoryRP = (AirportDefaultConsistencyRepository ) ac
306+ .getBean ("airportDefaultConsistencyRepository" );
276307
277308 List <Airport > sizeBeforeTest = airportRepositoryRP .findAll ();
278309 assertEquals (0 , sizeBeforeTest .size ());
@@ -357,6 +388,7 @@ public void testStreamQuery() {
357388 void count () {
358389 String [] iatas = { "JFK" , "IAD" , "SFO" , "SJC" , "SEA" , "LAX" , "PHX" };
359390
391+ airportRepository .countOne ();
360392 try {
361393
362394 airportRepository .saveAll (
@@ -366,6 +398,11 @@ void count() {
366398 Long count = airportRepository .countFancyExpression (asList ("JFK" ), asList ("jfk" ), false );
367399 assertEquals (1 , count );
368400
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+
369406 Pageable pageable = PageRequest .of (0 , 2 );
370407 Page <Airport > aPage = airportRepository .findAllByIataNot ("JFK" , pageable );
371408 assertEquals (iatas .length - 1 , aPage .getTotalElements ());
@@ -392,6 +429,16 @@ void count() {
392429 }
393430 }
394431
432+ @ Test
433+ void badCount () {
434+ assertThrows (CouchbaseQueryExecutionException .class , () -> airportRepository .countBad ());
435+ }
436+
437+ @ Test
438+ void goodCount () {
439+ airportRepository .countGood ();
440+ }
441+
395442 @ Test
396443 void threadSafeParametersTest () throws Exception {
397444 String [] iatas = { "JFK" , "IAD" , "SFO" , "SJC" , "SEA" , "LAX" , "PHX" };
0 commit comments