Search in sources :

Example 11 with MongoCursor

use of com.mongodb.client.MongoCursor in project spring-data-mongodb by spring-projects.

the class MongoTemplateUnitTests method mapReduceShouldUseZeroAsDefaultLimit.

// DATAMONGO-1334
@Test
@Disabled("TODO: mongo3 - a bit hard to tests with the immutable object stuff")
void mapReduceShouldUseZeroAsDefaultLimit() {
    MongoCursor cursor = mock(MongoCursor.class);
    MapReduceIterable output = mock(MapReduceIterable.class);
    when(output.limit(anyInt())).thenReturn(output);
    when(output.sort(any(Document.class))).thenReturn(output);
    when(output.filter(any(Document.class))).thenReturn(output);
    when(output.iterator()).thenReturn(cursor);
    when(cursor.hasNext()).thenReturn(false);
    when(collection.mapReduce(anyString(), anyString())).thenReturn(output);
    Query query = new BasicQuery("{'foo':'bar'}");
    template.mapReduce(query, "collection", "function(){}", "function(key,values){}", Wrapper.class);
    verify(output, times(1)).limit(1);
}
Also used : BasicQuery(org.springframework.data.mongodb.core.query.BasicQuery) NearQuery(org.springframework.data.mongodb.core.query.NearQuery) Query(org.springframework.data.mongodb.core.query.Query) BasicQuery(org.springframework.data.mongodb.core.query.BasicQuery) MapReduceIterable(com.mongodb.client.MapReduceIterable) MongoCursor(com.mongodb.client.MongoCursor) Document(org.bson.Document) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 12 with MongoCursor

use of com.mongodb.client.MongoCursor in project spring-data-mongodb by spring-projects.

the class MongoTemplateUnitTests method mapReduceShouldPickUpLimitFromOptionsEvenWhenQueryDefinesItDifferently.

// DATAMONGO-1334
@Test
void mapReduceShouldPickUpLimitFromOptionsEvenWhenQueryDefinesItDifferently() {
    MongoCursor cursor = mock(MongoCursor.class);
    MapReduceIterable output = mock(MapReduceIterable.class);
    when(output.limit(anyInt())).thenReturn(output);
    when(output.sort(any())).thenReturn(output);
    when(output.filter(any(Document.class))).thenReturn(output);
    when(output.iterator()).thenReturn(cursor);
    when(cursor.hasNext()).thenReturn(false);
    when(collection.mapReduce(anyString(), anyString(), eq(Document.class))).thenReturn(output);
    Query query = new BasicQuery("{'foo':'bar'}");
    query.limit(100);
    template.mapReduce(query, "collection", "function(){}", "function(key,values){}", new MapReduceOptions().limit(1000), Wrapper.class);
    verify(output, times(1)).limit(1000);
}
Also used : MapReduceOptions(org.springframework.data.mongodb.core.mapreduce.MapReduceOptions) BasicQuery(org.springframework.data.mongodb.core.query.BasicQuery) NearQuery(org.springframework.data.mongodb.core.query.NearQuery) Query(org.springframework.data.mongodb.core.query.Query) BasicQuery(org.springframework.data.mongodb.core.query.BasicQuery) MapReduceIterable(com.mongodb.client.MapReduceIterable) MongoCursor(com.mongodb.client.MongoCursor) Document(org.bson.Document) Test(org.junit.jupiter.api.Test)

Example 13 with MongoCursor

use of com.mongodb.client.MongoCursor in project spring-data-mongodb by spring-projects.

the class MongoTemplateUnitTests method mapReduceShouldPickUpLimitFromOptionsWhenQueryIsNotPresent.

// DATAMONGO-1334
@Test
void mapReduceShouldPickUpLimitFromOptionsWhenQueryIsNotPresent() {
    MongoCursor cursor = mock(MongoCursor.class);
    MapReduceIterable output = mock(MapReduceIterable.class);
    when(output.limit(anyInt())).thenReturn(output);
    when(output.sort(any())).thenReturn(output);
    when(output.filter(any())).thenReturn(output);
    when(output.iterator()).thenReturn(cursor);
    when(cursor.hasNext()).thenReturn(false);
    when(collection.mapReduce(anyString(), anyString(), eq(Document.class))).thenReturn(output);
    template.mapReduce("collection", "function(){}", "function(key,values){}", new MapReduceOptions().limit(1000), Wrapper.class);
    verify(output, times(1)).limit(1000);
}
Also used : MapReduceOptions(org.springframework.data.mongodb.core.mapreduce.MapReduceOptions) MapReduceIterable(com.mongodb.client.MapReduceIterable) MongoCursor(com.mongodb.client.MongoCursor) Document(org.bson.Document) Test(org.junit.jupiter.api.Test)

Aggregations

MongoCursor (com.mongodb.client.MongoCursor)13 Document (org.bson.Document)10 MapReduceIterable (com.mongodb.client.MapReduceIterable)5 MongoCollection (com.mongodb.client.MongoCollection)5 List (java.util.List)5 Test (org.junit.jupiter.api.Test)5 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 Set (java.util.Set)4 Bson (org.bson.conversions.Bson)4 BasicQuery (org.springframework.data.mongodb.core.query.BasicQuery)4 NearQuery (org.springframework.data.mongodb.core.query.NearQuery)4 Query (org.springframework.data.mongodb.core.query.Query)4 FindIterable (com.mongodb.client.FindIterable)3 MongoDatabase (com.mongodb.client.MongoDatabase)3 Filters (com.mongodb.client.model.Filters)3 HashSet (java.util.HashSet)3 BasicDBObject (com.mongodb.BasicDBObject)2 ServerAddress (com.mongodb.ServerAddress)2 IOException (java.io.IOException)2