Search in sources :

Example 16 with PartTree

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

the class MongoQueryCreatorUnitTests method shouldCreateNearQueryForMinMaxDistance.

// DATAMONGO-1110
@Test
void shouldCreateNearQueryForMinMaxDistance() {
    Point point = new Point(10, 20);
    Range<Distance> range = Distance.between(new Distance(10), new Distance(20));
    PartTree tree = new PartTree("findByAddress_GeoNear", User.class);
    MongoQueryCreator creator = new MongoQueryCreator(tree, getAccessor(converter, point, range), context);
    Query query = creator.createQuery();
    assertThat(query).isEqualTo(query(where("address.geo").near(point).minDistance(10D).maxDistance(20D)));
}
Also used : Query(org.springframework.data.mongodb.core.query.Query) Point(org.springframework.data.geo.Point) GeoJsonPoint(org.springframework.data.mongodb.core.geo.GeoJsonPoint) PartTree(org.springframework.data.repository.query.parser.PartTree) Distance(org.springframework.data.geo.Distance) Test(org.junit.jupiter.api.Test)

Example 17 with PartTree

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

the class MongoQueryCreatorUnitTests method createsGreaterThanEqualQueryCorrectly.

@Test
void createsGreaterThanEqualQueryCorrectly() {
    PartTree tree = new PartTree("findByAgeGreaterThanEqual", Person.class);
    MongoQueryCreator creator = new MongoQueryCreator(tree, getAccessor(converter, 18), context);
    Query reference = query(where("age").gte(18));
    assertThat(creator.createQuery()).isEqualTo(reference);
}
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 18 with PartTree

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

the class MongoQueryCreatorUnitTests method createsRegexQueryForPatternWithOptionsCorrectly.

// DATAMONGO-2003
@Test
void createsRegexQueryForPatternWithOptionsCorrectly() {
    Pattern pattern = Pattern.compile(".*", Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE);
    PartTree tree = new PartTree("findByFirstNameRegex", Person.class);
    MongoQueryCreator creator = new MongoQueryCreator(tree, getAccessor(converter, pattern), context);
    assertThat(creator.createQuery()).isEqualTo(query(where("firstName").regex(".*", "iu")));
}
Also used : Pattern(java.util.regex.Pattern) PartTree(org.springframework.data.repository.query.parser.PartTree) Test(org.junit.jupiter.api.Test)

Example 19 with PartTree

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

the class MongoQueryCreatorUnitTests method shouldCreateWithinQueryCorrectly.

// DATAMONGO-1136
@Test
void shouldCreateWithinQueryCorrectly() {
    Point first = new Point(1, 1);
    Point second = new Point(2, 2);
    Point third = new Point(3, 3);
    Shape shape = new Polygon(first, second, third);
    PartTree tree = new PartTree("findByAddress_GeoWithin", User.class);
    MongoQueryCreator creator = new MongoQueryCreator(tree, getAccessor(converter, shape), context);
    Query query = creator.createQuery();
    assertThat(query).isEqualTo(query(where("address.geo").within(shape)));
}
Also used : Shape(org.springframework.data.geo.Shape) Query(org.springframework.data.mongodb.core.query.Query) Point(org.springframework.data.geo.Point) GeoJsonPoint(org.springframework.data.mongodb.core.geo.GeoJsonPoint) Polygon(org.springframework.data.geo.Polygon) PartTree(org.springframework.data.repository.query.parser.PartTree) Test(org.junit.jupiter.api.Test)

Example 20 with PartTree

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

the class MongoQueryCreatorUnitTests method createsFalseClauseCorrectly.

// DATAMONGO-338
@Test
void createsFalseClauseCorrectly() {
    PartTree tree = new PartTree("findByActiveFalse", Person.class);
    MongoQueryCreator creator = new MongoQueryCreator(tree, getAccessor(converter), context);
    Query query = query(where("active").is(false));
    assertThat(creator.createQuery()).isEqualTo(query);
}
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