diff --git a/src/main/java/org/springframework/data/couchbase/core/ReactiveInsertByIdOperationSupport.java b/src/main/java/org/springframework/data/couchbase/core/ReactiveInsertByIdOperationSupport.java index 4ce76dae..a7e35e37 100644 --- a/src/main/java/org/springframework/data/couchbase/core/ReactiveInsertByIdOperationSupport.java +++ b/src/main/java/org/springframework/data/couchbase/core/ReactiveInsertByIdOperationSupport.java @@ -68,7 +68,7 @@ public class ReactiveInsertByIdOperationSupport implements ReactiveInsertByIdOpe return Mono.just(object).flatMap(o -> { CouchbaseDocument converted = template.support().encodeEntity(o); return template.getCollection(collection).reactive() - .insert(converted.getId(), converted.getContent(), buildInsertOptions()).map(result -> { + .insert(converted.getId(), converted.export(), buildInsertOptions()).map(result -> { template.support().applyUpdatedCas(object, result.cas()); return o; }); diff --git a/src/main/java/org/springframework/data/couchbase/core/ReactiveReplaceByIdOperationSupport.java b/src/main/java/org/springframework/data/couchbase/core/ReactiveReplaceByIdOperationSupport.java index 399a4260..2c8c97ed 100644 --- a/src/main/java/org/springframework/data/couchbase/core/ReactiveReplaceByIdOperationSupport.java +++ b/src/main/java/org/springframework/data/couchbase/core/ReactiveReplaceByIdOperationSupport.java @@ -68,7 +68,7 @@ public class ReactiveReplaceByIdOperationSupport implements ReactiveReplaceByIdO return Mono.just(object).flatMap(o -> { CouchbaseDocument converted = template.support().encodeEntity(o); return template.getCollection(collection).reactive() - .replace(converted.getId(), converted.getContent(), buildReplaceOptions()).map(result -> { + .replace(converted.getId(), converted.export(), buildReplaceOptions()).map(result -> { template.support().applyUpdatedCas(object, result.cas()); return o; }); diff --git a/src/main/java/org/springframework/data/couchbase/core/ReactiveUpsertByIdOperationSupport.java b/src/main/java/org/springframework/data/couchbase/core/ReactiveUpsertByIdOperationSupport.java index a05c91bf..26d47c09 100644 --- a/src/main/java/org/springframework/data/couchbase/core/ReactiveUpsertByIdOperationSupport.java +++ b/src/main/java/org/springframework/data/couchbase/core/ReactiveUpsertByIdOperationSupport.java @@ -68,7 +68,7 @@ public class ReactiveUpsertByIdOperationSupport implements ReactiveUpsertByIdOpe return Mono.just(object).flatMap(o -> { CouchbaseDocument converted = template.support().encodeEntity(o); return template.getCollection(collection).reactive() - .upsert(converted.getId(), converted.getContent(), buildUpsertOptions()).map(result -> { + .upsert(converted.getId(), converted.export(), buildUpsertOptions()).map(result -> { template.support().applyUpdatedCas(object, result.cas()); return o; }); diff --git a/src/test/java/org/springframework/data/couchbase/domain/Library.java b/src/test/java/org/springframework/data/couchbase/domain/Library.java new file mode 100644 index 00000000..531a4dc5 --- /dev/null +++ b/src/test/java/org/springframework/data/couchbase/domain/Library.java @@ -0,0 +1,63 @@ +/* + * Copyright 2012-2020 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 java.util.List; + +import org.springframework.data.annotation.Id; +import org.springframework.data.couchbase.core.mapping.Document; + +@Document +public class Library { + + @Id String id; + List books; + + public Library(String id, List books) { + this.id = id; + this.books = books; + } + + public String getId() { + return id; + } + + public List getBooks() { + return books; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + + Library library = (Library) o; + + if (id != null ? !id.equals(library.id) : library.id != null) + return false; + return books != null ? books.equals(library.books) : library.books == null; + } + + @Override + public int hashCode() { + int result = id != null ? id.hashCode() : 0; + result = 31 * result + (books != null ? books.hashCode() : 0); + return result; + } + +} diff --git a/src/test/java/org/springframework/data/couchbase/domain/LibraryRepository.java b/src/test/java/org/springframework/data/couchbase/domain/LibraryRepository.java new file mode 100644 index 00000000..6831968b --- /dev/null +++ b/src/test/java/org/springframework/data/couchbase/domain/LibraryRepository.java @@ -0,0 +1,30 @@ +/* + * Copyright 2012-2020 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 org.springframework.data.repository.PagingAndSortingRepository; +import org.springframework.stereotype.Repository; + +/** + * Library Repository for tests + * + * @author Andrea Torlaschi + */ +@Repository +public interface LibraryRepository extends PagingAndSortingRepository { + +} 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 15cab50d..b375c637 100644 --- a/src/test/java/org/springframework/data/couchbase/repository/CouchbaseRepositoryKeyValueIntegrationTests.java +++ b/src/test/java/org/springframework/data/couchbase/repository/CouchbaseRepositoryKeyValueIntegrationTests.java @@ -18,6 +18,8 @@ package org.springframework.data.couchbase.repository; import static org.junit.jupiter.api.Assertions.*; +import java.util.ArrayList; +import java.util.List; import java.util.Optional; import java.util.UUID; @@ -25,6 +27,8 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.data.couchbase.config.AbstractCouchbaseConfiguration; +import org.springframework.data.couchbase.domain.Library; +import org.springframework.data.couchbase.domain.LibraryRepository; import org.springframework.data.couchbase.domain.User; import org.springframework.data.couchbase.domain.UserRepository; import org.springframework.data.couchbase.repository.config.EnableCouchbaseRepositories; @@ -44,6 +48,7 @@ import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; public class CouchbaseRepositoryKeyValueIntegrationTests extends ClusterAwareIntegrationTests { @Autowired UserRepository userRepository; + @Autowired LibraryRepository libraryRepository; @Test @IgnoreWhen(clusterTypes = ClusterType.MOCKED) @@ -62,6 +67,28 @@ public class CouchbaseRepositoryKeyValueIntegrationTests extends ClusterAwareInt userRepository.delete(user); } + @Test // DATACOUCH-564 + @IgnoreWhen(clusterTypes = ClusterType.MOCKED) + void saveAndFindByIdWithList() { + List books = new ArrayList<>(); + books.add("book1"); + books.add("book2"); + Library library = new Library(UUID.randomUUID().toString(), books); + // this currently fails when using mocked in integration.properties with status "UNKNOWN" + assertFalse(libraryRepository.existsById(library.getId())); + + libraryRepository.save(library); + + Optional found = libraryRepository.findById(library.getId()); + assertTrue(found.isPresent()); + found.ifPresent(l -> assertEquals(library, l)); + + assertTrue(userRepository.existsById(library.getId())); + libraryRepository.delete(library); + + assertFalse(userRepository.existsById(library.getId())); + } + @Configuration @EnableCouchbaseRepositories("org.springframework.data.couchbase") static class Config extends AbstractCouchbaseConfiguration {