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