Browse Source

DATAMONGO-990 - Polishing.

Removed EvaluationExpressionContext from all AbstractMongoQuery implementations that don't actually need it and from AbstractMongoQuery itself, too. Cleaned up test cases after that.

Moved SpEL related tests into AbstractPersonRepositoryIntegrationTests to make sure they're executed for all sub-types. JavaDoc and assertion polishes.

Original pull request: #285.
pull/299/merge
Oliver Gierke 11 years ago
parent
commit
2c27e8576f
  1. 20
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/AbstractMongoQuery.java
  2. 7
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/ConvertingParameterAccessor.java
  3. 11
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/MongoParametersParameterAccessor.java
  4. 7
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/PartTreeMongoQuery.java
  5. 59
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/StringBasedMongoQuery.java
  6. 19
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/MongoRepositoryFactory.java
  7. 90
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/AbstractPersonRepositoryIntegrationTests.java
  8. 49
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/PersonRepositoryIntegrationTests.java
  9. 3
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/config/MongoNamespaceIntegrationTests.java
  10. 19
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/query/AbstractMongoQueryUnitTests.java
  11. 12
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/query/PartTreeMongoQueryUnitTests.java
  12. 50
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/query/StringBasedMongoQueryUnitTests.java
  13. 7
      spring-data-mongodb/src/test/resources/org/springframework/data/mongodb/repository/PersonRepositoryIntegrationTests-context.xml
  14. 2
      spring-data-mongodb/src/test/resources/org/springframework/data/mongodb/repository/config/MongoNamespaceIntegrationTests-context.xml

20
spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/AbstractMongoQuery.java

@ -31,7 +31,6 @@ import org.springframework.data.geo.Point;
import org.springframework.data.mongodb.core.MongoOperations; import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.query.NearQuery; import org.springframework.data.mongodb.core.query.NearQuery;
import org.springframework.data.mongodb.core.query.Query; import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.repository.query.EvaluationContextProvider;
import org.springframework.data.repository.query.ParameterAccessor; import org.springframework.data.repository.query.ParameterAccessor;
import org.springframework.data.repository.query.RepositoryQuery; import org.springframework.data.repository.query.RepositoryQuery;
import org.springframework.data.util.CloseableIterator; import org.springframework.data.util.CloseableIterator;
@ -52,25 +51,20 @@ public abstract class AbstractMongoQuery implements RepositoryQuery {
private final MongoQueryMethod method; private final MongoQueryMethod method;
private final MongoOperations operations; private final MongoOperations operations;
private final EvaluationContextProvider evaluationContextProvider;
/** /**
* Creates a new {@link AbstractMongoQuery} from the given {@link MongoQueryMethod} and {@link MongoOperations}. * Creates a new {@link AbstractMongoQuery} from the given {@link MongoQueryMethod} and {@link MongoOperations}.
* *
* @param method must not be {@literal null}. * @param method must not be {@literal null}.
* @param operations must not be {@literal null}. * @param operations must not be {@literal null}.
* @param evaluationContextProvider must not be {@literal null}.
*/ */
public AbstractMongoQuery(MongoQueryMethod method, MongoOperations operations, public AbstractMongoQuery(MongoQueryMethod method, MongoOperations operations) {
EvaluationContextProvider evaluationContextProvider) {
Assert.notNull(operations); Assert.notNull(operations, "MongoOperations must not be null!");
Assert.notNull(method); Assert.notNull(method, "MongoQueryMethod must not be null!");
Assert.notNull(evaluationContextProvider, "ExpressionEvaluationContextProvider must not be null!");
this.method = method; this.method = method;
this.operations = operations; this.operations = operations;
this.evaluationContextProvider = evaluationContextProvider;
} }
/* /*
@ -164,10 +158,6 @@ public abstract class AbstractMongoQuery implements RepositoryQuery {
*/ */
protected abstract boolean isDeleteQuery(); protected abstract boolean isDeleteQuery();
public EvaluationContextProvider getEvaluationContextProvider() {
return evaluationContextProvider;
}
private abstract class Execution { private abstract class Execution {
abstract Object execute(Query query); abstract Object execute(Query query);
@ -318,8 +308,8 @@ public abstract class AbstractMongoQuery implements RepositoryQuery {
Object execute(Query query) { Object execute(Query query) {
MongoEntityMetadata<?> metadata = method.getEntityInformation(); MongoEntityMetadata<?> metadata = method.getEntityInformation();
return countProjection ? operations.count(query, metadata.getJavaType()) : operations.findOne(query, return countProjection ? operations.count(query, metadata.getJavaType())
metadata.getJavaType(), metadata.getCollectionName()); : operations.findOne(query, metadata.getJavaType(), metadata.getCollectionName());
} }
} }

7
spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/ConvertingParameterAccessor.java

@ -217,7 +217,7 @@ public class ConvertingParameterAccessor implements MongoParameterAccessor {
/** /**
* Returns the given object as {@link Collection}. Will do a copy of it if it implements {@link Iterable} or is an * Returns the given object as {@link Collection}. Will do a copy of it if it implements {@link Iterable} or is an
* array. Will return an empty {@link Collection} in case {@literal null} is given. Will wrap all other types into a * array. Will return an empty {@link Collection} in case {@literal null} is given. Will wrap all other types into a
* single-element collction * single-element collection.
* *
* @param source * @param source
* @return * @return
@ -240,8 +240,9 @@ public class ConvertingParameterAccessor implements MongoParameterAccessor {
return source.getClass().isArray() ? CollectionUtils.arrayToList(source) : Collections.singleton(source); return source.getClass().isArray() ? CollectionUtils.arrayToList(source) : Collections.singleton(source);
} }
/* (non-Javadoc) /*
* (non-Javadoc)
* @see org.springframework.data.mongodb.repository.query.MongoParameterAccessor#getValues() * @see org.springframework.data.mongodb.repository.query.MongoParameterAccessor#getValues()
*/ */
@Override @Override

11
spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/MongoParametersParameterAccessor.java

@ -120,12 +120,13 @@ public class MongoParametersParameterAccessor extends ParametersParameterAccesso
return ((TextCriteria) fullText); return ((TextCriteria) fullText);
} }
throw new IllegalArgumentException(String.format( throw new IllegalArgumentException(
"Expected full text parameter to be one of String, Term or TextCriteria but found %s.", String.format("Expected full text parameter to be one of String, Term or TextCriteria but found %s.",
ClassUtils.getShortName(fullText.getClass()))); ClassUtils.getShortName(fullText.getClass())));
} }
/* (non-Javadoc) /*
* (non-Javadoc)
* @see org.springframework.data.mongodb.repository.query.MongoParameterAccessor#getValues() * @see org.springframework.data.mongodb.repository.query.MongoParameterAccessor#getValues()
*/ */
@Override @Override

