|
34 | 34 | import java.util.concurrent.Future;
|
35 | 35 | import java.util.stream.Collectors;
|
36 | 36 |
|
37 |
| -import com.couchbase.client.java.query.QueryScanConsistency; |
38 | 37 | import org.junit.jupiter.api.BeforeEach;
|
39 | 38 | import org.junit.jupiter.api.Test;
|
40 | 39 | import org.springframework.beans.factory.annotation.Autowired;
|
|
66 | 65 | import org.springframework.data.repository.core.support.DefaultRepositoryMetadata;
|
67 | 66 | import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
68 | 67 |
|
| 68 | +import com.couchbase.client.core.error.CouchbaseException; |
69 | 69 | import com.couchbase.client.core.error.IndexExistsException;
|
| 70 | +import com.couchbase.client.java.query.QueryScanConsistency; |
70 | 71 |
|
71 | 72 | /**
|
72 | 73 | * Repository tests
|
@@ -180,6 +181,7 @@ void findByEnum() {
|
180 | 181 | airportRepository.delete(vie);
|
181 | 182 | }
|
182 | 183 | }
|
| 184 | + |
183 | 185 | @Test
|
184 | 186 | public void testCas() {
|
185 | 187 | User user = new User("1", "Dave", "Wilson");
|
@@ -271,6 +273,19 @@ void threadSafeParametersTest() throws Exception {
|
271 | 273 | }
|
272 | 274 | }
|
273 | 275 |
|
| 276 | + @Test |
| 277 | + void stringQueryTest() throws Exception { |
| 278 | + Airport airport = new Airport("airports::vie", "vie", "lowx"); |
| 279 | + try { |
| 280 | + airportRepository.save(airport); |
| 281 | + airportRepository.getAllByIata("vie").get(0); // gets at least one with no exception |
| 282 | + assertThrows(CouchbaseException.class, () -> airportRepository.getAllByIataNoID("vie")); |
| 283 | + assertThrows(CouchbaseException.class, () -> airportRepository.getAllByIataNoCAS("vie")); |
| 284 | + } finally { |
| 285 | + airportRepository.deleteById(airport.getId()); |
| 286 | + } |
| 287 | + } |
| 288 | + |
274 | 289 | @Test
|
275 | 290 | void threadSafeStringParametersTest() throws Exception {
|
276 | 291 | String[] iatas = { "JFK", "IAD", "SFO", "SJC", "SEA", "LAX", "PHX" };
|
@@ -332,14 +347,15 @@ void deleteAllById() {
|
332 | 347 | void couchbaseRepositoryQuery() throws Exception {
|
333 | 348 | User user = new User("1", "Dave", "Wilson");
|
334 | 349 | userRepository.save(user);
|
335 |
| - couchbaseTemplate.findByQuery(User.class).withConsistency(QueryScanConsistency.REQUEST_PLUS).matching(QueryCriteria.where("firstname").is("Dave").and("`1`").is("`1`")).all(); |
| 350 | + couchbaseTemplate.findByQuery(User.class).withConsistency(QueryScanConsistency.REQUEST_PLUS) |
| 351 | + .matching(QueryCriteria.where("firstname").is("Dave").and("`1`").is("`1`")).all(); |
336 | 352 | String input = "findByFirstname";
|
337 | 353 | Method method = UserRepository.class.getMethod(input, String.class);
|
338 | 354 | CouchbaseQueryMethod queryMethod = new CouchbaseQueryMethod(method,
|
339 | 355 | new DefaultRepositoryMetadata(UserRepository.class), new SpelAwareProxyProjectionFactory(),
|
340 | 356 | couchbaseTemplate.getConverter().getMappingContext());
|
341 | 357 | CouchbaseRepositoryQuery query = new CouchbaseRepositoryQuery(couchbaseTemplate, queryMethod, null);
|
342 |
| - List<User> users = (List<User>)query.execute(new String[] { "Dave" }); |
| 358 | + List<User> users = (List<User>) query.execute(new String[] { "Dave" }); |
343 | 359 | assertEquals(user, users.get(0));
|
344 | 360 | }
|
345 | 361 |
|
|
0 commit comments