Search in sources :

Example 31 with PartTree

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

the class MongoQueryCreatorUnitTests method shouldCreateRegexWhenUsingNotContainsOnStringProperty.

// DATAMONGO-1075, DATAMONGO-1425
@Test
void shouldCreateRegexWhenUsingNotContainsOnStringProperty() {
    PartTree tree = new PartTree("findByUsernameNotContaining", User.class);
    MongoQueryCreator creator = new MongoQueryCreator(tree, getAccessor(converter, "thew"), context);
    Query query = creator.createQuery();
    assertThat(query.getQueryObject().toJson()).isEqualTo(query(where("username").not().regex(".*thew.*")).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 32 with PartTree

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

the class MongoQueryCreatorUnitTests method createsExistsClauseCorrectly.

// DATAMONGO-338
@Test
void createsExistsClauseCorrectly() {
    PartTree tree = new PartTree("findByAgeExists", Person.class);
    MongoQueryCreator creator = new MongoQueryCreator(tree, getAccessor(converter, true), context);
    Query query = query(where("age").exists(true));
    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 33 with PartTree

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

the class MongoQueryCreatorUnitTests method createsRegexQueryForPatternCorrectly.

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

Example 34 with PartTree

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

the class MongoQueryCreatorUnitTests method likeShouldBeTreatedCorrectlyWhenUsedWithWildcardOnly.

// DATAMONGO-1232
@Test
void likeShouldBeTreatedCorrectlyWhenUsedWithWildcardOnly() {
    PartTree tree = new PartTree("findByUsernameLike", User.class);
    ConvertingParameterAccessor accessor = getAccessor(converter, "*");
    Query query = new MongoQueryCreator(tree, accessor, context).createQuery();
    assertThat(query).isEqualTo(query(where("username").regex(".*")));
}
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 35 with PartTree

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

the class ParameterMetadataProviderUnitTests method getParameterMetadata.

private ParameterMetadata getParameterMetadata(String methodName, Object value) throws Exception {
    Method method = UserRepository.class.getMethod(methodName, String.class);
    ParameterMetadataProvider provider = new ParameterMetadataProvider(new RelationalParametersParameterAccessor(new RelationalQueryMethod(method, new DefaultRepositoryMetadata(UserRepository.class), new SpelAwareProxyProjectionFactory()), new Object[] { value }));
    PartTree tree = new PartTree(methodName, User.class);
    return provider.next(tree.getParts().iterator().next());
}
Also used : SpelAwareProxyProjectionFactory(org.springframework.data.projection.SpelAwareProxyProjectionFactory) DefaultRepositoryMetadata(org.springframework.data.repository.core.support.DefaultRepositoryMetadata) QueryMethod(org.springframework.data.repository.query.QueryMethod) Method(java.lang.reflect.Method) PartTree(org.springframework.data.repository.query.parser.PartTree)

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