Search in sources :

Example 1 with MapReduceIterable

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

the class MongoTemplateUnitTests method mapReduceShouldPickUpLimitFromOptions.

// DATAMONGO-1334
@Test
public void mapReduceShouldPickUpLimitFromOptions() {
    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(Mockito.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'}");
    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.Test)

Example 2 with MapReduceIterable

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

the class MongoTemplateUnitTests method mapReduceShouldPickUpLimitFromQuery.

// DATAMONGO-1334
@Test
public void mapReduceShouldPickUpLimitFromQuery() {
    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(Mockito.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){}", Wrapper.class);
    verify(output, times(1)).limit(100);
}
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.Test)

Example 3 with MapReduceIterable

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

the class MongoTemplateUnitTests method mapReduceShouldUseZeroAsDefaultLimit.

// DATAMONGO-1334
@Test
@Ignore("TODO: mongo3 - a bit hard to tests with the immutable object stuff")
public void mapReduceShouldUseZeroAsDefaultLimit() {
    MongoCursor cursor = mock(MongoCursor.class);
    MapReduceIterable output = mock(MapReduceIterable.class);
    when(output.limit(anyInt())).thenReturn(output);
    when(output.sort(Mockito.any(Document.class))).thenReturn(output);
    when(output.filter(Mockito.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) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with MapReduceIterable

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

the class MongoTemplateUnitTests method mapReduceShouldPickUpLimitFromOptionsWhenQueryIsNotPresent.

// DATAMONGO-1334
@Test
public 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.Test)

Example 5 with MapReduceIterable

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

the class MongoTemplateUnitTests method mapReduceShouldPickUpLimitFromOptionsEvenWhenQueryDefinesItDifferently.

// DATAMONGO-1334
@Test
public 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(Mockito.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.Test)

Aggregations

MapReduceIterable (com.mongodb.client.MapReduceIterable)5 MongoCursor (com.mongodb.client.MongoCursor)5 Document (org.bson.Document)5 Test (org.junit.Test)5 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 MapReduceOptions (org.springframework.data.mongodb.core.mapreduce.MapReduceOptions)3 Ignore (org.junit.Ignore)1