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