Skip to content

Commit 4a04419

Browse files
committed
Add mechanism for save to do one of insert, replace or upsert. (#1316)
Closes #1277.
1 parent 1fdbf6d commit 4a04419

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/test/java/org/springframework/data/couchbase/repository/ReactiveCouchbaseRepositoryKeyValueIntegrationTests.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,31 @@ void saveReplaceUpsertInsert() {
8787
airlineRepository.delete(airline).block();
8888
}
8989

90+
@Autowired ReactiveAirlineRepository airlineRepository;
91+
92+
@Test
93+
@IgnoreWhen(clusterTypes = ClusterType.MOCKED)
94+
void saveReplaceUpsertInsert() {
95+
// the User class has a version.
96+
User user = new User(UUID.randomUUID().toString(), "f", "l");
97+
// save the document - we don't care how on this call
98+
userRepository.save(user).block();
99+
// Now set the version to 0, it should attempt an insert and fail.
100+
long saveVersion = user.getVersion();
101+
user.setVersion(0);
102+
assertThrows(DuplicateKeyException.class, () -> userRepository.save(user).block());
103+
user.setVersion(saveVersion + 1);
104+
assertThrows(DataIntegrityViolationException.class, () -> userRepository.save(user).block());
105+
userRepository.delete(user);
106+
107+
// Airline does not have a version
108+
Airline airline = new Airline(UUID.randomUUID().toString(), "MyAirline");
109+
// save the document - we don't care how on this call
110+
airlineRepository.save(airline).block();
111+
airlineRepository.save(airline).block(); // If it was an insert it would fail. Can't tell if an upsert or replace.
112+
airlineRepository.delete(airline).block();
113+
}
114+
90115
@Test
91116
void saveAndFindById() {
92117
User user = new User(UUID.randomUUID().toString(), "saveAndFindById_reactive", "l");

0 commit comments

Comments
 (0)