DATAMONGO-2227 - Moved off Spring Data Commons' deprecations and unused types.
Related ticket: DATACMNS-1496.
This commit is contained in:
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2019 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
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.mongodb;
|
||||
|
||||
import org.springframework.dao.DataAccessResourceFailureException;
|
||||
import org.springframework.data.authentication.UserCredentials;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Exception being thrown in case we cannot connect to a MongoDB instance.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class CannotGetMongoDbConnectionException extends DataAccessResourceFailureException {
|
||||
|
||||
private final UserCredentials credentials;
|
||||
private final @Nullable String database;
|
||||
|
||||
private static final long serialVersionUID = 1172099106475265589L;
|
||||
|
||||
public CannotGetMongoDbConnectionException(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
this.database = null;
|
||||
this.credentials = UserCredentials.NO_CREDENTIALS;
|
||||
}
|
||||
|
||||
public CannotGetMongoDbConnectionException(String msg) {
|
||||
this(msg, null, UserCredentials.NO_CREDENTIALS);
|
||||
}
|
||||
|
||||
public CannotGetMongoDbConnectionException(String msg, @Nullable String database, UserCredentials credentials) {
|
||||
super(msg);
|
||||
this.database = database;
|
||||
this.credentials = credentials;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link UserCredentials} that were used when trying to connect to the MongoDB instance.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public UserCredentials getCredentials() {
|
||||
return this.credentials;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the database trying to be accessed.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Nullable
|
||||
public String getDatabase() {
|
||||
return database;
|
||||
}
|
||||
}
|
||||
@@ -51,7 +51,6 @@ import org.springframework.core.type.filter.AssignableTypeFilter;
|
||||
import org.springframework.core.type.filter.TypeFilter;
|
||||
import org.springframework.data.annotation.Persistent;
|
||||
import org.springframework.data.config.BeanComponentDefinitionBuilder;
|
||||
import org.springframework.data.mapping.context.MappingContextIsNewStrategyFactory;
|
||||
import org.springframework.data.mapping.model.CamelCaseAbbreviatingFieldNamingStrategy;
|
||||
import org.springframework.data.mongodb.core.convert.MappingMongoConverter;
|
||||
import org.springframework.data.mongodb.core.convert.MongoCustomConversions;
|
||||
@@ -102,8 +101,6 @@ public class MappingMongoConverterParser implements BeanDefinitionParser {
|
||||
BeanDefinition conversionsDefinition = getCustomConversions(element, parserContext);
|
||||
String ctxRef = potentiallyCreateMappingContext(element, parserContext, conversionsDefinition, id);
|
||||
|
||||
createIsNewStrategyFactoryBeanDefinition(ctxRef, parserContext, element);
|
||||
|
||||
// Need a reference to a Mongo instance
|
||||
String dbFactoryRef = element.getAttribute("db-factory-ref");
|
||||
if (!StringUtils.hasText(dbFactoryRef)) {
|
||||
@@ -348,20 +345,6 @@ public class MappingMongoConverterParser implements BeanDefinitionParser {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String createIsNewStrategyFactoryBeanDefinition(String mappingContextRef, ParserContext context,
|
||||
Element element) {
|
||||
|
||||
BeanDefinitionBuilder mappingContextStrategyFactoryBuilder = BeanDefinitionBuilder
|
||||
.rootBeanDefinition(MappingContextIsNewStrategyFactory.class);
|
||||
mappingContextStrategyFactoryBuilder.addConstructorArgReference(mappingContextRef);
|
||||
|
||||
BeanComponentDefinitionBuilder builder = new BeanComponentDefinitionBuilder(element, context);
|
||||
context.registerBeanComponent(
|
||||
builder.getComponent(mappingContextStrategyFactoryBuilder, IS_NEW_STRATEGY_FACTORY_BEAN_NAME));
|
||||
|
||||
return IS_NEW_STRATEGY_FACTORY_BEAN_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link TypeFilter} that returns {@literal false} in case any of the given delegates matches.
|
||||
*
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.mongodb.config;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
@@ -28,17 +27,12 @@ import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.core.type.filter.AnnotationTypeFilter;
|
||||
import org.springframework.data.annotation.Persistent;
|
||||
import org.springframework.data.convert.CustomConversions;
|
||||
import org.springframework.data.mapping.context.MappingContext;
|
||||
import org.springframework.data.mapping.context.MappingContextIsNewStrategyFactory;
|
||||
import org.springframework.data.mapping.context.PersistentEntities;
|
||||
import org.springframework.data.mapping.model.CamelCaseAbbreviatingFieldNamingStrategy;
|
||||
import org.springframework.data.mapping.model.FieldNamingStrategy;
|
||||
import org.springframework.data.mapping.model.PropertyNameFieldNamingStrategy;
|
||||
import org.springframework.data.mongodb.core.convert.MongoCustomConversions;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
|
||||
import org.springframework.data.support.CachingIsNewStrategyFactory;
|
||||
import org.springframework.data.support.IsNewStrategyFactory;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -92,19 +86,6 @@ public abstract class MongoConfigurationSupport {
|
||||
return mappingContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@link MappingContextIsNewStrategyFactory} wrapped into a {@link CachingIsNewStrategyFactory}.
|
||||
*
|
||||
* @return
|
||||
* @throws ClassNotFoundException
|
||||
*/
|
||||
@Bean
|
||||
public IsNewStrategyFactory isNewStrategyFactory() throws ClassNotFoundException {
|
||||
|
||||
return new CachingIsNewStrategyFactory(new MappingContextIsNewStrategyFactory(
|
||||
new PersistentEntities(Arrays.<MappingContext<?, ?>> asList(new MappingContext[] { mongoMappingContext() }))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Register custom {@link Converter}s in a {@link CustomConversions} object if required. These
|
||||
* {@link CustomConversions} will be registered with the {@link #mappingMongoConverter()} and
|
||||
|
||||
@@ -16,18 +16,14 @@
|
||||
package org.springframework.data.mongodb.config;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assume.*;
|
||||
import static org.springframework.data.mongodb.util.MongoClientVersion.*;
|
||||
import static org.springframework.test.util.ReflectionTestUtils.*;
|
||||
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.data.authentication.UserCredentials;
|
||||
import org.springframework.data.mongodb.MongoDbFactory;
|
||||
import org.springframework.data.mongodb.core.MongoClientFactoryBean;
|
||||
import org.springframework.data.mongodb.core.MongoOperations;
|
||||
@@ -38,7 +34,6 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import com.mongodb.MongoClient;
|
||||
import com.mongodb.MongoClientOptions;
|
||||
import com.mongodb.MongoOptions;
|
||||
import com.mongodb.WriteConcern;
|
||||
|
||||
/**
|
||||
@@ -232,8 +227,8 @@ public class MongoNamespaceTests {
|
||||
assertEquals(4, mongoOpts.getThreadsAllowedToBlockForConnectionMultiplier());
|
||||
|
||||
// TODO: check the damned defaults
|
||||
// assertEquals("w", mongoOpts.getWriteConcern().getW());
|
||||
// assertEquals(0, mongoOpts.getWriteConcern().getWtimeout());
|
||||
// assertEquals(true, mongoOpts.getWriteConcern().fsync());
|
||||
// assertEquals("w", mongoOpts.getWriteConcern().getW());
|
||||
// assertEquals(0, mongoOpts.getWriteConcern().getWtimeout());
|
||||
// assertEquals(true, mongoOpts.getWriteConcern().fsync());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,11 +15,12 @@
|
||||
*/
|
||||
package org.springframework.data.mongodb.core.aggregation;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.data.mongodb.core.aggregation.Aggregation.*;
|
||||
import static org.springframework.data.mongodb.core.aggregation.AggregationFunctionExpressions.*;
|
||||
import static org.springframework.data.mongodb.core.aggregation.Fields.*;
|
||||
import static org.springframework.data.mongodb.core.aggregation.VariableOperators.Let.ExpressionVariable.*;
|
||||
import static org.springframework.data.mongodb.test.util.Assertions.*;
|
||||
import static org.springframework.data.mongodb.test.util.Assertions.assertThat;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@@ -29,6 +30,7 @@ import java.util.List;
|
||||
import org.bson.Document;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.domain.Range;
|
||||
import org.springframework.data.domain.Range.Bound;
|
||||
import org.springframework.data.mongodb.core.DocumentTestUtils;
|
||||
import org.springframework.data.mongodb.core.aggregation.ArrayOperators.Reduce;
|
||||
import org.springframework.data.mongodb.core.aggregation.ArrayOperators.Reduce.PropertyExpression;
|
||||
@@ -70,7 +72,7 @@ public class ProjectionOperationUnitTests {
|
||||
|
||||
Document document = operation.toDocument(Aggregation.DEFAULT_CONTEXT);
|
||||
Document projectClause = DocumentTestUtils.getAsDocument(document, PROJECT);
|
||||
assertThat(projectClause.get("prop")).isEqualTo((Object) Fields.UNDERSCORE_ID_REF);
|
||||
assertThat(projectClause.get("prop")).isEqualTo(Fields.UNDERSCORE_ID_REF);
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-586
|
||||
@@ -81,8 +83,8 @@ public class ProjectionOperationUnitTests {
|
||||
Document document = operation.toDocument(Aggregation.DEFAULT_CONTEXT);
|
||||
Document projectClause = DocumentTestUtils.getAsDocument(document, PROJECT);
|
||||
|
||||
assertThat(projectClause.get("foo")).isEqualTo((Object) 1);
|
||||
assertThat(projectClause.get("bar")).isEqualTo((Object) "$foobar");
|
||||
assertThat(projectClause.get("foo")).isEqualTo(1);
|
||||
assertThat(projectClause.get("bar")).isEqualTo("$foobar");
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-586
|
||||
@@ -93,7 +95,7 @@ public class ProjectionOperationUnitTests {
|
||||
Document document = operation.and("foo").as("bar").toDocument(Aggregation.DEFAULT_CONTEXT);
|
||||
Document projectClause = DocumentTestUtils.getAsDocument(document, PROJECT);
|
||||
|
||||
assertThat(projectClause.get("bar")).isEqualTo((Object) "$foo");
|
||||
assertThat(projectClause.get("bar")).isEqualTo("$foo");
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-586
|
||||
@@ -107,8 +109,8 @@ public class ProjectionOperationUnitTests {
|
||||
List<Object> addClause = (List<Object>) barClause.get("$add");
|
||||
|
||||
assertThat(addClause).hasSize(2);
|
||||
assertThat(addClause.get(0)).isEqualTo((Object) "$foo");
|
||||
assertThat(addClause.get(1)).isEqualTo((Object) 41);
|
||||
assertThat(addClause.get(0)).isEqualTo("$foo");
|
||||
assertThat(addClause.get(1)).isEqualTo(41);
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-586
|
||||
@@ -121,7 +123,7 @@ public class ProjectionOperationUnitTests {
|
||||
Document oper = exctractOperation(fieldName, projectClause);
|
||||
|
||||
assertThat(oper.containsKey(ADD)).isTrue();
|
||||
assertThat(oper.get(ADD)).isEqualTo((Object) Arrays.<Object> asList("$a", 1));
|
||||
assertThat(oper.get(ADD)).isEqualTo(Arrays.<Object> asList("$a", 1));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-586
|
||||
@@ -135,7 +137,7 @@ public class ProjectionOperationUnitTests {
|
||||
|
||||
Document oper = exctractOperation(fieldAlias, projectClause);
|
||||
assertThat(oper.containsKey(ADD)).isTrue();
|
||||
assertThat(oper.get(ADD)).isEqualTo((Object) Arrays.<Object> asList("$a", 1));
|
||||
assertThat(oper.get(ADD)).isEqualTo(Arrays.<Object> asList("$a", 1));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-586
|
||||
@@ -149,7 +151,7 @@ public class ProjectionOperationUnitTests {
|
||||
Document oper = exctractOperation(fieldAlias, projectClause);
|
||||
|
||||
assertThat(oper.containsKey(SUBTRACT)).isTrue();
|
||||
assertThat(oper.get(SUBTRACT)).isEqualTo((Object) Arrays.<Object> asList("$a", 1));
|
||||
assertThat(oper.get(SUBTRACT)).isEqualTo(Arrays.<Object> asList("$a", 1));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-586
|
||||
@@ -163,7 +165,7 @@ public class ProjectionOperationUnitTests {
|
||||
Document oper = exctractOperation(fieldAlias, projectClause);
|
||||
|
||||
assertThat(oper.containsKey(MULTIPLY)).isTrue();
|
||||
assertThat(oper.get(MULTIPLY)).isEqualTo((Object) Arrays.<Object> asList("$a", 1));
|
||||
assertThat(oper.get(MULTIPLY)).isEqualTo(Arrays.<Object> asList("$a", 1));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-586
|
||||
@@ -177,7 +179,7 @@ public class ProjectionOperationUnitTests {
|
||||
Document oper = exctractOperation(fieldAlias, projectClause);
|
||||
|
||||
assertThat(oper.containsKey(DIVIDE)).isTrue();
|
||||
assertThat(oper.get(DIVIDE)).isEqualTo((Object) Arrays.<Object> asList("$a", 1));
|
||||
assertThat(oper.get(DIVIDE)).isEqualTo(Arrays.<Object> asList("$a", 1));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATAMONGO-586
|
||||
@@ -197,7 +199,7 @@ public class ProjectionOperationUnitTests {
|
||||
Document oper = exctractOperation(fieldAlias, projectClause);
|
||||
|
||||
assertThat(oper.containsKey(MOD)).isTrue();
|
||||
assertThat(oper.get(MOD)).isEqualTo((Object) Arrays.<Object> asList("$a", 3));
|
||||
assertThat(oper.get(MOD)).isEqualTo(Arrays.<Object> asList("$a", 3));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-758, DATAMONGO-1893
|
||||
@@ -252,11 +254,11 @@ public class ProjectionOperationUnitTests {
|
||||
Document document = operation.toDocument(Aggregation.DEFAULT_CONTEXT);
|
||||
Document projectClause = DocumentTestUtils.getAsDocument(document, PROJECT);
|
||||
|
||||
assertThat(projectClause.get("foo")).isEqualTo((Object) 1); // implicit
|
||||
assertThat(projectClause.get("bar")).isEqualTo((Object) "$foobar"); // explicit
|
||||
assertThat(projectClause.get("inc1")).isEqualTo((Object) 1); // include shortcut
|
||||
assertThat(projectClause.get("inc2")).isEqualTo((Object) 1);
|
||||
assertThat(projectClause.get("_id")).isEqualTo((Object) 0);
|
||||
assertThat(projectClause.get("foo")).isEqualTo(1); // implicit
|
||||
assertThat(projectClause.get("bar")).isEqualTo("$foobar"); // explicit
|
||||
assertThat(projectClause.get("inc1")).isEqualTo(1); // include shortcut
|
||||
assertThat(projectClause.get("inc2")).isEqualTo(1);
|
||||
assertThat(projectClause.get("_id")).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@@ -323,16 +325,16 @@ public class ProjectionOperationUnitTests {
|
||||
|
||||
Document projected = exctractOperation("$project", document);
|
||||
|
||||
assertThat(projected.get("hour")).isEqualTo((Object) new Document("$hour", Arrays.asList("$date")));
|
||||
assertThat(projected.get("min")).isEqualTo((Object) new Document("$minute", Arrays.asList("$date")));
|
||||
assertThat(projected.get("second")).isEqualTo((Object) new Document("$second", Arrays.asList("$date")));
|
||||
assertThat(projected.get("millis")).isEqualTo((Object) new Document("$millisecond", Arrays.asList("$date")));
|
||||
assertThat(projected.get("year")).isEqualTo((Object) new Document("$year", Arrays.asList("$date")));
|
||||
assertThat(projected.get("month")).isEqualTo((Object) new Document("$month", Arrays.asList("$date")));
|
||||
assertThat(projected.get("week")).isEqualTo((Object) new Document("$week", Arrays.asList("$date")));
|
||||
assertThat(projected.get("dayOfYear")).isEqualTo((Object) new Document("$dayOfYear", Arrays.asList("$date")));
|
||||
assertThat(projected.get("dayOfMonth")).isEqualTo((Object) new Document("$dayOfMonth", Arrays.asList("$date")));
|
||||
assertThat(projected.get("dayOfWeek")).isEqualTo((Object) new Document("$dayOfWeek", Arrays.asList("$date")));
|
||||
assertThat(projected.get("hour")).isEqualTo(new Document("$hour", Arrays.asList("$date")));
|
||||
assertThat(projected.get("min")).isEqualTo(new Document("$minute", Arrays.asList("$date")));
|
||||
assertThat(projected.get("second")).isEqualTo(new Document("$second", Arrays.asList("$date")));
|
||||
assertThat(projected.get("millis")).isEqualTo(new Document("$millisecond", Arrays.asList("$date")));
|
||||
assertThat(projected.get("year")).isEqualTo(new Document("$year", Arrays.asList("$date")));
|
||||
assertThat(projected.get("month")).isEqualTo(new Document("$month", Arrays.asList("$date")));
|
||||
assertThat(projected.get("week")).isEqualTo(new Document("$week", Arrays.asList("$date")));
|
||||
assertThat(projected.get("dayOfYear")).isEqualTo(new Document("$dayOfYear", Arrays.asList("$date")));
|
||||
assertThat(projected.get("dayOfMonth")).isEqualTo(new Document("$dayOfMonth", Arrays.asList("$date")));
|
||||
assertThat(projected.get("dayOfWeek")).isEqualTo(new Document("$dayOfWeek", Arrays.asList("$date")));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-975
|
||||
@@ -364,7 +366,7 @@ public class ProjectionOperationUnitTests {
|
||||
Document document = operation.toDocument(Aggregation.DEFAULT_CONTEXT);
|
||||
|
||||
Document projected = exctractOperation("$project", document);
|
||||
assertThat(projected.get("tags_count")).isEqualTo((Object) new Document("$size", Arrays.asList("$tags")));
|
||||
assertThat(projected.get("tags_count")).isEqualTo(new Document("$size", Arrays.asList("$tags")));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-979
|
||||
@@ -378,7 +380,7 @@ public class ProjectionOperationUnitTests {
|
||||
Document document = operation.toDocument(Aggregation.DEFAULT_CONTEXT);
|
||||
|
||||
Document projected = exctractOperation("$project", document);
|
||||
assertThat(projected.get("tags_count")).isEqualTo((Object) new Document("$size", Arrays.asList("$tags")));
|
||||
assertThat(projected.get("tags_count")).isEqualTo(new Document("$size", Arrays.asList("$tags")));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1457
|
||||
@@ -389,8 +391,7 @@ public class ProjectionOperationUnitTests {
|
||||
Document document = operation.toDocument(Aggregation.DEFAULT_CONTEXT);
|
||||
Document projected = exctractOperation("$project", document);
|
||||
|
||||
assertThat(projected.get("renamed"))
|
||||
.isEqualTo((Object) new Document("$slice", Arrays.<Object> asList("$field", 10)));
|
||||
assertThat(projected.get("renamed")).isEqualTo(new Document("$slice", Arrays.<Object> asList("$field", 10)));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1457
|
||||
@@ -401,8 +402,7 @@ public class ProjectionOperationUnitTests {
|
||||
Document document = operation.toDocument(Aggregation.DEFAULT_CONTEXT);
|
||||
Document projected = exctractOperation("$project", document);
|
||||
|
||||
assertThat(projected.get("renamed"))
|
||||
.isEqualTo((Object) new Document("$slice", Arrays.<Object> asList("$field", 5, 10)));
|
||||
assertThat(projected.get("renamed")).isEqualTo(new Document("$slice", Arrays.<Object> asList("$field", 5, 10)));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-784
|
||||
@@ -1111,12 +1111,11 @@ public class ProjectionOperationUnitTests {
|
||||
@Test // DATAMONGO-1834
|
||||
public void shouldRenderTimeZoneFromField() {
|
||||
|
||||
Document agg = project()
|
||||
.and(DateOperators.dateOf("date").withTimezone(Timezone.ofField("tz")).dayOfYear()).as("dayOfYear")
|
||||
.toDocument(Aggregation.DEFAULT_CONTEXT);
|
||||
Document agg = project().and(DateOperators.dateOf("date").withTimezone(Timezone.ofField("tz")).dayOfYear())
|
||||
.as("dayOfYear").toDocument(Aggregation.DEFAULT_CONTEXT);
|
||||
|
||||
assertThat(agg).isEqualTo(Document.parse(
|
||||
"{ $project: { dayOfYear: { $dayOfYear: { \"date\" : \"$date\", \"timezone\" : \"$tz\" } } } }"));
|
||||
assertThat(agg).isEqualTo(Document
|
||||
.parse("{ $project: { dayOfYear: { $dayOfYear: { \"date\" : \"$date\", \"timezone\" : \"$tz\" } } } }"));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1834
|
||||
@@ -1687,7 +1686,9 @@ public class ProjectionOperationUnitTests {
|
||||
@Test // DATAMONGO-1548
|
||||
public void shouldRenderIndexOfBytesWithRangeCorrectly() {
|
||||
|
||||
Document agg = project().and(StringOperators.valueOf("item").indexOf("foo").within(new Range<Long>(5L, 9L)))
|
||||
Document agg = project()
|
||||
.and(StringOperators.valueOf("item").indexOf("foo")
|
||||
.within(Range.from(Bound.inclusive(5L)).to(Bound.exclusive(9L))))
|
||||
.as("byteLocation").toDocument(Aggregation.DEFAULT_CONTEXT);
|
||||
|
||||
assertThat(agg).containsEntry("$project.byteLocation.$indexOfBytes.[2]", 5L)
|
||||
@@ -1706,7 +1707,9 @@ public class ProjectionOperationUnitTests {
|
||||
@Test // DATAMONGO-1548
|
||||
public void shouldRenderIndexOfCPWithRangeCorrectly() {
|
||||
|
||||
Document agg = project().and(StringOperators.valueOf("item").indexOfCP("foo").within(new Range<Long>(5L, 9L)))
|
||||
Document agg = project()
|
||||
.and(StringOperators.valueOf("item").indexOfCP("foo")
|
||||
.within(Range.from(Bound.inclusive(5L)).to(Bound.exclusive(9L))))
|
||||
.as("cpLocation").toDocument(Aggregation.DEFAULT_CONTEXT);
|
||||
|
||||
assertThat(agg).containsEntry("$project.cpLocation.$indexOfCP.[2]", 5L)
|
||||
|
||||
@@ -20,13 +20,14 @@ import static org.junit.Assert.*;
|
||||
import static org.springframework.data.mongodb.core.query.Criteria.*;
|
||||
import static org.springframework.data.mongodb.test.util.IsBsonObject.*;
|
||||
|
||||
import org.bson.Document;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.domain.Sort.Direction;
|
||||
|
||||
import nl.jqno.equalsverifier.EqualsVerifier;
|
||||
import nl.jqno.equalsverifier.Warning;
|
||||
|
||||
import org.bson.Document;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.domain.Sort.Direction;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link BasicQuery}.
|
||||
*
|
||||
@@ -56,7 +57,7 @@ public class BasicQueryUnitTests {
|
||||
|
||||
BasicQuery query = new BasicQuery("{}");
|
||||
query.setSortObject(new Document("name", -1));
|
||||
query.with(new org.springframework.data.domain.Sort(Direction.ASC, "lastname"));
|
||||
query.with(Sort.by(Direction.ASC, "lastname"));
|
||||
|
||||
Document sortReference = new Document("name", -1);
|
||||
sortReference.put("lastname", 1);
|
||||
@@ -160,5 +161,4 @@ public class BasicQueryUnitTests {
|
||||
|
||||
assertThat(query1.getFieldsObject(), isBsonObject().containing("name").containing("age").containing("gender"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.domain.Sort.Direction;
|
||||
import org.springframework.data.domain.Sort.Order;
|
||||
import org.springframework.data.mongodb.InvalidMongoDbApiUsageException;
|
||||
import org.springframework.data.mongodb.core.SpecialDoc;
|
||||
|
||||
@@ -197,11 +198,10 @@ public class QueryTests {
|
||||
public void rejectsOrderWithIgnoreCase() {
|
||||
|
||||
assertThatExceptionOfType(IllegalArgumentException.class)
|
||||
.isThrownBy(() -> new Query().with(Sort.by(new Sort.Order("foo").ignoreCase())));
|
||||
.isThrownBy(() -> new Query().with(Sort.by(Order.asc("foo").ignoreCase())));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-709, DATAMONGO-1735, // DATAMONGO-2198
|
||||
@SuppressWarnings("unchecked")
|
||||
public void shouldReturnClassHierarchyOfRestrictedTypes() {
|
||||
|
||||
Query query = new Query(where("name").is("foo")).restrict(SpecialDoc.class);
|
||||
|
||||
@@ -18,15 +18,14 @@ package org.springframework.data.mongodb.repository;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.data.repository.query.spi.EvaluationContextExtension;
|
||||
import org.springframework.data.repository.query.spi.EvaluationContextExtensionSupport;
|
||||
import org.springframework.data.spel.spi.EvaluationContextExtension;
|
||||
|
||||
/**
|
||||
* A sample implementation of a custom {@link EvaluationContextExtension}.
|
||||
*
|
||||
* @author Thomas Darimont
|
||||
*/
|
||||
public class SampleEvaluationContextExtension extends EvaluationContextExtensionSupport {
|
||||
public class SampleEvaluationContextExtension implements EvaluationContextExtension {
|
||||
|
||||
@Override
|
||||
public String getExtensionId() {
|
||||
@@ -45,6 +44,7 @@ public class SampleEvaluationContextExtension extends EvaluationContextExtension
|
||||
|
||||
private static ThreadLocal<SampleAuthentication> auth = new ThreadLocal<SampleAuthentication>() {
|
||||
|
||||
@Override
|
||||
protected SampleAuthentication initialValue() {
|
||||
return new SampleAuthentication(new SampleUser(-1, "anonymous"));
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ package org.springframework.data.mongodb.repository.query;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
@@ -32,6 +33,7 @@ import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Range;
|
||||
import org.springframework.data.domain.Range.Bound;
|
||||
import org.springframework.data.geo.Distance;
|
||||
import org.springframework.data.geo.GeoResult;
|
||||
import org.springframework.data.geo.Point;
|
||||
@@ -60,7 +62,8 @@ public class ReactiveMongoQueryExecutionUnitTests {
|
||||
Method geoNear = ClassUtils.getMethod(GeoRepo.class, "geoNear");
|
||||
Query query = new Query();
|
||||
when(parameterAccessor.getGeoNearLocation()).thenReturn(new Point(1, 2));
|
||||
when(parameterAccessor.getDistanceRange()).thenReturn(new Range<>(new Distance(10), new Distance(15)));
|
||||
when(parameterAccessor.getDistanceRange())
|
||||
.thenReturn(Range.from(Bound.inclusive(new Distance(10))).to(Bound.inclusive(new Distance(15))));
|
||||
when(parameterAccessor.getPageable()).thenReturn(PageRequest.of(1, 10));
|
||||
|
||||
new GeoNearExecution(operations, parameterAccessor, ClassTypeInformation.fromReturnTypeOf(geoNear)).execute(query,
|
||||
@@ -83,7 +86,7 @@ public class ReactiveMongoQueryExecutionUnitTests {
|
||||
Query query = new Query();
|
||||
when(parameterAccessor.getPageable()).thenReturn(Pageable.unpaged());
|
||||
when(parameterAccessor.getGeoNearLocation()).thenReturn(new Point(1, 2));
|
||||
when(parameterAccessor.getDistanceRange()).thenReturn(new Range<>(null, null));
|
||||
when(parameterAccessor.getDistanceRange()).thenReturn(Range.unbounded());
|
||||
|
||||
new GeoNearExecution(operations, parameterAccessor, ClassTypeInformation.fromReturnTypeOf(geoNear)).execute(query,
|
||||
Person.class, "person");
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.util.Optional;
|
||||
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Range;
|
||||
import org.springframework.data.domain.Range.Bound;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.geo.Distance;
|
||||
import org.springframework.data.geo.Point;
|
||||
@@ -38,7 +39,7 @@ import org.springframework.data.repository.query.ParameterAccessor;
|
||||
class StubParameterAccessor implements MongoParameterAccessor {
|
||||
|
||||
private final Object[] values;
|
||||
private Range<Distance> range = new Range<Distance>(null, null);
|
||||
private Range<Distance> range = Range.unbounded();
|
||||
|
||||
/**
|
||||
* Creates a new {@link ConvertingParameterAccessor} backed by a {@link StubParameterAccessor} simply returning the
|
||||
@@ -61,7 +62,7 @@ class StubParameterAccessor implements MongoParameterAccessor {
|
||||
if (value instanceof Range) {
|
||||
this.range = (Range<Distance>) value;
|
||||
} else if (value instanceof Distance) {
|
||||
this.range = new Range<Distance>(null, (Distance) value);
|
||||
this.range = Range.from(Bound.<Distance> unbounded()).to(Bound.inclusive((Distance) value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user