Search in sources :

Example 6 with PartTree

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

the class MongoQueryCreatorUnitTests method createsRegexClauseCorrectly.

// DATAMONGO-338
@Test
void createsRegexClauseCorrectly() {
    PartTree tree = new PartTree("findByFirstNameRegex", Person.class);
    MongoQueryCreator creator = new MongoQueryCreator(tree, getAccessor(converter, ".*"), context);
    Query query = query(where("firstName").regex(".*"));
    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)

Example 7 with PartTree

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

the class MongoQueryCreatorUnitTests method shouldCreateInClauseWhenUsingContainsOnCollectionLikeProperty.

// DATAMONGO-1075
@Test
void shouldCreateInClauseWhenUsingContainsOnCollectionLikeProperty() {
    PartTree tree = new PartTree("findByEmailAddressesContaining", User.class);
    MongoQueryCreator creator = new MongoQueryCreator(tree, getAccessor(converter, "dave"), context);
    Query query = creator.createQuery();
    assertThat(query).isEqualTo(query(where("emailAddresses").in("dave")));
}
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 8 with PartTree

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

the class MongoQueryCreatorUnitTests method createsQueryReferencingADBRefCorrectly.

// DATAMONGO-347
@Test
void createsQueryReferencingADBRefCorrectly() {
    User user = new User();
    user.id = new ObjectId();
    PartTree tree = new PartTree("findByCreator", User.class);
    MongoQueryCreator creator = new MongoQueryCreator(tree, getAccessor(converter, user), context);
    Document queryObject = creator.createQuery().getQueryObject();
    assertThat(queryObject.get("creator")).isEqualTo(user);
}
Also used : ObjectId(org.bson.types.ObjectId) PartTree(org.springframework.data.repository.query.parser.PartTree) Document(org.bson.Document) Test(org.junit.jupiter.api.Test)

Example 9 with PartTree

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

the class MongoQueryCreatorUnitTests method notLikeShouldEscapeSourceWhenUsedWithLeadingAndTrailingWildcard.

// DATAMONGO-1424
@Test
void notLikeShouldEscapeSourceWhenUsedWithLeadingAndTrailingWildcard() {
    PartTree tree = new PartTree("findByUsernameNotLike", User.class);
    ConvertingParameterAccessor accessor = getAccessor(converter, "*fire.fight+*");
    Query query = new MongoQueryCreator(tree, accessor, context).createQuery();
    assertThat(query.getQueryObject().toJson()).isEqualTo(query(where("username").not().regex(".*\\Qfire.fight+\\E.*")).getQueryObject().toJson());
}
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 10 with PartTree

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

the class MongoQueryCreatorUnitTests method notLikeShouldEscapeSourceWhenUsedWithLeadingWildcard.

// DATAMONGO-1424
@Test
void notLikeShouldEscapeSourceWhenUsedWithLeadingWildcard() {
    PartTree tree = new PartTree("findByUsernameNotLike", User.class);
    ConvertingParameterAccessor accessor = getAccessor(converter, "*steel.heart+");
    Query query = new MongoQueryCreator(tree, accessor, context).createQuery();
    assertThat(query.getQueryObject().toJson()).isEqualTo(query(where("username").not().regex(".*\\Qsteel.heart+\\E")).getQueryObject().toJson());
}
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