Search in sources :

Example 36 with Document

use of org.springframework.data.mongodb.core.mapping.Document 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)

Example 37 with Document

use of org.springframework.data.mongodb.core.mapping.Document in project spring-data-mongodb by spring-projects.

the class MappingMongoConverterUnitTests method shouldWriteEntityWithGeoBoxCorrectly.

// DATAMONGO-858
@Test
void shouldWriteEntityWithGeoBoxCorrectly() {
    ClassWithGeoBox object = new ClassWithGeoBox();
    object.box = new Box(new Point(1, 2), new Point(3, 4));
    org.bson.Document document = new org.bson.Document();
    converter.write(object, document);
    assertThat(document).isNotNull();
    assertThat(document.get("box")).isInstanceOf(org.bson.Document.class);
    assertThat(document.get("box")).isEqualTo((Object) new org.bson.Document().append("first", toDocument(object.box.getFirst())).append("second", toDocument(object.box.getSecond())));
}
Also used : Box(org.springframework.data.geo.Box) Point(org.springframework.data.geo.Point) Document(org.springframework.data.mongodb.core.mapping.Document) Test(org.junit.jupiter.api.Test)

Example 38 with Document

use of org.springframework.data.mongodb.core.mapping.Document in project spring-data-mongodb by spring-projects.

the class MappingMongoConverterUnitTests method shouldWriteEntityWithGeoShapeCorrectly.

// DATAMONGO-858
@Test
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).isNotNull();
    assertThat(document.get("shape")).isInstanceOf(org.bson.Document.class);
    assertThat(document.get("shape")).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 39 with Document

use of org.springframework.data.mongodb.core.mapping.Document in project spring-data-mongodb by spring-projects.

the class MappingMongoConverterUnitTests method shouldReadEntityWithGeoPolygonCorrectly.

// DATAMONGO-858
@Test
void shouldReadEntityWithGeoPolygonCorrectly() {
    ClassWithGeoPolygon object = new ClassWithGeoPolygon();
    object.polygon = new Polygon(new Point(1, 2), new Point(3, 4), new Point(4, 5));
    org.bson.Document document = new org.bson.Document();
    converter.write(object, document);
    ClassWithGeoPolygon result = converter.read(ClassWithGeoPolygon.class, document);
    assertThat(result).isNotNull();
    assertThat(result.polygon).isEqualTo(object.polygon);
}
Also used : Point(org.springframework.data.geo.Point) Polygon(org.springframework.data.geo.Polygon) Document(org.springframework.data.mongodb.core.mapping.Document) Test(org.junit.jupiter.api.Test)

Example 40 with Document

use of org.springframework.data.mongodb.core.mapping.Document in project spring-data-mongodb by spring-projects.

the class MappingMongoConverterUnitTests method shouldWriteEntityWithGeoCircleCorrectly.

// DATAMONGO-858
@Test
void shouldWriteEntityWithGeoCircleCorrectly() {
    ClassWithGeoCircle object = new ClassWithGeoCircle();
    Circle circle = new Circle(new Point(1, 2), 3);
    Distance radius = circle.getRadius();
    object.circle = circle;
    org.bson.Document document = new org.bson.Document();
    converter.write(object, document);
    assertThat(document).isNotNull();
    assertThat(document.get("circle")).isInstanceOf(org.bson.Document.class);
    assertThat(document.get("circle")).isEqualTo((Object) new org.bson.Document("center", new org.bson.Document("x", circle.getCenter().getX()).append("y", circle.getCenter().getY())).append("radius", radius.getNormalizedValue()).append("metric", radius.getMetric().toString()));
}
Also used : Circle(org.springframework.data.geo.Circle) 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

Document (org.springframework.data.mongodb.core.mapping.Document)55 Test (org.junit.jupiter.api.Test)53 BasicQuery (org.springframework.data.mongodb.core.query.BasicQuery)16 Query (org.springframework.data.mongodb.core.query.Query)16 TextQuery (org.springframework.data.mongodb.core.query.TextQuery)16 Point (org.springframework.data.geo.Point)12 BasicDBList (com.mongodb.BasicDBList)8 BasicDBObject (com.mongodb.BasicDBObject)6 DBObject (com.mongodb.DBObject)5 DBRef (com.mongodb.DBRef)5 Sphere (org.springframework.data.mongodb.core.geo.Sphere)5 ObjectId (org.bson.types.ObjectId)4 Distance (org.springframework.data.geo.Distance)4 LocalDate (org.joda.time.LocalDate)3 MongoException (com.mongodb.MongoException)2 BigInteger (java.math.BigInteger)2 HashSet (java.util.HashSet)2 DataAccessException (org.springframework.dao.DataAccessException)2 Circle (org.springframework.data.geo.Circle)2 Polygon (org.springframework.data.geo.Polygon)2