use of org.springframework.data.geo.Distance in project spring-data-mongodb by spring-projects.
the class MongoQueryCreatorUnitTests method shouldCreateNearSphereQueryForSphericalPropertyHavingDistanceWithDefaultMetric.
// DATAMONGO-1110
@Test
public void shouldCreateNearSphereQueryForSphericalPropertyHavingDistanceWithDefaultMetric() {
Point point = new Point(1.0, 1.0);
Distance distance = new Distance(1.0);
PartTree tree = new PartTree("findByAddress2dSphere_GeoNear", User.class);
MongoQueryCreator creator = new MongoQueryCreator(tree, getAccessor(converter, point, distance), context);
Query query = creator.createQuery();
assertThat(query, is(query(where("address2dSphere.geo").nearSphere(point).maxDistance(1.0))));
}
use of org.springframework.data.geo.Distance in project spring-data-mongodb by spring-projects.
the class MongoQueryCreatorUnitTests method bindsMetricDistanceParameterToNearSphereCorrectly.
@Test
public void bindsMetricDistanceParameterToNearSphereCorrectly() throws Exception {
Point point = new Point(10, 20);
Distance distance = new Distance(2.5, Metrics.KILOMETERS);
Query query = query(where("location").nearSphere(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 ReactiveMongoQueryExecutionUnitTests method geoNearExecutionShouldApplyQuerySettings.
// DATAMONGO-1444
@Test
public void geoNearExecutionShouldApplyQuerySettings() throws Exception {
Method geoNear = ClassUtils.getMethod(GeoRepo.class, "geoNear");
Query query = new Query();
when(parameterAccessor.getGeoNearLocation()).thenReturn(new Point(1, 2));
when(parameterAccessor.getDistanceRange()).thenReturn(new Range<>(new Distance(10), new Distance(15)));
when(parameterAccessor.getPageable()).thenReturn(PageRequest.of(1, 10));
new GeoNearExecution(operations, parameterAccessor, ClassTypeInformation.fromReturnTypeOf(geoNear)).execute(query, Person.class, "person");
ArgumentCaptor<NearQuery> queryArgumentCaptor = ArgumentCaptor.forClass(NearQuery.class);
verify(operations).geoNear(queryArgumentCaptor.capture(), eq(Person.class), eq("person"));
NearQuery nearQuery = queryArgumentCaptor.getValue();
assertThat(nearQuery.toDocument().get("near"), is(equalTo(Arrays.asList(1d, 2d))));
assertThat(nearQuery.getSkip(), is(10L));
assertThat(nearQuery.getMinDistance(), is(equalTo(new Distance(10))));
assertThat(nearQuery.getMaxDistance(), is(equalTo(new Distance(15))));
}
use of org.springframework.data.geo.Distance in project spring-data-mongodb by spring-projects.
the class GeoConvertersUnitTests method convertsSphereToDocumentAndBackCorrectlyWithKilometerDistance.
// DATAMONGO-858
@Test
public void convertsSphereToDocumentAndBackCorrectlyWithKilometerDistance() {
Distance radius = new Distance(3, Metrics.KILOMETERS);
Sphere sphere = new Sphere(new Point(1, 2), radius);
Document document = SphereToDocumentConverter.INSTANCE.convert(sphere);
Sphere result = DocumentToSphereConverter.INSTANCE.convert(document);
assertThat(result, is(sphere));
assertThat(result.getRadius(), is(radius));
assertThat(result.getClass().equals(org.springframework.data.mongodb.core.geo.Sphere.class), is(true));
}
use of org.springframework.data.geo.Distance in project spring-data-mongodb by spring-projects.
the class MappingMongoConverterUnitTests method shouldWriteEntityWithGeoShapeCorrectly.
// DATAMONGO-858
@Test
public void shouldWriteEntityWithGeoShapeCorrectly() {
ClassWithGeoShape object = new ClassWithGeoShape();
Sphere sphere = new Sphere(new Point(1, 2), 3);
Distance radius = sphere.getRadius();
object.shape = sphere;
org.bson.Document document = new org.bson.Document();
converter.write(object, document);
assertThat(document, is(notNullValue()));
assertThat(document.get("shape"), is(instanceOf(org.bson.Document.class)));
assertThat(document.get("shape"), is((Object) new org.bson.Document("center", new org.bson.Document("x", sphere.getCenter().getX()).append("y", sphere.getCenter().getY())).append("radius", radius.getNormalizedValue()).append("metric", radius.getMetric().toString())));
}
Aggregations