57
57
import org .springframework .data .couchbase .core .query .N1QLExpression ;
58
58
import org .springframework .data .couchbase .core .query .Query ;
59
59
import 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 ;
60
+ import org .springframework .data .couchbase .domain .*;
69
61
import org .springframework .data .couchbase .domain .time .AuditingDateTimeProvider ;
70
62
import org .springframework .data .couchbase .repository .auditing .EnableCouchbaseAuditing ;
71
63
import org .springframework .data .couchbase .repository .config .EnableCouchbaseRepositories ;
72
64
import org .springframework .data .couchbase .repository .query .CouchbaseQueryMethod ;
73
65
import org .springframework .data .couchbase .repository .query .CouchbaseRepositoryQuery ;
66
+ import org .springframework .data .couchbase .repository .support .SimpleCouchbaseRepository ;
74
67
import org .springframework .data .couchbase .util .Capabilities ;
75
68
import org .springframework .data .couchbase .util .ClusterAwareIntegrationTests ;
76
69
import org .springframework .data .couchbase .util .ClusterType ;
92
85
* @author Michael Nitschinger
93
86
* @author Michael Reiche
94
87
* @author Jens Schauder
88
+ * @author Jonathan Massuchetti
95
89
*/
96
90
@ SpringJUnitConfig (CouchbaseRepositoryQueryIntegrationTests .Config .class )
97
91
@ IgnoreWhen (missesCapabilities = Capabilities .QUERY , clusterTypes = ClusterType .MOCKED )
@@ -101,6 +95,9 @@ public class CouchbaseRepositoryQueryIntegrationTests extends ClusterAwareIntegr
101
95
102
96
@ Autowired AirportRepository airportRepository ;
103
97
98
+ @ Autowired
99
+ AirportDefaultConsistencyRepository airportDefaultConsistencyRepository ;
100
+
104
101
@ Autowired UserRepository userRepository ;
105
102
106
103
@ Autowired CouchbaseTemplate couchbaseTemplate ;
@@ -212,9 +209,9 @@ public void saveNotBounded() {
212
209
Airport airport2 = null ;
213
210
for (int i = 1 ; i <= 100 ; i ++) {
214
211
// set version == 0 so save() will be an upsert, not a replace
215
- Airport saved = airportRepository .save (vie .clearVersion ());
212
+ Airport saved = airportDefaultConsistencyRepository .save (vie .clearVersion ());
216
213
try {
217
- airport2 = airportRepository .iata (saved .getIata ());
214
+ airport2 = airportDefaultConsistencyRepository .iata (saved .getIata ());
218
215
if (airport2 == null ) {
219
216
break ;
220
217
}
@@ -227,14 +224,14 @@ public void saveNotBounded() {
227
224
assertEquals (vie .getId (), removeResult .getId ());
228
225
assertTrue (removeResult .getCas () != 0 );
229
226
assertTrue (removeResult .getMutationToken ().isPresent ());
230
- Airport airport3 = airportRepository .iata (vie .getIata ());
227
+ Airport airport3 = airportDefaultConsistencyRepository .iata (vie .getIata ());
231
228
assertNull (airport3 , "should have been removed" );
232
229
}
233
230
}
234
231
assertNull (airport2 , "airport2 should have likely been null at least once" );
235
- Airport saved = airportRepository .save (vie .clearVersion ());
232
+ Airport saved = airportDefaultConsistencyRepository .save (vie .clearVersion ());
236
233
couchbaseTemplate .findByQuery (Airport .class ).withConsistency (REQUEST_PLUS ).all ();
237
- airport2 = airportRepository .iata (vie .getIata ());
234
+ airport2 = airportDefaultConsistencyRepository .iata (vie .getIata ());
238
235
RemoveResult removeResult = couchbaseTemplate .removeById ().one (saved .getId ());
239
236
assertNotNull (airport2 , "airport2 should have been found" );
240
237
}
@@ -244,7 +241,7 @@ public void saveNotBoundedRequestPlus() {
244
241
ApplicationContext ac = new AnnotationConfigApplicationContext (ConfigRequestPlus .class );
245
242
// the Config class has been modified, these need to be loaded again
246
243
CouchbaseTemplate couchbaseTemplateRP = (CouchbaseTemplate ) ac .getBean (COUCHBASE_TEMPLATE );
247
- AirportRepository airportRepositoryRP = (AirportRepository ) ac .getBean ("airportRepository " );
244
+ AirportDefaultConsistencyRepository airportRepositoryRP = (AirportDefaultConsistencyRepository ) ac .getBean ("airportDefaultConsistencyRepository " );
248
245
249
246
// save() followed by query with NOT_BOUNDED will result in not finding the document
250
247
Airport vie = new Airport ("airports::vie" , "vie" , "low9" );
@@ -277,6 +274,36 @@ public void saveNotBoundedRequestPlus() {
277
274
assertFalse (!airports .isEmpty (), "airports should have been empty" );
278
275
}
279
276
277
+
278
+ @ Test
279
+ public void saveNotBoundedRequestPlusWithDefaultRepository () {
280
+ ApplicationContext ac = new AnnotationConfigApplicationContext (ConfigRequestPlus .class );
281
+ // the Config class has been modified, these need to be loaded again
282
+ CouchbaseTemplate couchbaseTemplateRP = (CouchbaseTemplate ) ac .getBean (COUCHBASE_TEMPLATE );
283
+ AirportDefaultConsistencyRepository airportRepositoryRP = (AirportDefaultConsistencyRepository ) ac .getBean ("airportDefaultConsistencyRepository" );
284
+
285
+ List <Airport > sizeBeforeTest = airportRepositoryRP .findAll ();
286
+ assertEquals (0 , sizeBeforeTest .size ());
287
+
288
+ List <String > idsToRemove = new ArrayList <>(100 );
289
+ for (int i = 1 ; i <= 100 ; i ++) {
290
+ Airport vie = new Airport ("airports::vie" + i , "vie" + i , "low9" );
291
+ Airport saved = airportRepositoryRP .save (vie );
292
+ idsToRemove .add (saved .getId ());
293
+ }
294
+
295
+ List <Airport > allSaved = airportRepositoryRP .findAll ();
296
+
297
+ boolean success = allSaved .size () == 100 ;
298
+
299
+ for (String idToRemove : idsToRemove ) {
300
+ couchbaseTemplateRP .removeById ().one (idToRemove );
301
+ }
302
+
303
+ assertTrue (success );
304
+ }
305
+
306
+
280
307
@ Test
281
308
void findByTypeAlias () {
282
309
Airport vie = null ;
0 commit comments