Search in sources :

Example 46 with PartTree

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

the class MongoQueryCreatorUnitTests method likeShouldEscapeSourceWhenUsedWithLeadingWildcard.

// DATAMONGO-1232
@Test
public void likeShouldEscapeSourceWhenUsedWithLeadingWildcard() {
    PartTree tree = new PartTree("findByUsernameLike", User.class);
    ConvertingParameterAccessor accessor = getAccessor(converter, "*steel.heart+");
    Query query = new MongoQueryCreator(tree, accessor, context).createQuery();
    assertThat(query, is(query(where("username").regex(".*\\Qsteel.heart+\\E"))));
}
Also used : Query(org.springframework.data.mongodb.core.query.Query) PartTree(org.springframework.data.repository.query.parser.PartTree) Test(org.junit.Test)

Example 47 with PartTree

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

the class MongoQueryCreatorUnitTests method likeShouldEscapeSourceWhenUsedWithLeadingAndTrailingWildcard.

// DATAMONGO-1232
@Test
public void likeShouldEscapeSourceWhenUsedWithLeadingAndTrailingWildcard() {
    PartTree tree = new PartTree("findByUsernameLike", User.class);
    ConvertingParameterAccessor accessor = getAccessor(converter, "*fire.fight+*");
    Query query = new MongoQueryCreator(tree, accessor, context).createQuery();
    assertThat(query, is(query(where("username").regex(".*\\Qfire.fight+\\E.*"))));
}
Also used : Query(org.springframework.data.mongodb.core.query.Query) PartTree(org.springframework.data.repository.query.parser.PartTree) Test(org.junit.Test)

Example 48 with PartTree

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

the class MongoQueryCreatorUnitTests method createsLessThanEqualQueryCorrectly.

@Test
public void createsLessThanEqualQueryCorrectly() throws Exception {
    PartTree tree = new PartTree("findByAgeLessThanEqual", Person.class);
    MongoQueryCreator creator = new MongoQueryCreator(tree, getAccessor(converter, 18), context);
    Query reference = query(where("age").lte(18));
    assertThat(creator.createQuery(), is(reference));
}
Also used : Query(org.springframework.data.mongodb.core.query.Query) PartTree(org.springframework.data.repository.query.parser.PartTree) Test(org.junit.Test)

Example 49 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
public void createsQueryWithFindByIgnoreCaseCorrectly() {
    PartTree tree = new PartTree("findByfirstNameIgnoreCase", Person.class);
    MongoQueryCreator creator = new MongoQueryCreator(tree, getAccessor(converter, "dave"), context);
    Query query = creator.createQuery();
    assertThat(query, is(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.Test)

Example 50 with PartTree

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

the class MongoQueryCreatorUnitTests method likeShouldEscapeSourceWhenUsedWithTrailingWildcard.

// DATAMONGO-1232
@Test
public void likeShouldEscapeSourceWhenUsedWithTrailingWildcard() {
    PartTree tree = new PartTree("findByUsernameLike", User.class);
    ConvertingParameterAccessor accessor = getAccessor(converter, "cala.mity+*");
    Query query = new MongoQueryCreator(tree, accessor, context).createQuery();
    assertThat(query, is(query(where("username").regex("\\Qcala.mity+\\E.*"))));
}
Also used : Query(org.springframework.data.mongodb.core.query.Query) PartTree(org.springframework.data.repository.query.parser.PartTree) Test(org.junit.Test)

Aggregations

PartTree (org.springframework.data.repository.query.parser.PartTree)51 Test (org.junit.Test)48 Query (org.springframework.data.mongodb.core.query.Query)44 GeoJsonPoint (org.springframework.data.mongodb.core.geo.GeoJsonPoint)7 Point (org.springframework.data.geo.Point)6 Distance (org.springframework.data.geo.Distance)3 Part (org.springframework.data.repository.query.parser.Part)2 Method (java.lang.reflect.Method)1 Document (org.bson.Document)1 ObjectId (org.bson.types.ObjectId)1 NotNull (org.jetbrains.annotations.NotNull)1 Sort (org.springframework.data.domain.Sort)1 Direction (org.springframework.data.domain.Sort.Direction)1 Order (org.springframework.data.domain.Sort.Order)1 Polygon (org.springframework.data.geo.Polygon)1 Shape (org.springframework.data.geo.Shape)1 Person (org.springframework.data.mongodb.core.Person)1 GeoJsonLineString (org.springframework.data.mongodb.core.geo.GeoJsonLineString)1 Index (org.springframework.data.mongodb.core.index.Index)1 MongoMappingContext (org.springframework.data.mongodb.core.mapping.MongoMappingContext)1