Search in sources :

Example 1 with Box

use of org.springframework.data.geo.Box in project spring-data-mongodb by spring-projects.

the class GeoConvertersUnitTests method convertsBoxToDocumentAndBackCorrectly.

// DATAMONGO-858
@Test
public void convertsBoxToDocumentAndBackCorrectly() {
    Box box = new Box(new Point(1, 2), new Point(3, 4));
    Document document = BoxToDocumentConverter.INSTANCE.convert(box);
    Box result = DocumentToBoxConverter.INSTANCE.convert(document);
    assertThat(result, is(box));
    assertThat(result.getClass().equals(Box.class), is(true));
}
Also used : Box(org.springframework.data.geo.Box) Point(org.springframework.data.geo.Point) Document(org.bson.Document) Test(org.junit.Test)

Example 2 with Box

use of org.springframework.data.geo.Box in project spring-data-mongodb by spring-projects.

the class GeoConvertersUnitTests method convertsGeoCommandToDocumentCorrectly.

// DATAMONGO-858
@Test
public void convertsGeoCommandToDocumentCorrectly() {
    Box box = new Box(new double[] { 1, 2 }, new double[] { 3, 4 });
    GeoCommand cmd = new GeoCommand(box);
    Document document = GeoCommandToDocumentConverter.INSTANCE.convert(cmd);
    assertThat(document, is(notNullValue()));
    List<Object> boxObject = (List<Object>) document.get("$box");
    assertThat(boxObject, is((Object) Arrays.asList(GeoConverters.toList(box.getFirst()), GeoConverters.toList(box.getSecond()))));
}
Also used : GeoCommand(org.springframework.data.mongodb.core.query.GeoCommand) Box(org.springframework.data.geo.Box) List(java.util.List) Document(org.bson.Document) Test(org.junit.Test)

Example 3 with Box

use of org.springframework.data.geo.Box in project spring-data-mongodb by spring-projects.

the class MappingMongoConverterUnitTests method shouldReadEntityWithGeoBoxCorrectly.

// DATAMONGO-858
@Test
public void shouldReadEntityWithGeoBoxCorrectly() {
    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);
    ClassWithGeoBox result = converter.read(ClassWithGeoBox.class, document);
    assertThat(result, is(notNullValue()));
    assertThat(result.box, is(object.box));
}
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.Test)

Example 4 with Box

use of org.springframework.data.geo.Box in project spring-data-mongodb by spring-projects.

the class AbstractPersonRepositoryIntegrationTests method findsPeopleByLocationWithinBox.

@Test
public void findsPeopleByLocationWithinBox() {
    Point point = new Point(-73.99171, 40.738868);
    dave.setLocation(point);
    repository.save(dave);
    Box box = new Box(new Point(-78.99171, 35.738868), new Point(-68.99171, 45.738868));
    List<Person> result = repository.findByLocationWithin(box);
    assertThat(result.size(), is(1));
    assertThat(result, hasItem(dave));
}
Also used : Box(org.springframework.data.geo.Box) Point(org.springframework.data.geo.Point) GeoJsonPoint(org.springframework.data.mongodb.core.geo.GeoJsonPoint) Test(org.junit.Test)

Example 5 with Box

use of org.springframework.data.geo.Box in project spring-data-mongodb by spring-projects.

the class AbstractGeoSpatialTests method withinBox.

@Test
public void withinBox() {
    Box box = new Box(new Point(-73.99756, 40.73083), new Point(-73.988135, 40.741404));
    List<Venue> venues = template.find(query(where("location").within(box)), Venue.class);
    assertThat(venues.size(), is(4));
}
Also used : Venue(org.springframework.data.mongodb.core.Venue) Box(org.springframework.data.geo.Box) Point(org.springframework.data.geo.Point) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)9 Box (org.springframework.data.geo.Box)9 Point (org.springframework.data.geo.Point)7 Document (org.bson.Document)4 Document (org.springframework.data.mongodb.core.mapping.Document)2 Product (com.nixmash.blog.solr.model.Product)1 List (java.util.List)1 Shape (org.springframework.data.geo.Shape)1 Venue (org.springframework.data.mongodb.core.Venue)1 GeoJsonPoint (org.springframework.data.mongodb.core.geo.GeoJsonPoint)1 GeoCommand (org.springframework.data.mongodb.core.query.GeoCommand)1 Query (org.springframework.data.mongodb.core.query.Query)1