Search in sources :

Example 16 with Distance

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

the class AbstractPersonRepositoryIntegrationTests method executesGeoNearQueryForResultsCorrectly.

@Test
public void executesGeoNearQueryForResultsCorrectly() {
    Point point = new Point(-73.99171, 40.738868);
    dave.setLocation(point);
    repository.save(dave);
    GeoResults<Person> results = repository.findByLocationNear(new Point(-73.99, 40.73), new Distance(2000, Metrics.KILOMETERS));
    assertThat(results.getContent().isEmpty(), is(false));
}
Also used : 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 17 with Distance

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

the class AbstractPersonRepositoryIntegrationTests method executesGeoPageQueryForWithPageRequestForJustOneElementEmptyPage.

// DATAMONGO-445
@Test
public void executesGeoPageQueryForWithPageRequestForJustOneElementEmptyPage() {
    dave.setLocation(new Point(-73.99171, 40.738868));
    repository.save(dave);
    GeoPage<Person> results = repository.findByLocationNear(new Point(-73.99, 40.73), new Distance(2000, Metrics.KILOMETERS), PageRequest.of(1, 2));
    assertThat(results.getContent().isEmpty(), is(true));
    assertThat(results.getNumberOfElements(), is(0));
    assertThat(results.isFirst(), is(false));
    assertThat(results.isLast(), is(true));
    assertThat(results.getAverageDistance().getMetric(), is((Metric) Metrics.KILOMETERS));
}
Also used : Metric(org.springframework.data.geo.Metric) 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 18 with Distance

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

the class AbstractPersonRepositoryIntegrationTests method executesGeoPageQueryForWithPageRequestForJustOneElement.

// DATAMONGO-445
@Test
public void executesGeoPageQueryForWithPageRequestForJustOneElement() {
    Point point = new Point(-73.99171, 40.738868);
    dave.setLocation(point);
    repository.save(dave);
    GeoPage<Person> results = repository.findByLocationNear(new Point(-73.99, 40.73), new Distance(2000, Metrics.KILOMETERS), PageRequest.of(0, 2));
    assertThat(results.getContent().isEmpty(), is(false));
    assertThat(results.getNumberOfElements(), is(1));
    assertThat(results.isFirst(), is(true));
    assertThat(results.isLast(), is(true));
    assertThat(results.getAverageDistance().getMetric(), is((Metric) Metrics.KILOMETERS));
}
Also used : Metric(org.springframework.data.geo.Metric) 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 19 with Distance

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

the class ReactiveMongoRepositoryTests method findsPeoplePageableGeoresultByLocationWithinBox.

// DATAMONGO-1444
@Test
public void findsPeoplePageableGeoresultByLocationWithinBox() {
    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), // 
    PageRequest.of(0, 10))).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 20 with Distance

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

the class MongoParametersParameterAccessorUnitTests method shouldDetectMinAndMaxDistance.

// DATAMONGO-1110
@Test
public void shouldDetectMinAndMaxDistance() throws NoSuchMethodException, SecurityException {
    Method method = PersonRepository.class.getMethod("findByLocationNear", Point.class, Range.class);
    MongoQueryMethod queryMethod = new MongoQueryMethod(method, metadata, factory, context);
    Distance min = new Distance(10, Metrics.KILOMETERS);
    Distance max = new Distance(20, Metrics.KILOMETERS);
    MongoParameterAccessor accessor = new MongoParametersParameterAccessor(queryMethod, new Object[] { new Point(10, 20), Distance.between(min, max) });
    Range<Distance> range = accessor.getDistanceRange();
    assertThat(range.getLowerBound(), is(Bound.inclusive(min)));
    assertThat(range.getUpperBound(), is(Bound.inclusive(max)));
}
Also used : Method(java.lang.reflect.Method) Point(org.springframework.data.geo.Point) 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