Search in sources :

Example 41 with PartTree

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

the class MongoQueryCreatorUnitTests method createsQueryWithEndingWithPredicateCorrectly.

// DATAMONGO-418
@Test
void createsQueryWithEndingWithPredicateCorrectly() {
    PartTree tree = new PartTree("findByUsernameEndingWith", User.class);
    MongoQueryCreator creator = new MongoQueryCreator(tree, getAccessor(converter, "ews"), context);
    Query query = creator.createQuery();
    assertThat(query).isEqualTo(query(where("username").regex("ews$")));
}
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 42 with PartTree

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

the class MongoQueryCreatorUnitTests method queryShouldAcceptSubclassOfDeclaredArgument.

// DATAMONGO-1588
@Test
void queryShouldAcceptSubclassOfDeclaredArgument() {
    PartTree tree = new PartTree("findByLocationNear", User.class);
    ConvertingParameterAccessor accessor = getAccessor(converter, new GeoJsonPoint(-74.044502D, 40.689247D));
    Query query = new MongoQueryCreator(tree, accessor, context).createQuery();
    assertThat(query.getQueryObject()).containsKey("location");
}
Also used : Query(org.springframework.data.mongodb.core.query.Query) PartTree(org.springframework.data.repository.query.parser.PartTree) GeoJsonPoint(org.springframework.data.mongodb.core.geo.GeoJsonPoint) Test(org.junit.jupiter.api.Test)

Example 43 with PartTree

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

the class MongoQueryCreatorUnitTests method nearShouldUseMetricDistanceForGeoJsonTypes.

// DATAMONGO-2394
@Test
void nearShouldUseMetricDistanceForGeoJsonTypes() {
    GeoJsonPoint point = new GeoJsonPoint(27.987901, 86.9165379);
    PartTree tree = new PartTree("findByLocationNear", User.class);
    MongoQueryCreator creator = new MongoQueryCreator(tree, getAccessor(converter, point, new Distance(1, Metrics.KILOMETERS)), context);
    assertThat(creator.createQuery()).isEqualTo(query(where("location").nearSphere(point).maxDistance(1000.0D)));
}
Also used : PartTree(org.springframework.data.repository.query.parser.PartTree) GeoJsonPoint(org.springframework.data.mongodb.core.geo.GeoJsonPoint) Distance(org.springframework.data.geo.Distance) Test(org.junit.jupiter.api.Test)

Example 44 with PartTree

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

the class MongoQueryCreatorUnitTests method createsQueryWithFindByIgnoreCaseCorrectly.

// DATAMONGO-770
@Test
void createsQueryWithFindByIgnoreCaseCorrectly() {
    PartTree tree = new PartTree("findByfirstNameIgnoreCase", 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 45 with PartTree

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

the class MongoQueryCreatorUnitTests method createsQueryWithFindByNotIgnoreCaseCorrectly.

// DATAMONGO-770
@Test
void createsQueryWithFindByNotIgnoreCaseCorrectly() {
    PartTree tree = new PartTree("findByFirstNameNotIgnoreCase", Person.class);
    MongoQueryCreator creator = new MongoQueryCreator(tree, getAccessor(converter, "dave"), context);
    Query query = creator.createQuery();
    assertThat(query.toString()).isEqualTo(query(where("firstName").not().regex("^dave$", "i")).toString());
}
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