Search in sources :

Example 1 with GeoNearExecution

use of org.springframework.data.mongodb.repository.query.ReactiveMongoQueryExecution.GeoNearExecution in project spring-data-mongodb by spring-projects.

the class ReactiveMongoQueryExecutionUnitTests method geoNearExecutionShouldApplyQuerySettings.

// DATAMONGO-1444
@Test
public void geoNearExecutionShouldApplyQuerySettings() throws Exception {
    Method geoNear = ClassUtils.getMethod(GeoRepo.class, "geoNear");
    Query query = new Query();
    when(parameterAccessor.getGeoNearLocation()).thenReturn(new Point(1, 2));
    when(parameterAccessor.getDistanceRange()).thenReturn(new Range<>(new Distance(10), new Distance(15)));
    when(parameterAccessor.getPageable()).thenReturn(PageRequest.of(1, 10));
    new GeoNearExecution(operations, parameterAccessor, ClassTypeInformation.fromReturnTypeOf(geoNear)).execute(query, Person.class, "person");
    ArgumentCaptor<NearQuery> queryArgumentCaptor = ArgumentCaptor.forClass(NearQuery.class);
    verify(operations).geoNear(queryArgumentCaptor.capture(), eq(Person.class), eq("person"));
    NearQuery nearQuery = queryArgumentCaptor.getValue();
    assertThat(nearQuery.toDocument().get("near"), is(equalTo(Arrays.asList(1d, 2d))));
    assertThat(nearQuery.getSkip(), is(10L));
    assertThat(nearQuery.getMinDistance(), is(equalTo(new Distance(10))));
    assertThat(nearQuery.getMaxDistance(), is(equalTo(new Distance(15))));
}
Also used : NearQuery(org.springframework.data.mongodb.core.query.NearQuery) NearQuery(org.springframework.data.mongodb.core.query.NearQuery) Query(org.springframework.data.mongodb.core.query.Query) GeoNearExecution(org.springframework.data.mongodb.repository.query.ReactiveMongoQueryExecution.GeoNearExecution) Method(java.lang.reflect.Method) Point(org.springframework.data.geo.Point) Person(org.springframework.data.mongodb.repository.Person) Distance(org.springframework.data.geo.Distance) Test(org.junit.Test)

Example 2 with GeoNearExecution

use of org.springframework.data.mongodb.repository.query.ReactiveMongoQueryExecution.GeoNearExecution in project spring-data-mongodb by spring-projects.

the class ReactiveMongoQueryExecutionUnitTests method geoNearExecutionShouldApplyMinimalSettings.

// DATAMONGO-1444
@Test
public void geoNearExecutionShouldApplyMinimalSettings() throws Exception {
    Method geoNear = ClassUtils.getMethod(GeoRepo.class, "geoNear");
    Query query = new Query();
    when(parameterAccessor.getPageable()).thenReturn(Pageable.unpaged());
    when(parameterAccessor.getGeoNearLocation()).thenReturn(new Point(1, 2));
    when(parameterAccessor.getDistanceRange()).thenReturn(new Range<>(null, null));
    new GeoNearExecution(operations, parameterAccessor, ClassTypeInformation.fromReturnTypeOf(geoNear)).execute(query, Person.class, "person");
    ArgumentCaptor<NearQuery> queryArgumentCaptor = ArgumentCaptor.forClass(NearQuery.class);
    verify(operations).geoNear(queryArgumentCaptor.capture(), eq(Person.class), eq("person"));
    NearQuery nearQuery = queryArgumentCaptor.getValue();
    assertThat(nearQuery.toDocument().get("near"), is(equalTo(Arrays.asList(1d, 2d))));
    assertThat(nearQuery.getSkip(), is(0L));
    assertThat(nearQuery.getMinDistance(), is(nullValue()));
    assertThat(nearQuery.getMaxDistance(), is(nullValue()));
}
Also used : NearQuery(org.springframework.data.mongodb.core.query.NearQuery) NearQuery(org.springframework.data.mongodb.core.query.NearQuery) Query(org.springframework.data.mongodb.core.query.Query) GeoNearExecution(org.springframework.data.mongodb.repository.query.ReactiveMongoQueryExecution.GeoNearExecution) Method(java.lang.reflect.Method) Point(org.springframework.data.geo.Point) Person(org.springframework.data.mongodb.repository.Person) Test(org.junit.Test)

Aggregations

Method (java.lang.reflect.Method)2 Test (org.junit.Test)2 Point (org.springframework.data.geo.Point)2 NearQuery (org.springframework.data.mongodb.core.query.NearQuery)2 Query (org.springframework.data.mongodb.core.query.Query)2 Person (org.springframework.data.mongodb.repository.Person)2 GeoNearExecution (org.springframework.data.mongodb.repository.query.ReactiveMongoQueryExecution.GeoNearExecution)2 Distance (org.springframework.data.geo.Distance)1