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));
}
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));
}
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));
}
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();
}
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)));
}
Aggregations