DATAMONGO-2652 - Polishing.
Reorder implementation methods. Reduce visibility of test methods according to JUnit 5 requirements. Original pull request: #892.
This commit is contained in:
@@ -64,16 +64,4 @@ public interface ReactiveMongoRepository<T, ID> extends ReactiveSortingRepositor
|
||||
*/
|
||||
<S extends T> Flux<S> insert(Publisher<S> entities);
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.query.QueryByExampleExecutor#findAll(org.springframework.data.domain.Example)
|
||||
*/
|
||||
<S extends T> Flux<S> findAll(Example<S> example);
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.query.QueryByExampleExecutor#findAll(org.springframework.data.domain.Example, org.springframework.data.domain.Sort)
|
||||
*/
|
||||
<S extends T> Flux<S> findAll(Example<S> example, Sort sort);
|
||||
|
||||
}
|
||||
|
||||
@@ -73,6 +73,10 @@ public class SimpleMongoRepository<T, ID> implements MongoRepository<T, ID> {
|
||||
this.mongoOperations = mongoOperations;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Methods from CrudRepository
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.CrudRepository#save(java.lang.Object)
|
||||
@@ -136,6 +140,27 @@ public class SimpleMongoRepository<T, ID> implements MongoRepository<T, ID> {
|
||||
entityInformation.getCollectionName());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.CrudRepository#findAll()
|
||||
*/
|
||||
@Override
|
||||
public List<T> findAll() {
|
||||
return findAll(new Query());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.CrudRepository#findAllById(java.lang.Iterable)
|
||||
*/
|
||||
@Override
|
||||
public Iterable<T> findAllById(Iterable<ID> ids) {
|
||||
|
||||
Assert.notNull(ids, "The given Ids of entities not be null!");
|
||||
|
||||
return findAll(getIdQuery(ids));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.CrudRepository#count()
|
||||
@@ -176,6 +201,19 @@ public class SimpleMongoRepository<T, ID> implements MongoRepository<T, ID> {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.CrudRepository#deleteAllById(java.lang.Iterable)
|
||||
*/
|
||||
@Override
|
||||
public void deleteAllById(Iterable<? extends ID> ids) {
|
||||
|
||||
Assert.notNull(ids, "The given Iterable of ids must not be null!");
|
||||
|
||||
mongoOperations.remove(getIdQuery(ids), entityInformation.getJavaType(),
|
||||
entityInformation.getCollectionName());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.CrudRepository#delete(java.lang.Iterable)
|
||||
@@ -188,14 +226,6 @@ public class SimpleMongoRepository<T, ID> implements MongoRepository<T, ID> {
|
||||
entities.forEach(this::delete);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteAllById(Iterable<? extends ID> ids) {
|
||||
|
||||
Assert.notNull(ids, "The given Iterable of ids must not be null!");
|
||||
|
||||
ids.forEach(this::deleteById);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.CrudRepository#deleteAll()
|
||||
@@ -205,27 +235,9 @@ public class SimpleMongoRepository<T, ID> implements MongoRepository<T, ID> {
|
||||
mongoOperations.remove(new Query(), entityInformation.getCollectionName());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.CrudRepository#findAll()
|
||||
*/
|
||||
@Override
|
||||
public List<T> findAll() {
|
||||
return findAll(new Query());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.CrudRepository#findAllById(java.lang.Iterable)
|
||||
*/
|
||||
@Override
|
||||
public Iterable<T> findAllById(Iterable<ID> ids) {
|
||||
|
||||
Assert.notNull(ids, "The given Ids of entities not be null!");
|
||||
|
||||
return findAll(new Query(new Criteria(entityInformation.getIdAttribute())
|
||||
.in(Streamable.of(ids).stream().collect(StreamUtils.toUnmodifiableList()))));
|
||||
}
|
||||
// -------------------------------------------------------------------------
|
||||
// Methods from PagingAndSortingRepository
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
@@ -254,6 +266,10 @@ public class SimpleMongoRepository<T, ID> implements MongoRepository<T, ID> {
|
||||
return findAll(new Query().with(sort));
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Methods from MongoRepository
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.repository.MongoRepository#insert(java.lang.Object)
|
||||
@@ -284,23 +300,33 @@ public class SimpleMongoRepository<T, ID> implements MongoRepository<T, ID> {
|
||||
return new ArrayList<>(mongoOperations.insertAll(list));
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Methods from QueryByExampleExecutor
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.repository.MongoRepository#findAllByExample(org.springframework.data.domain.Example, org.springframework.data.domain.Pageable)
|
||||
* @see org.springframework.data.repository.query.QueryByExampleExecutor#findOne(org.springframework.data.domain.Example)
|
||||
*/
|
||||
@Override
|
||||
public <S extends T> Page<S> findAll(final Example<S> example, Pageable pageable) {
|
||||
public <S extends T> Optional<S> findOne(Example<S> example) {
|
||||
|
||||
Assert.notNull(example, "Sample must not be null!");
|
||||
Assert.notNull(pageable, "Pageable must not be null!");
|
||||
|
||||
Query query = new Query(new Criteria().alike(example)) //
|
||||
.collation(entityInformation.getCollation()).with(pageable); //
|
||||
.collation(entityInformation.getCollation());
|
||||
|
||||
List<S> list = mongoOperations.find(query, example.getProbeType(), entityInformation.getCollectionName());
|
||||
return Optional
|
||||
.ofNullable(mongoOperations.findOne(query, example.getProbeType(), entityInformation.getCollectionName()));
|
||||
}
|
||||
|
||||
return PageableExecutionUtils.getPage(list, pageable,
|
||||
() -> mongoOperations.count(Query.of(query).limit(-1).skip(-1), example.getProbeType(), entityInformation.getCollectionName()));
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.repository.MongoRepository#findAllByExample(org.springframework.data.domain.Example)
|
||||
*/
|
||||
@Override
|
||||
public <S extends T> List<S> findAll(Example<S> example) {
|
||||
return findAll(example, Sort.unsorted());
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -322,27 +348,21 @@ public class SimpleMongoRepository<T, ID> implements MongoRepository<T, ID> {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.repository.MongoRepository#findAllByExample(org.springframework.data.domain.Example)
|
||||
* @see org.springframework.data.mongodb.repository.MongoRepository#findAllByExample(org.springframework.data.domain.Example, org.springframework.data.domain.Pageable)
|
||||
*/
|
||||
@Override
|
||||
public <S extends T> List<S> findAll(Example<S> example) {
|
||||
return findAll(example, Sort.unsorted());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.query.QueryByExampleExecutor#findOne(org.springframework.data.domain.Example)
|
||||
*/
|
||||
@Override
|
||||
public <S extends T> Optional<S> findOne(Example<S> example) {
|
||||
public <S extends T> Page<S> findAll(Example<S> example, Pageable pageable) {
|
||||
|
||||
Assert.notNull(example, "Sample must not be null!");
|
||||
Assert.notNull(pageable, "Pageable must not be null!");
|
||||
|
||||
Query query = new Query(new Criteria().alike(example)) //
|
||||
.collation(entityInformation.getCollation());
|
||||
.collation(entityInformation.getCollation()).with(pageable); //
|
||||
|
||||
return Optional
|
||||
.ofNullable(mongoOperations.findOne(query, example.getProbeType(), entityInformation.getCollectionName()));
|
||||
List<S> list = mongoOperations.find(query, example.getProbeType(), entityInformation.getCollectionName());
|
||||
|
||||
return PageableExecutionUtils.getPage(list, pageable,
|
||||
() -> mongoOperations.count(Query.of(query).limit(-1).skip(-1), example.getProbeType(), entityInformation.getCollectionName()));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -375,6 +395,10 @@ public class SimpleMongoRepository<T, ID> implements MongoRepository<T, ID> {
|
||||
return mongoOperations.exists(query, example.getProbeType(), entityInformation.getCollectionName());
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Utility methods
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
private Query getIdQuery(Object id) {
|
||||
return new Query(getIdCriteria(id));
|
||||
}
|
||||
@@ -383,6 +407,11 @@ public class SimpleMongoRepository<T, ID> implements MongoRepository<T, ID> {
|
||||
return where(entityInformation.getIdAttribute()).is(id);
|
||||
}
|
||||
|
||||
private Query getIdQuery(Iterable<? extends ID> ids) {
|
||||
return new Query(new Criteria(entityInformation.getIdAttribute())
|
||||
.in(Streamable.of(ids).stream().collect(StreamUtils.toUnmodifiableList())));
|
||||
}
|
||||
|
||||
private List<T> findAll(@Nullable Query query) {
|
||||
|
||||
if (query == null) {
|
||||
@@ -391,4 +420,5 @@ public class SimpleMongoRepository<T, ID> implements MongoRepository<T, ID> {
|
||||
|
||||
return mongoOperations.find(query, entityInformation.getJavaType(), entityInformation.getCollectionName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,12 +17,16 @@ package org.springframework.data.mongodb.repository.support;
|
||||
|
||||
import static org.springframework.data.mongodb.core.query.Criteria.*;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.reactivestreams.Publisher;
|
||||
|
||||
import org.springframework.dao.IncorrectResultSizeDataAccessException;
|
||||
import org.springframework.dao.OptimisticLockingFailureException;
|
||||
import org.springframework.data.domain.Example;
|
||||
@@ -38,9 +42,6 @@ import org.springframework.util.Assert;
|
||||
|
||||
import com.mongodb.client.result.DeleteResult;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
* Reactive repository base implementation for Mongo.
|
||||
*
|
||||
@@ -66,232 +67,9 @@ public class SimpleReactiveMongoRepository<T, ID extends Serializable> implement
|
||||
this.mongoOperations = mongoOperations;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#findById(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public Mono<T> findById(ID id) {
|
||||
|
||||
Assert.notNull(id, "The given id must not be null!");
|
||||
|
||||
return mongoOperations.findById(id, entityInformation.getJavaType(), entityInformation.getCollectionName());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#findById(org.reactivestreams.Publisher)
|
||||
*/
|
||||
@Override
|
||||
public Mono<T> findById(Publisher<ID> publisher) {
|
||||
|
||||
Assert.notNull(publisher, "The given id must not be null!");
|
||||
|
||||
return Mono.from(publisher).flatMap(
|
||||
id -> mongoOperations.findById(id, entityInformation.getJavaType(), entityInformation.getCollectionName()));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.query.ReactiveQueryByExampleExecutor#findOne(org.springframework.data.domain.Example)
|
||||
*/
|
||||
@Override
|
||||
public <S extends T> Mono<S> findOne(Example<S> example) {
|
||||
|
||||
Assert.notNull(example, "Sample must not be null!");
|
||||
|
||||
Query query = new Query(new Criteria().alike(example)) //
|
||||
.collation(entityInformation.getCollation()) //
|
||||
.limit(2);
|
||||
|
||||
return mongoOperations.find(query, example.getProbeType(), entityInformation.getCollectionName()).buffer(2)
|
||||
.map(vals -> {
|
||||
|
||||
if (vals.size() > 1) {
|
||||
throw new IncorrectResultSizeDataAccessException(1);
|
||||
}
|
||||
return vals.iterator().next();
|
||||
}).next();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#existsById(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public Mono<Boolean> existsById(ID id) {
|
||||
|
||||
Assert.notNull(id, "The given id must not be null!");
|
||||
|
||||
return mongoOperations.exists(getIdQuery(id), entityInformation.getJavaType(),
|
||||
entityInformation.getCollectionName());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#existsById(org.reactivestreams.Publisher)
|
||||
*/
|
||||
@Override
|
||||
public Mono<Boolean> existsById(Publisher<ID> publisher) {
|
||||
|
||||
Assert.notNull(publisher, "The given id must not be null!");
|
||||
|
||||
return Mono.from(publisher).flatMap(id -> mongoOperations.exists(getIdQuery(id), entityInformation.getJavaType(),
|
||||
entityInformation.getCollectionName()));
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.query.ReactiveQueryByExampleExecutor#exists(org.springframework.data.domain.Example)
|
||||
*/
|
||||
@Override
|
||||
public <S extends T> Mono<Boolean> exists(Example<S> example) {
|
||||
|
||||
Assert.notNull(example, "Sample must not be null!");
|
||||
|
||||
Query query = new Query(new Criteria().alike(example)) //
|
||||
.collation(entityInformation.getCollation());
|
||||
|
||||
return mongoOperations.exists(query, example.getProbeType(), entityInformation.getCollectionName());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.reactive.ReactiveSortingRepository#findAll()
|
||||
*/
|
||||
@Override
|
||||
public Flux<T> findAll() {
|
||||
return findAll(new Query());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#findAllById(java.lang.Iterable)
|
||||
*/
|
||||
@Override
|
||||
public Flux<T> findAllById(Iterable<ID> ids) {
|
||||
|
||||
Assert.notNull(ids, "The given Iterable of Id's must not be null!");
|
||||
|
||||
return findAll(new Query(new Criteria(entityInformation.getIdAttribute())
|
||||
.in(Streamable.of(ids).stream().collect(StreamUtils.toUnmodifiableList()))));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#findAllById(org.reactivestreams.Publisher)
|
||||
*/
|
||||
@Override
|
||||
public Flux<T> findAllById(Publisher<ID> ids) {
|
||||
|
||||
Assert.notNull(ids, "The given Publisher of Id's must not be null!");
|
||||
|
||||
return Flux.from(ids).buffer().flatMap(this::findAllById);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.reactive.ReactiveSortingRepository#findAll(org.springframework.data.domain.Sort)
|
||||
*/
|
||||
@Override
|
||||
public Flux<T> findAll(Sort sort) {
|
||||
|
||||
Assert.notNull(sort, "Sort must not be null!");
|
||||
|
||||
return findAll(new Query().with(sort));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.repository.ReactiveMongoRepository#findAll(org.springframework.data.domain.Example, org.springframework.data.domain.Sort)
|
||||
*/
|
||||
@Override
|
||||
public <S extends T> Flux<S> findAll(Example<S> example, Sort sort) {
|
||||
|
||||
Assert.notNull(example, "Sample must not be null!");
|
||||
Assert.notNull(sort, "Sort must not be null!");
|
||||
|
||||
Query query = new Query(new Criteria().alike(example)) //
|
||||
.collation(entityInformation.getCollation()) //
|
||||
.with(sort);
|
||||
|
||||
return mongoOperations.find(query, example.getProbeType(), entityInformation.getCollectionName());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.repository.ReactiveMongoRepository#findAll(org.springframework.data.domain.Example)
|
||||
*/
|
||||
@Override
|
||||
public <S extends T> Flux<S> findAll(Example<S> example) {
|
||||
|
||||
Assert.notNull(example, "Example must not be null!");
|
||||
|
||||
return findAll(example, Sort.unsorted());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#count()
|
||||
*/
|
||||
@Override
|
||||
public Mono<Long> count() {
|
||||
return mongoOperations.count(new Query(), entityInformation.getCollectionName());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.query.ReactiveQueryByExampleExecutor#count(org.springframework.data.domain.Example)
|
||||
*/
|
||||
@Override
|
||||
public <S extends T> Mono<Long> count(Example<S> example) {
|
||||
|
||||
Assert.notNull(example, "Sample must not be null!");
|
||||
|
||||
Query query = new Query(new Criteria().alike(example)) //
|
||||
.collation(entityInformation.getCollation());
|
||||
|
||||
return mongoOperations.count(query, example.getProbeType(), entityInformation.getCollectionName());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.repository.ReactiveMongoRepository#insert(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public <S extends T> Mono<S> insert(S entity) {
|
||||
|
||||
Assert.notNull(entity, "Entity must not be null!");
|
||||
|
||||
return mongoOperations.insert(entity, entityInformation.getCollectionName());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.repository.ReactiveMongoRepository#insert(java.lang.Iterable)
|
||||
*/
|
||||
@Override
|
||||
public <S extends T> Flux<S> insert(Iterable<S> entities) {
|
||||
|
||||
Assert.notNull(entities, "The given Iterable of entities must not be null!");
|
||||
|
||||
List<S> source = Streamable.of(entities).stream().collect(StreamUtils.toUnmodifiableList());
|
||||
|
||||
return source.isEmpty() ? Flux.empty() : Flux.from(mongoOperations.insertAll(source));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.repository.ReactiveMongoRepository#insert(org.reactivestreams.Publisher)
|
||||
*/
|
||||
@Override
|
||||
public <S extends T> Flux<S> insert(Publisher<S> entities) {
|
||||
|
||||
Assert.notNull(entities, "The given Publisher of entities must not be null!");
|
||||
|
||||
return Flux.from(entities).flatMap(entity -> mongoOperations.insert(entity, entityInformation.getCollectionName()));
|
||||
}
|
||||
// -------------------------------------------------------------------------
|
||||
// Methods from ReactiveCrudRepository
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
@@ -339,6 +117,100 @@ public class SimpleReactiveMongoRepository<T, ID extends Serializable> implement
|
||||
mongoOperations.save(entity, entityInformation.getCollectionName()).then(Mono.just(entity)));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#findById(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public Mono<T> findById(ID id) {
|
||||
|
||||
Assert.notNull(id, "The given id must not be null!");
|
||||
|
||||
return mongoOperations.findById(id, entityInformation.getJavaType(), entityInformation.getCollectionName());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#findById(org.reactivestreams.Publisher)
|
||||
*/
|
||||
@Override
|
||||
public Mono<T> findById(Publisher<ID> publisher) {
|
||||
|
||||
Assert.notNull(publisher, "The given id must not be null!");
|
||||
|
||||
return Mono.from(publisher).flatMap(
|
||||
id -> mongoOperations.findById(id, entityInformation.getJavaType(), entityInformation.getCollectionName()));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#existsById(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public Mono<Boolean> existsById(ID id) {
|
||||
|
||||
Assert.notNull(id, "The given id must not be null!");
|
||||
|
||||
return mongoOperations.exists(getIdQuery(id), entityInformation.getJavaType(),
|
||||
entityInformation.getCollectionName());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#existsById(org.reactivestreams.Publisher)
|
||||
*/
|
||||
@Override
|
||||
public Mono<Boolean> existsById(Publisher<ID> publisher) {
|
||||
|
||||
Assert.notNull(publisher, "The given id must not be null!");
|
||||
|
||||
return Mono.from(publisher).flatMap(id -> mongoOperations.exists(getIdQuery(id), entityInformation.getJavaType(),
|
||||
entityInformation.getCollectionName()));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.reactive.ReactiveSortingRepository#findAll()
|
||||
*/
|
||||
@Override
|
||||
public Flux<T> findAll() {
|
||||
return findAll(new Query());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#findAllById(java.lang.Iterable)
|
||||
*/
|
||||
@Override
|
||||
public Flux<T> findAllById(Iterable<ID> ids) {
|
||||
|
||||
Assert.notNull(ids, "The given Iterable of Id's must not be null!");
|
||||
|
||||
return findAll(getIdQuery(ids));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#findAllById(org.reactivestreams.Publisher)
|
||||
*/
|
||||
@Override
|
||||
public Flux<T> findAllById(Publisher<ID> ids) {
|
||||
|
||||
Assert.notNull(ids, "The given Publisher of Id's must not be null!");
|
||||
|
||||
return Flux.from(ids).buffer().flatMap(this::findAllById);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#count()
|
||||
*/
|
||||
@Override
|
||||
public Mono<Long> count() {
|
||||
return mongoOperations.count(new Query(), entityInformation.getCollectionName());
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#deleteById(java.lang.Object)
|
||||
@@ -394,6 +266,19 @@ public class SimpleReactiveMongoRepository<T, ID extends Serializable> implement
|
||||
return remove.then();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#deleteAllById(java.lang.Iterable)
|
||||
*/
|
||||
@Override
|
||||
public Mono<Void> deleteAllById(Iterable<? extends ID> ids) {
|
||||
|
||||
Assert.notNull(ids, "The given Iterable of Id's must not be null!");
|
||||
|
||||
return mongoOperations
|
||||
.remove(getIdQuery(ids), entityInformation.getJavaType(), entityInformation.getCollectionName()).then();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#deleteAll(java.lang.Iterable)
|
||||
@@ -403,8 +288,7 @@ public class SimpleReactiveMongoRepository<T, ID extends Serializable> implement
|
||||
|
||||
Assert.notNull(entities, "The given Iterable of entities must not be null!");
|
||||
|
||||
Collection<?> idCollection = StreamUtils.createStreamFromIterator(entities.iterator())
|
||||
.map(entityInformation::getId)
|
||||
Collection<?> idCollection = StreamUtils.createStreamFromIterator(entities.iterator()).map(entityInformation::getId)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
Criteria idsInCriteria = where(entityInformation.getIdAttribute()).in(idCollection);
|
||||
@@ -414,19 +298,6 @@ public class SimpleReactiveMongoRepository<T, ID extends Serializable> implement
|
||||
.then();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> deleteAllById(Iterable<? extends ID> ids) {
|
||||
|
||||
Assert.notNull(ids, "The given Iterable of ids must not be null!");
|
||||
|
||||
Collection<?> idCollection = StreamUtils.createStreamFromIterator(ids.iterator()).collect(Collectors.toList());
|
||||
Criteria idsInCriteria = where(entityInformation.getIdAttribute()).in(idCollection);
|
||||
|
||||
return mongoOperations
|
||||
.remove(new Query(idsInCriteria), entityInformation.getJavaType(), entityInformation.getCollectionName())
|
||||
.then();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#deleteAll(org.reactivestreams.Publisher)
|
||||
@@ -451,6 +322,151 @@ public class SimpleReactiveMongoRepository<T, ID extends Serializable> implement
|
||||
return mongoOperations.remove(new Query(), entityInformation.getCollectionName()).then(Mono.empty());
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Methods from ReactiveSortingRepository
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.reactive.ReactiveSortingRepository#findAll(org.springframework.data.domain.Sort)
|
||||
*/
|
||||
@Override
|
||||
public Flux<T> findAll(Sort sort) {
|
||||
|
||||
Assert.notNull(sort, "Sort must not be null!");
|
||||
|
||||
return findAll(new Query().with(sort));
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Methods from ReactiveMongoRepository
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.repository.ReactiveMongoRepository#insert(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public <S extends T> Mono<S> insert(S entity) {
|
||||
|
||||
Assert.notNull(entity, "Entity must not be null!");
|
||||
|
||||
return mongoOperations.insert(entity, entityInformation.getCollectionName());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.repository.ReactiveMongoRepository#insert(java.lang.Iterable)
|
||||
*/
|
||||
@Override
|
||||
public <S extends T> Flux<S> insert(Iterable<S> entities) {
|
||||
|
||||
Assert.notNull(entities, "The given Iterable of entities must not be null!");
|
||||
|
||||
List<S> source = Streamable.of(entities).stream().collect(StreamUtils.toUnmodifiableList());
|
||||
|
||||
return source.isEmpty() ? Flux.empty() : Flux.from(mongoOperations.insertAll(source));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.repository.ReactiveMongoRepository#insert(org.reactivestreams.Publisher)
|
||||
*/
|
||||
@Override
|
||||
public <S extends T> Flux<S> insert(Publisher<S> entities) {
|
||||
|
||||
Assert.notNull(entities, "The given Publisher of entities must not be null!");
|
||||
|
||||
return Flux.from(entities).flatMap(entity -> mongoOperations.insert(entity, entityInformation.getCollectionName()));
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Methods from ReactiveMongoRepository
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.query.ReactiveQueryByExampleExecutor#findOne(org.springframework.data.domain.Example)
|
||||
*/
|
||||
@Override
|
||||
public <S extends T> Mono<S> findOne(Example<S> example) {
|
||||
|
||||
Assert.notNull(example, "Sample must not be null!");
|
||||
|
||||
Query query = new Query(new Criteria().alike(example)) //
|
||||
.collation(entityInformation.getCollation()) //
|
||||
.limit(2);
|
||||
|
||||
return mongoOperations.find(query, example.getProbeType(), entityInformation.getCollectionName()).buffer(2)
|
||||
.map(vals -> {
|
||||
|
||||
if (vals.size() > 1) {
|
||||
throw new IncorrectResultSizeDataAccessException(1);
|
||||
}
|
||||
return vals.iterator().next();
|
||||
}).next();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.repository.ReactiveMongoRepository#findAll(org.springframework.data.domain.Example)
|
||||
*/
|
||||
@Override
|
||||
public <S extends T> Flux<S> findAll(Example<S> example) {
|
||||
|
||||
Assert.notNull(example, "Example must not be null!");
|
||||
|
||||
return findAll(example, Sort.unsorted());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.repository.ReactiveMongoRepository#findAll(org.springframework.data.domain.Example, org.springframework.data.domain.Sort)
|
||||
*/
|
||||
@Override
|
||||
public <S extends T> Flux<S> findAll(Example<S> example, Sort sort) {
|
||||
|
||||
Assert.notNull(example, "Sample must not be null!");
|
||||
Assert.notNull(sort, "Sort must not be null!");
|
||||
|
||||
Query query = new Query(new Criteria().alike(example)) //
|
||||
.collation(entityInformation.getCollation()) //
|
||||
.with(sort);
|
||||
|
||||
return mongoOperations.find(query, example.getProbeType(), entityInformation.getCollectionName());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.query.ReactiveQueryByExampleExecutor#count(org.springframework.data.domain.Example)
|
||||
*/
|
||||
@Override
|
||||
public <S extends T> Mono<Long> count(Example<S> example) {
|
||||
|
||||
Assert.notNull(example, "Sample must not be null!");
|
||||
|
||||
Query query = new Query(new Criteria().alike(example)) //
|
||||
.collation(entityInformation.getCollation());
|
||||
|
||||
return mongoOperations.count(query, example.getProbeType(), entityInformation.getCollectionName());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.query.ReactiveQueryByExampleExecutor#exists(org.springframework.data.domain.Example)
|
||||
*/
|
||||
@Override
|
||||
public <S extends T> Mono<Boolean> exists(Example<S> example) {
|
||||
|
||||
Assert.notNull(example, "Sample must not be null!");
|
||||
|
||||
Query query = new Query(new Criteria().alike(example)) //
|
||||
.collation(entityInformation.getCollation());
|
||||
|
||||
return mongoOperations.exists(query, example.getProbeType(), entityInformation.getCollectionName());
|
||||
}
|
||||
|
||||
|
||||
private Query getIdQuery(Object id) {
|
||||
return new Query(getIdCriteria(id));
|
||||
}
|
||||
@@ -459,6 +475,13 @@ public class SimpleReactiveMongoRepository<T, ID extends Serializable> implement
|
||||
return where(entityInformation.getIdAttribute()).is(id);
|
||||
}
|
||||
|
||||
private Query getIdQuery(Iterable<? extends ID> ids) {
|
||||
Collection<?> idCollection = StreamUtils.createStreamFromIterator(ids.iterator()).collect(Collectors.toList());
|
||||
Criteria idsInCriteria = where(entityInformation.getIdAttribute()).in(idCollection);
|
||||
|
||||
return new Query(idsInCriteria);
|
||||
}
|
||||
|
||||
private Flux<T> findAll(Query query) {
|
||||
|
||||
return mongoOperations.find(query, entityInformation.getJavaType(), entityInformation.getCollectionName());
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.mongodb.repository;
|
||||
|
||||
import static java.util.Arrays.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.springframework.data.domain.Sort.Direction.*;
|
||||
import static org.springframework.data.mongodb.core.query.Criteria.*;
|
||||
@@ -80,10 +79,10 @@ import com.mongodb.reactivestreams.client.MongoClient;
|
||||
* @author Jens Schauder
|
||||
*/
|
||||
@ExtendWith({ MongoClientExtension.class, SpringExtension.class })
|
||||
public class ReactiveMongoRepositoryTests {
|
||||
class ReactiveMongoRepositoryTests {
|
||||
|
||||
public static final int PERSON_COUNT = 7;
|
||||
static @Client MongoClient mongoClient;
|
||||
private static final int PERSON_COUNT = 7;
|
||||
private static @Client MongoClient mongoClient;
|
||||
|
||||
@Autowired ReactiveMongoTemplate template;
|
||||
|
||||
@@ -91,8 +90,8 @@ public class ReactiveMongoRepositoryTests {
|
||||
@Autowired ReactiveContactRepository contactRepository;
|
||||
@Autowired ReactiveCappedCollectionRepository cappedRepository;
|
||||
|
||||
Person dave, oliver, carter, boyd, stefan, leroi, alicia;
|
||||
QPerson person = QPerson.person;
|
||||
private Person dave, oliver, carter, boyd, stefan, leroi, alicia;
|
||||
private QPerson person = QPerson.person;
|
||||
|
||||
@Configuration
|
||||
static class Config extends AbstractReactiveMongoConfiguration {
|
||||
@@ -142,59 +141,59 @@ public class ReactiveMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@BeforeAll
|
||||
public static void cleanDb() {
|
||||
static void cleanDb() {
|
||||
|
||||
MongoTestUtils.createOrReplaceCollectionNow("reactive", "person", mongoClient);
|
||||
MongoTestUtils.createOrReplaceCollectionNow("reactive", "capped", mongoClient);
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
void setUp() throws Exception {
|
||||
|
||||
repository.deleteAll().as(StepVerifier::create).verifyComplete();
|
||||
|
||||
dave = new Person("Dave", "Matthews", 42);
|
||||
oliver = new Person("Oliver August", "Matthews", 4);
|
||||
carter = new Person("Carter", "Beauford", 49);
|
||||
carter.setSkills(asList("Drums", "percussion", "vocals"));
|
||||
carter.setSkills(Arrays.asList("Drums", "percussion", "vocals"));
|
||||
Thread.sleep(10);
|
||||
boyd = new Person("Boyd", "Tinsley", 45);
|
||||
boyd.setSkills(asList("Violin", "Electric Violin", "Viola", "Mandolin", "Vocals", "Guitar"));
|
||||
boyd.setSkills(Arrays.asList("Violin", "Electric Violin", "Viola", "Mandolin", "Vocals", "Guitar"));
|
||||
stefan = new Person("Stefan", "Lessard", 34);
|
||||
leroi = new Person("Leroi", "Moore", 41);
|
||||
|
||||
alicia = new Person("Alicia", "Keys", 30, Sex.FEMALE);
|
||||
|
||||
repository.saveAll(asList(oliver, carter, boyd, stefan, leroi, alicia, dave)).as(StepVerifier::create) //
|
||||
repository.saveAll(Arrays.asList(oliver, carter, boyd, stefan, leroi, alicia, dave)).as(StepVerifier::create) //
|
||||
.expectNextCount(PERSON_COUNT) //
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1444
|
||||
public void shouldFindByLastName() {
|
||||
void shouldFindByLastName() {
|
||||
repository.findByLastname(dave.getLastname()).as(StepVerifier::create).expectNextCount(2).verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1444
|
||||
public void shouldFindOneByLastName() {
|
||||
void shouldFindOneByLastName() {
|
||||
repository.findOneByLastname(carter.getLastname()).as(StepVerifier::create).expectNext(carter).verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1444
|
||||
public void shouldFindOneByPublisherOfLastName() {
|
||||
void shouldFindOneByPublisherOfLastName() {
|
||||
repository.findByLastname(Mono.just(carter.getLastname())).as(StepVerifier::create).expectNext(carter)
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1444
|
||||
public void shouldFindByPublisherOfLastNameIn() {
|
||||
void shouldFindByPublisherOfLastNameIn() {
|
||||
repository.findByLastnameIn(Flux.just(carter.getLastname(), dave.getLastname())).as(StepVerifier::create) //
|
||||
.expectNextCount(3) //
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1444
|
||||
public void shouldFindByPublisherOfLastNameInAndAgeGreater() {
|
||||
void shouldFindByPublisherOfLastNameInAndAgeGreater() {
|
||||
|
||||
repository.findByLastnameInAndAgeGreaterThan(Flux.just(carter.getLastname(), dave.getLastname()), 41)
|
||||
.as(StepVerifier::create) //
|
||||
@@ -203,7 +202,7 @@ public class ReactiveMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1444
|
||||
public void shouldFindUsingPublishersInStringQuery() {
|
||||
void shouldFindUsingPublishersInStringQuery() {
|
||||
|
||||
repository.findStringQuery(Flux.just("Beauford", "Matthews"), Mono.just(41)).as(StepVerifier::create) //
|
||||
.expectNextCount(2) //
|
||||
@@ -211,7 +210,7 @@ public class ReactiveMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1444
|
||||
public void shouldFindByLastNameAndSort() {
|
||||
void shouldFindByLastNameAndSort() {
|
||||
|
||||
repository.findByLastname("Matthews", Sort.by(ASC, "age")).as(StepVerifier::create) //
|
||||
.expectNext(oliver, dave) //
|
||||
@@ -223,7 +222,7 @@ public class ReactiveMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1444
|
||||
public void shouldUseTailableCursor() throws Exception {
|
||||
void shouldUseTailableCursor() throws Exception {
|
||||
|
||||
template.dropCollection(Capped.class) //
|
||||
.then(template.createCollection(Capped.class, //
|
||||
@@ -248,7 +247,7 @@ public class ReactiveMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1444
|
||||
public void shouldUseTailableCursorWithProjection() throws Exception {
|
||||
void shouldUseTailableCursorWithProjection() throws Exception {
|
||||
|
||||
template.dropCollection(Capped.class) //
|
||||
.then(template.createCollection(Capped.class, //
|
||||
@@ -279,7 +278,7 @@ public class ReactiveMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2080
|
||||
public void shouldUseTailableCursorWithDtoProjection() {
|
||||
void shouldUseTailableCursorWithDtoProjection() {
|
||||
|
||||
template.dropCollection(Capped.class) //
|
||||
.then(template.createCollection(Capped.class, //
|
||||
@@ -292,7 +291,7 @@ public class ReactiveMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1444
|
||||
public void findsPeopleByLocationWithinCircle() {
|
||||
void findsPeopleByLocationWithinCircle() {
|
||||
|
||||
Point point = new Point(-73.99171, 40.738868);
|
||||
dave.setLocation(point);
|
||||
@@ -304,7 +303,7 @@ public class ReactiveMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1444
|
||||
public void findsPeopleByPageableLocationWithinCircle() {
|
||||
void findsPeopleByPageableLocationWithinCircle() {
|
||||
|
||||
Point point = new Point(-73.99171, 40.738868);
|
||||
dave.setLocation(point);
|
||||
@@ -317,7 +316,7 @@ public class ReactiveMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1444
|
||||
public void findsPeopleGeoresultByLocationWithinBox() {
|
||||
void findsPeopleGeoresultByLocationWithinBox() {
|
||||
|
||||
Point point = new Point(-73.99171, 40.738868);
|
||||
dave.setLocation(point);
|
||||
@@ -332,7 +331,7 @@ public class ReactiveMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1444
|
||||
public void findsPeoplePageableGeoresultByLocationWithinBox() throws InterruptedException {
|
||||
void findsPeoplePageableGeoresultByLocationWithinBox() throws InterruptedException {
|
||||
|
||||
Point point = new Point(-73.99171, 40.738868);
|
||||
dave.setLocation(point);
|
||||
@@ -352,7 +351,7 @@ public class ReactiveMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1444
|
||||
public void findsPeopleByLocationWithinBox() throws InterruptedException {
|
||||
void findsPeopleByLocationWithinBox() throws InterruptedException {
|
||||
|
||||
Point point = new Point(-73.99171, 40.738868);
|
||||
dave.setLocation(point);
|
||||
@@ -368,23 +367,23 @@ public class ReactiveMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1865
|
||||
public void shouldErrorOnFindOneWithNonUniqueResult() {
|
||||
void shouldErrorOnFindOneWithNonUniqueResult() {
|
||||
repository.findOneByLastname(dave.getLastname()).as(StepVerifier::create)
|
||||
.expectError(IncorrectResultSizeDataAccessException.class).verify();
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1865
|
||||
public void shouldReturnFirstFindFirstWithMoreResults() {
|
||||
void shouldReturnFirstFindFirstWithMoreResults() {
|
||||
repository.findFirstByLastname(dave.getLastname()).as(StepVerifier::create).expectNextCount(1).verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2030
|
||||
public void shouldReturnExistsBy() {
|
||||
void shouldReturnExistsBy() {
|
||||
repository.existsByLastname(dave.getLastname()).as(StepVerifier::create).expectNext(true).verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1979
|
||||
public void findAppliesAnnotatedSort() {
|
||||
void findAppliesAnnotatedSort() {
|
||||
|
||||
repository.findByAgeGreaterThan(40).collectList().as(StepVerifier::create).consumeNextWith(result -> {
|
||||
assertThat(result).containsSequence(carter, boyd, dave, leroi);
|
||||
@@ -392,7 +391,7 @@ public class ReactiveMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1979
|
||||
public void findWithSortOverwritesAnnotatedSort() {
|
||||
void findWithSortOverwritesAnnotatedSort() {
|
||||
|
||||
repository.findByAgeGreaterThan(40, Sort.by(Direction.ASC, "age")).collectList().as(StepVerifier::create)
|
||||
.consumeNextWith(result -> {
|
||||
@@ -401,7 +400,7 @@ public class ReactiveMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2181
|
||||
public void considersRepositoryCollectionName() {
|
||||
void considersRepositoryCollectionName() {
|
||||
|
||||
repository.deleteAll() //
|
||||
.as(StepVerifier::create) //
|
||||
@@ -413,7 +412,7 @@ public class ReactiveMongoRepositoryTests {
|
||||
|
||||
leroi.id = null;
|
||||
boyd.id = null;
|
||||
contactRepository.saveAll(asList(leroi, boyd)) //
|
||||
contactRepository.saveAll(Arrays.asList(leroi, boyd)) //
|
||||
.as(StepVerifier::create) //
|
||||
.expectNextCount(2) //
|
||||
.verifyComplete();
|
||||
@@ -430,9 +429,9 @@ public class ReactiveMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2182
|
||||
public void shouldFindPersonsWhenUsingQueryDslPerdicatedOnIdProperty() {
|
||||
void shouldFindPersonsWhenUsingQueryDslPerdicatedOnIdProperty() {
|
||||
|
||||
repository.findAll(person.id.in(asList(dave.id, carter.id))) //
|
||||
repository.findAll(person.id.in(Arrays.asList(dave.id, carter.id))) //
|
||||
.collectList() //
|
||||
.as(StepVerifier::create) //
|
||||
.assertNext(actual -> {
|
||||
@@ -441,24 +440,19 @@ public class ReactiveMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2153
|
||||
public void findListOfSingleValue() {
|
||||
void findListOfSingleValue() {
|
||||
|
||||
repository.findAllLastnames() //
|
||||
.collectList() //
|
||||
.as(StepVerifier::create) //
|
||||
.assertNext(actual -> {
|
||||
assertThat(actual) //
|
||||
.contains("Lessard") //
|
||||
.contains("Keys") //
|
||||
.contains("Tinsley") //
|
||||
.contains("Beauford") //
|
||||
.contains("Moore") //
|
||||
.contains("Matthews");
|
||||
assertThat(actual)
|
||||
.contains("Lessard", "Keys", "Tinsley", "Beauford", "Moore", "Matthews");
|
||||
}).verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2153
|
||||
public void annotatedAggregationWithPlaceholderValue() {
|
||||
void annotatedAggregationWithPlaceholderValue() {
|
||||
|
||||
repository.groupByLastnameAnd("firstname") //
|
||||
.collectList() //
|
||||
@@ -470,12 +464,12 @@ public class ReactiveMongoRepositoryTests {
|
||||
.contains(new PersonAggregate("Tinsley", "Boyd")) //
|
||||
.contains(new PersonAggregate("Beauford", "Carter")) //
|
||||
.contains(new PersonAggregate("Moore", "Leroi")) //
|
||||
.contains(new PersonAggregate("Matthews", asList("Dave", "Oliver August")));
|
||||
.contains(new PersonAggregate("Matthews", Arrays.asList("Dave", "Oliver August")));
|
||||
}).verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2153
|
||||
public void annotatedAggregationWithSort() {
|
||||
void annotatedAggregationWithSort() {
|
||||
|
||||
repository.groupByLastnameAnd("firstname", Sort.by("lastname")) //
|
||||
.collectList() //
|
||||
@@ -486,7 +480,7 @@ public class ReactiveMongoRepositoryTests {
|
||||
new PersonAggregate("Beauford", "Carter"), //
|
||||
new PersonAggregate("Keys", "Alicia"), //
|
||||
new PersonAggregate("Lessard", "Stefan"), //
|
||||
new PersonAggregate("Matthews", asList("Dave", "Oliver August")), //
|
||||
new PersonAggregate("Matthews", Arrays.asList("Dave", "Oliver August")), //
|
||||
new PersonAggregate("Moore", "Leroi"), //
|
||||
new PersonAggregate("Tinsley", "Boyd"));
|
||||
}) //
|
||||
@@ -494,7 +488,7 @@ public class ReactiveMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2153
|
||||
public void annotatedAggregationWithPageable() {
|
||||
void annotatedAggregationWithPageable() {
|
||||
|
||||
repository.groupByLastnameAnd("firstname", PageRequest.of(1, 2, Sort.by("lastname"))) //
|
||||
.collectList() //
|
||||
@@ -503,13 +497,13 @@ public class ReactiveMongoRepositoryTests {
|
||||
assertThat(actual) //
|
||||
.containsExactly( //
|
||||
new PersonAggregate("Lessard", "Stefan"), //
|
||||
new PersonAggregate("Matthews", asList("Dave", "Oliver August")));
|
||||
new PersonAggregate("Matthews", Arrays.asList("Dave", "Oliver August")));
|
||||
}) //
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2153
|
||||
public void annotatedAggregationWithSingleSimpleResult() {
|
||||
void annotatedAggregationWithSingleSimpleResult() {
|
||||
|
||||
repository.sumAge() //
|
||||
.as(StepVerifier::create) //
|
||||
@@ -518,7 +512,7 @@ public class ReactiveMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2153
|
||||
public void annotatedAggregationWithAggregationResultAsReturnType() {
|
||||
void annotatedAggregationWithAggregationResultAsReturnType() {
|
||||
|
||||
repository.sumAgeAndReturnRawResult() //
|
||||
.as(StepVerifier::create) //
|
||||
@@ -527,7 +521,7 @@ public class ReactiveMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2153
|
||||
public void annotatedAggregationWithAggregationResultAsReturnTypeAndProjection() {
|
||||
void annotatedAggregationWithAggregationResultAsReturnTypeAndProjection() {
|
||||
|
||||
repository.sumAgeAndReturnSumWrapper() //
|
||||
.as(StepVerifier::create) //
|
||||
@@ -536,7 +530,7 @@ public class ReactiveMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2374
|
||||
public void findsWithNativeProjection() {
|
||||
void findsWithNativeProjection() {
|
||||
|
||||
repository.findDocumentById(dave.getId()) //
|
||||
.as(StepVerifier::create) //
|
||||
@@ -546,7 +540,7 @@ public class ReactiveMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2153
|
||||
public void annotatedAggregationWithAggregationResultAsMap() {
|
||||
void annotatedAggregationWithAggregationResultAsMap() {
|
||||
|
||||
repository.sumAgeAndReturnSumAsMap() //
|
||||
.as(StepVerifier::create) //
|
||||
@@ -556,7 +550,7 @@ public class ReactiveMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2403
|
||||
public void annotatedAggregationExtractingSimpleValueIsEmptyForEmptyDocument() {
|
||||
void annotatedAggregationExtractingSimpleValueIsEmptyForEmptyDocument() {
|
||||
|
||||
Person p = new Person("project-on-lastanme", null);
|
||||
repository.save(p).then().as(StepVerifier::create).verifyComplete();
|
||||
@@ -567,7 +561,7 @@ public class ReactiveMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2403
|
||||
public void annotatedAggregationSkipsEmptyDocumentsWhenExtractingSimpleValue() {
|
||||
void annotatedAggregationSkipsEmptyDocumentsWhenExtractingSimpleValue() {
|
||||
|
||||
String firstname = "project-on-lastanme";
|
||||
|
||||
@@ -578,7 +572,7 @@ public class ReactiveMongoRepositoryTests {
|
||||
Person p3 = new Person(firstname, null);
|
||||
p3.setEmail("p3@example.com");
|
||||
|
||||
repository.saveAll(asList(p1, p2, p3)).then().as(StepVerifier::create).verifyComplete();
|
||||
repository.saveAll(Arrays.asList(p1, p2, p3)).then().as(StepVerifier::create).verifyComplete();
|
||||
|
||||
repository.projectToLastnameAndRemoveId(firstname) //
|
||||
.as(StepVerifier::create) //
|
||||
@@ -586,7 +580,7 @@ public class ReactiveMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2406
|
||||
public void deleteByShouldHandleVoidResultTypeCorrectly() {
|
||||
void deleteByShouldHandleVoidResultTypeCorrectly() {
|
||||
|
||||
repository.deleteByLastname(dave.getLastname()) //
|
||||
.as(StepVerifier::create) //
|
||||
@@ -598,7 +592,7 @@ public class ReactiveMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1997
|
||||
public void deleteByShouldAllowDeletedCountAsResult() {
|
||||
void deleteByShouldAllowDeletedCountAsResult() {
|
||||
|
||||
repository.deleteCountByLastname(dave.getLastname()) //
|
||||
.as(StepVerifier::create) //
|
||||
@@ -607,7 +601,7 @@ public class ReactiveMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1997
|
||||
public void deleteByShouldAllowSingleDocumentRemovalCorrectly() {
|
||||
void deleteByShouldAllowSingleDocumentRemovalCorrectly() {
|
||||
|
||||
repository.deleteSinglePersonByLastname(carter.getLastname()) //
|
||||
.as(StepVerifier::create) //
|
||||
@@ -620,9 +614,9 @@ public class ReactiveMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2652
|
||||
public void deleteAllById() {
|
||||
void deleteAllById() {
|
||||
|
||||
repository.deleteAllById(asList(carter.id, dave.id)) //
|
||||
repository.deleteAllById(Arrays.asList(carter.id, dave.id)) //
|
||||
.as(StepVerifier::create) //
|
||||
.verifyComplete();
|
||||
|
||||
@@ -731,7 +725,7 @@ public class ReactiveMongoRepositoryTests {
|
||||
String key;
|
||||
double random;
|
||||
|
||||
public Capped(String key, double random) {
|
||||
Capped(String key, double random) {
|
||||
this.key = key;
|
||||
this.random = random;
|
||||
}
|
||||
|
||||
@@ -61,10 +61,10 @@ import org.springframework.transaction.support.TransactionTemplate;
|
||||
* @author Jens Schauder
|
||||
*/
|
||||
@ExtendWith({ MongoTemplateExtension.class, MongoServerCondition.class })
|
||||
public class SimpleMongoRepositoryTests {
|
||||
class SimpleMongoRepositoryTests {
|
||||
|
||||
@Template(initialEntitySet = Person.class) //
|
||||
static MongoTestTemplate template;
|
||||
private static MongoTestTemplate template;
|
||||
|
||||
private Person oliver, dave, carter, boyd, stefan, leroi, alicia;
|
||||
private List<Person> all;
|
||||
@@ -74,7 +74,7 @@ public class SimpleMongoRepositoryTests {
|
||||
template);
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
void setUp() {
|
||||
|
||||
repository.deleteAll();
|
||||
|
||||
@@ -90,17 +90,17 @@ public class SimpleMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findAllFromCustomCollectionName() {
|
||||
assertThat(repository.findAll()).hasSize(all.size());
|
||||
void findAllFromCustomCollectionName() {
|
||||
assertThat(repository.findAll()).hasSameSizeAs(all);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findOneFromCustomCollectionName() {
|
||||
assertThat(repository.findById(dave.getId()).get()).isEqualTo(dave);
|
||||
void findOneFromCustomCollectionName() {
|
||||
assertThat(repository.findById(dave.getId())).contains(dave);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deleteFromCustomCollectionName() {
|
||||
void deleteFromCustomCollectionName() {
|
||||
|
||||
repository.delete(dave);
|
||||
|
||||
@@ -108,7 +108,7 @@ public class SimpleMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deleteByIdFromCustomCollectionName() {
|
||||
void deleteByIdFromCustomCollectionName() {
|
||||
|
||||
repository.deleteById(dave.getId());
|
||||
|
||||
@@ -116,7 +116,7 @@ public class SimpleMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1054
|
||||
public void shouldInsertSingle() {
|
||||
void shouldInsertSingle() {
|
||||
|
||||
String randomId = UUID.randomUUID().toString();
|
||||
|
||||
@@ -127,7 +127,7 @@ public class SimpleMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1054
|
||||
public void shouldInsertMultipleFromList() {
|
||||
void shouldInsertMultipleFromList() {
|
||||
|
||||
String randomId = UUID.randomUUID().toString();
|
||||
Map<String, Person> idToPerson = new HashMap<String, Person>();
|
||||
@@ -141,12 +141,12 @@ public class SimpleMongoRepositoryTests {
|
||||
|
||||
List<Person> saved = repository.insert(persons);
|
||||
|
||||
assertThat(saved).hasSize(persons.size());
|
||||
assertThat(saved).hasSameSizeAs(persons);
|
||||
assertThatAllReferencePersonsWereStoredCorrectly(idToPerson, saved);
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1054
|
||||
public void shouldInsertMutlipleFromSet() {
|
||||
void shouldInsertMutlipleFromSet() {
|
||||
|
||||
String randomId = UUID.randomUUID().toString();
|
||||
Map<String, Person> idToPerson = new HashMap<String, Person>();
|
||||
@@ -160,12 +160,12 @@ public class SimpleMongoRepositoryTests {
|
||||
|
||||
List<Person> saved = repository.insert(persons);
|
||||
|
||||
assertThat(saved).hasSize(persons.size());
|
||||
assertThat(saved).hasSameSizeAs(persons);
|
||||
assertThatAllReferencePersonsWereStoredCorrectly(idToPerson, saved);
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1245, DATAMONGO-1464
|
||||
public void findByExampleShouldLookUpEntriesCorrectly() {
|
||||
void findByExampleShouldLookUpEntriesCorrectly() {
|
||||
|
||||
Person sample = new Person();
|
||||
sample.setLastname("Matthews");
|
||||
@@ -178,7 +178,7 @@ public class SimpleMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1464
|
||||
public void findByExampleMultiplePagesShouldLookUpEntriesCorrectly() {
|
||||
void findByExampleMultiplePagesShouldLookUpEntriesCorrectly() {
|
||||
|
||||
Person sample = new Person();
|
||||
sample.setLastname("Matthews");
|
||||
@@ -191,7 +191,7 @@ public class SimpleMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1245
|
||||
public void findAllByExampleShouldLookUpEntriesCorrectly() {
|
||||
void findAllByExampleShouldLookUpEntriesCorrectly() {
|
||||
|
||||
Person sample = new Person();
|
||||
sample.setLastname("Matthews");
|
||||
@@ -201,7 +201,7 @@ public class SimpleMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1245
|
||||
public void findAllByExampleShouldLookUpEntriesCorrectlyWhenUsingNestedObject() {
|
||||
void findAllByExampleShouldLookUpEntriesCorrectlyWhenUsingNestedObject() {
|
||||
|
||||
dave.setAddress(new Address("1600 Pennsylvania Ave NW", "20500", "Washington"));
|
||||
repository.save(dave);
|
||||
@@ -217,7 +217,7 @@ public class SimpleMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1245
|
||||
public void findAllByExampleShouldLookUpEntriesCorrectlyWhenUsingPartialNestedObject() {
|
||||
void findAllByExampleShouldLookUpEntriesCorrectlyWhenUsingPartialNestedObject() {
|
||||
|
||||
dave.setAddress(new Address("1600 Pennsylvania Ave NW", "20500", "Washington"));
|
||||
repository.save(dave);
|
||||
@@ -233,7 +233,7 @@ public class SimpleMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1245
|
||||
public void findAllByExampleShouldNotFindEntriesWhenUsingPartialNestedObjectInStrictMode() {
|
||||
void findAllByExampleShouldNotFindEntriesWhenUsingPartialNestedObjectInStrictMode() {
|
||||
|
||||
dave.setAddress(new Address("1600 Pennsylvania Ave NW", "20500", "Washington"));
|
||||
repository.save(dave);
|
||||
@@ -248,7 +248,7 @@ public class SimpleMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1245
|
||||
public void findAllByExampleShouldLookUpEntriesCorrectlyWhenUsingNestedObjectInStrictMode() {
|
||||
void findAllByExampleShouldLookUpEntriesCorrectlyWhenUsingNestedObjectInStrictMode() {
|
||||
|
||||
dave.setAddress(new Address("1600 Pennsylvania Ave NW", "20500", "Washington"));
|
||||
repository.save(dave);
|
||||
@@ -263,7 +263,7 @@ public class SimpleMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1245
|
||||
public void findAllByExampleShouldRespectStringMatchMode() {
|
||||
void findAllByExampleShouldRespectStringMatchMode() {
|
||||
|
||||
Person sample = new Person();
|
||||
sample.setLastname("Mat");
|
||||
@@ -275,7 +275,7 @@ public class SimpleMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1245
|
||||
public void findAllByExampleShouldResolveDbRefCorrectly() {
|
||||
void findAllByExampleShouldResolveDbRefCorrectly() {
|
||||
|
||||
User user = new User();
|
||||
user.setId("c0nf1ux");
|
||||
@@ -295,7 +295,7 @@ public class SimpleMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1245
|
||||
public void findAllByExampleShouldResolveLegacyCoordinatesCorrectly() {
|
||||
void findAllByExampleShouldResolveLegacyCoordinatesCorrectly() {
|
||||
|
||||
Person megan = new Person("megan", "tarash");
|
||||
megan.setLocation(new Point(41.85003D, -87.65005D));
|
||||
@@ -310,7 +310,7 @@ public class SimpleMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1245
|
||||
public void findAllByExampleShouldResolveGeoJsonCoordinatesCorrectly() {
|
||||
void findAllByExampleShouldResolveGeoJsonCoordinatesCorrectly() {
|
||||
|
||||
Person megan = new Person("megan", "tarash");
|
||||
megan.setLocation(new GeoJsonPoint(41.85003D, -87.65005D));
|
||||
@@ -325,7 +325,7 @@ public class SimpleMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1245
|
||||
public void findAllByExampleShouldProcessInheritanceCorrectly() {
|
||||
void findAllByExampleShouldProcessInheritanceCorrectly() {
|
||||
|
||||
PersonExtended reference = new PersonExtended();
|
||||
reference.setLastname("Matthews");
|
||||
@@ -341,7 +341,7 @@ public class SimpleMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1245
|
||||
public void findOneByExampleShouldLookUpEntriesCorrectly() {
|
||||
void findOneByExampleShouldLookUpEntriesCorrectly() {
|
||||
|
||||
Person sample = new Person();
|
||||
sample.setFirstname("Dave");
|
||||
@@ -352,7 +352,7 @@ public class SimpleMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1245
|
||||
public void existsByExampleShouldLookUpEntriesCorrectly() {
|
||||
void existsByExampleShouldLookUpEntriesCorrectly() {
|
||||
|
||||
Person sample = new Person();
|
||||
sample.setFirstname("Dave");
|
||||
@@ -363,7 +363,7 @@ public class SimpleMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1245
|
||||
public void countByExampleShouldLookUpEntriesCorrectly() {
|
||||
void countByExampleShouldLookUpEntriesCorrectly() {
|
||||
|
||||
Person sample = new Person();
|
||||
sample.setLastname("Matthews");
|
||||
@@ -373,7 +373,7 @@ public class SimpleMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1896
|
||||
public void saveAllUsesEntityCollection() {
|
||||
void saveAllUsesEntityCollection() {
|
||||
|
||||
Person first = new PersonExtended();
|
||||
first.setEmail("foo@bar.com");
|
||||
@@ -393,7 +393,7 @@ public class SimpleMongoRepositoryTests {
|
||||
@Test // DATAMONGO-2130
|
||||
@EnableIfReplicaSetAvailable
|
||||
@EnableIfMongoServerVersion(isGreaterThanEqual = "4.0")
|
||||
public void countShouldBePossibleInTransaction() {
|
||||
void countShouldBePossibleInTransaction() {
|
||||
|
||||
MongoTransactionManager txmgr = new MongoTransactionManager(template.getMongoDbFactory());
|
||||
TransactionTemplate tt = new TransactionTemplate(txmgr);
|
||||
@@ -417,7 +417,7 @@ public class SimpleMongoRepositoryTests {
|
||||
@Test // DATAMONGO-2130
|
||||
@EnableIfReplicaSetAvailable
|
||||
@EnableIfMongoServerVersion(isGreaterThanEqual = "4.0")
|
||||
public void existsShouldBePossibleInTransaction() {
|
||||
void existsShouldBePossibleInTransaction() {
|
||||
|
||||
MongoTransactionManager txmgr = new MongoTransactionManager(template.getMongoDbFactory());
|
||||
TransactionTemplate tt = new TransactionTemplate(txmgr);
|
||||
@@ -437,14 +437,12 @@ public class SimpleMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2652
|
||||
public void deleteAllByIds() {
|
||||
void deleteAllByIds() {
|
||||
|
||||
repository.deleteAllById(asList(dave.getId(), carter.getId()));
|
||||
|
||||
assertThat(repository.findAll()) //
|
||||
.hasSize(all.size() - 2) //
|
||||
.doesNotContain(dave) //
|
||||
.doesNotContain(carter);
|
||||
.hasSize(all.size() - 2).doesNotContain(dave, carter);
|
||||
}
|
||||
|
||||
private void assertThatAllReferencePersonsWereStoredCorrectly(Map<String, Person> references, List<Person> saved) {
|
||||
|
||||
Reference in New Issue
Block a user