use of org.springframework.data.repository.query.parser.PartTree in project spring-data-mongodb by spring-projects.
the class MongoQueryCreatorUnitTests method assertBindsDistanceToQuery.
private void assertBindsDistanceToQuery(Point point, Distance distance, Query reference) throws Exception {
PartTree tree = new PartTree("findByLocationNearAndFirstname", org.springframework.data.mongodb.repository.Person.class);
Method method = PersonRepository.class.getMethod("findByLocationNearAndFirstname", Point.class, Distance.class, String.class);
MongoQueryMethod queryMethod = new MongoQueryMethod(method, new DefaultRepositoryMetadata(PersonRepository.class), new SpelAwareProxyProjectionFactory(), new MongoMappingContext());
MongoParameterAccessor accessor = new MongoParametersParameterAccessor(queryMethod, new Object[] { point, distance, "Dave" });
Query query = new MongoQueryCreator(tree, new ConvertingParameterAccessor(converter, accessor), context).createQuery();
assertThat(query).isEqualTo(query);
}
use of org.springframework.data.repository.query.parser.PartTree in project spring-data-mongodb by spring-projects.
the class MongoQueryCreatorUnitTests method notLikeShouldBeTreatedCorrectlyWhenUsedWithWildcardOnly.
// DATAMONGO-1424
@Test
void notLikeShouldBeTreatedCorrectlyWhenUsedWithWildcardOnly() {
PartTree tree = new PartTree("findByUsernameNotLike", User.class);
ConvertingParameterAccessor accessor = getAccessor(converter, "*");
Query query = new MongoQueryCreator(tree, accessor, context).createQuery();
assertThat(query.getQueryObject().toJson()).isEqualTo(query(where("username").not().regex(".*")).getQueryObject().toJson());
}
use of org.springframework.data.repository.query.parser.PartTree in project spring-data-mongodb by spring-projects.
the class MongoQueryCreatorUnitTests method createsQueryWithStartingWithPredicateCorrectly.
// DATAMONGO-418
@Test
void createsQueryWithStartingWithPredicateCorrectly() {
PartTree tree = new PartTree("findByUsernameStartingWith", User.class);
MongoQueryCreator creator = new MongoQueryCreator(tree, getAccessor(converter, "Matt"), context);
Query query = creator.createQuery();
assertThat(query).isEqualTo(query(where("username").regex("^Matt")));
}
use of org.springframework.data.repository.query.parser.PartTree in project spring-data-mongodb by spring-projects.
the class MongoQueryCreatorUnitTests method createsIsNullQueryCorrectly.
@Test
void createsIsNullQueryCorrectly() {
PartTree tree = new PartTree("findByFirstNameIsNull", Person.class);
Query query = new MongoQueryCreator(tree, getAccessor(converter), context).createQuery();
assertThat(query).isEqualTo(new Query(Criteria.where("firstName").is(null)));
}
use of org.springframework.data.repository.query.parser.PartTree in project spring-data-mongodb by spring-projects.
the class MongoQueryCreatorUnitTests method shouldOnlyGenerateLikeExpressionsForStringPropertiesIfAllIgnoreCase.
// DATAMONGO-770
@Test
void shouldOnlyGenerateLikeExpressionsForStringPropertiesIfAllIgnoreCase() {
PartTree tree = new PartTree("findByFirstNameAndAgeAllIgnoreCase", Person.class);
MongoQueryCreator creator = new MongoQueryCreator(tree, getAccessor(converter, "dave", 42), context);
Query query = creator.createQuery();
assertThat(query).isEqualTo(query(where("firstName").regex("^dave$", "i").and("age").is(42)));
}
Aggregations