Search in sources :

Example 6 with Distance

use of org.springframework.data.geo.Distance in project spring-data-mongodb by spring-projects.

the class ReactiveMongoRepositoryTests method findsPeopleGeoresultByLocationWithinBox.

// DATAMONGO-1444
@Test
public void findsPeopleGeoresultByLocationWithinBox() {
    Point point = new Point(-73.99171, 40.738868);
    dave.setLocation(point);
    StepVerifier.create(repository.save(dave)).expectNextCount(1).verifyComplete();
    StepVerifier.create(// 
    repository.findByLocationNear(// 
    new Point(-73.99, 40.73), // 
    new Distance(2000, Metrics.KILOMETERS))).consumeNextWith(actual -> {
        assertThat(actual.getDistance().getValue(), is(closeTo(1, 1)));
        assertThat(actual.getContent(), is(equalTo(dave)));
    }).verifyComplete();
}
Also used : Arrays(java.util.Arrays) IncorrectResultSizeDataAccessException(org.springframework.dao.IncorrectResultSizeDataAccessException) Disposable(reactor.core.Disposable) StepVerifier(reactor.test.StepVerifier) CollectionOptions(org.springframework.data.mongodb.core.CollectionOptions) Metrics(org.springframework.data.geo.Metrics) RunWith(org.junit.runner.RunWith) Autowired(org.springframework.beans.factory.annotation.Autowired) Distance(org.springframework.data.geo.Distance) SimpleReactiveMongoRepository(org.springframework.data.mongodb.repository.support.SimpleReactiveMongoRepository) Document(org.springframework.data.mongodb.core.mapping.Document) SpringJUnit4ClassRunner(org.springframework.test.context.junit4.SpringJUnit4ClassRunner) BeanFactoryAware(org.springframework.beans.factory.BeanFactoryAware) Repository(org.springframework.data.repository.Repository) Pageable(org.springframework.data.domain.Pageable) Sort(org.springframework.data.domain.Sort) Direction(org.springframework.data.domain.Sort.Direction) Sex(org.springframework.data.mongodb.repository.Person.Sex) Point(org.springframework.data.geo.Point) Before(org.junit.Before) ClassUtils(org.springframework.util.ClassUtils) Publisher(org.reactivestreams.Publisher) Matchers(org.hamcrest.Matchers) PageRequest(org.springframework.data.domain.PageRequest) Mono(reactor.core.publisher.Mono) BlockingQueue(java.util.concurrent.BlockingQueue) Test(org.junit.Test) BeansException(org.springframework.beans.BeansException) DefaultEvaluationContextProvider(org.springframework.data.repository.query.DefaultEvaluationContextProvider) ReactiveMongoRepositoryFactory(org.springframework.data.mongodb.repository.support.ReactiveMongoRepositoryFactory) TimeUnit(java.util.concurrent.TimeUnit) Flux(reactor.core.publisher.Flux) Circle(org.springframework.data.geo.Circle) BeanFactory(org.springframework.beans.factory.BeanFactory) ContextConfiguration(org.springframework.test.context.ContextConfiguration) LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) ReactiveMongoTemplate(org.springframework.data.mongodb.core.ReactiveMongoTemplate) Assert(org.junit.Assert) BeanClassLoaderAware(org.springframework.beans.factory.BeanClassLoaderAware) GeoResult(org.springframework.data.geo.GeoResult) NoArgsConstructor(lombok.NoArgsConstructor) Point(org.springframework.data.geo.Point) Distance(org.springframework.data.geo.Distance) Test(org.junit.Test)

Example 7 with Distance

use of org.springframework.data.geo.Distance in project spring-data-mongodb by spring-projects.

the class ReactiveMongoRepositoryTests method findsPeopleByLocationWithinBox.

// DATAMONGO-1444
@Test
public void findsPeopleByLocationWithinBox() {
    Point point = new Point(-73.99171, 40.738868);
    dave.setLocation(point);
    StepVerifier.create(repository.save(dave)).expectNextCount(1).verifyComplete();
    StepVerifier.create(// 
    repository.findPersonByLocationNear(// 
    new Point(-73.99, 40.73), // 
    new Distance(2000, Metrics.KILOMETERS))).expectNext(// 
    dave).verifyComplete();
}
Also used : Point(org.springframework.data.geo.Point) Distance(org.springframework.data.geo.Distance) Test(org.junit.Test)

Example 8 with Distance

use of org.springframework.data.geo.Distance in project spring-data-mongodb by spring-projects.

the class MongoQueryCreatorUnitTests method bindsDistanceParameterToNearCorrectly.

@Test
public void bindsDistanceParameterToNearCorrectly() throws Exception {
    Point point = new Point(10, 20);
    Distance distance = new Distance(2.5);
    Query query = query(where("location").near(point).maxDistance(distance.getNormalizedValue()).and("firstname").is("Dave"));
    assertBindsDistanceToQuery(point, distance, query);
}
Also used : Query(org.springframework.data.mongodb.core.query.Query) Point(org.springframework.data.geo.Point) GeoJsonPoint(org.springframework.data.mongodb.core.geo.GeoJsonPoint) Distance(org.springframework.data.geo.Distance) Test(org.junit.Test)

Example 9 with Distance

use of org.springframework.data.geo.Distance in project spring-data-mongodb by spring-projects.

the class MongoQueryCreatorUnitTests method createsNonSphericalNearForDistanceWithDefaultMetric.

// DATAMONGO-1139
@Test
public 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, is(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.Test)

Example 10 with Distance

use of org.springframework.data.geo.Distance in project spring-data-mongodb by spring-projects.

the class MongoQueryCreatorUnitTests method shouldCreateNearQueryForMinMaxDistance.

// DATAMONGO-1110
@Test
public 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, is(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.Test)

Aggregations

Distance (org.springframework.data.geo.Distance)28 Point (org.springframework.data.geo.Point)27 Test (org.junit.Test)25 GeoJsonPoint (org.springframework.data.mongodb.core.geo.GeoJsonPoint)12 Query (org.springframework.data.mongodb.core.query.Query)7 Document (org.springframework.data.mongodb.core.mapping.Document)6 Document (org.bson.Document)5 Circle (org.springframework.data.geo.Circle)5 Metric (org.springframework.data.geo.Metric)5 Sphere (org.springframework.data.mongodb.core.geo.Sphere)5 PartTree (org.springframework.data.repository.query.parser.PartTree)4 Arrays (java.util.Arrays)3 Sort (org.springframework.data.domain.Sort)3 Metrics (org.springframework.data.geo.Metrics)3 Method (java.lang.reflect.Method)2 BlockingQueue (java.util.concurrent.BlockingQueue)2 LinkedBlockingDeque (java.util.concurrent.LinkedBlockingDeque)2 TimeUnit (java.util.concurrent.TimeUnit)2 NoArgsConstructor (lombok.NoArgsConstructor)2 Matchers (org.hamcrest.Matchers)2