Search in sources :

Example 11 with NearQuery

use of org.springframework.data.mongodb.core.query.NearQuery in project spring-data-mongodb by spring-projects.

the class MongoTemplateUnitTests method geoNearShouldHonorReadPreferenceWhenSet.

// DATAMONGO-1166
@Test
public void geoNearShouldHonorReadPreferenceWhenSet() {
    when(db.runCommand(Mockito.any(org.bson.Document.class), Mockito.any(ReadPreference.class), eq(Document.class))).thenReturn(mock(Document.class));
    template.setReadPreference(ReadPreference.secondary());
    NearQuery query = NearQuery.near(new Point(1, 1));
    template.geoNear(query, Wrapper.class);
    verify(this.db, times(1)).runCommand(Mockito.any(org.bson.Document.class), eq(ReadPreference.secondary()), eq(Document.class));
}
Also used : ReadPreference(com.mongodb.ReadPreference) NearQuery(org.springframework.data.mongodb.core.query.NearQuery) Point(org.springframework.data.geo.Point) Document(org.bson.Document) Test(org.junit.Test)

Example 12 with NearQuery

use of org.springframework.data.mongodb.core.query.NearQuery in project spring-data-mongodb by spring-projects.

the class MongoTemplateUnitTests method geoNearShouldIgnoreReadPreferenceWhenNotSet.

// DATAMONGO-1166
@Test
public void geoNearShouldIgnoreReadPreferenceWhenNotSet() {
    when(db.runCommand(Mockito.any(Document.class), eq(Document.class))).thenReturn(mock(Document.class));
    NearQuery query = NearQuery.near(new Point(1, 1));
    template.geoNear(query, Wrapper.class);
    verify(this.db, times(1)).runCommand(Mockito.any(Document.class), eq(Document.class));
}
Also used : NearQuery(org.springframework.data.mongodb.core.query.NearQuery) Point(org.springframework.data.geo.Point) Document(org.bson.Document) Test(org.junit.Test)

Example 13 with NearQuery

use of org.springframework.data.mongodb.core.query.NearQuery in project spring-data-mongodb by spring-projects.

the class MongoTemplateUnitTests method geoNearShouldUseCollationWhenPresent.

// DATAMONGO-1518
@Test
public void geoNearShouldUseCollationWhenPresent() {
    NearQuery query = NearQuery.near(0D, 0D).query(new BasicQuery("{}").collation(Collation.of("fr")));
    template.geoNear(query, AutogenerateableId.class);
    ArgumentCaptor<Document> cmd = ArgumentCaptor.forClass(Document.class);
    verify(db).runCommand(cmd.capture(), Mockito.any(Class.class));
    assertThat(cmd.getValue().get("collation", Document.class), equalTo(new Document("locale", "fr")));
}
Also used : NearQuery(org.springframework.data.mongodb.core.query.NearQuery) BasicQuery(org.springframework.data.mongodb.core.query.BasicQuery) Document(org.bson.Document) Test(org.junit.Test)

Example 14 with NearQuery

use of org.springframework.data.mongodb.core.query.NearQuery in project spring-data-mongodb by spring-projects.

the class ReactiveMongoTemplateUnitTests method geoNearShouldUseCollationWhenPresent.

// DATAMONGO-1518
@Test
public void geoNearShouldUseCollationWhenPresent() {
    NearQuery query = NearQuery.near(0D, 0D).query(new BasicQuery("{}").collation(Collation.of("fr")));
    template.geoNear(query, AutogenerateableId.class).subscribe();
    ArgumentCaptor<Document> cmd = ArgumentCaptor.forClass(Document.class);
    verify(db).runCommand(cmd.capture(), Mockito.any(Class.class));
    assertThat(cmd.getValue().get("collation", Document.class), equalTo(new Document("locale", "fr")));
}
Also used : NearQuery(org.springframework.data.mongodb.core.query.NearQuery) BasicQuery(org.springframework.data.mongodb.core.query.BasicQuery) AutogenerateableId(org.springframework.data.mongodb.core.MongoTemplateUnitTests.AutogenerateableId) Document(org.bson.Document) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)14 NearQuery (org.springframework.data.mongodb.core.query.NearQuery)14 Document (org.bson.Document)6 Point (org.springframework.data.geo.Point)6 Metric (org.springframework.data.geo.Metric)3 Venue (org.springframework.data.mongodb.core.Venue)3 Method (java.lang.reflect.Method)2 GeospatialIndex (org.springframework.data.mongodb.core.index.GeospatialIndex)2 BasicQuery (org.springframework.data.mongodb.core.query.BasicQuery)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 ReadPreference (com.mongodb.ReadPreference)1 Distance (org.springframework.data.geo.Distance)1 AutogenerateableId (org.springframework.data.mongodb.core.MongoTemplateUnitTests.AutogenerateableId)1 Aggregation (org.springframework.data.mongodb.core.aggregation.Aggregation)1