use of org.springframework.data.mongodb.core.geo.Sphere in project spring-data-mongodb by spring-projects.
the class GeoConvertersUnitTests method convertsSphereCorrectlyWhenUsingNonDoubleForCoordinates.
// DATAMONGO-1607
@Test
public void convertsSphereCorrectlyWhenUsingNonDoubleForCoordinates() {
Document sphere = new Document();
sphere.put("center", new Document().append("x", 1).append("y", 2));
sphere.put("radius", 3L);
assertThat(DocumentToSphereConverter.INSTANCE.convert(sphere)).isEqualTo(new Sphere(new Point(1, 2), new Distance(3)));
}
use of org.springframework.data.mongodb.core.geo.Sphere in project spring-data-mongodb by spring-projects.
the class GeoConvertersUnitTests method convertsSphereToDocumentAndBackCorrectlyWithNeutralDistance.
// DATAMONGO-858
@Test
public void convertsSphereToDocumentAndBackCorrectlyWithNeutralDistance() {
Sphere sphere = new Sphere(new Point(1, 2), 3);
Document document = SphereToDocumentConverter.INSTANCE.convert(sphere);
Sphere result = DocumentToSphereConverter.INSTANCE.convert(document);
assertThat(result).isEqualTo(sphere);
assertThat(result.getClass().equals(Sphere.class)).isTrue();
}
use of org.springframework.data.mongodb.core.geo.Sphere in project spring-data-mongodb by spring-projects.
the class MongoConvertersUnitTests method convertsSphereToDocumentAndBackCorrectly.
// DATAMONGO-858
@Test
void convertsSphereToDocumentAndBackCorrectly() {
Sphere sphere = new Sphere(new Point(1, 2), 3);
Document document = GeoConverters.SphereToDocumentConverter.INSTANCE.convert(sphere);
org.springframework.data.geo.Shape shape = GeoConverters.DocumentToSphereConverter.INSTANCE.convert(document);
assertThat(shape).isEqualTo(sphere);
}
use of org.springframework.data.mongodb.core.geo.Sphere in project spring-data-mongodb by spring-projects.
the class MappingMongoConverterUnitTests method shouldWriteEntityWithGeoSphereCorrectly.
// DATAMONGO-858
@Test
void shouldWriteEntityWithGeoSphereCorrectly() {
ClassWithGeoSphere object = new ClassWithGeoSphere();
Sphere sphere = new Sphere(new Point(1, 2), 3);
Distance radius = sphere.getRadius();
object.sphere = sphere;
org.bson.Document document = new org.bson.Document();
converter.write(object, document);
assertThat(document).isNotNull();
assertThat(document.get("sphere")).isInstanceOf(org.bson.Document.class);
assertThat(document.get("sphere")).isEqualTo((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()));
}
use of org.springframework.data.mongodb.core.geo.Sphere in project spring-data-mongodb by spring-projects.
the class MappingMongoConverterUnitTests method shouldWriteEntityWithGeoSphereWithMetricDistanceCorrectly.
// DATAMONGO-858
@Test
void shouldWriteEntityWithGeoSphereWithMetricDistanceCorrectly() {
ClassWithGeoSphere object = new ClassWithGeoSphere();
Sphere sphere = new Sphere(new Point(1, 2), new Distance(3, Metrics.KILOMETERS));
Distance radius = sphere.getRadius();
object.sphere = sphere;
org.bson.Document document = new org.bson.Document();
converter.write(object, document);
assertThat(document).isNotNull();
assertThat(document.get("sphere")).isInstanceOf(org.bson.Document.class);
assertThat(document.get("sphere")).isEqualTo((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