Search in sources :

Example 26 with PartTree

use of org.springframework.data.repository.query.parser.PartTree in project spring-data-mongodb by spring-projects.

the class MongoQueryCreatorUnitTests method appliesIgnoreCaseToLeafProperty.

// DATAMONGO-1229
@Test
void appliesIgnoreCaseToLeafProperty() {
    PartTree tree = new PartTree("findByAddressStreetIgnoreCase", User.class);
    ConvertingParameterAccessor accessor = getAccessor(converter, "Street");
    assertThat(new MongoQueryCreator(tree, accessor, context).createQuery()).isNotNull();
}
Also used : PartTree(org.springframework.data.repository.query.parser.PartTree) Test(org.junit.jupiter.api.Test)

Example 27 with PartTree

use of org.springframework.data.repository.query.parser.PartTree in project spring-data-mongodb by spring-projects.

the class MongoQueryCreatorUnitTests method ignoreCaseShouldEscapeSourceWhenUsedForEndingWith.

// DATAMONGO-1232
@Test
void ignoreCaseShouldEscapeSourceWhenUsedForEndingWith() {
    PartTree tree = new PartTree("findByUsernameEndingWithIgnoreCase", User.class);
    ConvertingParameterAccessor accessor = getAccessor(converter, "new.ton+");
    Query query = new MongoQueryCreator(tree, accessor, context).createQuery();
    assertThat(query).isEqualTo(query(where("username").regex("\\Qnew.ton+\\E$", "i")));
}
Also used : Query(org.springframework.data.mongodb.core.query.Query) PartTree(org.springframework.data.repository.query.parser.PartTree) Test(org.junit.jupiter.api.Test)

Example 28 with PartTree

use of org.springframework.data.repository.query.parser.PartTree in project spring-data-mongodb by spring-projects.

the class MongoQueryCreatorUnitTests method createsQueryWithFindByContainingIgnoreCaseCorrectly.

// DATAMONGO-770
@Test
void createsQueryWithFindByContainingIgnoreCaseCorrectly() {
    PartTree tree = new PartTree("findByFirstNameContainingIgnoreCase", Person.class);
    MongoQueryCreator creator = new MongoQueryCreator(tree, getAccessor(converter, "dave"), context);
    Query query = creator.createQuery();
    assertThat(query).isEqualTo(query(where("firstName").regex(".*dave.*", "i")));
}
Also used : Query(org.springframework.data.mongodb.core.query.Query) PartTree(org.springframework.data.repository.query.parser.PartTree) Test(org.junit.jupiter.api.Test)

Example 29 with PartTree

use of org.springframework.data.repository.query.parser.PartTree in project spring-data-mongodb by spring-projects.

the class MongoQueryCreatorUnitTests method ignoreCaseShouldEscapeSourceWhenUsedForStartingWith.

// DATAMONGO-1232
@Test
void ignoreCaseShouldEscapeSourceWhenUsedForStartingWith() {
    PartTree tree = new PartTree("findByUsernameStartingWithIgnoreCase", User.class);
    ConvertingParameterAccessor accessor = getAccessor(converter, "dawns.light+");
    Query query = new MongoQueryCreator(tree, accessor, context).createQuery();
    assertThat(query).isEqualTo(query(where("username").regex("^\\Qdawns.light+\\E", "i")));
}
Also used : Query(org.springframework.data.mongodb.core.query.Query) PartTree(org.springframework.data.repository.query.parser.PartTree) Test(org.junit.jupiter.api.Test)

Example 30 with PartTree

use of org.springframework.data.repository.query.parser.PartTree in project spring-data-mongodb by spring-projects.

the class MongoQueryCreatorUnitTests method shouldCreateDeleteByQueryCorrectlyForMultipleCriteriaAndCaseExpressions.

// DATAMONGO-566
@Test
void shouldCreateDeleteByQueryCorrectlyForMultipleCriteriaAndCaseExpressions() {
    PartTree tree = new PartTree("deleteByFirstNameAndAgeAllIgnoreCase", Person.class);
    MongoQueryCreator creator = new MongoQueryCreator(tree, getAccessor(converter, "dave", 42), context);
    Query query = creator.createQuery();
    assertThat(tree.isDelete()).isTrue();
    assertThat(query).isEqualTo(query(where("firstName").regex("^dave$", "i").and("age").is(42)));
}
Also used : Query(org.springframework.data.mongodb.core.query.Query) PartTree(org.springframework.data.repository.query.parser.PartTree) Test(org.junit.jupiter.api.Test)

Aggregations

PartTree (org.springframework.data.repository.query.parser.PartTree)60 Test (org.junit.jupiter.api.Test)51 Query (org.springframework.data.mongodb.core.query.Query)44 GeoJsonPoint (org.springframework.data.mongodb.core.geo.GeoJsonPoint)8 Point (org.springframework.data.geo.Point)6 Method (java.lang.reflect.Method)4 Distance (org.springframework.data.geo.Distance)4 SpelAwareProxyProjectionFactory (org.springframework.data.projection.SpelAwareProxyProjectionFactory)4 QueryMethod (org.springframework.data.repository.query.QueryMethod)3 Part (org.springframework.data.repository.query.parser.Part)3 DefaultRepositoryMetadata (org.springframework.data.repository.core.support.DefaultRepositoryMetadata)2 ParametersParameterAccessor (org.springframework.data.repository.query.ParametersParameterAccessor)2 StandardEvaluationContext (org.springframework.expression.spel.support.StandardEvaluationContext)2 MongoException (com.mongodb.MongoException)1 ArrayList (java.util.ArrayList)1 Pattern (java.util.regex.Pattern)1 Document (org.bson.Document)1 ObjectId (org.bson.types.ObjectId)1 NotNull (org.jetbrains.annotations.NotNull)1 Test (org.junit.Test)1