Search in sources :

Example 21 with PartTree

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

the class MongoQueryCreatorUnitTests method createsNonSphericalNearForDistanceWithDefaultMetric.

// DATAMONGO-1139
@Test
void createsNonSphericalNearForDistanceWithDefaultMetric() {
    Point point = new Point(1.0, 1.0);
    Distance distance = new Distance(1.0);
    PartTree tree = new PartTree("findByLocationNear", Venue.class);
    MongoQueryCreator creator = new MongoQueryCreator(tree, getAccessor(converter, point, distance), context);
    Query query = creator.createQuery();
    assertThat(query).isEqualTo(query(where("location").near(point).maxDistance(1.0)));
}
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 22 with PartTree

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

the class MongoQueryCreatorUnitTests method shouldCreateInClauseWhenUsingNotContainsOnCollectionLikeProperty.

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

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

the class MongoQueryCreatorUnitTests method shouldCreateDeleteByQueryCorrectly.

// DATAMONGO-566
@Test
void shouldCreateDeleteByQueryCorrectly() {
    PartTree tree = new PartTree("deleteByFirstName", Person.class);
    MongoQueryCreator creator = new MongoQueryCreator(tree, getAccessor(converter, "dave", 42), context);
    Query query = creator.createQuery();
    assertThat(tree.isDelete()).isTrue();
    assertThat(query).isEqualTo(query(where("firstName").is("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 24 with PartTree

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

the class MongoQueryCreatorUnitTests method queryShouldThrowExceptionWhenArgumentDoesNotMatchDeclaration.

// DATAMONGO-1588
@Test
void queryShouldThrowExceptionWhenArgumentDoesNotMatchDeclaration() {
    PartTree tree = new PartTree("findByLocationNear", User.class);
    ConvertingParameterAccessor accessor = getAccessor(converter, new GeoJsonLineString(new Point(-74.044502D, 40.689247D), new Point(-73.997330D, 40.730824D)));
    assertThatIllegalArgumentException().isThrownBy(() -> new MongoQueryCreator(tree, accessor, context).createQuery()).withMessageContaining("Expected parameter type of " + Point.class);
}
Also used : GeoJsonLineString(org.springframework.data.mongodb.core.geo.GeoJsonLineString) Point(org.springframework.data.geo.Point) GeoJsonPoint(org.springframework.data.mongodb.core.geo.GeoJsonPoint) PartTree(org.springframework.data.repository.query.parser.PartTree) Test(org.junit.jupiter.api.Test)

Example 25 with PartTree

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

the class MongoQueryCreatorUnitTests method createsQueryWithContainingPredicateCorrectly.

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