use of org.springframework.data.mongodb.core.mapreduce.MapReduceOptions in project spring-data-mongodb by spring-projects.
the class ExecutableMapReduceOperationSupportUnitTests method usesMapReduceOptionsWhenPresent.
// DATAMONGO-1929
@Test
void usesMapReduceOptionsWhenPresent() {
when(template.getCollectionName(eq(Person.class))).thenReturn(STAR_WARS);
MapReduceOptions options = MapReduceOptions.options();
mapReduceOpsSupport.mapReduce(Person.class).map(MAP_FUNCTION).reduce(REDUCE_FUNCTION).with(options).all();
verify(template).mapReduce(any(Query.class), eq(Person.class), eq(STAR_WARS), eq(MAP_FUNCTION), eq(REDUCE_FUNCTION), eq(options), eq(Person.class));
}
use of org.springframework.data.mongodb.core.mapreduce.MapReduceOptions in project spring-data-mongodb by spring-projects.
the class MongoTemplateUnitTests method mapReduceShouldPickUpLimitFromOptions.
// DATAMONGO-1334
@Test
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(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);
}
use of org.springframework.data.mongodb.core.mapreduce.MapReduceOptions in project spring-data-mongodb by spring-projects.
the class MapReduceTests method testMapReduceInlineWithScope.
// DATADOC-7
@Test
public void testMapReduceInlineWithScope() {
createMapReduceData();
Map<String, Object> scopeVariables = new HashMap<String, Object>();
scopeVariables.put("exclude", "a");
String mapWithExcludeFunction = "function(){ for ( var i=0; i<this.x.length; i++ ){ if(this.x[i] != exclude) emit( this.x[i] , 1 ); } }";
MapReduceResults<ValueObject> results = mongoTemplate.mapReduce("jmr1", mapWithExcludeFunction, REDUCE_FUNCTION, new MapReduceOptions().scopeVariables(scopeVariables).outputTypeInline(), ValueObject.class);
//
assertThat(copyToMap(results)).hasSize(//
3).containsEntry("b", //
2F).containsEntry("c", //
2F).containsEntry("d", 1F);
}
use of org.springframework.data.mongodb.core.mapreduce.MapReduceOptions 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);
}
use of org.springframework.data.mongodb.core.mapreduce.MapReduceOptions 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);
}
Aggregations