Search in sources :

Example 6 with Circle

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

the class AbstractPersonRepositoryIntegrationTests method findsPeopleByLocationWithinCircle.

@Test
void findsPeopleByLocationWithinCircle() {
    Point point = new Point(-73.99171, 40.738868);
    dave.setLocation(point);
    repository.save(dave);
    List<Person> result = repository.findByLocationWithin(new Circle(-78.99171, 45.738868, 170));
    assertThat(result).hasSize(1).contains(dave);
}
Also used : Circle(org.springframework.data.geo.Circle) Point(org.springframework.data.geo.Point) GeoJsonPoint(org.springframework.data.mongodb.core.geo.GeoJsonPoint) Test(org.junit.jupiter.api.Test)

Example 7 with Circle

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

the class ReactiveMongoRepositoryTests method findsPeopleByLocationWithinCircle.

// DATAMONGO-1444
@Test
void findsPeopleByLocationWithinCircle() {
    Point point = new Point(-73.99171, 40.738868);
    dave.setLocation(point);
    repository.save(dave).as(StepVerifier::create).expectNextCount(1).verifyComplete();
    // 
    repository.findByLocationWithin(new Circle(-78.99171, 45.738868, 170)).as(StepVerifier::create).expectNext(// 
    dave).verifyComplete();
}
Also used : Circle(org.springframework.data.geo.Circle) Point(org.springframework.data.geo.Point) StepVerifier(reactor.test.StepVerifier) Test(org.junit.jupiter.api.Test)

Example 8 with Circle

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

the class ReactiveMongoRepositoryTests method findsPeopleByPageableLocationWithinCircle.

// DATAMONGO-1444
@Test
void findsPeopleByPageableLocationWithinCircle() {
    Point point = new Point(-73.99171, 40.738868);
    dave.setLocation(point);
    repository.save(dave).as(StepVerifier::create).expectNextCount(1).verifyComplete();
    // 
    repository.findByLocationWithin(// 
    new Circle(-78.99171, 45.738868, 170), PageRequest.of(0, 10)).as(// 
    StepVerifier::create).expectNext(// 
    dave).verifyComplete();
}
Also used : Circle(org.springframework.data.geo.Circle) Point(org.springframework.data.geo.Point) StepVerifier(reactor.test.StepVerifier) Test(org.junit.jupiter.api.Test)

Example 9 with Circle

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

the class MappingMongoConverterUnitTests method shouldReadEntityWithGeoCircleCorrectly.

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

Example 10 with Circle

use of org.springframework.data.geo.Circle 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

Circle (org.springframework.data.geo.Circle)12 Point (org.springframework.data.geo.Point)10 Test (org.junit.jupiter.api.Test)9 Document (org.bson.Document)4 Test (org.junit.Test)3 Distance (org.springframework.data.geo.Distance)3 Venue (org.springframework.data.mongodb.core.Venue)2 Document (org.springframework.data.mongodb.core.mapping.Document)2 NearQuery (org.springframework.data.mongodb.core.query.NearQuery)2 Query (org.springframework.data.mongodb.core.query.Query)2 StepVerifier (reactor.test.StepVerifier)2 Shape (org.springframework.data.geo.Shape)1 GeoJsonPoint (org.springframework.data.mongodb.core.geo.GeoJsonPoint)1 RedisGeoCommands (org.springframework.data.redis.connection.RedisGeoCommands)1 RedisTemplate (org.springframework.data.redis.core.RedisTemplate)1