DATAMONGO-1712 - Adopt to ReactiveCrudRepository.findById(Publisher) and existsById(Publisher).
Related ticket: DATACMNS-1063. Original Pull Request: #467
This commit is contained in:
committed by
Christoph Strobl
parent
3440bf6c4d
commit
a2f7c3f482
@@ -67,14 +67,14 @@ public class SimpleReactiveMongoRepository<T, ID extends Serializable> implement
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#findById(reactor.core.publisher.Mono)
|
||||
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#findById(org.reactivestreams.Publisher)
|
||||
*/
|
||||
@Override
|
||||
public Mono<T> findById(Mono<ID> mono) {
|
||||
public Mono<T> findById(Publisher<ID> publisher) {
|
||||
|
||||
Assert.notNull(mono, "The given id must not be null!");
|
||||
Assert.notNull(publisher, "The given id must not be null!");
|
||||
|
||||
return mono.flatMap(
|
||||
return Mono.from(publisher).flatMap(
|
||||
id -> mongoOperations.findById(id, entityInformation.getJavaType(), entityInformation.getCollectionName()));
|
||||
}
|
||||
|
||||
@@ -115,14 +115,14 @@ public class SimpleReactiveMongoRepository<T, ID extends Serializable> implement
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#existsById(reactor.core.publisher.Mono)
|
||||
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#existsById(org.reactivestreams.Publisher)
|
||||
*/
|
||||
@Override
|
||||
public Mono<Boolean> existsById(Mono<ID> mono) {
|
||||
public Mono<Boolean> existsById(Publisher<ID> publisher) {
|
||||
|
||||
Assert.notNull(mono, "The given id must not be null!");
|
||||
Assert.notNull(publisher, "The given id must not be null!");
|
||||
|
||||
return mono.flatMap(id -> mongoOperations.exists(getIdQuery(id), entityInformation.getJavaType(),
|
||||
return Mono.from(publisher).flatMap(id -> mongoOperations.exists(getIdQuery(id), entityInformation.getJavaType(),
|
||||
entityInformation.getCollectionName()));
|
||||
|
||||
}
|
||||
|
||||
@@ -119,28 +119,38 @@ public class SimpleReactiveMongoRepositoryTests implements BeanClassLoaderAware,
|
||||
StepVerifier.create(repository.existsById(Mono.just(dave.id))).expectNext(true).verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1712
|
||||
public void existsByFlusOfIdShouldReturnTrueForExistingObject() {
|
||||
StepVerifier.create(repository.existsById(Flux.just(dave.id, oliver.id))).expectNext(true).verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1444
|
||||
public void existsByEmptyMonoOfIdShouldReturnEmptyMono() {
|
||||
StepVerifier.create(repository.existsById(Mono.empty())).verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1444
|
||||
public void findOneShouldReturnObject() {
|
||||
public void findByIdShouldReturnObject() {
|
||||
StepVerifier.create(repository.findById(dave.id)).expectNext(dave).verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1444
|
||||
public void findOneShouldCompleteWithoutValueForAbsentObject() {
|
||||
public void findByIdShouldCompleteWithoutValueForAbsentObject() {
|
||||
StepVerifier.create(repository.findById("unknown")).verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1444
|
||||
public void findOneByMonoOfIdShouldReturnTrueForExistingObject() {
|
||||
public void findByIdByMonoOfIdShouldReturnTrueForExistingObject() {
|
||||
StepVerifier.create(repository.findById(Mono.just(dave.id))).expectNext(dave).verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1444
|
||||
public void findOneByEmptyMonoOfIdShouldReturnEmptyMono() {
|
||||
public void findByIdByFluxOfIdShouldReturnTrueForExistingObject() {
|
||||
StepVerifier.create(repository.findById(Flux.just(dave.id, oliver.id))).expectNext(dave).verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1444
|
||||
public void findByIdByEmptyMonoOfIdShouldReturnEmptyMono() {
|
||||
StepVerifier.create(repository.findById(Mono.empty())).verifyComplete();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user