1616
1717package org .springframework .data .couchbase .repository ;
1818
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-
19+ import com .couchbase .client .core .error .CouchbaseException ;
20+ import com .couchbase .client .core .error .IndexExistsException ;
21+ import com .couchbase .client .java .query .QueryScanConsistency ;
4322import org .junit .jupiter .api .BeforeEach ;
4423import org .junit .jupiter .api .Test ;
4524import org .springframework .beans .factory .annotation .Autowired ;
5736import org .springframework .data .couchbase .core .query .N1QLExpression ;
5837import org .springframework .data .couchbase .core .query .Query ;
5938import org .springframework .data .couchbase .core .query .QueryCriteria ;
60- import org .springframework .data .couchbase .domain .Address ;
61- import org .springframework .data .couchbase .domain .Airport ;
62- import org .springframework .data .couchbase .domain .AirportRepository ;
63- import org .springframework .data .couchbase .domain .Iata ;
64- import org .springframework .data .couchbase .domain .NaiveAuditorAware ;
65- import org .springframework .data .couchbase .domain .Person ;
66- import org .springframework .data .couchbase .domain .PersonRepository ;
67- import org .springframework .data .couchbase .domain .User ;
68- import org .springframework .data .couchbase .domain .UserRepository ;
39+ import org .springframework .data .couchbase .domain .*;
6940import org .springframework .data .couchbase .domain .time .AuditingDateTimeProvider ;
7041import org .springframework .data .couchbase .repository .auditing .EnableCouchbaseAuditing ;
7142import org .springframework .data .couchbase .repository .config .EnableCouchbaseRepositories ;
8253import org .springframework .data .repository .core .support .DefaultRepositoryMetadata ;
8354import org .springframework .test .context .junit .jupiter .SpringJUnitConfig ;
8455
85- import com .couchbase .client .core .error .CouchbaseException ;
86- import com .couchbase .client .core .error .IndexExistsException ;
87- import com .couchbase .client .java .query .QueryScanConsistency ;
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 ;
8874
8975/**
9076 * Repository tests
9177 *
9278 * @author Michael Nitschinger
9379 * @author Michael Reiche
9480 * @author Jens Schauder
81+ * @author Jonathan Massuchetti
9582 */
9683@ SpringJUnitConfig (CouchbaseRepositoryQueryIntegrationTests .Config .class )
9784@ IgnoreWhen (missesCapabilities = Capabilities .QUERY , clusterTypes = ClusterType .MOCKED )
@@ -101,6 +88,9 @@ public class CouchbaseRepositoryQueryIntegrationTests extends ClusterAwareIntegr
10188
10289 @ Autowired AirportRepository airportRepository ;
10390
91+ @ Autowired
92+ AirportDefaultConsistencyRepository airportDefaultConsistencyRepository ;
93+
10494 @ Autowired UserRepository userRepository ;
10595
10696 @ Autowired CouchbaseTemplate couchbaseTemplate ;
@@ -212,9 +202,9 @@ public void saveNotBounded() {
212202 Airport airport2 = null ;
213203 for (int i = 1 ; i <= 100 ; i ++) {
214204 // set version == 0 so save() will be an upsert, not a replace
215- Airport saved = airportRepository .save (vie .clearVersion ());
205+ Airport saved = airportDefaultConsistencyRepository .save (vie .clearVersion ());
216206 try {
217- airport2 = airportRepository .iata (saved .getIata ());
207+ airport2 = airportDefaultConsistencyRepository .iata (saved .getIata ());
218208 if (airport2 == null ) {
219209 break ;
220210 }
@@ -227,14 +217,14 @@ public void saveNotBounded() {
227217 assertEquals (vie .getId (), removeResult .getId ());
228218 assertTrue (removeResult .getCas () != 0 );
229219 assertTrue (removeResult .getMutationToken ().isPresent ());
230- Airport airport3 = airportRepository .iata (vie .getIata ());
220+ Airport airport3 = airportDefaultConsistencyRepository .iata (vie .getIata ());
231221 assertNull (airport3 , "should have been removed" );
232222 }
233223 }
234224 assertNull (airport2 , "airport2 should have likely been null at least once" );
235- Airport saved = airportRepository .save (vie .clearVersion ());
225+ Airport saved = airportDefaultConsistencyRepository .save (vie .clearVersion ());
236226 couchbaseTemplate .findByQuery (Airport .class ).withConsistency (REQUEST_PLUS ).all ();
237- airport2 = airportRepository .iata (vie .getIata ());
227+ airport2 = airportDefaultConsistencyRepository .iata (vie .getIata ());
238228 RemoveResult removeResult = couchbaseTemplate .removeById ().one (saved .getId ());
239229 assertNotNull (airport2 , "airport2 should have been found" );
240230 }
@@ -244,7 +234,7 @@ public void saveNotBoundedRequestPlus() {
244234 ApplicationContext ac = new AnnotationConfigApplicationContext (ConfigRequestPlus .class );
245235 // the Config class has been modified, these need to be loaded again
246236 CouchbaseTemplate couchbaseTemplateRP = (CouchbaseTemplate ) ac .getBean (COUCHBASE_TEMPLATE );
247- AirportRepository airportRepositoryRP = (AirportRepository ) ac .getBean ("airportRepository " );
237+ AirportDefaultConsistencyRepository airportRepositoryRP = (AirportDefaultConsistencyRepository ) ac .getBean ("airportDefaultConsistencyRepository " );
248238
249239 // save() followed by query with NOT_BOUNDED will result in not finding the document
250240 Airport vie = new Airport ("airports::vie" , "vie" , "low9" );
@@ -277,6 +267,28 @@ public void saveNotBoundedRequestPlus() {
277267 assertFalse (!airports .isEmpty (), "airports should have been empty" );
278268 }
279269
270+ @ Test
271+ public void saveNotBoundedRequestPlusWithDefaultRepository () {
272+ ApplicationContext ac = new AnnotationConfigApplicationContext (ConfigRequestPlus .class );
273+ // the Config class has been modified, these need to be loaded again
274+ CouchbaseTemplate couchbaseTemplateRP = (CouchbaseTemplate ) ac .getBean (COUCHBASE_TEMPLATE );
275+ AirportDefaultConsistencyRepository airportRepositoryRP = (AirportDefaultConsistencyRepository ) ac .getBean ("airportDefaultConsistencyRepository" );
276+
277+ List <Airport > sizeBeforeTest = airportRepositoryRP .findAll ();
278+ assertEquals (0 , sizeBeforeTest .size ());
279+
280+ for (int i = 1 ; i <= 100 ; i ++) {
281+ Airport vie = new Airport ("airports::vie" + i , "vie" + i , "low9" );
282+ airportRepositoryRP .save (vie );
283+ }
284+
285+ List <Airport > allSaved = airportRepositoryRP .findAll ();
286+
287+ airportRepository .deleteAll ();
288+
289+ assertEquals (100 , allSaved .size ());
290+ }
291+
280292 @ Test
281293 void findByTypeAlias () {
282294 Airport vie = null ;
0 commit comments