16
16
17
17
package org .springframework .data .couchbase .repository ;
18
18
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 ;
43
22
import org .junit .jupiter .api .BeforeEach ;
44
23
import org .junit .jupiter .api .Test ;
45
24
import org .springframework .beans .factory .annotation .Autowired ;
57
36
import org .springframework .data .couchbase .core .query .N1QLExpression ;
58
37
import org .springframework .data .couchbase .core .query .Query ;
59
38
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 ;
39
+ import org .springframework .data .couchbase .domain .*;
69
40
import org .springframework .data .couchbase .domain .time .AuditingDateTimeProvider ;
70
41
import org .springframework .data .couchbase .repository .auditing .EnableCouchbaseAuditing ;
71
42
import org .springframework .data .couchbase .repository .config .EnableCouchbaseRepositories ;
82
53
import org .springframework .data .repository .core .support .DefaultRepositoryMetadata ;
83
54
import org .springframework .test .context .junit .jupiter .SpringJUnitConfig ;
84
55
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 ;
88
74
89
75
/**
90
76
* Repository tests
91
77
*
92
78
* @author Michael Nitschinger
93
79
* @author Michael Reiche
94
80
* @author Jens Schauder
81
+ * @author Jonathan Massuchetti
95
82
*/
96
83
@ SpringJUnitConfig (CouchbaseRepositoryQueryIntegrationTests .Config .class )
97
84
@ IgnoreWhen (missesCapabilities = Capabilities .QUERY , clusterTypes = ClusterType .MOCKED )
@@ -101,6 +88,9 @@ public class CouchbaseRepositoryQueryIntegrationTests extends ClusterAwareIntegr
101
88
102
89
@ Autowired AirportRepository airportRepository ;
103
90
91
+ @ Autowired
92
+ AirportDefaultConsistencyRepository airportDefaultConsistencyRepository ;
93
+
104
94
@ Autowired UserRepository userRepository ;
105
95
106
96
@ Autowired CouchbaseTemplate couchbaseTemplate ;
@@ -212,9 +202,9 @@ public void saveNotBounded() {
212
202
Airport airport2 = null ;
213
203
for (int i = 1 ; i <= 100 ; i ++) {
214
204
// 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 ());
216
206
try {
217
- airport2 = airportRepository .iata (saved .getIata ());
207
+ airport2 = airportDefaultConsistencyRepository .iata (saved .getIata ());
218
208
if (airport2 == null ) {
219
209
break ;
220
210
}
@@ -227,14 +217,14 @@ public void saveNotBounded() {
227
217
assertEquals (vie .getId (), removeResult .getId ());
228
218
assertTrue (removeResult .getCas () != 0 );
229
219
assertTrue (removeResult .getMutationToken ().isPresent ());
230
- Airport airport3 = airportRepository .iata (vie .getIata ());
220
+ Airport airport3 = airportDefaultConsistencyRepository .iata (vie .getIata ());
231
221
assertNull (airport3 , "should have been removed" );
232
222
}
233
223
}
234
224
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 ());
236
226
couchbaseTemplate .findByQuery (Airport .class ).withConsistency (REQUEST_PLUS ).all ();
237
- airport2 = airportRepository .iata (vie .getIata ());
227
+ airport2 = airportDefaultConsistencyRepository .iata (vie .getIata ());
238
228
RemoveResult removeResult = couchbaseTemplate .removeById ().one (saved .getId ());
239
229
assertNotNull (airport2 , "airport2 should have been found" );
240
230
}
@@ -244,7 +234,7 @@ public void saveNotBoundedRequestPlus() {
244
234
ApplicationContext ac = new AnnotationConfigApplicationContext (ConfigRequestPlus .class );
245
235
// the Config class has been modified, these need to be loaded again
246
236
CouchbaseTemplate couchbaseTemplateRP = (CouchbaseTemplate ) ac .getBean (COUCHBASE_TEMPLATE );
247
- AirportRepository airportRepositoryRP = (AirportRepository ) ac .getBean ("airportRepository " );
237
+ AirportDefaultConsistencyRepository airportRepositoryRP = (AirportDefaultConsistencyRepository ) ac .getBean ("airportDefaultConsistencyRepository " );
248
238
249
239
// save() followed by query with NOT_BOUNDED will result in not finding the document
250
240
Airport vie = new Airport ("airports::vie" , "vie" , "low9" );
@@ -277,6 +267,28 @@ public void saveNotBoundedRequestPlus() {
277
267
assertFalse (!airports .isEmpty (), "airports should have been empty" );
278
268
}
279
269
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
+
280
292
@ Test
281
293
void findByTypeAlias () {
282
294
Airport vie = null ;
0 commit comments