Search in sources :

Example 1 with Sphere

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)));
}
Also used : Sphere(org.springframework.data.mongodb.core.geo.Sphere) Point(org.springframework.data.geo.Point) Document(org.bson.Document) Distance(org.springframework.data.geo.Distance) Test(org.junit.jupiter.api.Test)

Example 2 with Sphere

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();
}
Also used : Sphere(org.springframework.data.mongodb.core.geo.Sphere) Point(org.springframework.data.geo.Point) Document(org.bson.Document) Test(org.junit.jupiter.api.Test)

Example 3 with Sphere

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);
}
Also used : Sphere(org.springframework.data.mongodb.core.geo.Sphere) Shape(org.springframework.data.geo.Shape) Point(org.springframework.data.geo.Point) Document(org.bson.Document) Test(org.junit.jupiter.api.Test)

Example 4 with 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()));
}
Also used : Sphere(org.springframework.data.mongodb.core.geo.Sphere) Point(org.springframework.data.geo.Point) Document(org.springframework.data.mongodb.core.mapping.Document) Distance(org.springframework.data.geo.Distance) Test(org.junit.jupiter.api.Test)

Example 5 with Sphere

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()));
}
Also used : Sphere(org.springframework.data.mongodb.core.geo.Sphere) Point(org.springframework.data.geo.Point) Document(org.springframework.data.mongodb.core.mapping.Document) Distance(org.springframework.data.geo.Distance) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)9 Point (org.springframework.data.geo.Point)9 Sphere (org.springframework.data.mongodb.core.geo.Sphere)9 Distance (org.springframework.data.geo.Distance)5 Document (org.springframework.data.mongodb.core.mapping.Document)5 Document (org.bson.Document)4 Disabled (org.junit.jupiter.api.Disabled)1 Shape (org.springframework.data.geo.Shape)1