7
spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/PartTreeMongoQuery.java

@ -22,7 +22,6 @@ import org.springframework.data.mongodb.core.mapping.MongoPersistentProperty;
import org.springframework.data.mongodb.core.query.BasicQuery; import org.springframework.data.mongodb.core.query.BasicQuery;
import org.springframework.data.mongodb.core.query.Query; import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.TextCriteria; import org.springframework.data.mongodb.core.query.TextCriteria;
import org.springframework.data.repository.query.EvaluationContextProvider;
import org.springframework.data.repository.query.QueryMethod; import org.springframework.data.repository.query.QueryMethod;
import org.springframework.data.repository.query.RepositoryQuery; import org.springframework.data.repository.query.RepositoryQuery;
import org.springframework.data.repository.query.parser.PartTree; import org.springframework.data.repository.query.parser.PartTree;
@ -48,12 +47,10 @@ public class PartTreeMongoQuery extends AbstractMongoQuery {
* *
* @param method must not be {@literal null}. * @param method must not be {@literal null}.
* @param mongoOperations must not be {@literal null}. * @param mongoOperations must not be {@literal null}.
* @param evaluationContextProvider must not be {@literal null}.
*/ */
public PartTreeMongoQuery(MongoQueryMethod method, MongoOperations mongoOperations, public PartTreeMongoQuery(MongoQueryMethod method, MongoOperations mongoOperations) {
EvaluationContextProvider evaluationContextProvider) {
super(method, mongoOperations, evaluationContextProvider); super(method, mongoOperations);
this.tree = new PartTree(method.getName(), method.getEntityInformation().getJavaType()); this.tree = new PartTree(method.getName(), method.getEntityInformation().getJavaType());
this.isGeoNearQuery = method.isGeoNearQuery(); this.isGeoNearQuery = method.isGeoNearQuery();
this.context = mongoOperations.getConverter().getMappingContext(); this.context = mongoOperations.getConverter().getMappingContext();

59
spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/StringBasedMongoQuery.java

@ -57,36 +57,40 @@ public class StringBasedMongoQuery extends AbstractMongoQuery {
private final List<ParameterBinding> queryParameterBindings; private final List<ParameterBinding> queryParameterBindings;
private final List<ParameterBinding> fieldSpecParameterBindings; private final List<ParameterBinding> fieldSpecParameterBindings;
private final SpelExpressionParser expressionParser; private final SpelExpressionParser expressionParser;
private final EvaluationContextProvider evaluationContextProvider;
/** /**
* Creates a new {@link StringBasedMongoQuery} for the given {@link MongoQueryMethod} and {@link MongoOperations}. * Creates a new {@link StringBasedMongoQuery} for the given {@link MongoQueryMethod} and {@link MongoOperations}.
* *
* @param method must not be {@literal null}. * @param method must not be {@literal null}.
* @param mongoOperations must not be {@literal null}. * @param mongoOperations must not be {@literal null}.
* @param evaluationContextProvider must not be {@literal null}.
* @param expressionParser must not be {@literal null}. * @param expressionParser must not be {@literal null}.
* @param evaluationContextProvider must not be {@literal null}.
*/ */
public StringBasedMongoQuery(MongoQueryMethod method, MongoOperations mongoOperations, public StringBasedMongoQuery(MongoQueryMethod method, MongoOperations mongoOperations,
EvaluationContextProvider evaluationContextProvider, SpelExpressionParser expressionParser) { SpelExpressionParser expressionParser, EvaluationContextProvider evaluationContextProvider) {
this(method.getAnnotatedQuery(), method, mongoOperations, evaluationContextProvider, expressionParser); this(method.getAnnotatedQuery(), method, mongoOperations, expressionParser, evaluationContextProvider);
} }
/** /**
* Creates a new {@link StringBasedMongoQuery} for the given {@link String}, {@link MongoQueryMethod} and * Creates a new {@link StringBasedMongoQuery} for the given {@link String}, {@link MongoQueryMethod},
* {@link MongoOperations}. * {@link MongoOperations}, {@link SpelExpressionParser} and {@link EvaluationContextProvider}.
* *
* @param query must not be {@literal null}.
* @param method must not be {@literal null}. * @param method must not be {@literal null}.
* @param mongoOperations must not be {@literal null}.
* @param expressionParser must not be {@literal null}. * @param expressionParser must not be {@literal null}.
* @param template must not be {@literal null}.
*/ */
public StringBasedMongoQuery(String query, MongoQueryMethod method, MongoOperations mongoOperations, public StringBasedMongoQuery(String query, MongoQueryMethod method, MongoOperations mongoOperations,
EvaluationContextProvider evaluationContextProvider, SpelExpressionParser expressionParser) { SpelExpressionParser expressionParser, EvaluationContextProvider evaluationContextProvider) {
super(method, mongoOperations, evaluationContextProvider); super(method, mongoOperations);
Assert.notNull(query, "Query must not be null!");
Assert.notNull(expressionParser, "SpelExpressionParser must not be null!"); Assert.notNull(expressionParser, "SpelExpressionParser must not be null!");
this.expressionParser = expressionParser; this.expressionParser = expressionParser;
this.evaluationContextProvider = evaluationContextProvider;
this.queryParameterBindings = new ArrayList<ParameterBinding>(); this.queryParameterBindings = new ArrayList<ParameterBinding>();
this.query = BINDING_PARSER.parseAndCollectParameterBindingsFromQueryIntoBindings(query, this.query = BINDING_PARSER.parseAndCollectParameterBindingsFromQueryIntoBindings(query,
@ -157,7 +161,8 @@ public class StringBasedMongoQuery extends AbstractMongoQuery {
* @param bindings * @param bindings
* @return * @return
*/ */
private String replacePlaceholders(String input, ConvertingParameterAccessor accessor, List<ParameterBinding> bindings) { private String replacePlaceholders(String input, ConvertingParameterAccessor accessor,
List<ParameterBinding> bindings) {
if (bindings.isEmpty()) { if (bindings.isEmpty()) {
return input; return input;
@ -187,12 +192,8 @@ public class StringBasedMongoQuery extends AbstractMongoQuery {
*/ */
private String getParameterValueForBinding(ConvertingParameterAccessor accessor, ParameterBinding binding) { private String getParameterValueForBinding(ConvertingParameterAccessor accessor, ParameterBinding binding) {
Object value = null; Object value = binding.isExpression() ? evaluateExpression(binding.getExpression(), accessor.getValues())
if (binding.isExpression()) { : accessor.getBindableValue(binding.getParameterIndex());
value = evaluateExpression(binding.getExpression(), accessor.getValues());
} else {
value = accessor.getBindableValue(binding.getParameterIndex());
}
if (value instanceof String && binding.isQuoted()) { if (value instanceof String && binding.isQuoted()) {
return (String) value; return (String) value;
@ -210,8 +211,8 @@ public class StringBasedMongoQuery extends AbstractMongoQuery {
*/ */
private Object evaluateExpression(String expressionString, Object[] parameterValues) { private Object evaluateExpression(String expressionString, Object[] parameterValues) {
EvaluationContext evaluationContext = getEvaluationContextProvider().getEvaluationContext( EvaluationContext evaluationContext = evaluationContextProvider
getQueryMethod().getParameters(), parameterValues); .getEvaluationContext(getQueryMethod().getParameters(), parameterValues);
Expression expression = expressionParser.parseExpression(expressionString); Expression expression = expressionParser.parseExpression(expressionString);
return expression.getValue(evaluationContext, Object.class); return expression.getValue(evaluationContext, Object.class);
} }
@ -237,8 +238,8 @@ public class StringBasedMongoQuery extends AbstractMongoQuery {
* Returns a list of {@link ParameterBinding}s found in the given {@code input} or an * Returns a list of {@link ParameterBinding}s found in the given {@code input} or an
* {@link Collections#emptyList()}. * {@link Collections#emptyList()}.
* *
* @param input * @param input can be {@literal null} or empty.
* @param bindings * @param bindings must not be {@literal null}.
* @return * @return
*/ */
public String parseAndCollectParameterBindingsFromQueryIntoBindings(String input, List<ParameterBinding> bindings) { public String parseAndCollectParameterBindingsFromQueryIntoBindings(String input, List<ParameterBinding> bindings) {
@ -247,8 +248,9 @@ public class StringBasedMongoQuery extends AbstractMongoQuery {
return input; return input;
} }
String transformedInput = transformQueryAndCollectExpressionParametersIntoBindings(bindings, input); Assert.notNull(bindings, "Parameter bindings must not be null!");
String transformedInput = transformQueryAndCollectExpressionParametersIntoBindings(input, bindings);
String parseableInput = makeParameterReferencesParseable(transformedInput); String parseableInput = makeParameterReferencesParseable(transformedInput);
collectParameterReferencesIntoBindings(bindings, JSON.parse(parseableInput)); collectParameterReferencesIntoBindings(bindings, JSON.parse(parseableInput));
@ -256,28 +258,26 @@ public class StringBasedMongoQuery extends AbstractMongoQuery {
return transformedInput; return transformedInput;
} }
private String transformQueryAndCollectExpressionParametersIntoBindings(List<ParameterBinding> bindings, private String transformQueryAndCollectExpressionParametersIntoBindings(String input,
String input) { List<ParameterBinding> bindings) {
Matcher matcher = PARAMETER_EXPRESSION_PATTERN.matcher(input); Matcher matcher = PARAMETER_EXPRESSION_PATTERN.matcher(input);
StringBuilder result = new StringBuilder(); StringBuilder result = new StringBuilder();
int lastPos = 0; int lastPos = 0;
int exprIndex = 0; int exprIndex = 0;
while (matcher.find()) { while (matcher.find()) {
int startOffSet = matcher.start(); int startOffSet = matcher.start();
result.append(input.subSequence(lastPos, startOffSet));
String expression = matcher.group(3);
result.append(input.subSequence(lastPos, startOffSet));
result.append("'?expr").append(exprIndex).append("'"); result.append("'?expr").append(exprIndex).append("'");
lastPos = matcher.end(); lastPos = matcher.end();
bindings.add(new ParameterBinding(exprIndex, true, expression)); bindings.add(new ParameterBinding(exprIndex, true, matcher.group(3)));
exprIndex++; exprIndex++;
} }
@ -305,9 +305,10 @@ public class StringBasedMongoQuery extends AbstractMongoQuery {
} else if (value instanceof Pattern) { } else if (value instanceof Pattern) {
String string = ((Pattern) value).toString().trim(); String string = ((Pattern) value).toString().trim();
Matcher valueMatcher = PARSEABLE_BINDING_PATTERN.matcher(string); Matcher valueMatcher = PARSEABLE_BINDING_PATTERN.matcher(string);
while (valueMatcher.find()) { while (valueMatcher.find()) {
int paramIndex = Integer.parseInt(valueMatcher.group(PARAMETER_INDEX_GROUP)); int paramIndex = Integer.parseInt(valueMatcher.group(PARAMETER_INDEX_GROUP));
/* /*

19
spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/MongoRepositoryFactory.java

@ -15,7 +15,7 @@
*/ */
package org.springframework.data.mongodb.repository.support; package org.springframework.data.mongodb.repository.support;
import static org.springframework.data.querydsl.QueryDslUtils.QUERY_DSL_PRESENT; import static org.springframework.data.querydsl.QueryDslUtils.*;
import java.io.Serializable; import java.io.Serializable;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@ -51,7 +51,7 @@ import org.springframework.util.Assert;
public class MongoRepositoryFactory extends RepositoryFactorySupport { public class MongoRepositoryFactory extends RepositoryFactorySupport {
private static final SpelExpressionParser EXPRESSION_PARSER = new SpelExpressionParser(); private static final SpelExpressionParser EXPRESSION_PARSER = new SpelExpressionParser();
private final MongoOperations mongoOperations; private final MongoOperations mongoOperations;
private final MappingContext<? extends MongoPersistentEntity<?>, MongoPersistentProperty> mappingContext; private final MappingContext<? extends MongoPersistentEntity<?>, MongoPersistentProperty> mappingContext;
@ -92,8 +92,8 @@ public class MongoRepositoryFactory extends RepositoryFactorySupport {
return getTargetRepositoryViaReflection(information, entityInformation, mongoOperations); return getTargetRepositoryViaReflection(information, entityInformation, mongoOperations);
} }
/*
/* (non-Javadoc) * (non-Javadoc)
* @see org.springframework.data.repository.core.support.RepositoryFactorySupport#getQueryLookupStrategy(org.springframework.data.repository.query.QueryLookupStrategy.Key, org.springframework.data.repository.query.EvaluationContextProvider) * @see org.springframework.data.repository.core.support.RepositoryFactorySupport#getQueryLookupStrategy(org.springframework.data.repository.query.QueryLookupStrategy.Key, org.springframework.data.repository.query.EvaluationContextProvider)
*/ */
@Override @Override
@ -112,8 +112,8 @@ public class MongoRepositoryFactory extends RepositoryFactorySupport {
MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(domainClass); MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(domainClass);
if (entity == null) { if (entity == null) {
throw new MappingException(String.format("Could not lookup mapping metadata for domain class %s!", throw new MappingException(
domainClass.getName())); String.format("Could not lookup mapping metadata for domain class %s!", domainClass.getName()));
} }
return new MappingMongoEntityInformation<T, ID>((MongoPersistentEntity<T>) entity); return new MappingMongoEntityInformation<T, ID>((MongoPersistentEntity<T>) entity);
@ -144,11 +144,12 @@ public class MongoRepositoryFactory extends RepositoryFactorySupport {
if (namedQueries.hasQuery(namedQueryName)) { if (namedQueries.hasQuery(namedQueryName)) {
String namedQuery = namedQueries.getQuery(namedQueryName); String namedQuery = namedQueries.getQuery(namedQueryName);
return new StringBasedMongoQuery(namedQuery, queryMethod, mongoOperations, evaluationContextProvider, EXPRESSION_PARSER); return new StringBasedMongoQuery(namedQuery, queryMethod, mongoOperations, EXPRESSION_PARSER,
evaluationContextProvider);
} else if (queryMethod.hasAnnotatedQuery()) { } else if (queryMethod.hasAnnotatedQuery()) {
return new StringBasedMongoQuery(queryMethod, mongoOperations, evaluationContextProvider, EXPRESSION_PARSER); return new StringBasedMongoQuery(queryMethod, mongoOperations, EXPRESSION_PARSER, evaluationContextProvider);
} else { } else {
return new PartTreeMongoQuery(queryMethod, mongoOperations, evaluationContextProvider); return new PartTreeMongoQuery(queryMethod, mongoOperations);
} }
} }
} }

90
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/AbstractPersonRepositoryIntegrationTests.java

@ -52,6 +52,7 @@ import org.springframework.data.geo.Polygon;
import org.springframework.data.mongodb.core.MongoOperations; import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.query.BasicQuery; import org.springframework.data.mongodb.core.query.BasicQuery;
import org.springframework.data.mongodb.repository.Person.Sex; import org.springframework.data.mongodb.repository.Person.Sex;
import org.springframework.data.mongodb.repository.SampleEvaluationContextExtension.SampleSecurityContextHolder;
import org.springframework.data.querydsl.QSort; import org.springframework.data.querydsl.QSort;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@ -174,8 +175,8 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
@Test @Test
public void executesPagedFinderCorrectly() throws Exception { public void executesPagedFinderCorrectly() throws Exception {
Page<Person> page = repository.findByLastnameLike("*a*", new PageRequest(0, 2, Direction.ASC, "lastname", Page<Person> page = repository.findByLastnameLike("*a*",
"firstname")); new PageRequest(0, 2, Direction.ASC, "lastname", "firstname"));
assertThat(page.isFirst(), is(true)); assertThat(page.isFirst(), is(true));
assertThat(page.isLast(), is(false)); assertThat(page.isLast(), is(false));
assertThat(page.getNumberOfElements(), is(2)); assertThat(page.getNumberOfElements(), is(2));
@ -185,8 +186,8 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
@Test @Test
public void executesPagedFinderWithAnnotatedQueryCorrectly() throws Exception { public void executesPagedFinderWithAnnotatedQueryCorrectly() throws Exception {
Page<Person> page = repository.findByLastnameLikeWithPageable(".*a.*", new PageRequest(0, 2, Direction.ASC, Page<Person> page = repository.findByLastnameLikeWithPageable(".*a.*",
"lastname", "firstname")); new PageRequest(0, 2, Direction.ASC, "lastname", "firstname"));
assertThat(page.isFirst(), is(true)); assertThat(page.isFirst(), is(true));
assertThat(page.isLast(), is(false)); assertThat(page.isLast(), is(false));
assertThat(page.getNumberOfElements(), is(2)); assertThat(page.getNumberOfElements(), is(2));
@ -310,8 +311,8 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
@Test @Test
public void findsPagedPeopleByPredicate() throws Exception { public void findsPagedPeopleByPredicate() throws Exception {
Page<Person> page = repository.findAll(person.lastname.contains("a"), new PageRequest(0, 2, Direction.ASC, Page<Person> page = repository.findAll(person.lastname.contains("a"),
"lastname")); new PageRequest(0, 2, Direction.ASC, "lastname"));
assertThat(page.isFirst(), is(true)); assertThat(page.isFirst(), is(true));
assertThat(page.isLast(), is(false)); assertThat(page.isLast(), is(false));
assertThat(page.getNumberOfElements(), is(2)); assertThat(page.getNumberOfElements(), is(2));
@ -397,8 +398,8 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
dave.setLocation(point); dave.setLocation(point);
repository.save(dave); repository.save(dave);
GeoResults<Person> results = repository.findByLocationNear(new Point(-73.99, 40.73), new Distance(2000, GeoResults<Person> results = repository.findByLocationNear(new Point(-73.99, 40.73),
Metrics.KILOMETERS)); new Distance(2000, Metrics.KILOMETERS));
assertThat(results.getContent().isEmpty(), is(false)); assertThat(results.getContent().isEmpty(), is(false));
} }
@ -409,8 +410,8 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
dave.setLocation(point); dave.setLocation(point);
repository.save(dave); repository.save(dave);
GeoPage<Person> results = repository.findByLocationNear(new Point(-73.99, 40.73), new Distance(2000, GeoPage<Person> results = repository.findByLocationNear(new Point(-73.99, 40.73),
Metrics.KILOMETERS), new PageRequest(0, 20)); new Distance(2000, Metrics.KILOMETERS), new PageRequest(0, 20));
assertThat(results.getContent().isEmpty(), is(false)); assertThat(results.getContent().isEmpty(), is(false));
// DATAMONGO-607 // DATAMONGO-607
@ -620,8 +621,8 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
repository.save(Arrays.asList(dave, oliver, carter, boyd, leroi)); repository.save(Arrays.asList(dave, oliver, carter, boyd, leroi));
GeoPage<Person> results = repository.findByLocationNear(new Point(-73.99, 40.73), new Distance(2000, GeoPage<Person> results = repository.findByLocationNear(new Point(-73.99, 40.73),
Metrics.KILOMETERS), new PageRequest(1, 2)); new Distance(2000, Metrics.KILOMETERS), new PageRequest(1, 2));
assertThat(results.getContent().isEmpty(), is(false)); assertThat(results.getContent().isEmpty(), is(false));
assertThat(results.getNumberOfElements(), is(2)); assertThat(results.getNumberOfElements(), is(2));
@ -645,8 +646,8 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
repository.save(Arrays.asList(dave, oliver, carter)); repository.save(Arrays.asList(dave, oliver, carter));
GeoPage<Person> results = repository.findByLocationNear(new Point(-73.99, 40.73), new Distance(2000, GeoPage<Person> results = repository.findByLocationNear(new Point(-73.99, 40.73),
Metrics.KILOMETERS), new PageRequest(1, 2)); new Distance(2000, Metrics.KILOMETERS), new PageRequest(1, 2));
assertThat(results.getContent().isEmpty(), is(false)); assertThat(results.getContent().isEmpty(), is(false));
assertThat(results.getNumberOfElements(), is(1)); assertThat(results.getNumberOfElements(), is(1));
assertThat(results.isFirst(), is(false)); assertThat(results.isFirst(), is(false));
@ -664,8 +665,8 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
dave.setLocation(point); dave.setLocation(point);
repository.save(dave); repository.save(dave);
GeoPage<Person> results = repository.findByLocationNear(new Point(-73.99, 40.73), new Distance(2000, GeoPage<Person> results = repository.findByLocationNear(new Point(-73.99, 40.73),
Metrics.KILOMETERS), new PageRequest(0, 2)); new Distance(2000, Metrics.KILOMETERS), new PageRequest(0, 2));
assertThat(results.getContent().isEmpty(), is(false)); assertThat(results.getContent().isEmpty(), is(false));
assertThat(results.getNumberOfElements(), is(1)); assertThat(results.getNumberOfElements(), is(1));
@ -683,8 +684,8 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
dave.setLocation(new Point(-73.99171, 40.738868)); dave.setLocation(new Point(-73.99171, 40.738868));
repository.save(dave); repository.save(dave);
GeoPage<Person> results = repository.findByLocationNear(new Point(-73.99, 40.73), new Distance(2000, GeoPage<Person> results = repository.findByLocationNear(new Point(-73.99, 40.73),
Metrics.KILOMETERS), new PageRequest(1, 2)); new Distance(2000, Metrics.KILOMETERS), new PageRequest(1, 2));
assertThat(results.getContent().isEmpty(), is(true)); assertThat(results.getContent().isEmpty(), is(true));
assertThat(results.getNumberOfElements(), is(0)); assertThat(results.getNumberOfElements(), is(0));
@ -934,8 +935,8 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
@Test @Test
public void shouldLimitCollectionQueryToMaxResultsWhenPresent() { public void shouldLimitCollectionQueryToMaxResultsWhenPresent() {
repository.save(Arrays.asList(new Person("Bob-1", "Dylan"), new Person("Bob-2", "Dylan"), new Person("Bob-3", repository.save(Arrays.asList(new Person("Bob-1", "Dylan"), new Person("Bob-2", "Dylan"),
"Dylan"), new Person("Bob-4", "Dylan"), new Person("Bob-5", "Dylan"))); new Person("Bob-3", "Dylan"), new Person("Bob-4", "Dylan"), new Person("Bob-5", "Dylan")));
List<Person> result = repository.findTop3ByLastnameStartingWith("Dylan"); List<Person> result = repository.findTop3ByLastnameStartingWith("Dylan");
assertThat(result.size(), is(3)); assertThat(result.size(), is(3));
} }
@ -946,8 +947,8 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
@Test @Test
public void shouldNotLimitPagedQueryWhenPageRequestWithinBounds() { public void shouldNotLimitPagedQueryWhenPageRequestWithinBounds() {
repository.save(Arrays.asList(new Person("Bob-1", "Dylan"), new Person("Bob-2", "Dylan"), new Person("Bob-3", repository.save(Arrays.asList(new Person("Bob-1", "Dylan"), new Person("Bob-2", "Dylan"),
"Dylan"), new Person("Bob-4", "Dylan"), new Person("Bob-5", "Dylan"))); new Person("Bob-3", "Dylan"), new Person("Bob-4", "Dylan"), new Person("Bob-5", "Dylan")));
Page<Person> result = repository.findTop3ByLastnameStartingWith("Dylan", new PageRequest(0, 2)); Page<Person> result = repository.findTop3ByLastnameStartingWith("Dylan", new PageRequest(0, 2));
assertThat(result.getContent().size(), is(2)); assertThat(result.getContent().size(), is(2));
} }
@ -958,8 +959,8 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
@Test @Test
public void shouldLimitPagedQueryWhenPageRequestExceedsUpperBoundary() { public void shouldLimitPagedQueryWhenPageRequestExceedsUpperBoundary() {
repository.save(Arrays.asList(new Person("Bob-1", "Dylan"), new Person("Bob-2", "Dylan"), new Person("Bob-3", repository.save(Arrays.asList(new Person("Bob-1", "Dylan"), new Person("Bob-2", "Dylan"),
"Dylan"), new Person("Bob-4", "Dylan"), new Person("Bob-5", "Dylan"))); new Person("Bob-3", "Dylan"), new Person("Bob-4", "Dylan"), new Person("Bob-5", "Dylan")));
Page<Person> result = repository.findTop3ByLastnameStartingWith("Dylan", new PageRequest(1, 2)); Page<Person> result = repository.findTop3ByLastnameStartingWith("Dylan", new PageRequest(1, 2));
assertThat(result.getContent().size(), is(1)); assertThat(result.getContent().size(), is(1));
} }
@ -970,8 +971,8 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
@Test @Test
public void shouldReturnEmptyWhenPageRequestedPageIsTotallyOutOfScopeForLimit() { public void shouldReturnEmptyWhenPageRequestedPageIsTotallyOutOfScopeForLimit() {
repository.save(Arrays.asList(new Person("Bob-1", "Dylan"), new Person("Bob-2", "Dylan"), new Person("Bob-3", repository.save(Arrays.asList(new Person("Bob-1", "Dylan"), new Person("Bob-2", "Dylan"),
"Dylan"), new Person("Bob-4", "Dylan"), new Person("Bob-5", "Dylan"))); new Person("Bob-3", "Dylan"), new Person("Bob-4", "Dylan"), new Person("Bob-5", "Dylan")));
Page<Person> result = repository.findTop3ByLastnameStartingWith("Dylan", new PageRequest(2, 2)); Page<Person> result = repository.findTop3ByLastnameStartingWith("Dylan", new PageRequest(2, 2));
assertThat(result.getContent().size(), is(0)); assertThat(result.getContent().size(), is(0));
} }
@ -1183,4 +1184,41 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
GeoResults<Person> results = repository.findPersonByLocationNear(new Point(-73.99, 40.73), range); GeoResults<Person> results = repository.findPersonByLocationNear(new Point(-73.99, 40.73), range);
assertThat(results.getContent().isEmpty(), is(false)); assertThat(results.getContent().isEmpty(), is(false));
} }
/**
* @see DATAMONGO-990
*/
@Test
public void shouldFindByFirstnameForSpELExpressionWithParameterIndexOnly() {
List<Person> users = repository.findWithSpelByFirstnameForSpELExpressionWithParameterIndexOnly("Dave");
assertThat(users, hasSize(1));
assertThat(users.get(0), is(dave));
}
/**
* @see DATAMONGO-990
*/
@Test
public void shouldFindByFirstnameAndCurrentUserWithCustomQuery() {
SampleSecurityContextHolder.getCurrent().setPrincipal(dave);
List<Person> users = repository.findWithSpelByFirstnameAndCurrentUserWithCustomQuery("Dave");
assertThat(users, hasSize(1));
assertThat(users.get(0), is(dave));
}
/**
* @see DATAMONGO-990
*/
@Test
public void shouldFindByFirstnameForSpELExpressionWithParameterVariableOnly() {
List<Person> users = repository.findWithSpelByFirstnameForSpELExpressionWithParameterVariableOnly("Dave");
assertThat(users, hasSize(1));
assertThat(users.get(0), is(dave));
}
} }

49
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/PersonRepositoryIntegrationTests.java

@ -15,14 +15,6 @@
*/ */
package org.springframework.data.mongodb.repository; package org.springframework.data.mongodb.repository;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import java.util.List;
import org.junit.Test;
import org.springframework.data.mongodb.repository.SampleEvaluationContextExtension.SampleSecurityContextHolder;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
/** /**
@ -32,43 +24,4 @@ import org.springframework.test.context.ContextConfiguration;
* @author Thomas Darimont * @author Thomas Darimont
*/ */
@ContextConfiguration @ContextConfiguration
public class PersonRepositoryIntegrationTests extends AbstractPersonRepositoryIntegrationTests { public class PersonRepositoryIntegrationTests extends AbstractPersonRepositoryIntegrationTests {}
/**
* @see DATAMONGO-990
*/
@Test
public void shouldFindByFirstnameForSpELExpressionWithParameterIndexOnly() {
List<Person> users = repository.findWithSpelByFirstnameForSpELExpressionWithParameterIndexOnly("Dave");
assertThat(users, hasSize(1));
assertThat(users.get(0), is(dave));
}
/**
* @see DATAMONGO-990
*/
@Test
public void shouldFindByFirstnameAndCurrentUserWithCustomQuery() {
SampleSecurityContextHolder.getCurrent().setPrincipal(dave);
List<Person> users = repository.findWithSpelByFirstnameAndCurrentUserWithCustomQuery("Dave");
assertThat(users, hasSize(1));
assertThat(users.get(0), is(dave));
}
/**
* @see DATAMONGO-990
*/
@Test
public void shouldFindByFirstnameForSpELExpressionWithParameterVariableOnly() {
List<Person> users = repository.findWithSpelByFirstnameForSpELExpressionWithParameterVariableOnly("Dave");
assertThat(users, hasSize(1));
assertThat(users.get(0), is(dave));
}
}

3
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/config/MongoNamespaceIntegrationTests.java

@ -45,8 +45,7 @@ public class MongoNamespaceIntegrationTests extends AbstractPersonRepositoryInte
DefaultListableBeanFactory factory; DefaultListableBeanFactory factory;
BeanDefinitionReader reader; BeanDefinitionReader reader;
@Autowired @Autowired ApplicationContext context;
ApplicationContext context;
@Before @Before
@Override @Override

19
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/query/AbstractMongoQueryUnitTests.java

@ -15,14 +15,10 @@
*/ */
package org.springframework.data.mongodb.repository.query; package org.springframework.data.mongodb.repository.query;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.*;
import static org.hamcrest.Matchers.nullValue; import static org.junit.Assert.*;
import static org.junit.Assert.assertThat; import static org.mockito.Matchers.*;
import static org.mockito.Matchers.eq; import static org.mockito.Mockito.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Arrays; import java.util.Arrays;
@ -58,7 +54,6 @@ import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.repository.Meta; import org.springframework.data.mongodb.repository.Meta;
import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.repository.core.RepositoryMetadata; import org.springframework.data.repository.core.RepositoryMetadata;
import org.springframework.data.repository.query.DefaultEvaluationContextProvider;
import com.mongodb.BasicDBObjectBuilder; import com.mongodb.BasicDBObjectBuilder;
import com.mongodb.DBObject; import com.mongodb.DBObject;
@ -148,8 +143,8 @@ public class AbstractMongoQueryUnitTests {
public void testDeleteExecutionReturnsNrDocumentsDeletedFromWriteResult() { public void testDeleteExecutionReturnsNrDocumentsDeletedFromWriteResult() {
when(writeResultMock.getN()).thenReturn(100); when(writeResultMock.getN()).thenReturn(100);
when(this.mongoOperationsMock.remove(Matchers.any(Query.class), eq(Person.class), eq("persons"))).thenReturn( when(this.mongoOperationsMock.remove(Matchers.any(Query.class), eq(Person.class), eq("persons")))
writeResultMock); .thenReturn(writeResultMock);
MongoQueryFake query = createQueryForMethod("deletePersonByLastname", String.class); MongoQueryFake query = createQueryForMethod("deletePersonByLastname", String.class);
query.setDeleteQuery(true); query.setDeleteQuery(true);
@ -320,7 +315,7 @@ public class AbstractMongoQueryUnitTests {
private boolean isDeleteQuery; private boolean isDeleteQuery;
public MongoQueryFake(MongoQueryMethod method, MongoOperations operations) { public MongoQueryFake(MongoQueryMethod method, MongoOperations operations) {
super(method, operations, DefaultEvaluationContextProvider.INSTANCE); super(method, operations);
} }
@Override @Override

12
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/query/PartTreeMongoQueryUnitTests.java

@ -15,11 +15,10 @@
*/ */
package org.springframework.data.mongodb.repository.query; package org.springframework.data.mongodb.repository.query;
import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.assertThat; import static org.junit.Assert.*;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.*;
import static org.mockito.Mockito.when; import static org.springframework.data.mongodb.core.query.IsTextQuery.*;
import static org.springframework.data.mongodb.core.query.IsTextQuery.isTextQuery;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@ -44,7 +43,6 @@ import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.Person; import org.springframework.data.mongodb.repository.Person;
import org.springframework.data.mongodb.repository.Query; import org.springframework.data.mongodb.repository.Query;
import org.springframework.data.repository.core.RepositoryMetadata; import org.springframework.data.repository.core.RepositoryMetadata;
import org.springframework.data.repository.query.DefaultEvaluationContextProvider;
import com.mongodb.BasicDBObjectBuilder; import com.mongodb.BasicDBObjectBuilder;
import com.mongodb.util.JSONParseException; import com.mongodb.util.JSONParseException;
@ -172,7 +170,7 @@ public class PartTreeMongoQueryUnitTests {
Method method = Repo.class.getMethod(methodName, paramTypes); Method method = Repo.class.getMethod(methodName, paramTypes);
MongoQueryMethod queryMethod = new MongoQueryMethod(method, metadataMock, mappingContext); MongoQueryMethod queryMethod = new MongoQueryMethod(method, metadataMock, mappingContext);
return new PartTreeMongoQuery(queryMethod, mongoOperationsMock, DefaultEvaluationContextProvider.INSTANCE); return new PartTreeMongoQuery(queryMethod, mongoOperationsMock);
} catch (NoSuchMethodException e) { } catch (NoSuchMethodException e) {
throw new IllegalArgumentException(e.getMessage(), e); throw new IllegalArgumentException(e.getMessage(), e);
} catch (SecurityException e) { } catch (SecurityException e) {

50
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/query/StringBasedMongoQueryUnitTests.java

@ -15,10 +15,9 @@
*/ */
package org.springframework.data.mongodb.repository.query; package org.springframework.data.mongodb.repository.query;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.*;
import static org.hamcrest.Matchers.nullValue; import static org.junit.Assert.*;
import static org.junit.Assert.assertThat; import static org.mockito.Mockito.*;
import static org.mockito.Mockito.when;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Collections; import java.util.Collections;
@ -61,7 +60,7 @@ import com.mongodb.DBRef;
public class StringBasedMongoQueryUnitTests { public class StringBasedMongoQueryUnitTests {
SpelExpressionParser PARSER = new SpelExpressionParser(); SpelExpressionParser PARSER = new SpelExpressionParser();
@Mock MongoOperations operations; @Mock MongoOperations operations;
@Mock RepositoryMetadata metadata; @Mock RepositoryMetadata metadata;
@Mock DbRefResolver factory; @Mock DbRefResolver factory;
@ -81,8 +80,8 @@ public class StringBasedMongoQueryUnitTests {
Method method = SampleRepository.class.getMethod("findByLastname", String.class); Method method = SampleRepository.class.getMethod("findByLastname", String.class);
MongoQueryMethod queryMethod = new MongoQueryMethod(method, metadata, converter.getMappingContext()); MongoQueryMethod queryMethod = new MongoQueryMethod(method, metadata, converter.getMappingContext());
StringBasedMongoQuery mongoQuery = new StringBasedMongoQuery(queryMethod, operations, StringBasedMongoQuery mongoQuery = new StringBasedMongoQuery(queryMethod, operations, PARSER,
DefaultEvaluationContextProvider.INSTANCE, PARSER); DefaultEvaluationContextProvider.INSTANCE);
ConvertingParameterAccessor accesor = StubParameterAccessor.getAccessor(converter, "Matthews"); ConvertingParameterAccessor accesor = StubParameterAccessor.getAccessor(converter, "Matthews");
org.springframework.data.mongodb.core.query.Query query = mongoQuery.createQuery(accesor); org.springframework.data.mongodb.core.query.Query query = mongoQuery.createQuery(accesor);
@ -215,8 +214,9 @@ public class StringBasedMongoQueryUnitTests {
org.springframework.data.mongodb.core.query.Query query = mongoQuery.createQuery(accessor); org.springframework.data.mongodb.core.query.Query query = mongoQuery.createQuery(accessor);
assertThat(query.getQueryObject(), is(new BasicQuery( assertThat(query.getQueryObject(),
"{$where: 'return this.date.getUTCMonth() == 3 && this.date.getUTCDay() == 4;'}").getQueryObject())); is(new BasicQuery("{$where: 'return this.date.getUTCMonth() == 3 && this.date.getUTCDay() == 4;'}")
.getQueryObject()));
} }
/** /**
@ -264,21 +264,6 @@ public class StringBasedMongoQueryUnitTests {
assertThat(query.getQueryObject(), is(reference.getQueryObject())); assertThat(query.getQueryObject(), is(reference.getQueryObject()));
} }
/**
* @see DATAMONGO-990
*/
@Test
public void shouldSupportExpressionsInCustomQueries() throws Exception {
ConvertingParameterAccessor accesor = StubParameterAccessor.getAccessor(converter, "Matthews");
StringBasedMongoQuery mongoQuery = createQueryForMethod("findByQueryWithExpression", String.class);
org.springframework.data.mongodb.core.query.Query query = mongoQuery.createQuery(accesor);
org.springframework.data.mongodb.core.query.Query reference = new BasicQuery("{'lastname' : 'Matthews'}");
assertThat(query.getQueryObject(), is(reference.getQueryObject()));
}
/** /**
* @see DATAMONGO-1070 * @see DATAMONGO-1070
*/ */
@ -310,11 +295,26 @@ public class StringBasedMongoQueryUnitTests {
assertThat(query.getQueryObject(), is(new BasicDBObjectBuilder().add("key", "value").get())); assertThat(query.getQueryObject(), is(new BasicDBObjectBuilder().add("key", "value").get()));
} }
/**
* @see DATAMONGO-990
*/
@Test
public void shouldSupportExpressionsInCustomQueries() throws Exception {
ConvertingParameterAccessor accesor = StubParameterAccessor.getAccessor(converter, "Matthews");
StringBasedMongoQuery mongoQuery = createQueryForMethod("findByQueryWithExpression", String.class);
org.springframework.data.mongodb.core.query.Query query = mongoQuery.createQuery(accesor);
org.springframework.data.mongodb.core.query.Query reference = new BasicQuery("{'lastname' : 'Matthews'}");
assertThat(query.getQueryObject(), is(reference.getQueryObject()));
}
private StringBasedMongoQuery createQueryForMethod(String name, Class<?>... parameters) throws Exception { private StringBasedMongoQuery createQueryForMethod(String name, Class<?>... parameters) throws Exception {
Method method = SampleRepository.class.getMethod(name, parameters); Method method = SampleRepository.class.getMethod(name, parameters);
MongoQueryMethod queryMethod = new MongoQueryMethod(method, metadata, converter.getMappingContext()); MongoQueryMethod queryMethod = new MongoQueryMethod(method, metadata, converter.getMappingContext());
return new StringBasedMongoQuery(queryMethod, operations, DefaultEvaluationContextProvider.INSTANCE, PARSER); return new StringBasedMongoQuery(queryMethod, operations, PARSER, DefaultEvaluationContextProvider.INSTANCE);
} }
private interface SampleRepository { private interface SampleRepository {

7
spring-data-mongodb/src/test/resources/org/springframework/data/mongodb/repository/PersonRepositoryIntegrationTests-context.xml

@ -29,9 +29,10 @@
<property name="evaluationContextProvider" ref="extensionAwareEvaluationContextProvider"/> <property name="evaluationContextProvider" ref="extensionAwareEvaluationContextProvider"/>
</bean> </bean>
<bean id="sampleEvaluationContextExtension" class="org.springframework.data.mongodb.repository.SampleEvaluationContextExtension"/>
<bean id="extensionAwareEvaluationContextProvider" class="org.springframework.data.repository.query.ExtensionAwareEvaluationContextProvider"> <bean id="extensionAwareEvaluationContextProvider" class="org.springframework.data.repository.query.ExtensionAwareEvaluationContextProvider">
<constructor-arg ref="sampleEvaluationContextExtension"/> <constructor-arg>
<bean class="org.springframework.data.mongodb.repository.SampleEvaluationContextExtension"/>
</constructor-arg>
</bean> </bean>
</beans> </beans>

2
spring-data-mongodb/src/test/resources/org/springframework/data/mongodb/repository/config/MongoNamespaceIntegrationTests-context.xml

@ -22,4 +22,6 @@
<repository:exclude-filter type="regex" expression=".*MongoRepository"/> <repository:exclude-filter type="regex" expression=".*MongoRepository"/>
</mongo:repositories> </mongo:repositories>
<bean class="org.springframework.data.mongodb.repository.SampleEvaluationContextExtension"/>
</beans> </beans>

Loading…
Cancel
Save