diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/config/MappingMongoConverterParser.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/config/MappingMongoConverterParser.java index 3aae75689..fa4ac4946 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/config/MappingMongoConverterParser.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/config/MappingMongoConverterParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2011-2014 the original author or authors. + * Copyright 2011-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -361,7 +361,9 @@ public class MappingMongoConverterParser implements BeanDefinitionParser { * @param filters */ public NegatingFilter(TypeFilter... filters) { - Assert.notNull(filters); + + Assert.notNull(filters, "TypeFilters must not be null"); + this.delegates = new HashSet(Arrays.asList(filters)); } diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/DefaultIndexOperations.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/DefaultIndexOperations.java index f82371c74..ac4c24998 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/DefaultIndexOperations.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/DefaultIndexOperations.java @@ -1,5 +1,5 @@ /* - * Copyright 2011-2016 the original author or authors. + * Copyright 2011-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoAdmin.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoAdmin.java index 804ad5e59..aaa64ff27 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoAdmin.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoAdmin.java @@ -1,5 +1,5 @@ /* - * Copyright 2011-2013 the original author or authors. + * Copyright 2011-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,7 +27,8 @@ import com.mongodb.Mongo; * Mongo server administration exposed via JMX annotations * * @author Mark Pollack - * @author Thomas Darimont + * @author Thomas Darimont + * @author Mark Paluch */ @ManagedResource(description = "Mongo Admin Operations") public class MongoAdmin implements MongoAdminOperations { @@ -35,10 +36,11 @@ public class MongoAdmin implements MongoAdminOperations { private final Mongo mongo; private String username; private String password; - private String authenticationDatabaseName; + private String authenticationDatabaseName; public MongoAdmin(Mongo mongo) { - Assert.notNull(mongo); + + Assert.notNull(mongo, "Mongo must not be null!"); this.mongo = mongo; } @@ -84,16 +86,16 @@ public class MongoAdmin implements MongoAdminOperations { this.password = password; } - /** - * Sets the authenticationDatabaseName to use to authenticate with the Mongo database. - * - * @param authenticationDatabaseName The authenticationDatabaseName to use. - */ - public void setAuthenticationDatabaseName(String authenticationDatabaseName) { - this.authenticationDatabaseName = authenticationDatabaseName; - } - + /** + * Sets the authenticationDatabaseName to use to authenticate with the Mongo database. + * + * @param authenticationDatabaseName The authenticationDatabaseName to use. + */ + public void setAuthenticationDatabaseName(String authenticationDatabaseName) { + this.authenticationDatabaseName = authenticationDatabaseName; + } + DB getDB(String databaseName) { - return MongoDbUtils.getDB(mongo, databaseName, new UserCredentials(username, password), authenticationDatabaseName); + return MongoDbUtils.getDB(mongo, databaseName, new UserCredentials(username, password), authenticationDatabaseName); } } diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoTemplate.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoTemplate.java index b7e0d672c..7351d0711 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoTemplate.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoTemplate.java @@ -211,7 +211,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware { */ public MongoTemplate(MongoDbFactory mongoDbFactory, MongoConverter mongoConverter) { - Assert.notNull(mongoDbFactory); + Assert.notNull(mongoDbFactory, "MongoDbFactory must not be null!"); this.mongoDbFactory = mongoDbFactory; this.exceptionTranslator = mongoDbFactory.getExceptionTranslator(); @@ -423,7 +423,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware { protected void executeQuery(Query query, String collectionName, DocumentCallbackHandler dch, CursorPreparer preparer) { - Assert.notNull(query); + Assert.notNull(query, "Query must not be null!"); DBObject queryObject = queryMapper.getMappedObject(query.getQueryObject(), null); DBObject sortObject = query.getSortObject(); @@ -439,7 +439,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware { public T execute(DbCallback action) { - Assert.notNull(action); + Assert.notNull(action, "DbCallbackmust not be null!"); try { DB db = this.getDb(); @@ -455,7 +455,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware { public T execute(String collectionName, CollectionCallback callback) { - Assert.notNull(callback); + Assert.notNull(callback, "CollectionCallback must not be null!"); try { DBCollection collection = getAndPrepareCollection(getDb(), collectionName); @@ -733,7 +733,8 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware { } public long count(Query query, Class entityClass) { - Assert.notNull(entityClass); + + Assert.notNull(entityClass, "Entity class must not be null!"); return count(query, entityClass, determineCollectionName(entityClass)); } @@ -747,7 +748,8 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware { */ public long count(Query query, Class entityClass, String collectionName) { - Assert.hasText(collectionName); + Assert.hasText(collectionName, "Collection name must not be null or empty!"); + final DBObject dbObject = query == null ? null : queryMapper.getMappedObject(query.getQueryObject(), entityClass == null ? null : mappingContext.getPersistentEntity(entityClass)); @@ -918,7 +920,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware { protected void doInsertBatch(String collectionName, Collection batchToSave, MongoWriter writer) { - Assert.notNull(writer); + Assert.notNull(writer, "MongoWriter must not be null!"); List dbObjectList = new ArrayList(); for (T o : batchToSave) { @@ -947,14 +949,14 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware { public void save(Object objectToSave) { - Assert.notNull(objectToSave); + Assert.notNull(objectToSave, "Object to save must not be null!"); save(objectToSave, determineEntityCollectionName(objectToSave)); } public void save(Object objectToSave, String collectionName) { - Assert.notNull(objectToSave); - Assert.hasText(collectionName); + Assert.notNull(objectToSave, "Object to save must not be null!"); + Assert.hasText(collectionName, "Collection name must not be null or empty!"); MongoPersistentEntity mongoPersistentEntity = getPersistentEntity(objectToSave.getClass()); @@ -1200,7 +1202,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware { public WriteResult remove(Object object, String collection) { - Assert.hasText(collection); + Assert.hasText(collection, "Collection name must not be null or empty!"); if (object == null) { return null; @@ -2281,8 +2283,9 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware { public ReadDbObjectCallback(EntityReader reader, Class type, String collectionName) { - Assert.notNull(reader); - Assert.notNull(type); + Assert.notNull(reader, "EntityReader must not be null!"); + Assert.notNull(type, "Entity type must not be null!"); + this.reader = reader; this.type = type; this.collectionName = collectionName; @@ -2404,7 +2407,9 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware { * @param delegate must not be {@literal null}. */ public GeoNearResultDbObjectCallback(DbObjectCallback delegate, Metric metric) { - Assert.notNull(delegate); + + Assert.notNull(delegate, "DocumentCallback must not be null!"); + this.delegate = delegate; this.metric = metric; } diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/AggregationResults.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/AggregationResults.java index 2fbf96c4c..822335887 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/AggregationResults.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/AggregationResults.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2014 the original author or authors. + * Copyright 2013-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,6 +29,7 @@ import com.mongodb.DBObject; * @author Tobias Trelle * @author Oliver Gierke * @author Thomas Darimont + * @author Mark Paluch * @param The class in which the results are mapped onto. * @since 1.3 */ @@ -46,8 +47,8 @@ public class AggregationResults implements Iterable { */ public AggregationResults(List mappedResults, DBObject rawResults) { - Assert.notNull(mappedResults); - Assert.notNull(rawResults); + Assert.notNull(mappedResults, "List of mapped results must not be null!"); + Assert.notNull(rawResults, "Raw results must not be null!"); this.mappedResults = Collections.unmodifiableList(mappedResults); this.rawResults = rawResults; diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/ConverterRegistration.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/ConverterRegistration.java index 3365c2359..133d778a5 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/ConverterRegistration.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/ConverterRegistration.java @@ -1,5 +1,5 @@ /* - * Copyright 2011 the original author or authors. + * Copyright 2011-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,6 +23,7 @@ import org.springframework.util.Assert; * Conversion registration information. * * @author Oliver Gierke + * @author Mark Paluch */ class ConverterRegistration { @@ -39,7 +40,7 @@ class ConverterRegistration { */ public ConverterRegistration(ConvertiblePair convertiblePair, boolean isReading, boolean isWriting) { - Assert.notNull(convertiblePair); + Assert.notNull(convertiblePair, "ConvertiblePair must not be null!"); this.convertiblePair = convertiblePair; this.reading = isReading; diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/CustomConversions.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/CustomConversions.java index e57c92a6c..ffea59ed5 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/CustomConversions.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/CustomConversions.java @@ -89,7 +89,7 @@ public class CustomConversions { */ public CustomConversions(List converters) { - Assert.notNull(converters); + Assert.notNull(converters, "List of converters must not be null!"); this.readingPairs = new LinkedHashSet(); this.writingPairs = new LinkedHashSet(); @@ -346,8 +346,8 @@ public class CustomConversions { private static Class getCustomTarget(Class sourceType, Class requestedTargetType, Collection pairs) { - Assert.notNull(sourceType); - Assert.notNull(pairs); + Assert.notNull(sourceType, "Source Class must not be null!"); + Assert.notNull(pairs, "Collection of ConvertiblePair must not be null!"); if (requestedTargetType != null && pairs.contains(new ConvertiblePair(sourceType, requestedTargetType))) { return requestedTargetType; diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/MappingMongoConverter.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/MappingMongoConverter.java index 307554186..859b42236 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/MappingMongoConverter.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/MappingMongoConverter.java @@ -1,11 +1,11 @@ /* - * Copyright 2011-2017 by the original author(s). + * Copyright 2011-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -310,7 +310,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App return result; } - /* + /* * (non-Javadoc) * @see org.springframework.data.mongodb.core.convert.MongoWriter#toDBRef(java.lang.Object, org.springframework.data.mongodb.core.mapping.MongoPersistentProperty) */ @@ -478,7 +478,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App DBRef dbRefObj = null; /* - * If we already have a LazyLoadingProxy, we use it's cached DBRef value instead of + * If we already have a LazyLoadingProxy, we use it's cached DBRef value instead of * unnecessarily initializing it only to convert it to a DBRef a few instructions later. */ if (obj instanceof LazyLoadingProxy) { @@ -825,7 +825,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App protected DBRef createDBRef(Object target, MongoPersistentProperty property) { - Assert.notNull(target); + Assert.notNull(target, "Target object must not be null!"); if (target instanceof DBRef) { return (DBRef) target; @@ -1053,7 +1053,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App /** * Removes the type information from the entire conversion result. - * + * * @param object * @param recursively whether to apply the removal recursively * @return @@ -1114,22 +1114,22 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App /** * Creates a new {@link MongoDbPropertyValueProvider} for the given source, {@link SpELExpressionEvaluator} and * {@link ObjectPath}. - * + * * @param source must not be {@literal null}. * @param evaluator must not be {@literal null}. * @param path can be {@literal null}. */ public MongoDbPropertyValueProvider(DBObject source, SpELExpressionEvaluator evaluator, ObjectPath path) { - Assert.notNull(source); - Assert.notNull(evaluator); + Assert.notNull(source, "DBObject must not be null!"); + Assert.notNull(evaluator, "SpELExpressionEvaluator must not be null!"); this.source = new DBObjectAccessor(source); this.evaluator = evaluator; this.path = path; } - /* + /* * (non-Javadoc) * @see org.springframework.data.convert.PropertyValueProvider#getPropertyValue(org.springframework.data.mapping.PersistentProperty) */ @@ -1172,7 +1172,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App this.path = path; } - /* + /* * (non-Javadoc) * @see org.springframework.data.mapping.model.SpELExpressionParameterValueProvider#potentiallyConvertSpelValue(java.lang.Object, org.springframework.data.mapping.PreferredConstructor.Parameter) */ diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/QueryMapper.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/QueryMapper.java index d80423446..cabce8eed 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/QueryMapper.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/QueryMapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2011-2016 the original author or authors. + * Copyright 2011-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -82,7 +82,7 @@ public class QueryMapper { */ public QueryMapper(MongoConverter converter) { - Assert.notNull(converter); + Assert.notNull(converter, "MongoConverter must not be null!"); this.conversionService = converter.getConversionService(); this.converter = converter; diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/geo/Sphere.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/geo/Sphere.java index 0cb623ef2..ccfb41d3c 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/geo/Sphere.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/geo/Sphere.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,6 +29,7 @@ import org.springframework.util.Assert; * Represents a geospatial sphere value. * * @author Thomas Darimont + * @author Mark Paluch * @since 1.5 */ public class Sphere implements Shape { @@ -46,8 +47,8 @@ public class Sphere implements Shape { @PersistenceConstructor public Sphere(Point center, Distance radius) { - Assert.notNull(center); - Assert.notNull(radius); + Assert.notNull(center, "Center point must not be null!"); + Assert.notNull(radius, "Radius must not be null!"); Assert.isTrue(radius.getValue() >= 0, "Radius must not be negative!"); this.center = center; diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/IndexField.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/IndexField.java index 83bf35436..0e433aa21 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/IndexField.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/IndexField.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,8 +44,13 @@ public final class IndexField { private IndexField(String key, Direction direction, Type type, Float weight) { - Assert.hasText(key); - Assert.isTrue(direction != null ^ (Type.GEO.equals(type) || Type.TEXT.equals(type))); + Assert.hasText(key, "Key must not be null or empty"); + + if (Type.GEO.equals(type) || Type.TEXT.equals(type)) { + Assert.isTrue(direction == null, "Geo/Text indexes must not have a direction!"); + } else { + Assert.notNull(direction, "Default indexes require a direction"); + } this.key = key; this.direction = direction; @@ -58,17 +63,21 @@ public final class IndexField { * * @deprecated use {@link #create(String, Direction)}. * @param key must not be {@literal null} or emtpy. - * @param direction must not be {@literal null}. + * @param order must not be {@literal null}. * @return */ @Deprecated public static IndexField create(String key, Order order) { - Assert.notNull(order); + + Assert.notNull(order, "Order must not be null!"); + return new IndexField(key, order.toDirection(), Type.DEFAULT); } public static IndexField create(String key, Direction order) { - Assert.notNull(order); + + Assert.notNull(order, "Direction must not be null!"); + return new IndexField(key, order, Type.DEFAULT); } @@ -128,7 +137,7 @@ public final class IndexField { } /** - * Returns wheter the {@link IndexField} is a text index field. + * Returns whether the {@link IndexField} is a text index field. * * @return true if type is {@link Type#TEXT} * @since 1.6 @@ -158,7 +167,7 @@ public final class IndexField { && this.type == that.type; } - /* + /* * (non-Javadoc) * @see java.lang.Object#hashCode() */ @@ -173,7 +182,7 @@ public final class IndexField { return result; } - /* + /* * (non-Javadoc) * @see java.lang.Object#toString() */ diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/IndexInfo.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/IndexInfo.java index f4d4d6700..4d9e5a182 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/IndexInfo.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/IndexInfo.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,6 +32,7 @@ import com.mongodb.DBObject; * @author Mark Pollack * @author Oliver Gierke * @author Christoph Strobl + * @author Mark Paluch */ public class IndexInfo { @@ -147,7 +148,8 @@ public class IndexInfo { */ public boolean isIndexForFields(Collection keys) { - Assert.notNull(keys); + Assert.notNull(keys, "Collection of keys must not be null!"); + List indexKeys = new ArrayList(indexFields.size()); for (IndexField field : indexFields) { diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/MongoMappingEventPublisher.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/MongoMappingEventPublisher.java index 26ce21680..4f19ebd6c 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/MongoMappingEventPublisher.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/MongoMappingEventPublisher.java @@ -1,5 +1,5 @@ /* - * Copyright 2011-2015 the original author or authors. + * Copyright 2011-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,6 +34,7 @@ import org.springframework.util.Assert; * * @author Jon Brisbin * @author Oliver Gierke + * @author Mark Paluch */ public class MongoMappingEventPublisher implements ApplicationEventPublisher { @@ -46,7 +47,7 @@ public class MongoMappingEventPublisher implements ApplicationEventPublisher { */ public MongoMappingEventPublisher(MongoPersistentEntityIndexCreator indexCreator) { - Assert.notNull(indexCreator); + Assert.notNull(indexCreator, "MongoPersistentEntityIndexCreator must not be null!"); this.indexCreator = indexCreator; } @@ -61,7 +62,7 @@ public class MongoMappingEventPublisher implements ApplicationEventPublisher { } } - /* + /* * (non-Javadoc) * @see org.springframework.context.ApplicationEventPublisher#publishEvent(java.lang.Object) */ diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/MongoPersistentEntityIndexCreator.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/MongoPersistentEntityIndexCreator.java index 41018a8c8..7febac08a 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/MongoPersistentEntityIndexCreator.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/MongoPersistentEntityIndexCreator.java @@ -1,5 +1,5 @@ /* - * Copyright 2011-2015 the original author or authors. + * Copyright 2011-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -79,9 +79,9 @@ public class MongoPersistentEntityIndexCreator implements ApplicationListener extends BasicPersistentEntity implements MongoPersistentEntity, ApplicationContextAware { @@ -138,7 +139,7 @@ public class BasicMongoPersistentEntity extends BasicPersistentEntity extends BasicPersistentEntity The class in which the results are mapped onto, accessible via an {@link Iterator}. */ public class GroupByResults implements Iterable { @@ -40,10 +41,12 @@ public class GroupByResults implements Iterable { public GroupByResults(List mappedResults, DBObject rawResults) { - Assert.notNull(mappedResults); - Assert.notNull(rawResults); + Assert.notNull(mappedResults, "List of mapped results must not be null!"); + Assert.notNull(rawResults, "Raw results must not be null!"); + this.mappedResults = mappedResults; this.rawResults = rawResults; + parseKeys(); parseCount(); parseServerUsed(); diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapreduce/MapReduceResults.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapreduce/MapReduceResults.java index 4d7c1407e..282791752 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapreduce/MapReduceResults.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapreduce/MapReduceResults.java @@ -1,11 +1,11 @@ /* - * Copyright 2011-2015 the original author or authors. + * Copyright 2011-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -29,6 +29,7 @@ import com.mongodb.MapReduceOutput; * @author Mark Pollack * @author Oliver Gierke * @author Christoph Strobl + * @author Mark Paluch * @param The class in which the results are mapped onto, accessible via an iterator. */ public class MapReduceResults implements Iterable { @@ -49,8 +50,8 @@ public class MapReduceResults implements Iterable { @Deprecated public MapReduceResults(List mappedResults, DBObject rawResults) { - Assert.notNull(mappedResults); - Assert.notNull(rawResults); + Assert.notNull(mappedResults, "List of mapped results must not be null!"); + Assert.notNull(rawResults, "Raw results must not be null!"); this.mappedResults = mappedResults; this.rawResults = rawResults; diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Criteria.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Criteria.java index 0836cdae9..2821ee321 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Criteria.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Criteria.java @@ -50,6 +50,7 @@ import com.mongodb.DBObject; * @author Oliver Gierke * @author Thomas Darimont * @author Christoph Strobl + * @author Mark Paluch */ public class Criteria implements CriteriaDefinition { @@ -387,7 +388,7 @@ public class Criteria implements CriteriaDefinition { */ public Criteria regex(Pattern pattern) { - Assert.notNull(pattern); + Assert.notNull(pattern, "Pattern must not be null!"); if (lastOperatorWasNot()) { return not(pattern); @@ -398,7 +399,9 @@ public class Criteria implements CriteriaDefinition { } private Pattern toPattern(String regex, String options) { - Assert.notNull(regex); + + Assert.notNull(regex, "Regex string must not be null!"); + return Pattern.compile(regex, options == null ? 0 : BSON.regexFlags(options)); } @@ -412,7 +415,9 @@ public class Criteria implements CriteriaDefinition { * @return */ public Criteria withinSphere(Circle circle) { - Assert.notNull(circle); + + Assert.notNull(circle, "Circle must not be null!"); + criteria.put("$geoWithin", new GeoCommand(new Sphere(circle))); return this; } @@ -426,7 +431,8 @@ public class Criteria implements CriteriaDefinition { */ public Criteria within(Shape shape) { - Assert.notNull(shape); + Assert.notNull(shape, "Shape must not be null!"); + criteria.put("$geoWithin", new GeoCommand(shape)); return this; } @@ -439,7 +445,9 @@ public class Criteria implements CriteriaDefinition { * @return */ public Criteria near(Point point) { - Assert.notNull(point); + + Assert.notNull(point, "Point must not be null!"); + criteria.put("$near", point); return this; } @@ -453,7 +461,9 @@ public class Criteria implements CriteriaDefinition { * @return */ public Criteria nearSphere(Point point) { - Assert.notNull(point); + + Assert.notNull(point, "Point must not be null!"); + criteria.put("$nearSphere", point); return this; } @@ -707,7 +717,7 @@ public class Criteria implements CriteriaDefinition { return false; } - /* + /* * (non-Javadoc) * @see java.lang.Object#equals(java.lang.Object) */ @@ -770,7 +780,7 @@ public class Criteria implements CriteriaDefinition { return ObjectUtils.nullSafeEquals(left, right); } - /* + /* * (non-Javadoc) * @see java.lang.Object#hashCode() */ diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/NearQuery.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/NearQuery.java index b847d192e..22a571e90 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/NearQuery.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/NearQuery.java @@ -1,11 +1,11 @@ /* - * Copyright 2011-2015 the original author or authors. + * Copyright 2011-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -49,11 +49,11 @@ public final class NearQuery { /** * Creates a new {@link NearQuery}. * - * @param point + * @param point must not be {@literal null}. */ private NearQuery(Point point, Metric metric) { - Assert.notNull(point); + Assert.notNull(point, "Point must not be null!"); this.point = point; this.spherical = false; @@ -108,7 +108,6 @@ public final class NearQuery { * @return */ public static NearQuery near(Point point, Metric metric) { - Assert.notNull(point); return new NearQuery(point, metric); } @@ -185,7 +184,8 @@ public final class NearQuery { */ public NearQuery maxDistance(double maxDistance, Metric metric) { - Assert.notNull(metric); + Assert.notNull(metric, "Metric must not be null!"); + return maxDistance(new Distance(maxDistance, metric)); } @@ -198,7 +198,7 @@ public final class NearQuery { */ public NearQuery maxDistance(Distance distance) { - Assert.notNull(distance); + Assert.notNull(distance, "Distance must not be null!"); if (distance.getMetric() != Metrics.NEUTRAL) { this.spherical(true); @@ -241,7 +241,8 @@ public final class NearQuery { */ public NearQuery minDistance(double minDistance, Metric metric) { - Assert.notNull(metric); + Assert.notNull(metric, "Metric must not be null!"); + return minDistance(new Distance(minDistance, metric)); } @@ -255,7 +256,7 @@ public final class NearQuery { */ public NearQuery minDistance(Distance distance) { - Assert.notNull(distance); + Assert.notNull(distance, "Distance must not be null!"); if (distance.getMetric() != Metrics.NEUTRAL) { this.spherical(true); diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/spel/ExpressionNode.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/spel/ExpressionNode.java index b323b9cf3..763bbaa33 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/spel/ExpressionNode.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/spel/ExpressionNode.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 the original author or authors. + * Copyright 2013-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,6 +29,8 @@ import org.springframework.util.Assert; * A value object for nodes in an expression. Allows iterating ove potentially available child {@link ExpressionNode}s. * * @author Oliver Gierke + * @author Christoph Strobl + * @author Mark Paluch */ public class ExpressionNode implements Iterable { @@ -157,7 +159,7 @@ public class ExpressionNode implements Iterable { */ public ExpressionNode getChild(int index) { - Assert.isTrue(index >= 0); + Assert.isTrue(index >= 0, "Index must be greater or equal to zero!"); return from(node.getChild(index), state); } @@ -183,7 +185,7 @@ public class ExpressionNode implements Iterable { return from(node, state); } - /* + /* * (non-Javadoc) * @see java.lang.Iterable#iterator() */ diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/gridfs/AntPath.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/gridfs/AntPath.java index de20bc35d..a9fa8f84b 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/gridfs/AntPath.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/gridfs/AntPath.java @@ -1,5 +1,5 @@ /* - * Copyright 2011 the original author or authors. + * Copyright 2011-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,6 +24,7 @@ import org.springframework.util.Assert; * Value object to abstract Ant paths. * * @author Oliver Gierke + * @author Mark Paluch */ class AntPath { @@ -38,7 +39,9 @@ class AntPath { * @param path must not be {@literal null}. */ public AntPath(String path) { - Assert.notNull(path); + + Assert.notNull(path, "Path must not be null!"); + this.path = path; } diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/gridfs/GridFsTemplate.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/gridfs/GridFsTemplate.java index e523e8855..602cc7b5b 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/gridfs/GridFsTemplate.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/gridfs/GridFsTemplate.java @@ -1,5 +1,5 @@ /* - * Copyright 2011-2016 the original author or authors. + * Copyright 2011-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,6 +46,7 @@ import com.mongodb.gridfs.GridFSInputFile; * @author Thomas Darimont * @author Martin Baumgartner * @author Christoph Strobl + * @author Mark Paluch */ public class GridFsTemplate implements GridFsOperations, ResourcePatternResolver { @@ -73,8 +74,8 @@ public class GridFsTemplate implements GridFsOperations, ResourcePatternResolver */ public GridFsTemplate(MongoDbFactory dbFactory, MongoConverter converter, String bucket) { - Assert.notNull(dbFactory); - Assert.notNull(converter); + Assert.notNull(dbFactory, "MongoDbFactory must not be null!"); + Assert.notNull(converter, "MongoConverter must not be null!"); this.dbFactory = dbFactory; this.converter = converter; @@ -156,7 +157,7 @@ public class GridFsTemplate implements GridFsOperations, ResourcePatternResolver */ public GridFSFile store(InputStream content, String filename, String contentType, DBObject metadata) { - Assert.notNull(content); + Assert.notNull(content, "InputStream must not be null!"); GridFSInputFile file = getGridFs().createFile(content); diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/cdi/MongoRepositoryBean.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/cdi/MongoRepositoryBean.java index 0a43c72b2..6a43fa025 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/cdi/MongoRepositoryBean.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/cdi/MongoRepositoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -53,11 +53,11 @@ public class MongoRepositoryBean extends CdiRepositoryBean { super(qualifiers, repositoryType, beanManager, detector); - Assert.notNull(operations); + Assert.notNull(operations, "MongoOperations bean must not be null!"); this.operations = operations; } - /* + /* * (non-Javadoc) * @see org.springframework.data.repository.cdi.CdiRepositoryBean#create(javax.enterprise.context.spi.CreationalContext, java.lang.Class) */ diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/ConvertingParameterAccessor.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/ConvertingParameterAccessor.java index 15d0cd25e..f49f4d69d 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/ConvertingParameterAccessor.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/ConvertingParameterAccessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2011-2015 the original author or authors. + * Copyright 2011-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,6 +42,7 @@ import com.mongodb.DBRef; * @author Oliver Gierke * @author Christoph Strobl * @author Thomas Darimont + * @author Mark Paluch */ public class ConvertingParameterAccessor implements MongoParameterAccessor { @@ -56,41 +57,41 @@ public class ConvertingParameterAccessor implements MongoParameterAccessor { */ public ConvertingParameterAccessor(MongoWriter writer, MongoParameterAccessor delegate) { - Assert.notNull(writer); - Assert.notNull(delegate); + Assert.notNull(writer, "MongoWriter must not be null!"); + Assert.notNull(delegate, "MongoParameterAccessor must not be null!"); this.writer = writer; this.delegate = delegate; } /* - * (non-Javadoc) - * - * @see java.lang.Iterable#iterator() - */ + * (non-Javadoc) + * + * @see java.lang.Iterable#iterator() + */ public PotentiallyConvertingIterator iterator() { return new ConvertingIterator(delegate.iterator()); } /* - * (non-Javadoc) - * - * @see org.springframework.data.repository.query.ParameterAccessor#getPageable() - */ + * (non-Javadoc) + * + * @see org.springframework.data.repository.query.ParameterAccessor#getPageable() + */ public Pageable getPageable() { return delegate.getPageable(); } /* - * (non-Javadoc) - * - * @see org.springframework.data.repository.query.ParameterAccessor#getSort() - */ + * (non-Javadoc) + * + * @see org.springframework.data.repository.query.ParameterAccessor#getSort() + */ public Sort getSort() { return delegate.getSort(); } - /* + /* * (non-Javadoc) * @see org.springframework.data.repository.query.ParameterAccessor#getDynamicProjection() */ @@ -107,7 +108,7 @@ public class ConvertingParameterAccessor implements MongoParameterAccessor { return getConvertedValue(delegate.getBindableValue(index), null); } - /* + /* * (non-Javadoc) * @see org.springframework.data.mongodb.repository.query.MongoParameterAccessor#getDistanceRange() */ @@ -116,7 +117,7 @@ public class ConvertingParameterAccessor implements MongoParameterAccessor { return delegate.getDistanceRange(); } - /* + /* * (non-Javadoc) * @see org.springframework.data.mongodb.repository.MongoParameterAccessor#getGeoNearLocation() */ @@ -143,7 +144,7 @@ public class ConvertingParameterAccessor implements MongoParameterAccessor { return writer.convertToMongoType(value, typeInformation == null ? null : typeInformation.getActualType()); } - /* + /* * (non-Javadoc) * @see org.springframework.data.repository.query.ParameterAccessor#hasBindableNullValue() */ @@ -185,7 +186,7 @@ public class ConvertingParameterAccessor implements MongoParameterAccessor { return delegate.next(); } - /* + /* * (non-Javadoc) * @see org.springframework.data.mongodb.repository.ConvertingParameterAccessor.PotentiallConvertingIterator#nextConverted() */ diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/MongoQueryCreator.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/MongoQueryCreator.java index c2820727d..77f6088f2 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/MongoQueryCreator.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/MongoQueryCreator.java @@ -92,7 +92,7 @@ class MongoQueryCreator extends AbstractQueryCreator { super(tree, accessor); - Assert.notNull(context); + Assert.notNull(context, "MappingContext must not be null!"); this.accessor = accessor; this.isGeoNearQuery = isGeoNearQuery; diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/IndexEnsuringQueryCreationListener.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/IndexEnsuringQueryCreationListener.java index 4ae998db9..2b6ddec1b 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/IndexEnsuringQueryCreationListener.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/IndexEnsuringQueryCreationListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2011-2013 the original author or authors. + * Copyright 2011-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -53,7 +53,7 @@ class IndexEnsuringQueryCreationListener implements QueryCreationListener extends SimpleM super(entityInformation, mongoOperations); - Assert.notNull(resolver); + Assert.notNull(resolver, "EntityPathResolver must not be null!"); + EntityPath path = resolver.createPath(entityInformation.getJavaType()); this.builder = new PathBuilder(path.getType(), path.getMetadata()); @@ -122,7 +123,7 @@ public class QueryDslMongoRepository extends SimpleM return applySorting(createQueryFor(predicate), sort).fetchResults().getResults(); } - /* + /* * (non-Javadoc) * @see org.springframework.data.querydsl.QueryDslPredicateExecutor#findAll(com.mysema.query.types.OrderSpecifier[]) */ @@ -177,7 +178,7 @@ public class QueryDslMongoRepository extends SimpleM return createQueryFor(predicate).fetchCount(); } - /* + /* * (non-Javadoc) * @see org.springframework.data.querydsl.QueryDslPredicateExecutor#exists(com.mysema.query.types.Predicate) */ diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/QuerydslRepositorySupport.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/QuerydslRepositorySupport.java index bce77cd8b..bbfe8dd9b 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/QuerydslRepositorySupport.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/QuerydslRepositorySupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2011-2015 the original author or authors. + * Copyright 2011-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,6 +27,7 @@ import com.querydsl.mongodb.AbstractMongodbQuery; * Base class to create repository implementations based on Querydsl. * * @author Oliver Gierke + * @author Mark Paluch */ public abstract class QuerydslRepositorySupport { @@ -40,7 +41,7 @@ public abstract class QuerydslRepositorySupport { */ public QuerydslRepositorySupport(MongoOperations operations) { - Assert.notNull(operations); + Assert.notNull(operations, "MongoOperations must not be null!"); this.template = operations; this.context = operations.getConverter().getMappingContext(); @@ -54,7 +55,9 @@ public abstract class QuerydslRepositorySupport { * @return */ protected AbstractMongodbQuery> from(final EntityPath path) { - Assert.notNull(path); + + Assert.notNull(path, "EntityPath must not be null!"); + MongoPersistentEntity entity = context.getPersistentEntity(path.getType()); return from(path, entity.getCollection()); } @@ -68,8 +71,8 @@ public abstract class QuerydslRepositorySupport { */ protected AbstractMongodbQuery> from(final EntityPath path, String collection) { - Assert.notNull(path); - Assert.hasText(collection); + Assert.notNull(path, "EntityPath must not be null!"); + Assert.hasText(collection, "Collection name must not be null or empty!"); return new SpringDataMongodbQuery(template, path.getType(), collection); } diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/SimpleMongoRepository.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/SimpleMongoRepository.java index 21af693ba..5d84a3a09 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/SimpleMongoRepository.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/SimpleMongoRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2016 the original author or authors. + * Copyright 2010-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -59,8 +59,8 @@ public class SimpleMongoRepository implements MongoR */ public SimpleMongoRepository(MongoEntityInformation metadata, MongoOperations mongoOperations) { - Assert.notNull(mongoOperations); - Assert.notNull(metadata); + Assert.notNull(metadata, "MongoEntityInformation must not be null!"); + Assert.notNull(mongoOperations, "MongoOperations must not be null!"); this.entityInformation = metadata; this.mongoOperations = mongoOperations; @@ -195,7 +195,7 @@ public class SimpleMongoRepository implements MongoR return findAll(new Query()); } - /* + /* * (non-Javadoc) * @see org.springframework.data.repository.CrudRepository#findAll(java.lang.Iterable) */ @@ -229,7 +229,7 @@ public class SimpleMongoRepository implements MongoR return findAll(new Query().with(sort)); } - /* + /* * (non-Javadoc) * @see org.springframework.data.mongodb.repository.MongoRepository#insert(java.lang.Object) */ @@ -242,7 +242,7 @@ public class SimpleMongoRepository implements MongoR return entity; } - /* + /* * (non-Javadoc) * @see org.springframework.data.mongodb.repository.MongoRepository#insert(java.lang.Iterable) */ diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/monitor/MongoMonitorIntegrationTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/monitor/MongoMonitorIntegrationTests.java index da9290058..ca0f30fef 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/monitor/MongoMonitorIntegrationTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/monitor/MongoMonitorIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2013 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,63 +15,61 @@ */ package org.springframework.data.mongodb.monitor; -import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; - -import java.net.UnknownHostException; - +import static org.hamcrest.Matchers.*; +import static org.junit.Assert.*; + +import java.net.UnknownHostException; + import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.util.Assert; -import org.springframework.util.StringUtils; -import com.mongodb.Mongo; - +import com.mongodb.Mongo; + /** * This test class assumes that you are already running the MongoDB server. * * @author Mark Pollack - * @author Thomas Darimont + * @author Thomas Darimont + * @author Mark Paluch */ @RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration("classpath:infrastructure.xml") +@ContextConfiguration("classpath:infrastructure.xml") public class MongoMonitorIntegrationTests { - @Autowired Mongo mongo; + @Autowired Mongo mongo; @Test public void serverInfo() { ServerInfo serverInfo = new ServerInfo(mongo); serverInfo.getVersion(); - Assert.isTrue(StringUtils.hasText("1.")); } - /** - * @throws UnknownHostException - * @see DATAMONGO-685 - */ - @Test - public void getHostNameShouldReturnServerNameReportedByMongo() throws UnknownHostException { - - ServerInfo serverInfo = new ServerInfo(mongo); - - String hostName = null; - try { - hostName = serverInfo.getHostName(); - } catch (UnknownHostException e) { - throw e; - } - - assertThat(hostName, is(notNullValue())); - assertThat(hostName, is("127.0.0.1")); - } - + /** + * @throws UnknownHostException + * @see DATAMONGO-685 + */ + @Test + public void getHostNameShouldReturnServerNameReportedByMongo() throws UnknownHostException { + + ServerInfo serverInfo = new ServerInfo(mongo); + + String hostName = null; + try { + hostName = serverInfo.getHostName(); + } catch (UnknownHostException e) { + throw e; + } + + assertThat(hostName, is(notNullValue())); + assertThat(hostName, is("127.0.0.1")); + } + @Test public void operationCounters() { OperationCounters operationCounters = new OperationCounters(mongo); operationCounters.getInsertCount(); } -} +} diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/performance/PerformanceTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/performance/PerformanceTests.java index 915572121..0bd21a81a 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/performance/PerformanceTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/performance/PerformanceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,6 @@ package org.springframework.data.mongodb.performance; import static org.springframework.data.mongodb.core.query.Criteria.*; import static org.springframework.data.mongodb.core.query.Query.*; -import static org.springframework.util.Assert.*; import java.text.DecimalFormat; import java.util.ArrayList; @@ -47,6 +46,7 @@ import org.springframework.data.mongodb.core.mapping.MongoMappingContext; import org.springframework.data.mongodb.core.query.Query; import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.data.mongodb.repository.support.MongoRepositoryFactoryBean; +import org.springframework.util.Assert; import org.springframework.util.StopWatch; import org.springframework.util.StringUtils; @@ -66,6 +66,7 @@ import com.mongodb.WriteConcern; * * @author Oliver Gierke * @author Christoph Strobl + * @author Mark Paluch */ public class PerformanceTests { @@ -622,7 +623,7 @@ public class PerformanceTests { private static List pickRandomNumerOfItemsFrom(List source) { - isTrue(!source.isEmpty()); + Assert.isTrue(!source.isEmpty(), "Source must not be empty!"); Random random = new Random(); int numberOfItems = random.nextInt(source.size()); @@ -836,7 +837,7 @@ public class PerformanceTests { String.format(" %s%%", DEVIATION_FORMAT.format(getMediaDeviationFrom(referenceMedian)))) + '\n'; } - /* + /* * (non-Javadoc) * @see java.lang.Object#toString() */ @@ -895,7 +896,7 @@ public class PerformanceTests { return builder.toString(); } - /* + /* * (non-Javadoc) * @see java.lang.Object#toString() */