From ec8c86c610a6d8b099027f3468c1e677f4f83343 Mon Sep 17 00:00:00 2001 From: Michael Reiche Date: Wed, 9 Feb 2022 21:53:32 -0800 Subject: [PATCH] Have tests remove the documents they insert. Closes #1335. --- ...hbaseTemplateKeyValueIntegrationTests.java | 18 +++-- ...mplateQueryCollectionIntegrationTests.java | 60 +++++++------- ...ouchbaseTemplateQueryIntegrationTests.java | 35 ++++---- .../core/CustomTypeKeyIntegrationTests.java | 6 +- ...hbaseTemplateKeyValueIntegrationTests.java | 9 ++- ...mplateQueryCollectionIntegrationTests.java | 79 +++++++++++-------- .../data/couchbase/domain/FluxTest.java | 56 +++++++++---- ...aseRepositoryKeyValueIntegrationTests.java | 20 +++-- ...aseRepositoryKeyValueIntegrationTests.java | 8 +- 9 files changed, 173 insertions(+), 118 deletions(-) diff --git a/src/test/java/org/springframework/data/couchbase/core/CouchbaseTemplateKeyValueIntegrationTests.java b/src/test/java/org/springframework/data/couchbase/core/CouchbaseTemplateKeyValueIntegrationTests.java index 66bf472a6..ec405b741 100644 --- a/src/test/java/org/springframework/data/couchbase/core/CouchbaseTemplateKeyValueIntegrationTests.java +++ b/src/test/java/org/springframework/data/couchbase/core/CouchbaseTemplateKeyValueIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors + * Copyright 2012-2022 the original author or authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,7 +27,6 @@ import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.time.Duration; -import java.time.Instant; import java.util.Arrays; import java.util.Collection; import java.util.HashSet; @@ -289,13 +288,16 @@ void withExpiryAndExpiryAnnotation() User found = couchbaseTemplate.findById(user.getClass()).one(user.getId()); if (user.getId().endsWith(UserAnnotated3.class.getSimpleName())) { if (found == null) { - errorList.add("\nfound should be non null as it was set to have no expiry " + user.getId() ); + errorList.add("\nfound should be non null as it was set to have no expiry " + user.getId()); } } else { if (found != null) { errorList.add("\nfound should have been null as document should be expired " + user.getId()); } } + if (found != null) { + couchbaseTemplate.removeById(user.getClass()).one(user.getId()); + } } if (!errorList.isEmpty()) { @@ -310,7 +312,7 @@ void findDocWhichDoesNotExist() { @Test void upsertAndReplaceById() { - User user = new User(UUID.randomUUID().toString(), "firstname", "lastname"); + User user = new User(UUID.randomUUID().toString(), "firstname_upsertAndReplaceById", "lastname"); User modified = couchbaseTemplate.upsertById(User.class).one(user); assertEquals(user, modified); @@ -335,7 +337,6 @@ void upsertAndRemoveById() { assertEquals(user.getId(), removeResult.getId()); assertTrue(removeResult.getCas() != 0); assertTrue(removeResult.getMutationToken().isPresent()); - assertNull(couchbaseTemplate.findById(User.class).one(user.getId())); } { @@ -360,6 +361,7 @@ void insertById() { User inserted = couchbaseTemplate.insertById(User.class).one(user); assertEquals(user, inserted); assertThrows(DuplicateKeyException.class, () -> couchbaseTemplate.insertById(User.class).one(user)); + couchbaseTemplate.removeById(User.class).one(user.getId()); } @Test @@ -384,6 +386,7 @@ void insertByIdwithDurability() { } assertEquals(user, inserted); assertThrows(DuplicateKeyException.class, () -> couchbaseTemplate.insertById(User.class).one(user)); + couchbaseTemplate.removeById(User.class).one(user.getId()); } @Test @@ -395,12 +398,13 @@ void existsById() { User inserted = couchbaseTemplate.insertById(User.class).one(user); assertEquals(user, inserted); assertTrue(couchbaseTemplate.existsById().one(id)); + couchbaseTemplate.removeById(User.class).one(user.getId()); } @Test @IgnoreWhen(clusterTypes = ClusterType.MOCKED) void saveAndFindImmutableById() { - PersonValue personValue = new PersonValue(UUID.randomUUID().toString(), 123, "f", "l"); + PersonValue personValue = new PersonValue(UUID.randomUUID().toString(), 123, "408", "l"); PersonValue inserted = null; PersonValue upserted = null; PersonValue replaced = null; @@ -431,7 +435,7 @@ void saveAndFindImmutableById() { PersonValue foundReplaced = couchbaseTemplate.findById(PersonValue.class).one(replaced.getId()); assertNotNull(foundReplaced, "replaced personValue not found"); assertEquals(replaced, foundReplaced); - + couchbaseTemplate.removeById(PersonValue.class).one(replaced.getId()); } private void sleepSecs(int i) { diff --git a/src/test/java/org/springframework/data/couchbase/core/CouchbaseTemplateQueryCollectionIntegrationTests.java b/src/test/java/org/springframework/data/couchbase/core/CouchbaseTemplateQueryCollectionIntegrationTests.java index 7cb960916..1307cabbf 100644 --- a/src/test/java/org/springframework/data/couchbase/core/CouchbaseTemplateQueryCollectionIntegrationTests.java +++ b/src/test/java/org/springframework/data/couchbase/core/CouchbaseTemplateQueryCollectionIntegrationTests.java @@ -103,13 +103,16 @@ public void beforeEach() { // first call the super method super.beforeEach(); // then do processing for this class - couchbaseTemplate.removeByQuery(User.class).inCollection(collectionName).all(); + couchbaseTemplate.removeByQuery(User.class).withConsistency(QueryScanConsistency.REQUEST_PLUS) + .inCollection(collectionName).all(); couchbaseTemplate.findByQuery(User.class).withConsistency(QueryScanConsistency.REQUEST_PLUS) .inCollection(collectionName).all(); - couchbaseTemplate.removeByQuery(Airport.class).inScope(scopeName).inCollection(collectionName).all(); + couchbaseTemplate.removeByQuery(Airport.class).withConsistency(QueryScanConsistency.REQUEST_PLUS).inScope(scopeName) + .inCollection(collectionName).all(); couchbaseTemplate.findByQuery(Airport.class).withConsistency(QueryScanConsistency.REQUEST_PLUS).inScope(scopeName) .inCollection(collectionName).all(); - couchbaseTemplate.removeByQuery(Airport.class).inScope(otherScope).inCollection(otherCollection).all(); + couchbaseTemplate.removeByQuery(Airport.class).withConsistency(QueryScanConsistency.REQUEST_PLUS) + .inScope(otherScope).inCollection(otherCollection).all(); couchbaseTemplate.findByQuery(Airport.class).withConsistency(QueryScanConsistency.REQUEST_PLUS).inScope(otherScope) .inCollection(otherCollection).all(); } @@ -355,7 +358,7 @@ void distinctReactive() { assertEquals(2, count1); // count (distinct { iata, icao } ) - Long count2 = reactiveCouchbaseTemplate.findByQuery(Airport.class).distinct(new String[] {"iata", "icao"}) + Long count2 = reactiveCouchbaseTemplate.findByQuery(Airport.class).distinct(new String[] { "iata", "icao" }) .withConsistency(QueryScanConsistency.REQUEST_PLUS).inCollection(collectionName).count().block(); assertEquals(7, count2); @@ -384,7 +387,7 @@ public void existsById() { // 1 GetOptions options = GetOptions.getOptions().timeout(Duration.ofSeconds(10)); ExistsOptions existsOptions = ExistsOptions.existsOptions().timeout(Duration.ofSeconds(10)); Airport saved = couchbaseTemplate.insertById(Airport.class).inScope(scopeName).inCollection(collectionName) - .one(vie); + .one(vie.withIcao("398")); try { Boolean exists = couchbaseTemplate.existsById().inScope(scopeName).inCollection(collectionName) .withOptions(existsOptions).one(saved.getId()); @@ -399,7 +402,7 @@ public void existsById() { // 1 public void findByAnalytics() { // 2 AnalyticsOptions options = AnalyticsOptions.analyticsOptions().timeout(Duration.ofSeconds(10)); Airport saved = couchbaseTemplate.insertById(Airport.class).inScope(scopeName).inCollection(collectionName) - .one(vie); + .one(vie.withIcao("413")); try { List found = couchbaseTemplate.findByAnalytics(Airport.class).inScope(scopeName) .inCollection(collectionName).withOptions(options).all(); @@ -413,7 +416,7 @@ public void findByAnalytics() { // 2 public void findById() { // 3 GetOptions options = GetOptions.getOptions().timeout(Duration.ofSeconds(10)); Airport saved = couchbaseTemplate.insertById(Airport.class).inScope(scopeName).inCollection(collectionName) - .one(vie); + .one(vie.withIcao("427")); try { Airport found = couchbaseTemplate.findById(Airport.class).inScope(scopeName).inCollection(collectionName) .withOptions(options).one(saved.getId()); @@ -427,7 +430,7 @@ public void findById() { // 3 public void findByQuery() { // 4 QueryOptions options = QueryOptions.queryOptions().timeout(Duration.ofSeconds(10)); Airport saved = couchbaseTemplate.insertById(Airport.class).inScope(scopeName).inCollection(collectionName) - .one(vie); + .one(vie.withIcao("441")); try { List found = couchbaseTemplate.findByQuery(Airport.class) .withConsistency(QueryScanConsistency.REQUEST_PLUS).inScope(scopeName).inCollection(collectionName) @@ -442,7 +445,7 @@ public void findByQuery() { // 4 public void findFromReplicasById() { // 5 GetAnyReplicaOptions options = GetAnyReplicaOptions.getAnyReplicaOptions().timeout(Duration.ofSeconds(10)); Airport saved = couchbaseTemplate.insertById(Airport.class).inScope(scopeName).inCollection(collectionName) - .one(vie); + .one(vie.withIcao("456")); try { Airport found = couchbaseTemplate.findFromReplicasById(Airport.class).inScope(scopeName) .inCollection(collectionName).withOptions(options).any(saved.getId()); @@ -471,7 +474,7 @@ public void insertById() { // 6 public void removeById() { // 7 RemoveOptions options = RemoveOptions.removeOptions().timeout(Duration.ofSeconds(10)); Airport saved = couchbaseTemplate.insertById(Airport.class).inScope(scopeName).inCollection(collectionName) - .one(vie); + .one(vie.withIcao("485")); RemoveResult removeResult = couchbaseTemplate.removeById().inScope(scopeName).inCollection(collectionName) .withOptions(options).one(saved.getId()); assertEquals(saved.getId(), removeResult.getId()); @@ -481,7 +484,7 @@ public void removeById() { // 7 public void removeByQuery() { // 8 QueryOptions options = QueryOptions.queryOptions().timeout(Duration.ofSeconds(10)); Airport saved = couchbaseTemplate.insertById(Airport.class).inScope(scopeName).inCollection(collectionName) - .one(vie); + .one(vie.withIcao("495")); List removeResults = couchbaseTemplate.removeByQuery(Airport.class) .withConsistency(QueryScanConsistency.REQUEST_PLUS).inScope(scopeName).inCollection(collectionName) .withOptions(options).matching(Query.query(QueryCriteria.where("iata").is(vie.getIata()))).all(); @@ -494,7 +497,7 @@ public void replaceById() { // 9 ReplaceOptions options = ReplaceOptions.replaceOptions().timeout(Duration.ofSeconds(10)); GetOptions getOptions = GetOptions.getOptions().timeout(Duration.ofSeconds(10)); Airport saved = couchbaseTemplate.insertById(Airport.class).inScope(scopeName).inCollection(collectionName) - .withOptions(insertOptions).one(vie); + .withOptions(insertOptions).one(vie.withIcao("508")); Airport replaced = couchbaseTemplate.replaceById(Airport.class).inScope(scopeName).inCollection(collectionName) .withOptions(options).one(vie.withIcao("newIcao")); try { @@ -512,7 +515,7 @@ public void upsertById() { // 10 GetOptions getOptions = GetOptions.getOptions().timeout(Duration.ofSeconds(10)); Airport saved = couchbaseTemplate.upsertById(Airport.class).inScope(scopeName).inCollection(collectionName) - .withOptions(options).one(vie); + .withOptions(options).one(vie.withIcao("526")); try { Airport found = couchbaseTemplate.findById(Airport.class).inScope(scopeName).inCollection(collectionName) .withOptions(getOptions).one(saved.getId()); @@ -527,13 +530,14 @@ public void existsByIdOther() { // 1 GetOptions options = GetOptions.getOptions().timeout(Duration.ofSeconds(10)); ExistsOptions existsOptions = ExistsOptions.existsOptions().timeout(Duration.ofSeconds(10)); Airport saved = couchbaseTemplate.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection) - .one(vie); + .one(vie.withIcao("lowg")); + try { Boolean exists = couchbaseTemplate.existsById().inScope(otherScope).inCollection(otherCollection) - .withOptions(existsOptions).one(saved.getId()); - assertTrue(exists, "Airport should exist: " + saved.getId()); + .withOptions(existsOptions).one(vie.getId()); + assertTrue(exists, "Airport should exist: " + vie.getId()); } finally { - couchbaseTemplate.removeById().inScope(otherScope).inCollection(otherCollection).one(saved.getId()); + couchbaseTemplate.removeById().inScope(otherScope).inCollection(otherCollection).one(vie.getId()); } } @@ -542,7 +546,7 @@ public void existsByIdOther() { // 1 public void findByAnalyticsOther() { // 2 AnalyticsOptions options = AnalyticsOptions.analyticsOptions().timeout(Duration.ofSeconds(10)); Airport saved = couchbaseTemplate.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection) - .one(vie); + .one(vie.withIcao("566")); try { List found = couchbaseTemplate.findByAnalytics(Airport.class).inScope(otherScope) .inCollection(otherCollection).withOptions(options).all(); @@ -556,7 +560,7 @@ public void findByAnalyticsOther() { // 2 public void findByIdOther() { // 3 GetOptions options = GetOptions.getOptions().timeout(Duration.ofSeconds(10)); Airport saved = couchbaseTemplate.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection) - .one(vie); + .one(vie.withIcao("580")); try { Airport found = couchbaseTemplate.findById(Airport.class).inScope(otherScope).inCollection(otherCollection) .withOptions(options).one(saved.getId()); @@ -570,7 +574,7 @@ public void findByIdOther() { // 3 public void findByQueryOther() { // 4 QueryOptions options = QueryOptions.queryOptions().timeout(Duration.ofSeconds(10)); Airport saved = couchbaseTemplate.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection) - .one(vie); + .one(vie.withIcao("594")); try { List found = couchbaseTemplate.findByQuery(Airport.class) .withConsistency(QueryScanConsistency.REQUEST_PLUS).inScope(otherScope).inCollection(otherCollection) @@ -585,7 +589,7 @@ public void findByQueryOther() { // 4 public void findFromReplicasByIdOther() { // 5 GetAnyReplicaOptions options = GetAnyReplicaOptions.getAnyReplicaOptions().timeout(Duration.ofSeconds(10)); Airport saved = couchbaseTemplate.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection) - .one(vie); + .one(vie.withIcao("609")); try { Airport found = couchbaseTemplate.findFromReplicasById(Airport.class).inScope(otherScope) .inCollection(otherCollection).withOptions(options).any(saved.getId()); @@ -614,7 +618,7 @@ public void insertByIdOther() { // 6 public void removeByIdOther() { // 7 RemoveOptions options = RemoveOptions.removeOptions().timeout(Duration.ofSeconds(10)); Airport saved = couchbaseTemplate.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection) - .one(vie); + .one(vie.withIcao("638")); RemoveResult removeResult = couchbaseTemplate.removeById().inScope(otherScope).inCollection(otherCollection) .withOptions(options).one(saved.getId()); assertEquals(saved.getId(), removeResult.getId()); @@ -624,7 +628,7 @@ public void removeByIdOther() { // 7 public void removeByQueryOther() { // 8 QueryOptions options = QueryOptions.queryOptions().timeout(Duration.ofSeconds(10)); Airport saved = couchbaseTemplate.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection) - .one(vie); + .one(vie.withIcao("648")); List removeResults = couchbaseTemplate.removeByQuery(Airport.class) .withConsistency(QueryScanConsistency.REQUEST_PLUS).inScope(otherScope).inCollection(otherCollection) .withOptions(options).matching(Query.query(QueryCriteria.where("iata").is(vie.getIata()))).all(); @@ -637,7 +641,7 @@ public void replaceByIdOther() { // 9 ReplaceOptions options = ReplaceOptions.replaceOptions().timeout(Duration.ofSeconds(10)); GetOptions getOptions = GetOptions.getOptions().timeout(Duration.ofSeconds(10)); Airport saved = couchbaseTemplate.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection) - .withOptions(insertOptions).one(vie); + .withOptions(insertOptions).one(vie.withIcao("661")); Airport replaced = couchbaseTemplate.replaceById(Airport.class).inScope(otherScope).inCollection(otherCollection) .withOptions(options).one(vie.withIcao("newIcao")); try { @@ -655,7 +659,7 @@ public void upsertByIdOther() { // 10 GetOptions getOptions = GetOptions.getOptions().timeout(Duration.ofSeconds(10)); Airport saved = couchbaseTemplate.upsertById(Airport.class).inScope(otherScope).inCollection(otherCollection) - .withOptions(options).one(vie); + .withOptions(options).one(vie.withIcao("679")); try { Airport found = couchbaseTemplate.findById(Airport.class).inScope(otherScope).inCollection(otherCollection) .withOptions(getOptions).one(saved.getId()); @@ -699,7 +703,7 @@ public void findByQueryOptions() { // 4 public void findFromReplicasByIdOptions() { // 5 GetAnyReplicaOptions options = GetAnyReplicaOptions.getAnyReplicaOptions().timeout(Duration.ofNanos(1000)); Airport saved = couchbaseTemplate.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection) - .one(vie); + .one(vie.withIcao("723")); try { Airport found = couchbaseTemplate.findFromReplicasById(Airport.class).inScope(otherScope) .inCollection(otherCollection).withOptions(options).any(saved.getId()); @@ -719,7 +723,7 @@ public void insertByIdOptions() { // 6 @Test public void removeByIdOptions() { // 7 - options Airport saved = couchbaseTemplate.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection) - .one(vie); + .one(vie.withIcao("743")); RemoveOptions options = RemoveOptions.removeOptions().timeout(Duration.ofNanos(10)); assertThrows(AmbiguousTimeoutException.class, () -> couchbaseTemplate.removeById().inScope(otherScope) .inCollection(otherCollection).withOptions(options).one(vie.getId())); @@ -746,7 +750,7 @@ public void replaceByIdOptions() { // 9 - options public void upsertByIdOptions() { // 10 - options UpsertOptions options = UpsertOptions.upsertOptions().timeout(Duration.ofNanos(10)); assertThrows(AmbiguousTimeoutException.class, () -> couchbaseTemplate.upsertById(Airport.class).inScope(otherScope) - .inCollection(otherCollection).withOptions(options).one(vie)); + .inCollection(otherCollection).withOptions(options).one(vie.withIcao("770"))); } @Test diff --git a/src/test/java/org/springframework/data/couchbase/core/CouchbaseTemplateQueryIntegrationTests.java b/src/test/java/org/springframework/data/couchbase/core/CouchbaseTemplateQueryIntegrationTests.java index 4223646ab..e6e749f12 100644 --- a/src/test/java/org/springframework/data/couchbase/core/CouchbaseTemplateQueryIntegrationTests.java +++ b/src/test/java/org/springframework/data/couchbase/core/CouchbaseTemplateQueryIntegrationTests.java @@ -31,7 +31,6 @@ import java.util.UUID; import java.util.stream.Collectors; -import com.couchbase.client.java.query.QueryOptions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.data.couchbase.core.query.Query; @@ -51,8 +50,6 @@ import org.springframework.data.couchbase.util.ClusterType; import org.springframework.data.couchbase.util.IgnoreWhen; import org.springframework.data.couchbase.util.JavaIntegrationTests; - -import com.couchbase.client.java.query.QueryScanConsistency; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; @@ -90,8 +87,7 @@ void findByQueryAll() { couchbaseTemplate.upsertById(User.class).all(Arrays.asList(user1, user2)); - final List foundUsers = couchbaseTemplate.findByQuery(User.class) - .withConsistency(REQUEST_PLUS).all(); + final List foundUsers = couchbaseTemplate.findByQuery(User.class).withConsistency(REQUEST_PLUS).all(); for (User u : foundUsers) { if (!(u.equals(user1) || u.equals(user2))) { @@ -133,8 +129,8 @@ void findByMatchingQuery() { couchbaseTemplate.upsertById(User.class).all(Arrays.asList(user1, user2, specialUser)); Query specialUsers = new Query(QueryCriteria.where(i("firstname")).like("special")); - final List foundUsers = couchbaseTemplate.findByQuery(User.class) - .withConsistency(REQUEST_PLUS).matching(specialUsers).all(); + final List foundUsers = couchbaseTemplate.findByQuery(User.class).withConsistency(REQUEST_PLUS) + .matching(specialUsers).all(); assertEquals(1, foundUsers.size()); } @@ -152,6 +148,7 @@ void findAssessmentDO() { assertEquals("123", foundUsers.get(0).getId(), "id"); assertEquals("44444444", foundUsers.get(0).getDocumentId(), "documentId"); assertEquals(ado, foundUsers.get(0)); + couchbaseTemplate.removeById(AssessmentDO.class).one(ado.getDocumentId()); } @Test @@ -196,10 +193,10 @@ void findByMatchingQueryProjected() { assertEquals(1, foundUsers.size()); final List foundUsersReactive = reactiveCouchbaseTemplate.findByQuery(User.class) - .as(UserJustLastName.class).withConsistency(REQUEST_PLUS).matching(specialUsers).all() - .collectList().block(); + .as(UserJustLastName.class).withConsistency(REQUEST_PLUS).matching(specialUsers).all().collectList().block(); assertEquals(1, foundUsersReactive.size()); + couchbaseTemplate.removeById(User.class).all(Arrays.asList(user1.getId(), user2.getId(), specialUser.getId())); } @Test @@ -233,8 +230,7 @@ void removeByMatchingQuery() { Query nonSpecialUsers = new Query(QueryCriteria.where(i("firstname")).notLike("special")); - couchbaseTemplate.removeByQuery(User.class).withConsistency(REQUEST_PLUS) - .matching(nonSpecialUsers).all(); + couchbaseTemplate.removeByQuery(User.class).withConsistency(REQUEST_PLUS).matching(nonSpecialUsers).all(); assertNull(couchbaseTemplate.findById(User.class).one(user1.getId())); assertNull(couchbaseTemplate.findById(User.class).one(user2.getId())); @@ -324,24 +320,27 @@ void sortedTemplate() { String[] iatas = { "JFK", "IAD", "SFO", "SJC", "SEA", "LAX", "PHX" }; try { - couchbaseTemplate.insertById(Airport.class).all( - Arrays.stream(iatas).map((iata) -> new Airport("airports::" + iata, iata, iata.toLowerCase(Locale.ROOT))) + couchbaseTemplate.insertById(Airport.class) + .all(Arrays.stream(iatas).map((iata) -> new Airport("airports::" + iata, iata, iata.toLowerCase(Locale.ROOT))) .collect(Collectors.toSet())); - org.springframework.data.couchbase.core.query.Query query = org.springframework.data.couchbase.core.query.Query.query(QueryCriteria.where("iata").isNotNull()); + org.springframework.data.couchbase.core.query.Query query = org.springframework.data.couchbase.core.query.Query + .query(QueryCriteria.where("iata").isNotNull()); Pageable pageableWithSort = PageRequest.of(0, 7, Sort.by("iata")); query.with(pageableWithSort); - List airports = couchbaseTemplate.findByQuery(Airport.class).withConsistency(REQUEST_PLUS).matching(query).all(); + List airports = couchbaseTemplate.findByQuery(Airport.class).withConsistency(REQUEST_PLUS) + .matching(query).all(); String[] sortedIatas = iatas.clone(); - System.out.println(""+iatas.length+" "+sortedIatas.length); + System.out.println("" + iatas.length + " " + sortedIatas.length); Arrays.sort(sortedIatas); - for(int i=0; i< pageableWithSort.getPageSize(); i++){ + for (int i = 0; i < pageableWithSort.getPageSize(); i++) { System.out.println(airports.get(i).getIata()); assertEquals(sortedIatas[i], airports.get(i).getIata()); } } finally { - couchbaseTemplate.removeById(Airport.class).all(Arrays.stream(iatas).map((iata) -> "airports::" + iata).collect(Collectors.toSet())); + couchbaseTemplate.removeById(Airport.class) + .all(Arrays.stream(iatas).map((iata) -> "airports::" + iata).collect(Collectors.toSet())); } } diff --git a/src/test/java/org/springframework/data/couchbase/core/CustomTypeKeyIntegrationTests.java b/src/test/java/org/springframework/data/couchbase/core/CustomTypeKeyIntegrationTests.java index 40adb9c10..77a55c3c5 100644 --- a/src/test/java/org/springframework/data/couchbase/core/CustomTypeKeyIntegrationTests.java +++ b/src/test/java/org/springframework/data/couchbase/core/CustomTypeKeyIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors + * Copyright 2012-2022 the original author or authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,6 +37,9 @@ import com.couchbase.client.java.kv.GetResult; +/** + * @author Michael Reiche + */ @SpringJUnitConfig(CustomTypeKeyIntegrationTests.Config.class) @IgnoreWhen(clusterTypes = ClusterType.MOCKED) public class CustomTypeKeyIntegrationTests extends ClusterAwareIntegrationTests { @@ -62,6 +65,7 @@ void saveSimpleEntityCorrectlyWithDifferentTypeKey() { assertEquals("org.springframework.data.couchbase.domain.User", getResult.contentAsObject().getString(CUSTOM_TYPE_KEY)); assertFalse(getResult.contentAsObject().containsKey(DefaultCouchbaseTypeMapper.DEFAULT_TYPE_KEY)); + operations.removeById(User.class).one(user.getId()); } @Configuration diff --git a/src/test/java/org/springframework/data/couchbase/core/ReactiveCouchbaseTemplateKeyValueIntegrationTests.java b/src/test/java/org/springframework/data/couchbase/core/ReactiveCouchbaseTemplateKeyValueIntegrationTests.java index 379e76fc3..2bb669cbb 100644 --- a/src/test/java/org/springframework/data/couchbase/core/ReactiveCouchbaseTemplateKeyValueIntegrationTests.java +++ b/src/test/java/org/springframework/data/couchbase/core/ReactiveCouchbaseTemplateKeyValueIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors + * Copyright 2012-2022 the original author or authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -232,6 +232,9 @@ void withExpiryAndExpiryAnnotation() errorList.add("\nfound should have been null as document should be expired " + user.getId()); } } + if (found != null) { + couchbaseTemplate.removeById(user.getClass()).one(user.getId()); + } } if (!errorList.isEmpty()) { @@ -323,7 +326,7 @@ void existsById() { @Test @IgnoreWhen(clusterTypes = ClusterType.MOCKED) void saveAndFindImmutableById() { - PersonValue personValue = new PersonValue(UUID.randomUUID().toString(), 123, "f", "l"); + PersonValue personValue = new PersonValue(UUID.randomUUID().toString(), 123, "329", "l"); PersonValue inserted; PersonValue upserted; PersonValue replaced; @@ -354,7 +357,7 @@ void saveAndFindImmutableById() { PersonValue foundReplaced = reactiveCouchbaseTemplate.findById(PersonValue.class).one(replaced.getId()).block(); assertNotNull(foundReplaced, "replaced personValue not found"); assertEquals(replaced, foundReplaced); - + couchbaseTemplate.removeById(PersonValue.class).one(replaced.getId()); } private void sleepSecs(int i) { diff --git a/src/test/java/org/springframework/data/couchbase/core/query/ReactiveCouchbaseTemplateQueryCollectionIntegrationTests.java b/src/test/java/org/springframework/data/couchbase/core/query/ReactiveCouchbaseTemplateQueryCollectionIntegrationTests.java index 5c5fd29cf..42edc672a 100644 --- a/src/test/java/org/springframework/data/couchbase/core/query/ReactiveCouchbaseTemplateQueryCollectionIntegrationTests.java +++ b/src/test/java/org/springframework/data/couchbase/core/query/ReactiveCouchbaseTemplateQueryCollectionIntegrationTests.java @@ -76,7 +76,7 @@ @IgnoreWhen(missesCapabilities = { Capabilities.QUERY, Capabilities.COLLECTIONS }, clusterTypes = ClusterType.MOCKED) class ReactiveCouchbaseTemplateQueryCollectionIntegrationTests extends CollectionAwareIntegrationTests { - Airport vie = new Airport("airports::vie", "vie", "low7"); + Airport vie = new Airport("airports::vie", "vie", "low80"); ReactiveCouchbaseTemplate template = reactiveCouchbaseTemplate; @BeforeAll @@ -101,13 +101,16 @@ public void beforeEach() { // first call the super method super.beforeEach(); // then do processing for this class - couchbaseTemplate.removeByQuery(User.class).inCollection(collectionName).all(); + couchbaseTemplate.removeByQuery(User.class).withConsistency(QueryScanConsistency.REQUEST_PLUS) + .inCollection(collectionName).all(); couchbaseTemplate.findByQuery(User.class).withConsistency(QueryScanConsistency.REQUEST_PLUS) .inCollection(collectionName).all(); - couchbaseTemplate.removeByQuery(Airport.class).inScope(scopeName).inCollection(collectionName).all(); + couchbaseTemplate.removeByQuery(Airport.class).withConsistency(QueryScanConsistency.REQUEST_PLUS).inScope(scopeName) + .inCollection(collectionName).all(); couchbaseTemplate.findByQuery(Airport.class).withConsistency(QueryScanConsistency.REQUEST_PLUS).inScope(scopeName) .inCollection(collectionName).all(); - couchbaseTemplate.removeByQuery(Airport.class).inScope(otherScope).inCollection(otherCollection).all(); + couchbaseTemplate.removeByQuery(Airport.class).withConsistency(QueryScanConsistency.REQUEST_PLUS) + .inScope(otherScope).inCollection(otherCollection).all(); couchbaseTemplate.findByQuery(Airport.class).withConsistency(QueryScanConsistency.REQUEST_PLUS).inScope(otherScope) .inCollection(otherCollection).all(); } @@ -350,7 +353,7 @@ void distinctReactive() { assertEquals(2, count1); // count( distinct { iata, icao } ) - Long count2 = reactiveCouchbaseTemplate.findByQuery(Airport.class).distinct(new String[] {"iata","icao"}) + Long count2 = reactiveCouchbaseTemplate.findByQuery(Airport.class).distinct(new String[] { "iata", "icao" }) .withConsistency(QueryScanConsistency.REQUEST_PLUS).inCollection(collectionName).count().block(); assertEquals(7, count2); @@ -378,7 +381,8 @@ void distinctReactive() { public void existsById() { // 1 GetOptions options = GetOptions.getOptions().timeout(Duration.ofSeconds(10)); ExistsOptions existsOptions = ExistsOptions.existsOptions().timeout(Duration.ofSeconds(10)); - Airport saved = template.insertById(Airport.class).inScope(scopeName).inCollection(collectionName).one(vie.withIcao("low7")).block(); + Airport saved = template.insertById(Airport.class).inScope(scopeName).inCollection(collectionName) + .one(vie.withIcao("low7")).block(); try { Boolean exists = template.existsById().inScope(scopeName).inCollection(collectionName).withOptions(existsOptions) .one(saved.getId()).block(); @@ -392,7 +396,8 @@ public void existsById() { // 1 @Disabled // needs analytics data set public void findByAnalytics() { // 2 AnalyticsOptions options = AnalyticsOptions.analyticsOptions().timeout(Duration.ofSeconds(10)); - Airport saved = template.insertById(Airport.class).inScope(scopeName).inCollection(collectionName).one(vie.withIcao("low8")).block(); + Airport saved = template.insertById(Airport.class).inScope(scopeName).inCollection(collectionName) + .one(vie.withIcao("low8")).block(); try { List found = template.findByAnalytics(Airport.class).inScope(scopeName).inCollection(collectionName) .withOptions(options).all().collectList().block(); @@ -405,7 +410,8 @@ public void findByAnalytics() { // 2 @Test public void findById() { // 3 GetOptions options = GetOptions.getOptions().timeout(Duration.ofSeconds(10)); - Airport saved = template.insertById(Airport.class).inScope(scopeName).inCollection(collectionName).one(vie.withIcao("low9")).block(); + Airport saved = template.insertById(Airport.class).inScope(scopeName).inCollection(collectionName) + .one(vie.withIcao("low9")).block(); try { Airport found = template.findById(Airport.class).inScope(scopeName).inCollection(collectionName) .withOptions(options).one(saved.getId()).block(); @@ -418,7 +424,8 @@ public void findById() { // 3 @Test public void findByQuery() { // 4 QueryOptions options = QueryOptions.queryOptions().timeout(Duration.ofSeconds(10)); - Airport saved = template.insertById(Airport.class).inScope(scopeName).inCollection(collectionName).one(vie.withIcao("lowa")).block(); + Airport saved = template.insertById(Airport.class).inScope(scopeName).inCollection(collectionName) + .one(vie.withIcao("lowa")).block(); try { List found = template.findByQuery(Airport.class).withConsistency(QueryScanConsistency.REQUEST_PLUS) .inScope(scopeName).inCollection(collectionName).withOptions(options).all().collectList().block(); @@ -431,7 +438,8 @@ public void findByQuery() { // 4 @Test public void findFromReplicasById() { // 5 GetAnyReplicaOptions options = GetAnyReplicaOptions.getAnyReplicaOptions().timeout(Duration.ofSeconds(10)); - Airport saved = template.insertById(Airport.class).inScope(scopeName).inCollection(collectionName).one(vie.withIcao("lowb")).block(); + Airport saved = template.insertById(Airport.class).inScope(scopeName).inCollection(collectionName) + .one(vie.withIcao("lowb")).block(); try { Airport found = template.findFromReplicasById(Airport.class).inScope(scopeName).inCollection(collectionName) .withOptions(options).any(saved.getId()).block(); @@ -459,7 +467,8 @@ public void insertById() { // 6 @Test public void removeById() { // 7 RemoveOptions options = RemoveOptions.removeOptions().timeout(Duration.ofSeconds(10)); - Airport saved = template.insertById(Airport.class).inScope(scopeName).inCollection(collectionName).one(vie.withIcao("lowd")).block(); + Airport saved = template.insertById(Airport.class).inScope(scopeName).inCollection(collectionName) + .one(vie.withIcao("lowd")).block(); RemoveResult removeResult = template.removeById().inScope(scopeName).inCollection(collectionName) .withOptions(options).one(saved.getId()).block(); assertEquals(saved.getId(), removeResult.getId()); @@ -468,7 +477,8 @@ public void removeById() { // 7 @Test public void removeByQuery() { // 8 QueryOptions options = QueryOptions.queryOptions().timeout(Duration.ofSeconds(10)); - Airport saved = template.insertById(Airport.class).inScope(scopeName).inCollection(collectionName).one(vie.withIcao("lowe")).block(); + Airport saved = template.insertById(Airport.class).inScope(scopeName).inCollection(collectionName) + .one(vie.withIcao("lowe")).block(); List removeResults = template.removeByQuery(Airport.class) .withConsistency(QueryScanConsistency.REQUEST_PLUS).inScope(scopeName).inCollection(collectionName) .withOptions(options).matching(Query.query(QueryCriteria.where("iata").is(vie.getIata()))).all().collectList() @@ -514,14 +524,15 @@ public void upsertById() { // 10 public void existsByIdOther() { // 1 GetOptions options = GetOptions.getOptions().timeout(Duration.ofSeconds(10)); ExistsOptions existsOptions = ExistsOptions.existsOptions().timeout(Duration.ofSeconds(10)); - Airport saved = template.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection).one(vie.withIcao("lowg")) - .block(); + Airport saved = template.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection) + .one(vie.withIcao("lowg")).block(); + try { Boolean exists = template.existsById().inScope(otherScope).inCollection(otherCollection) - .withOptions(existsOptions).one(saved.getId()).block(); - assertTrue(exists, "Airport should exist: " + saved.getId()); + .withOptions(existsOptions).one(vie.getId()).block(); + assertTrue(exists, "Airport should exist: " + vie.getId()); } finally { - template.removeById().inScope(otherScope).inCollection(otherCollection).one(saved.getId()).block(); + template.removeById().inScope(otherScope).inCollection(otherCollection).one(vie.getId()).block(); } } @@ -529,8 +540,8 @@ public void existsByIdOther() { // 1 @Disabled // needs analytics data set public void findByAnalyticsOther() { // 2 AnalyticsOptions options = AnalyticsOptions.analyticsOptions().timeout(Duration.ofSeconds(10)); - Airport saved = template.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection).one(vie.withIcao("lowh")) - .block(); + Airport saved = template.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection) + .one(vie.withIcao("lowh")).block(); try { List found = template.findByAnalytics(Airport.class).inScope(otherScope).inCollection(otherCollection) .withOptions(options).all().collectList().block(); @@ -543,8 +554,8 @@ public void findByAnalyticsOther() { // 2 @Test public void findByIdOther() { // 3 GetOptions options = GetOptions.getOptions().timeout(Duration.ofSeconds(10)); - Airport saved = template.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection).one(vie.withIcao("lowi")) - .block(); + Airport saved = template.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection) + .one(vie.withIcao("lowi")).block(); try { Airport found = template.findById(Airport.class).inScope(otherScope).inCollection(otherCollection) .withOptions(options).one(saved.getId()).block(); @@ -557,8 +568,8 @@ public void findByIdOther() { // 3 @Test public void findByQueryOther() { // 4 QueryOptions options = QueryOptions.queryOptions().timeout(Duration.ofSeconds(10)); - Airport saved = template.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection).one(vie.withIcao("lowj")) - .block(); + Airport saved = template.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection) + .one(vie.withIcao("lowj")).block(); try { List found = template.findByQuery(Airport.class).withConsistency(QueryScanConsistency.REQUEST_PLUS) .inScope(otherScope).inCollection(otherCollection).withOptions(options).all().collectList().block(); @@ -571,8 +582,8 @@ public void findByQueryOther() { // 4 @Test public void findFromReplicasByIdOther() { // 5 GetAnyReplicaOptions options = GetAnyReplicaOptions.getAnyReplicaOptions().timeout(Duration.ofSeconds(10)); - Airport saved = template.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection).one(vie.withIcao("lowk")) - .block(); + Airport saved = template.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection) + .one(vie.withIcao("lowk")).block(); try { Airport found = template.findFromReplicasById(Airport.class).inScope(otherScope).inCollection(otherCollection) .withOptions(options).any(saved.getId()).block(); @@ -600,8 +611,8 @@ public void insertByIdOther() { // 6 @Test public void removeByIdOther() { // 7 RemoveOptions options = RemoveOptions.removeOptions().timeout(Duration.ofSeconds(10)); - Airport saved = template.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection).one(vie.withIcao("lowm")) - .block(); + Airport saved = template.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection) + .one(vie.withIcao("lowm")).block(); RemoveResult removeResult = template.removeById().inScope(otherScope).inCollection(otherCollection) .withOptions(options).one(saved.getId()).block(); assertEquals(saved.getId(), removeResult.getId()); @@ -610,8 +621,8 @@ public void removeByIdOther() { // 7 @Test public void removeByQueryOther() { // 8 QueryOptions options = QueryOptions.queryOptions().timeout(Duration.ofSeconds(10)); - Airport saved = template.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection).one(vie.withIcao("lown")) - .block(); + Airport saved = template.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection) + .one(vie.withIcao("lown")).block(); List removeResults = template.removeByQuery(Airport.class) .withConsistency(QueryScanConsistency.REQUEST_PLUS).inScope(otherScope).inCollection(otherCollection) .withOptions(options).matching(Query.query(QueryCriteria.where("iata").is(vie.getIata()))).all().collectList() @@ -686,8 +697,8 @@ public void findByQueryOptions() { // 4 @Test public void findFromReplicasByIdOptions() { // 5 GetAnyReplicaOptions options = GetAnyReplicaOptions.getAnyReplicaOptions().timeout(Duration.ofNanos(1000)); - Airport saved = template.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection).one(vie) - .block(); + Airport saved = template.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection) + .one(vie.withIcao("low712")).block(); try { Airport found = template.findFromReplicasById(Airport.class).inScope(otherScope).inCollection(otherCollection) .withOptions(options).any(saved.getId()).block(); @@ -706,8 +717,8 @@ public void insertByIdOptions() { // 6 @Test public void removeByIdOptions() { // 7 - options - Airport saved = template.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection).one(vie) - .block(); + Airport saved = template.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection) + .one(vie.withIcao("732")).block(); RemoveOptions options = RemoveOptions.removeOptions().timeout(Duration.ofNanos(10)); assertThrows(AmbiguousTimeoutException.class, () -> template.removeById().inScope(otherScope) .inCollection(otherCollection).withOptions(options).one(vie.getId()).block()); @@ -734,7 +745,7 @@ public void replaceByIdOptions() { // 9 - options public void upsertByIdOptions() { // 10 - options UpsertOptions options = UpsertOptions.upsertOptions().timeout(Duration.ofNanos(10)); assertThrows(AmbiguousTimeoutException.class, () -> template.upsertById(Airport.class).inScope(otherScope) - .inCollection(otherCollection).withOptions(options).one(vie).block()); + .inCollection(otherCollection).withOptions(options).one(vie.withIcao("760")).block()); } } diff --git a/src/test/java/org/springframework/data/couchbase/domain/FluxTest.java b/src/test/java/org/springframework/data/couchbase/domain/FluxTest.java index 634f4c9a7..674f6124f 100644 --- a/src/test/java/org/springframework/data/couchbase/domain/FluxTest.java +++ b/src/test/java/org/springframework/data/couchbase/domain/FluxTest.java @@ -1,20 +1,23 @@ +/* + * Copyright 2012-2022 the original author or authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.springframework.data.couchbase.domain; -import com.couchbase.client.java.query.QueryOptions; -import com.couchbase.client.java.query.QueryProfile; -import com.couchbase.client.java.query.QueryResult; -import com.couchbase.client.java.query.QueryScanConsistency; -import org.junit.jupiter.api.AfterAll; -import org.springframework.context.ApplicationContext; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; -import org.springframework.data.couchbase.config.BeanNames; -import org.springframework.data.couchbase.core.CouchbaseTemplate; -import org.springframework.data.couchbase.core.ReactiveCouchbaseTemplate; -import org.springframework.data.couchbase.core.RemoveResult; -import org.springframework.data.couchbase.util.Capabilities; -import org.springframework.data.couchbase.util.ClusterType; -import org.springframework.data.couchbase.util.IgnoreWhen; -import org.springframework.data.util.Pair; +import static org.junit.jupiter.api.Assertions.assertEquals; + import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.core.publisher.ParallelFlux; @@ -27,23 +30,39 @@ import java.util.UUID; import java.util.concurrent.atomic.AtomicInteger; +import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Configuration; import org.springframework.data.couchbase.config.AbstractCouchbaseConfiguration; +import org.springframework.data.couchbase.config.BeanNames; +import org.springframework.data.couchbase.core.CouchbaseTemplate; +import org.springframework.data.couchbase.core.ReactiveCouchbaseTemplate; +import org.springframework.data.couchbase.core.RemoveResult; import org.springframework.data.couchbase.repository.config.EnableReactiveCouchbaseRepositories; +import org.springframework.data.couchbase.util.Capabilities; +import org.springframework.data.couchbase.util.ClusterType; +import org.springframework.data.couchbase.util.IgnoreWhen; import org.springframework.data.couchbase.util.JavaIntegrationTests; +import org.springframework.data.util.Pair; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import com.couchbase.client.java.Collection; import com.couchbase.client.java.ReactiveCollection; import com.couchbase.client.java.json.JsonObject; import com.couchbase.client.java.kv.GetResult; +import com.couchbase.client.java.query.QueryOptions; +import com.couchbase.client.java.query.QueryProfile; +import com.couchbase.client.java.query.QueryResult; +import com.couchbase.client.java.query.QueryScanConsistency; -import static org.junit.jupiter.api.Assertions.assertEquals; - +/** + * @author Michael Reiche + */ @SpringJUnitConfig(FluxTest.Config.class) @IgnoreWhen(clusterTypes = ClusterType.MOCKED) public class FluxTest extends JavaIntegrationTests { @@ -69,6 +88,9 @@ public static void beforeEverything() { public static void afterEverthing() { couchbaseTemplate.removeByQuery(Airport.class).withConsistency(QueryScanConsistency.REQUEST_PLUS).all(); couchbaseTemplate.findByQuery(Airport.class).withConsistency(QueryScanConsistency.REQUEST_PLUS).all(); + for (String k : keyList) { + couchbaseTemplate.getCouchbaseClientFactory().getBucket().defaultCollection().remove(k); + } } @BeforeEach diff --git a/src/test/java/org/springframework/data/couchbase/repository/CouchbaseRepositoryKeyValueIntegrationTests.java b/src/test/java/org/springframework/data/couchbase/repository/CouchbaseRepositoryKeyValueIntegrationTests.java index 41612eedd..7039d10e1 100644 --- a/src/test/java/org/springframework/data/couchbase/repository/CouchbaseRepositoryKeyValueIntegrationTests.java +++ b/src/test/java/org/springframework/data/couchbase/repository/CouchbaseRepositoryKeyValueIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors + * Copyright 2012-2022 the original author or authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,17 +16,18 @@ package org.springframework.data.couchbase.repository; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Optional; import java.util.UUID; -import com.couchbase.client.java.kv.GetResult; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; @@ -50,6 +51,8 @@ import org.springframework.data.couchbase.util.IgnoreWhen; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; +import com.couchbase.client.java.kv.GetResult; + /** * Repository KV tests * @@ -76,12 +79,13 @@ void subscriptionToken() { GetResult jdkResult = couchbaseTemplate.getCouchbaseClientFactory().getDefaultCollection().get(st.getId()); assertNotEquals(0, st.getVersion()); assertEquals(jdkResult.cas(), st.getVersion()); + subscriptionTokenRepository.delete(st); } @Test @IgnoreWhen(clusterTypes = ClusterType.MOCKED) void saveAndFindById() { - User user = new User(UUID.randomUUID().toString(), "f", "l"); + User user = new User(UUID.randomUUID().toString(), "saveAndFindById", "l"); // this currently fails when using mocked in integration.properties with status "UNKNOWN" assertFalse(userRepository.existsById(user.getId())); @@ -98,7 +102,7 @@ void saveAndFindById() { @Test @IgnoreWhen(clusterTypes = ClusterType.MOCKED) void saveAndFindImmutableById() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { - PersonValue personValue = new PersonValue(null, 0, "f", "l"); + PersonValue personValue = new PersonValue(null, 0, "saveAndFindImmutableById", "l"); personValue = personValueRepository.save(personValue); Optional found = personValueRepository.findById(personValue.getId()); assertTrue(found.isPresent()); @@ -138,7 +142,7 @@ void saveAndFindByWithNestedId() { user.setCourses(Arrays.asList(new Course(UUID.randomUUID().toString(), user.getId(), "581"))); // this currently fails when using mocked in integration.properties with status "UNKNOWN" - assertFalse(userRepository.existsById(user.getId())); + assertFalse(userSubmissionRepository.existsById(user.getId())); userSubmissionRepository.save(user); @@ -146,7 +150,7 @@ void saveAndFindByWithNestedId() { assertTrue(found.isPresent()); found.ifPresent(u -> assertEquals(user, u)); - assertTrue(userRepository.existsById(user.getId())); + assertTrue(userSubmissionRepository.existsById(user.getId())); assertEquals(user.getSubmissions().get(0).getId(), found.get().getSubmissions().get(0).getId()); assertEquals(user.getCourses().get(0).getId(), found.get().getCourses().get(0).getId()); assertEquals(user, found.get()); diff --git a/src/test/java/org/springframework/data/couchbase/repository/ReactiveCouchbaseRepositoryKeyValueIntegrationTests.java b/src/test/java/org/springframework/data/couchbase/repository/ReactiveCouchbaseRepositoryKeyValueIntegrationTests.java index 6c1a89863..dd317cf1a 100644 --- a/src/test/java/org/springframework/data/couchbase/repository/ReactiveCouchbaseRepositoryKeyValueIntegrationTests.java +++ b/src/test/java/org/springframework/data/couchbase/repository/ReactiveCouchbaseRepositoryKeyValueIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors + * Copyright 2012-2022 the original author or authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,6 +42,9 @@ import org.springframework.data.couchbase.util.IgnoreWhen; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; +/** + * @author Michael Reiche + */ @SpringJUnitConfig(ReactiveCouchbaseRepositoryKeyValueIntegrationTests.Config.class) @IgnoreWhen(clusterTypes = ClusterType.MOCKED) public class ReactiveCouchbaseRepositoryKeyValueIntegrationTests extends ClusterAwareIntegrationTests { @@ -52,7 +55,7 @@ public class ReactiveCouchbaseRepositoryKeyValueIntegrationTests extends Cluster @Test void saveAndFindById() { - User user = new User(UUID.randomUUID().toString(), "f", "l"); + User user = new User(UUID.randomUUID().toString(), "saveAndFindById_reactive", "l"); assertFalse(userRepository.existsById(user.getId()).block()); @@ -63,6 +66,7 @@ void saveAndFindById() { found.ifPresent(u -> assertEquals(save, u)); assertTrue(userRepository.existsById(user.getId()).block()); + userRepository.delete(user).block(); } @Test