Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sdk/spring/azure-spring-data-cosmos/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#### Bugs Fixed
* Fixed all saveAll/insertAll bulk functionality to populated audit data - See [PR 39620](https://github.com/Azure/azure-sdk-for-java/pull/39620).
* Fixed `existsById` API in `ReactiveCosmosTemplate` to return `Mono<Boolean>` containing `False` in case the item does not exist - See [PR 40022](https://github.com/Azure/azure-sdk-for-java/pull/40022)

#### Other Changes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,8 @@ public Mono<Boolean> exists(CosmosQuery query, Class<?> domainType, String conta
*/
public Mono<Boolean> existsById(Object id, Class<?> domainType, String containerName) {
return findById(containerName, id, domainType)
.flatMap(o -> Mono.just(o != null));
.flatMap(o -> Mono.just(o != null))
.switchIfEmpty(Mono.just(false));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,26 @@ public void testExists() {
Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0);
}

@Test
public void testNotExists() {
final Criteria criteria = Criteria.getInstance(CriteriaType.IS_EQUAL, "firstName",
Collections.singletonList("randomFirstName"), Part.IgnoreCaseType.NEVER);
final CosmosQuery query = new CosmosQuery(criteria);
final Mono<Boolean> exists = cosmosTemplate.exists(query, Person.class, containerName);
StepVerifier.create(exists).expectNext(false).verifyComplete();

// add ignore testing
final Criteria criteriaIgnoreCase = Criteria.getInstance(CriteriaType.IS_EQUAL, "firstName",
Collections.singletonList("randomFirstName".toUpperCase()), Part.IgnoreCaseType.ALWAYS);
final CosmosQuery queryIgnoreCase = new CosmosQuery(criteriaIgnoreCase);
final Mono<Boolean> existsIgnoreCase = cosmosTemplate.exists(queryIgnoreCase, Person.class, containerName);
StepVerifier.create(existsIgnoreCase).expectNext(false).verifyComplete();

assertThat(responseDiagnosticsTestUtils.getCosmosDiagnostics()).isNotNull();
Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics()).isNotNull();
Assertions.assertThat(responseDiagnosticsTestUtils.getCosmosResponseStatistics().getRequestCharge()).isGreaterThan(0);
}

@Test
public void testCount() {
final Mono<Long> count = cosmosTemplate.count(containerName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ public void testExistsById() {

Mono<Boolean> booleanMono = this.repository.existsById(DOMAIN_1.getNumber());
StepVerifier.create(booleanMono).expectNext(true).expectComplete().verify();

booleanMono = this.repository.existsById(UUID.randomUUID());
StepVerifier.create(booleanMono).expectNext(false).expectComplete().verify();
}

private static class InvalidDomain {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ public void testExistsById() {

Mono<Boolean> booleanMono = this.repository.existsById(DOMAIN_1.getNumber());
StepVerifier.create(booleanMono).expectNext(true).expectComplete().verify();

booleanMono = this.repository.existsById(0L);
StepVerifier.create(booleanMono).expectNext(false).expectComplete().verify();
}

@Test
Expand Down