DATAMONGO-1609 - Fix failing tests.
Fix issues pointed out by failing tests. Main focus was to restore functionality and not a Java 8 code cleanup. So, this one still needs some love and polishing.
This commit is contained in:
committed by
Oliver Gierke
parent
90bb6262f9
commit
288f244c34
@@ -1172,7 +1172,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
public UpdateResult doInCollection(MongoCollection<Document> collection)
|
||||
throws MongoException, DataAccessException {
|
||||
|
||||
Optional<? extends MongoPersistentEntity<?>> entity = entityClass == null ? null
|
||||
Optional<? extends MongoPersistentEntity<?>> entity = entityClass == null ? Optional.empty()
|
||||
: getPersistentEntity(entityClass);
|
||||
|
||||
increaseVersionForUpdateIfNecessary(entity, update);
|
||||
@@ -2011,7 +2011,9 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
PersistentPropertyAccessor accessor = entity.getPropertyAccessor(savedObject);
|
||||
|
||||
Optional<Object> value = accessor.getProperty(idProp);
|
||||
value.ifPresent(it -> new ConvertingPropertyAccessor(accessor, conversionService).setProperty(idProp, value));
|
||||
if(!value.isPresent()) {
|
||||
new ConvertingPropertyAccessor(accessor, conversionService).setProperty(idProp, Optional.of(id));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -755,7 +755,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
|
||||
final Document Document = query == null ? null
|
||||
: queryMapper.getMappedObject(query.getQueryObject(),
|
||||
entityClass == null ? null : mappingContext.getPersistentEntity(entityClass));
|
||||
entityClass == null ? Optional.empty() : mappingContext.getPersistentEntity(entityClass));
|
||||
|
||||
return collection.count(Document);
|
||||
});
|
||||
@@ -976,8 +976,8 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
ReactiveMongoTemplate.this.assertUpdateableIdIfNotSet(objectToSave);
|
||||
|
||||
// Create query for entity with the id and old version
|
||||
Object id = convertingAccessor.getProperty(idProperty);
|
||||
Query query = new Query(Criteria.where(idProperty.getName()).is(id).and(versionProperty.getName()).is(version));
|
||||
Optional<Object> id = convertingAccessor.getProperty(idProperty);
|
||||
Query query = new Query(Criteria.where(idProperty.getName()).is(id.get()).and(versionProperty.getName()).is(version.get()));
|
||||
|
||||
// Bump version number
|
||||
convertingAccessor.setProperty(versionProperty, Optional.of(versionNumber.orElse(0).longValue() + 1));
|
||||
@@ -1308,8 +1308,8 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
throw new MappingException("No id property found for object of type " + objectType);
|
||||
}
|
||||
|
||||
Object idValue = entity.get().getPropertyAccessor(object).getProperty(idProp);
|
||||
return Collections.singletonMap(idProp.getFieldName(), idValue).entrySet().iterator().next();
|
||||
Optional<Object> idValue = entity.get().getPropertyAccessor(object).getProperty(idProp);
|
||||
return Collections.singletonMap(idProp.getFieldName(), idValue.get()).entrySet().iterator().next();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1706,7 +1706,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
MongoPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(savedObject.getClass());
|
||||
PersistentPropertyAccessor accessor = entity.getPropertyAccessor(savedObject);
|
||||
|
||||
if (accessor.getProperty(idProp) != null) {
|
||||
if (accessor.getProperty(idProp).isPresent()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -57,6 +57,6 @@ class DefaultDbRefResolverCallback implements DbRefResolverCallback {
|
||||
*/
|
||||
@Override
|
||||
public Object resolve(MongoPersistentProperty property) {
|
||||
return resolver.getValueInternal(property, surroundingObject, evaluator, path);
|
||||
return resolver.getValueInternal(property, surroundingObject, evaluator, path).orElse(null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ import org.springframework.data.util.TypeInformation;
|
||||
|
||||
import com.mongodb.BasicDBList;
|
||||
import com.mongodb.DBObject;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* Default implementation of {@link MongoTypeMapper} allowing configuration of the key to lookup and store type
|
||||
@@ -108,10 +109,10 @@ public class DefaultMongoTypeMapper extends DefaultTypeMapper<Bson> implements M
|
||||
|
||||
for (Class<?> restrictedType : restrictedTypes) {
|
||||
|
||||
Object typeAlias = getAliasFor(ClassTypeInformation.from(restrictedType));
|
||||
Alias typeAlias = getAliasFor(ClassTypeInformation.from(restrictedType));
|
||||
|
||||
if (typeAlias != null) {
|
||||
restrictedMappedTypes.add(typeAlias);
|
||||
if (typeAlias != null && !ObjectUtils.nullSafeEquals(Alias.NONE, typeAlias) && typeAlias.getValue().isPresent()) {
|
||||
restrictedMappedTypes.add(typeAlias.getValue().get());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -55,6 +55,7 @@ import org.springframework.data.mapping.model.SpELContext;
|
||||
import org.springframework.data.mapping.model.SpELExpressionEvaluator;
|
||||
import org.springframework.data.mapping.model.SpELExpressionParameterValueProvider;
|
||||
import org.springframework.data.mongodb.MongoDbFactory;
|
||||
import org.springframework.data.mongodb.core.convert.MongoConverters.ObjectIdToBigIntegerConverter;
|
||||
import org.springframework.data.mongodb.core.mapping.MongoPersistentEntity;
|
||||
import org.springframework.data.mongodb.core.mapping.MongoPersistentProperty;
|
||||
import org.springframework.data.mongodb.core.mapping.event.AfterConvertEvent;
|
||||
@@ -240,7 +241,9 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
}
|
||||
// Retrieve persistent entity info
|
||||
|
||||
return read((MongoPersistentEntity<S>) mappingContext.getRequiredPersistentEntity(typeToUse), (Document) bson,
|
||||
Document target = bson instanceof BasicDBObject ? new Document((BasicDBObject)bson) : (Document) bson;
|
||||
|
||||
return read((MongoPersistentEntity<S>) mappingContext.getRequiredPersistentEntity(typeToUse), target,
|
||||
path);
|
||||
}
|
||||
|
||||
@@ -271,7 +274,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
DocumentAccessor documentAccessor = new DocumentAccessor(bson);
|
||||
|
||||
// make sure id property is set before all other properties
|
||||
Object idValue = idProperty.filter(it -> documentAccessor.hasValue(it)).map(it -> {
|
||||
Optional<Object> idValue = idProperty.filter(it -> documentAccessor.hasValue(it)).map(it -> {
|
||||
|
||||
Optional<Object> value = getValueInternal(it, bson, evaluator, path);
|
||||
accessor.setProperty(it, value);
|
||||
@@ -280,7 +283,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
});
|
||||
|
||||
final ObjectPath currentPath = path.push(result, entity,
|
||||
idValue != null ? idProperty.map(it -> bson.get(it.getFieldName())).orElse(null) : null);
|
||||
idValue.isPresent() ? idProperty.map(it -> bson.get(it.getFieldName())).orElse(null) : null);
|
||||
|
||||
// Set properties not already set in the constructor
|
||||
entity.doWithProperties(new PropertyHandler<MongoPersistentProperty>() {
|
||||
@@ -867,7 +870,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
}
|
||||
|
||||
return dbRefResolver.createDbRef(property == null ? null : property.getDBRef(), entity,
|
||||
idMapper.convertId(Optional.of(id)));
|
||||
idMapper.convertId(id instanceof Optional ? (Optional)id : Optional.ofNullable(id)).orElse(null));
|
||||
|
||||
}).orElseThrow(() -> new MappingException("No id property found on class " + entity.getType()));
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.Stack;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -98,9 +99,9 @@ public class MongoExampleMapper {
|
||||
|
||||
Document reference = (Document) converter.convertToMongoType(example.getProbe());
|
||||
|
||||
Optionals.ifAllPresent(entity.getIdProperty(), //
|
||||
entity.getIdentifierAccessor(example.getProbe()).getIdentifier(), //
|
||||
(property, identifier) -> reference.remove(property.getFieldName()));
|
||||
if(entity.getIdProperty().isPresent() && !entity.getIdentifierAccessor(example.getProbe()).getIdentifier().isPresent()) {
|
||||
reference.remove(entity.getIdProperty().get().getFieldName());
|
||||
}
|
||||
|
||||
ExampleMatcherAccessor matcherAccessor = new ExampleMatcherAccessor(example.getMatcher());
|
||||
|
||||
@@ -241,7 +242,7 @@ public class MongoExampleMapper {
|
||||
}
|
||||
|
||||
private boolean isEmptyIdProperty(Entry<String, Object> entry) {
|
||||
return entry.getKey().equals("_id") && entry.getValue() == null;
|
||||
return entry.getKey().equals("_id") && entry.getValue() == null || entry.getValue().equals(Optional.empty());
|
||||
}
|
||||
|
||||
private void applyStringMatcher(Map.Entry<String, Object> entry, StringMatcher stringMatcher, boolean ignoreCase) {
|
||||
|
||||
@@ -318,11 +318,11 @@ public class QueryMapper {
|
||||
String inKey = valueDbo.containsField("$in") ? "$in" : "$nin";
|
||||
List<Object> ids = new ArrayList<Object>();
|
||||
for (Object id : (Iterable<?>) valueDbo.get(inKey)) {
|
||||
ids.add(convertId(id));
|
||||
ids.add(convertId(id).get());
|
||||
}
|
||||
resultDbo.put(inKey, ids);
|
||||
} else if (valueDbo.containsField("$ne")) {
|
||||
resultDbo.put("$ne", convertId(valueDbo.get("$ne")));
|
||||
resultDbo.put("$ne", convertId(valueDbo.get("$ne")).get());
|
||||
} else {
|
||||
return getMappedObject(resultDbo, Optional.empty());
|
||||
}
|
||||
@@ -337,18 +337,18 @@ public class QueryMapper {
|
||||
String inKey = valueDbo.containsKey("$in") ? "$in" : "$nin";
|
||||
List<Object> ids = new ArrayList<Object>();
|
||||
for (Object id : (Iterable<?>) valueDbo.get(inKey)) {
|
||||
ids.add(convertId(id));
|
||||
ids.add(convertId(id).orElse(null));
|
||||
}
|
||||
resultDbo.put(inKey, ids);
|
||||
} else if (valueDbo.containsKey("$ne")) {
|
||||
resultDbo.put("$ne", convertId(valueDbo.get("$ne")));
|
||||
resultDbo.put("$ne", convertId(valueDbo.get("$ne")).orElse(null));
|
||||
} else {
|
||||
return getMappedObject(resultDbo, Optional.empty());
|
||||
}
|
||||
return resultDbo;
|
||||
|
||||
} else {
|
||||
return convertId(value);
|
||||
return convertId(value).orElse(null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -461,7 +461,7 @@ public class QueryMapper {
|
||||
if (source instanceof DBRef) {
|
||||
|
||||
DBRef ref = (DBRef) source;
|
||||
return new DBRef(ref.getCollectionName(), convertId(ref.getId()));
|
||||
return new DBRef(ref.getCollectionName(), convertId(ref.getId()).get());
|
||||
}
|
||||
|
||||
if (source instanceof Iterable) {
|
||||
@@ -538,7 +538,7 @@ public class QueryMapper {
|
||||
}
|
||||
|
||||
private Optional<Object> convertId(Object id) {
|
||||
return convertId(Optional.of(id));
|
||||
return convertId(Optional.ofNullable(id));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -857,7 +857,7 @@ public class QueryMapper {
|
||||
@Override
|
||||
public MongoPersistentEntity<?> getPropertyEntity() {
|
||||
MongoPersistentProperty property = getProperty();
|
||||
return property == null ? null : mappingContext.getRequiredPersistentEntity(property);
|
||||
return property == null ? null : mappingContext.getPersistentEntity(property).orElse(null);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -131,7 +131,7 @@ public class MongoPersistentEntityIndexCreator implements ApplicationListener<Ma
|
||||
|
||||
private void checkForAndCreateIndexes(MongoPersistentEntity<?> entity) {
|
||||
|
||||
if (entity.findAnnotation(Document.class) != null) {
|
||||
if (entity.findAnnotation(Document.class).isPresent()) {
|
||||
for (IndexDefinitionHolder indexToCreate : indexResolver.resolveIndexFor(entity.getTypeInformation())) {
|
||||
createIndex(indexToCreate);
|
||||
}
|
||||
|
||||
@@ -261,13 +261,13 @@ public class MongoPersistentEntityIndexResolver implements IndexResolver {
|
||||
String propertyDotPath = (StringUtils.hasText(dotPath) ? dotPath + "." : "")
|
||||
+ persistentProperty.getFieldName();
|
||||
|
||||
Float weight = indexed != null ? indexed.get().weight()
|
||||
Float weight = indexed.isPresent() ? indexed.get().weight()
|
||||
: (includeOptions.getParentFieldSpec() != null ? includeOptions.getParentFieldSpec().getWeight() : 1.0F);
|
||||
|
||||
if (persistentProperty.isEntity()) {
|
||||
|
||||
TextIndexIncludeOptions optionsForNestedType = includeOptions;
|
||||
if (!IncludeStrategy.FORCE.equals(includeOptions.getStrategy()) && indexed != null) {
|
||||
if (!IncludeStrategy.FORCE.equals(includeOptions.getStrategy()) && indexed.isPresent()) {
|
||||
optionsForNestedType = new TextIndexIncludeOptions(IncludeStrategy.FORCE,
|
||||
new TextIndexedFieldSpec(propertyDotPath, weight));
|
||||
}
|
||||
@@ -281,7 +281,7 @@ public class MongoPersistentEntityIndexResolver implements IndexResolver {
|
||||
LOGGER.info(String.format("Potentially invalid index structure discovered. Breaking operation for %s.",
|
||||
entity.getName()), e);
|
||||
}
|
||||
} else if (includeOptions.isForce() || indexed != null) {
|
||||
} else if (includeOptions.isForce() || indexed.isPresent()) {
|
||||
indexDefinitionBuilder.onField(propertyDotPath, weight);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.springframework.data.geo.Metric;
|
||||
import org.springframework.data.geo.Metrics;
|
||||
import org.springframework.data.geo.Point;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* Builder class to build near-queries.
|
||||
@@ -150,8 +151,10 @@ public final class NearQuery {
|
||||
public NearQuery with(Pageable pageable) {
|
||||
|
||||
Assert.notNull(pageable, "Pageable must not be 'null'.");
|
||||
this.num = pageable.getOffset() + pageable.getPageSize();
|
||||
this.skip = pageable.getOffset();
|
||||
if(!ObjectUtils.nullSafeEquals(Pageable.NONE, pageable)) {
|
||||
this.num = pageable.getOffset() + pageable.getPageSize();
|
||||
this.skip = pageable.getOffset();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.domain.Sort.Order;
|
||||
import org.springframework.data.mongodb.InvalidMongoDbApiUsageException;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* @author Thomas Risberg
|
||||
@@ -151,7 +152,7 @@ public class Query {
|
||||
*/
|
||||
public Query with(Pageable pageable) {
|
||||
|
||||
if (pageable == null) {
|
||||
if (pageable == null || ObjectUtils.nullSafeEquals(Pageable.NONE, pageable)) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -169,7 +170,7 @@ public class Query {
|
||||
*/
|
||||
public Query with(Sort sort) {
|
||||
|
||||
if (sort == null) {
|
||||
if (sort == null || ObjectUtils.nullSafeEquals(Sort.unsorted(), sort)) {
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -68,6 +68,6 @@ public class MongoRepositoryBean<T> extends CdiRepositoryBean<T> {
|
||||
MongoOperations mongoOperations = getDependencyInstance(operations, MongoOperations.class);
|
||||
MongoRepositoryFactory factory = new MongoRepositoryFactory(mongoOperations);
|
||||
|
||||
return factory.getRepository(repositoryType, customImplementation);
|
||||
return customImplementation.isPresent() ? factory.getRepository(repositoryType, customImplementation.get()) : factory.getRepository(repositoryType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.mongodb.repository.support;
|
||||
|
||||
import org.bson.Document;
|
||||
import org.springframework.data.mongodb.core.MongoOperations;
|
||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
|
||||
@@ -58,7 +59,9 @@ public class SpringDataMongodbQuery<T> extends AbstractMongodbQuery<T, SpringDat
|
||||
|
||||
@Override
|
||||
public T apply(DBObject input) {
|
||||
return operations.getConverter().read(type, (BasicDBObject) input);
|
||||
|
||||
;
|
||||
return operations.getConverter().read(type, new Document((BasicDBObject) input));
|
||||
}
|
||||
}, new SpringDataMongodbSerializer(operations.getConverter()));
|
||||
|
||||
|
||||
@@ -120,6 +120,8 @@ class SpringDataMongodbSerializer extends MongodbSerializer {
|
||||
@Override
|
||||
protected DBObject asDBObject(String key, Object value) {
|
||||
|
||||
value = value instanceof Optional ? ((Optional)value).orElse(null) : value;
|
||||
|
||||
if (ID_KEY.equals(key)) {
|
||||
DBObject superIdValue = super.asDBObject(key, value);
|
||||
Document mappedIdValue = mapper.getMappedObject((BasicDBObject) superIdValue, Optional.empty());
|
||||
|
||||
@@ -19,6 +19,8 @@ import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -82,7 +84,7 @@ public class AuditingViaJavaConfigRepositoriesTests {
|
||||
@Test // DATAMONGO-792, DATAMONGO-883
|
||||
public void basicAuditing() {
|
||||
|
||||
doReturn(this.auditor).when(this.auditorAware).getCurrentAuditor();
|
||||
doReturn(Optional.of(this.auditor)).when(this.auditorAware).getCurrentAuditor();
|
||||
|
||||
AuditablePerson savedUser = auditablePersonRepository.save(new AuditablePerson("user"));
|
||||
|
||||
|
||||
@@ -22,6 +22,9 @@ import static org.mockito.Mockito.*;
|
||||
import java.io.IOException;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import com.mongodb.WriteConcern;
|
||||
import org.bson.BsonDocument;
|
||||
import org.bson.Document;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -48,15 +51,10 @@ import com.mongodb.ServerAddress;
|
||||
* @author Oliver Gierke
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class MongoExceptionTranslatorUnitTests {
|
||||
|
||||
MongoExceptionTranslator translator;
|
||||
|
||||
@Mock com.mongodb.DuplicateKeyException exception;
|
||||
@Mock MongoSocketException socketException;
|
||||
@Mock MongoCursorNotFoundException cursorNotFoundException;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
translator = new MongoExceptionTranslator();
|
||||
@@ -65,30 +63,27 @@ public class MongoExceptionTranslatorUnitTests {
|
||||
@Test
|
||||
public void translateDuplicateKey() {
|
||||
|
||||
DataAccessException translatedException = translator.translateExceptionIfPossible(exception);
|
||||
expectExceptionWithCauseMessage(translatedException, DuplicateKeyException.class, null);
|
||||
expectExceptionWithCauseMessage(
|
||||
translator.translateExceptionIfPossible(
|
||||
new com.mongodb.DuplicateKeyException(new BsonDocument(), new ServerAddress(), null)),
|
||||
DuplicateKeyException.class, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void translateSocketException() {
|
||||
|
||||
when(socketException.getMessage()).thenReturn("IOException");
|
||||
when(socketException.getCause()).thenReturn(new IOException("IOException"));
|
||||
DataAccessException translatedException = translator.translateExceptionIfPossible(socketException);
|
||||
|
||||
expectExceptionWithCauseMessage(translatedException, DataAccessResourceFailureException.class, "IOException");
|
||||
expectExceptionWithCauseMessage(
|
||||
translator.translateExceptionIfPossible(new MongoSocketException("IOException", new ServerAddress())),
|
||||
DataAccessResourceFailureException.class, "IOException");
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void translateCursorNotFound() throws UnknownHostException {
|
||||
|
||||
when(cursorNotFoundException.getCode()).thenReturn(1);
|
||||
when(cursorNotFoundException.getServerAddress()).thenReturn(new ServerAddress());
|
||||
|
||||
DataAccessException translatedException = translator.translateExceptionIfPossible(cursorNotFoundException);
|
||||
|
||||
expectExceptionWithCauseMessage(translatedException, DataAccessResourceFailureException.class);
|
||||
expectExceptionWithCauseMessage(
|
||||
translator.translateExceptionIfPossible(new MongoCursorNotFoundException(1L, new ServerAddress())),
|
||||
DataAccessResourceFailureException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -209,7 +209,7 @@ public abstract class MongoOperationsUnitTests {
|
||||
public void doWith(MongoOperations operations) {
|
||||
operations.findAll(Object.class);
|
||||
}
|
||||
}.assertDataAccessException();
|
||||
}.assertException(IllegalArgumentException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1493,7 +1493,7 @@ public class MongoTemplateTests {
|
||||
template.save(map, "maps");
|
||||
}
|
||||
|
||||
@Test(expected = MappingException.class) // DATAMONGO-549
|
||||
@Test(expected = IllegalArgumentException.class) // DATAMONGO-549
|
||||
public void savesMongoPrimitiveObjectCorrectly() {
|
||||
template.save(new Object(), "collection");
|
||||
}
|
||||
@@ -1512,7 +1512,7 @@ public class MongoTemplateTests {
|
||||
assertThat(document.containsKey("_id"), is(true));
|
||||
}
|
||||
|
||||
@Test(expected = InvalidDataAccessApiUsageException.class) // DATAMONGO-550
|
||||
@Test(expected = IllegalArgumentException.class) // DATAMONGO-550
|
||||
public void rejectsPlainObjectWithOutExplicitCollection() {
|
||||
|
||||
org.bson.Document document = new org.bson.Document("foo", "bar");
|
||||
@@ -2507,7 +2507,7 @@ public class MongoTemplateTests {
|
||||
|
||||
template.save(document);
|
||||
|
||||
Query query = query(where("id").is(document.id).and("models._id").exists(true));
|
||||
Query query = query(where("id").is(document.id).and("models.value").exists(true));
|
||||
Update update = new Update().set("models.$.value", "mongodb");
|
||||
template.findAndModify(query, update, DocumentWithCollection.class);
|
||||
|
||||
|
||||
@@ -104,13 +104,11 @@ public class MongoTemplateUnitTests extends MongoOperationsUnitTests {
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
// when(cursor.copy()).thenReturn(cursor);
|
||||
when(findIterable.iterator()).thenReturn(cursor);
|
||||
when(factory.getDb()).thenReturn(db);
|
||||
when(factory.getExceptionTranslator()).thenReturn(exceptionTranslator);
|
||||
when(db.getCollection(Mockito.any(String.class), eq(Document.class))).thenReturn(collection);
|
||||
when(collection.find(Mockito.any(org.bson.Document.class))).thenReturn(findIterable);
|
||||
when(findIterable.limit(anyInt())).thenReturn(findIterable);
|
||||
when(findIterable.sort(Mockito.any(org.bson.Document.class))).thenReturn(findIterable);
|
||||
when(findIterable.modifiers(Mockito.any(org.bson.Document.class))).thenReturn(findIterable);
|
||||
|
||||
@@ -131,8 +129,8 @@ public class MongoTemplateUnitTests extends MongoOperationsUnitTests {
|
||||
|
||||
@Test(expected = DataAccessException.class)
|
||||
public void removeHandlesMongoExceptionProperly() throws Exception {
|
||||
|
||||
MongoTemplate template = mockOutGetDb();
|
||||
when(db.getCollection("collection")).thenThrow(new MongoException("Exception!"));
|
||||
|
||||
template.remove(null, "collection");
|
||||
}
|
||||
@@ -338,8 +336,6 @@ public class MongoTemplateUnitTests extends MongoOperationsUnitTests {
|
||||
@Test // DATAMONGO-1166
|
||||
public void aggregateShouldHonorReadPreferenceWhenSet() {
|
||||
|
||||
when(db.runCommand(Mockito.any(org.bson.Document.class), Mockito.any(ReadPreference.class)))
|
||||
.thenReturn(mock(Document.class));
|
||||
when(db.runCommand(Mockito.any(org.bson.Document.class), Mockito.any(ReadPreference.class), eq(Document.class)))
|
||||
.thenReturn(mock(Document.class));
|
||||
template.setReadPreference(ReadPreference.secondary());
|
||||
@@ -353,8 +349,6 @@ public class MongoTemplateUnitTests extends MongoOperationsUnitTests {
|
||||
@Test // DATAMONGO-1166
|
||||
public void aggregateShouldIgnoreReadPreferenceWhenNotSet() {
|
||||
|
||||
when(db.runCommand(Mockito.any(org.bson.Document.class), Mockito.any(ReadPreference.class)))
|
||||
.thenReturn(mock(Document.class));
|
||||
when(db.runCommand(Mockito.any(org.bson.Document.class), eq(org.bson.Document.class)))
|
||||
.thenReturn(mock(Document.class));
|
||||
|
||||
@@ -366,8 +360,6 @@ public class MongoTemplateUnitTests extends MongoOperationsUnitTests {
|
||||
@Test // DATAMONGO-1166
|
||||
public void geoNearShouldHonorReadPreferenceWhenSet() {
|
||||
|
||||
when(db.runCommand(Mockito.any(org.bson.Document.class), Mockito.any(ReadPreference.class)))
|
||||
.thenReturn(mock(Document.class));
|
||||
when(db.runCommand(Mockito.any(org.bson.Document.class), Mockito.any(ReadPreference.class), eq(Document.class)))
|
||||
.thenReturn(mock(Document.class));
|
||||
template.setReadPreference(ReadPreference.secondary());
|
||||
@@ -382,8 +374,6 @@ public class MongoTemplateUnitTests extends MongoOperationsUnitTests {
|
||||
@Test // DATAMONGO-1166
|
||||
public void geoNearShouldIgnoreReadPreferenceWhenNotSet() {
|
||||
|
||||
when(db.runCommand(Mockito.any(Document.class), Mockito.any(ReadPreference.class)))
|
||||
.thenReturn(mock(Document.class));
|
||||
when(db.runCommand(Mockito.any(Document.class), eq(Document.class))).thenReturn(mock(Document.class));
|
||||
|
||||
NearQuery query = NearQuery.near(new Point(1, 1));
|
||||
@@ -461,8 +451,6 @@ public class MongoTemplateUnitTests extends MongoOperationsUnitTests {
|
||||
MongoCursor cursor = mock(MongoCursor.class);
|
||||
MapReduceIterable output = mock(MapReduceIterable.class);
|
||||
when(output.limit(anyInt())).thenReturn(output);
|
||||
when(output.sort(Mockito.any(Document.class))).thenReturn(output);
|
||||
when(output.filter(Mockito.any(Document.class))).thenReturn(output);
|
||||
when(output.iterator()).thenReturn(cursor);
|
||||
when(cursor.hasNext()).thenReturn(false);
|
||||
|
||||
|
||||
@@ -57,12 +57,8 @@ public class QueryCursorPreparerUnitTests {
|
||||
public void setUp() {
|
||||
|
||||
when(factory.getExceptionTranslator()).thenReturn(exceptionTranslatorMock);
|
||||
when(cursor.batchSize(anyInt())).thenReturn(cursor);
|
||||
when(cursor.filter(any(Document.class))).thenReturn(cursor);
|
||||
when(cursor.limit(anyInt())).thenReturn(cursor);
|
||||
when(cursor.modifiers(any(Document.class))).thenReturn(cursor);
|
||||
when(cursor.noCursorTimeout(anyBoolean())).thenReturn(cursor);
|
||||
when(cursor.partial(anyBoolean())).thenReturn(cursor);
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-185
|
||||
|
||||
@@ -569,7 +569,7 @@ public class ReactiveMongoTemplateTests {
|
||||
template.save(map, "maps").block();
|
||||
}
|
||||
|
||||
@Test(expected = MappingException.class) // DATAMONGO-1444
|
||||
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1444
|
||||
public void savesMongoPrimitiveObjectCorrectly() {
|
||||
template.save(new Object(), "collection").block();
|
||||
}
|
||||
@@ -588,7 +588,7 @@ public class ReactiveMongoTemplateTests {
|
||||
assertThat(dbObject.containsKey("_id"), is(true));
|
||||
}
|
||||
|
||||
@Test(expected = InvalidDataAccessApiUsageException.class) // DATAMONGO-1444
|
||||
@Test(expected = IllegalArgumentException.class) // DATAMONGO-1444
|
||||
public void rejectsPlainObjectWithOutExplicitCollection() {
|
||||
|
||||
Document dbObject = new Document("foo", "bar");
|
||||
|
||||
@@ -31,7 +31,9 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.mongodb.BasicDBObject;
|
||||
import org.bson.BsonDocument;
|
||||
import org.bson.Document;
|
||||
import org.bson.conversions.Bson;
|
||||
import org.bson.types.ObjectId;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -105,6 +107,8 @@ public class DbRefMappingMongoConverterUnitTests {
|
||||
mapValDocument.put("_id", BigInteger.ONE);
|
||||
|
||||
DBRef dbRef = mock(DBRef.class);
|
||||
when(dbRef.getId()).thenReturn(BigInteger.ONE);
|
||||
when(dbRef.getCollectionName()).thenReturn("collection-1");
|
||||
|
||||
if (MongoClientVersion.isMongo3Driver()) {
|
||||
MongoDatabase dbMock = mock(MongoDatabase.class);
|
||||
@@ -114,7 +118,7 @@ public class DbRefMappingMongoConverterUnitTests {
|
||||
|
||||
FindIterable fi = mock(FindIterable.class);
|
||||
when(fi.first()).thenReturn(mapValDocument);
|
||||
when(collectionMock.find(Matchers.any(Document.class))).thenReturn(fi);
|
||||
when(collectionMock.find(Mockito.any(Bson.class))).thenReturn(fi);
|
||||
} else {
|
||||
when(dbRefResolver.fetch(dbRef)).thenReturn(mapValDocument);
|
||||
}
|
||||
@@ -342,7 +346,6 @@ public class DbRefMappingMongoConverterUnitTests {
|
||||
String id = "42";
|
||||
String value = "bubu";
|
||||
MappingMongoConverter converterSpy = spy(converter);
|
||||
doReturn(new Document("_id", id).append("value", value)).when(converterSpy).readRef((DBRef) any());
|
||||
|
||||
Document document = new Document();
|
||||
WithObjectMethodOverrideLazyDbRefs lazyDbRefs = new WithObjectMethodOverrideLazyDbRefs();
|
||||
@@ -368,7 +371,6 @@ public class DbRefMappingMongoConverterUnitTests {
|
||||
String id = "42";
|
||||
String value = "bubu";
|
||||
MappingMongoConverter converterSpy = spy(converter);
|
||||
doReturn(new Document("_id", id).append("value", value)).when(converterSpy).readRef((DBRef) any());
|
||||
|
||||
Document document = new Document();
|
||||
WithObjectMethodOverrideLazyDbRefs lazyDbRefs = new WithObjectMethodOverrideLazyDbRefs();
|
||||
@@ -511,7 +513,7 @@ public class DbRefMappingMongoConverterUnitTests {
|
||||
public void shouldNotTriggerResolvingOfLazyLoadedProxyWhenFinalizeMethodIsInvoked() throws Exception {
|
||||
|
||||
MongoPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(WithObjectMethodOverrideLazyDbRefs.class);
|
||||
MongoPersistentProperty property = entity.getRequiredPersistentProperty("dbRefToConcreteTypeWithPropertyAccess");
|
||||
MongoPersistentProperty property = entity.getRequiredPersistentProperty("dbRefToPlainObject");
|
||||
|
||||
String idValue = new ObjectId().toString();
|
||||
DBRef dbRef = converter.toDBRef(new LazyDbRefTargetPropertyAccess(idValue), property);
|
||||
|
||||
@@ -23,6 +23,7 @@ import static org.mockito.Mockito.*;
|
||||
import static org.springframework.data.mongodb.util.MongoClientVersion.*;
|
||||
|
||||
import org.bson.Document;
|
||||
import org.bson.conversions.Bson;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -56,7 +57,7 @@ public class ReflectiveDBRefResolverUnitTests {
|
||||
when(dbRefMock.getId()).thenReturn("id-1");
|
||||
when(dbFactoryMock.getDb()).thenReturn(dbMock);
|
||||
when(dbMock.getCollection(eq("collection-1"), eq(Document.class))).thenReturn(collectionMock);
|
||||
when(collectionMock.find(any(org.bson.Document.class))).thenReturn(fi);
|
||||
when(collectionMock.find(any(Bson.class))).thenReturn(fi);
|
||||
when(fi.first()).thenReturn(new Document("_id", "id-1"));
|
||||
}
|
||||
|
||||
|
||||
@@ -39,12 +39,6 @@ public class PathUnitTests {
|
||||
|
||||
@Mock MongoPersistentEntity<?> entityMock;
|
||||
|
||||
@Before
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public void setUp() {
|
||||
when(entityMock.getType()).thenReturn((Class) Object.class);
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-962
|
||||
public void shouldIdentifyCycleForOwnerOfSameTypeAndMatchingPath() {
|
||||
|
||||
@@ -59,7 +53,6 @@ public class PathUnitTests {
|
||||
MongoPersistentProperty existing = createPersistentPropertyMock(entityMock, "foo");
|
||||
|
||||
MongoPersistentEntity entityOfDifferentType = Mockito.mock(MongoPersistentEntity.class);
|
||||
when(entityOfDifferentType.getType()).thenReturn(String.class);
|
||||
MongoPersistentProperty toBeVerified = createPersistentPropertyMock(entityOfDifferentType, "foo");
|
||||
|
||||
assertThat(new Path(existing, "foo.bar").cycles(toBeVerified, "foo.bar.bar"), is(false));
|
||||
@@ -77,7 +70,6 @@ public class PathUnitTests {
|
||||
|
||||
MongoPersistentProperty property = Mockito.mock(MongoPersistentProperty.class);
|
||||
when(property.getOwner()).thenReturn(owner);
|
||||
when(property.getFieldName()).thenReturn(fieldname);
|
||||
return property;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,7 +125,6 @@ public class BasicMongoPersistentEntityUnitTests {
|
||||
BasicMongoPersistentEntity<AnyDocument> entity = new BasicMongoPersistentEntity<AnyDocument>(
|
||||
ClassTypeInformation.from(AnyDocument.class));
|
||||
when(propertyMock.isExplicitLanguageProperty()).thenReturn(false);
|
||||
when(propertyMock.getActualType()).thenReturn((Class) Number.class);
|
||||
entity.addPersistentProperty(propertyMock);
|
||||
|
||||
entity.verify();
|
||||
@@ -197,7 +196,6 @@ public class BasicMongoPersistentEntityUnitTests {
|
||||
when(propertyMock.isDbReference()).thenReturn(true);
|
||||
when(propertyMock.getDBRef()).thenReturn(dbRefMock);
|
||||
when(dbRefMock.lazy()).thenReturn(false);
|
||||
when(propertyMock.getActualType()).thenReturn((Class) Class.class);
|
||||
entity.addPersistentProperty(propertyMock);
|
||||
|
||||
entity.verify();
|
||||
|
||||
@@ -22,6 +22,7 @@ import java.util.AbstractMap;
|
||||
import java.util.Collections;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
@@ -64,14 +65,14 @@ public class MongoMappingContextUnitTests {
|
||||
public void doesNotReturnPersistentEntityForMongoSimpleType() {
|
||||
|
||||
MongoMappingContext context = new MongoMappingContext();
|
||||
assertThat(context.getPersistentEntity(DBRef.class), is(nullValue()));
|
||||
assertThat(context.getPersistentEntity(DBRef.class), is(Optional.empty()));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-638
|
||||
public void doesNotCreatePersistentEntityForAbstractMap() {
|
||||
|
||||
MongoMappingContext context = new MongoMappingContext();
|
||||
assertThat(context.getPersistentEntity(AbstractMap.class), is(nullValue()));
|
||||
assertThat(context.getPersistentEntity(AbstractMap.class), is(Optional.empty()));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-607
|
||||
|
||||
@@ -34,7 +34,7 @@ public class IsQuery<T extends Query> extends TypeSafeMatcher<T> {
|
||||
protected Document sort;
|
||||
protected Document fields;
|
||||
|
||||
private int skip;
|
||||
private long skip;
|
||||
private int limit;
|
||||
private String hint;
|
||||
|
||||
@@ -52,7 +52,7 @@ public class IsQuery<T extends Query> extends TypeSafeMatcher<T> {
|
||||
return this;
|
||||
}
|
||||
|
||||
public IsQuery<T> skippig(int skip) {
|
||||
public IsQuery<T> skippig(long skip) {
|
||||
this.skip = skip;
|
||||
return this;
|
||||
}
|
||||
@@ -121,7 +121,7 @@ public class IsQuery<T extends Query> extends TypeSafeMatcher<T> {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (item.getSortObject() == null && !sort.isEmpty()) {
|
||||
if ((item.getSortObject() == null || item.getSortObject().isEmpty()) && !sort.isEmpty()) {
|
||||
if (!new IsEqual<Document>(sort).matches(item.getSortObject())) {
|
||||
return false;
|
||||
}
|
||||
@@ -135,7 +135,7 @@ public class IsQuery<T extends Query> extends TypeSafeMatcher<T> {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!new IsEqual<Integer>(this.skip).matches(item.getSkip())) {
|
||||
if (!new IsEqual(this.skip).matches(item.getSkip())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -103,7 +103,7 @@ public class IsTextQuery<T extends Query> extends IsQuery<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public IsQuery<T> skippig(int skip) {
|
||||
public IsQuery<T> skippig(long skip) {
|
||||
|
||||
super.skippig(skip);
|
||||
return this;
|
||||
|
||||
@@ -89,20 +89,20 @@ public class NearQueryUnitTests {
|
||||
Pageable pageable = new PageRequest(3, 5);
|
||||
NearQuery query = NearQuery.near(new Point(1, 1)).with(pageable);
|
||||
|
||||
assertThat(query.getSkip(), is(pageable.getPageNumber() * pageable.getPageSize()));
|
||||
assertThat((Integer) query.toDocument().get("num"), is((pageable.getPageNumber() + 1) * pageable.getPageSize()));
|
||||
assertThat(query.getSkip(), is((long)pageable.getPageNumber() * pageable.getPageSize()));
|
||||
assertThat((Long) query.toDocument().get("num"), is((long)(pageable.getPageNumber() + 1) * pageable.getPageSize()));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-445
|
||||
public void shouldTakeSkipAndLimitSettingsFromGivenQuery() {
|
||||
|
||||
int limit = 10;
|
||||
int skip = 5;
|
||||
long skip = 5;
|
||||
NearQuery query = NearQuery.near(new Point(1, 1))
|
||||
.query(Query.query(Criteria.where("foo").is("bar")).limit(limit).skip(skip));
|
||||
|
||||
assertThat(query.getSkip(), is(skip));
|
||||
assertThat((Integer) query.toDocument().get("num"), is(limit));
|
||||
assertThat((Long) query.toDocument().get("num"), is((long)limit));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-445
|
||||
@@ -114,8 +114,8 @@ public class NearQueryUnitTests {
|
||||
NearQuery query = NearQuery.near(new Point(1, 1))
|
||||
.query(Query.query(Criteria.where("foo").is("bar")).limit(limit).skip(skip)).with(pageable);
|
||||
|
||||
assertThat(query.getSkip(), is(pageable.getPageNumber() * pageable.getPageSize()));
|
||||
assertThat((Integer) query.toDocument().get("num"), is((pageable.getPageNumber() + 1) * pageable.getPageSize()));
|
||||
assertThat(query.getSkip(), is((long)pageable.getPageNumber() * pageable.getPageSize()));
|
||||
assertThat((Long) query.toDocument().get("num"), is((long)(pageable.getPageNumber() + 1) * pageable.getPageSize()));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-829
|
||||
@@ -133,11 +133,11 @@ public class NearQueryUnitTests {
|
||||
@Test // DATAMONGO-829
|
||||
public void numShouldNotBeAlteredByQueryWithoutPageable() {
|
||||
|
||||
int num = 100;
|
||||
long num = 100;
|
||||
NearQuery query = NearQuery.near(new Point(1, 2));
|
||||
query.num(num);
|
||||
query.query(Query.query(Criteria.where("foo").is("bar")));
|
||||
|
||||
assertThat(DocumentTestUtils.getTypedValue(query.toDocument(), "num", Integer.class), is(num));
|
||||
assertThat(DocumentTestUtils.getTypedValue(query.toDocument(), "num", Long.class), is(num));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import static org.springframework.data.mongodb.core.query.Criteria.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import lombok.ToString;
|
||||
import org.bson.Document;
|
||||
import org.junit.Before;
|
||||
import org.junit.ClassRule;
|
||||
@@ -228,6 +229,7 @@ public class TextQueryTests extends AbstractIntegrationTests {
|
||||
}
|
||||
|
||||
@org.springframework.data.mongodb.core.mapping.Document(collection = "fullTextDoc")
|
||||
@ToString
|
||||
static class FullTextDoc {
|
||||
|
||||
@Id String id;
|
||||
|
||||
@@ -24,6 +24,7 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@@ -109,7 +110,7 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
|
||||
@Test
|
||||
public void findsPersonById() throws Exception {
|
||||
|
||||
assertThat(repository.findOne(dave.getId().toString()), is(dave));
|
||||
assertThat(repository.findOne(dave.getId().toString()), is(Optional.of(dave)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -21,6 +21,7 @@ import static org.junit.Assert.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Before;
|
||||
@@ -106,7 +107,7 @@ public class ComplexIdRepositoryIntegrationTests {
|
||||
|
||||
repo.save(userWithId);
|
||||
|
||||
assertThat(repo.findOne(id), is(userWithId));
|
||||
assertThat(repo.findOne(id), is(Optional.of(userWithId)));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1078
|
||||
|
||||
@@ -60,7 +60,7 @@ public class CdiExtensionIntegrationTests {
|
||||
Person result = repository.save(person);
|
||||
|
||||
assertThat(result, is(notNullValue()));
|
||||
assertThat(repository.findOne(person.getId()).getId(), is(result.getId()));
|
||||
assertThat(repository.findOne(person.getId()).get().getId(), is(result.getId()));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1017
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package org.springframework.data.mongodb.repository.cdi;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.data.mongodb.repository.Person;
|
||||
import org.springframework.data.repository.Repository;
|
||||
|
||||
@@ -24,5 +26,5 @@ public interface CdiPersonRepository extends Repository<Person, String> {
|
||||
|
||||
Person save(Person person);
|
||||
|
||||
Person findOne(String id);
|
||||
Optional<Person> findOne(String id);
|
||||
}
|
||||
|
||||
@@ -81,7 +81,8 @@ public class AbstractMongoQueryUnitTests {
|
||||
public void setUp() {
|
||||
|
||||
doReturn("persons").when(persitentEntityMock).getCollection();
|
||||
doReturn(persitentEntityMock).when(mappingContextMock).getPersistentEntity(Matchers.any(Class.class));
|
||||
doReturn(Optional.of(persitentEntityMock)).when(mappingContextMock).getPersistentEntity(Mockito.any(Class.class));
|
||||
doReturn(persitentEntityMock).when(mappingContextMock).getRequiredPersistentEntity(Mockito.any(Class.class));
|
||||
doReturn(Person.class).when(persitentEntityMock).getType();
|
||||
|
||||
DbRefResolver dbRefResolver = new DefaultDbRefResolver(mock(MongoDbFactory.class));
|
||||
@@ -106,12 +107,9 @@ public class AbstractMongoQueryUnitTests {
|
||||
@Test // DATAMONGO-566, DATAMONGO-1040
|
||||
public void testDeleteExecutionLoadsListOfRemovedDocumentsWhenReturnTypeIsCollectionLike() {
|
||||
|
||||
when(mongoOperationsMock.find(Matchers.any(Query.class), Matchers.any(Class.class), Matchers.anyString()))
|
||||
.thenReturn(Arrays.asList(new Person(new ObjectId(new Date()), "bar")));
|
||||
|
||||
createQueryForMethod("deleteByLastname", String.class).setDeleteQuery(true).execute(new Object[] { "booh" });
|
||||
|
||||
verify(mongoOperationsMock, times(1)).findAllAndRemove(Matchers.any(Query.class), eq(Person.class), eq("persons"));
|
||||
verify(mongoOperationsMock, times(1)).findAllAndRemove(Mockito.any(Query.class), eq(Person.class), eq("persons"));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-566
|
||||
@@ -200,8 +198,8 @@ public class AbstractMongoQueryUnitTests {
|
||||
|
||||
verify(mongoOperationsMock, times(2)).find(captor.capture(), eq(Person.class), eq("persons"));
|
||||
|
||||
assertThat(captor.getAllValues().get(0).getSkip(), is(0));
|
||||
assertThat(captor.getAllValues().get(1).getSkip(), is(10));
|
||||
assertThat(captor.getAllValues().get(0).getSkip(), is(0L));
|
||||
assertThat(captor.getAllValues().get(1).getSkip(), is(10L));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1057
|
||||
|
||||
@@ -70,7 +70,7 @@ public class ReactiveMongoQueryExecutionUnitTests {
|
||||
|
||||
NearQuery nearQuery = queryArgumentCaptor.getValue();
|
||||
assertThat(nearQuery.toDocument().get("near"), is(equalTo(Arrays.asList(1d, 2d))));
|
||||
assertThat(nearQuery.getSkip(), is(10));
|
||||
assertThat(nearQuery.getSkip(), is(10L));
|
||||
assertThat(nearQuery.getMinDistance(), is(equalTo(new Distance(10))));
|
||||
assertThat(nearQuery.getMaxDistance(), is(equalTo(new Distance(15))));
|
||||
}
|
||||
@@ -91,7 +91,7 @@ public class ReactiveMongoQueryExecutionUnitTests {
|
||||
|
||||
NearQuery nearQuery = queryArgumentCaptor.getValue();
|
||||
assertThat(nearQuery.toDocument().get("near"), is(equalTo(Arrays.asList(1d, 2d))));
|
||||
assertThat(nearQuery.getSkip(), is(0));
|
||||
assertThat(nearQuery.getSkip(), is(0L));
|
||||
assertThat(nearQuery.getMinDistance(), is(nullValue()));
|
||||
assertThat(nearQuery.getMaxDistance(), is(nullValue()));
|
||||
}
|
||||
|
||||
@@ -69,9 +69,6 @@ public class ReactiveStringBasedMongoQueryUnitTests {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
when(operations.getConverter()).thenReturn(converter);
|
||||
|
||||
this.converter = new MappingMongoConverter(factory, new MongoMappingContext());
|
||||
}
|
||||
|
||||
|
||||
@@ -74,8 +74,6 @@ public class StringBasedMongoQueryUnitTests {
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
when(operations.getConverter()).thenReturn(converter);
|
||||
|
||||
this.converter = new MappingMongoConverter(factory, new MongoMappingContext());
|
||||
}
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ public class MongoRepositoryFactoryUnitTests {
|
||||
@SuppressWarnings("unchecked")
|
||||
public void usesMappingMongoEntityInformationIfMappingContextSet() {
|
||||
|
||||
when(mappingContext.getPersistentEntity(Person.class)).thenReturn(Optional.of(entity));
|
||||
when(mappingContext.getRequiredPersistentEntity(Person.class)).thenReturn(entity);
|
||||
when(entity.getType()).thenReturn(Person.class);
|
||||
|
||||
MongoRepositoryFactory factory = new MongoRepositoryFactory(template);
|
||||
@@ -80,7 +80,7 @@ public class MongoRepositoryFactoryUnitTests {
|
||||
@SuppressWarnings("unchecked")
|
||||
public void createsRepositoryWithIdTypeLong() {
|
||||
|
||||
when(mappingContext.getPersistentEntity(Person.class)).thenReturn(Optional.of(entity));
|
||||
when(mappingContext.getRequiredPersistentEntity(Person.class)).thenReturn(entity);
|
||||
when(entity.getType()).thenReturn(Person.class);
|
||||
|
||||
MongoRepositoryFactory factory = new MongoRepositoryFactory(template);
|
||||
|
||||
Reference in New Issue
Block a user