|
1 | 1 | /*
|
2 |
| - * Copyright 2011 the original author or authors. |
| 2 | + * Copyright 2011-2014 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
32 | 32 | import org.junit.Test;
|
33 | 33 | import org.junit.runner.RunWith;
|
34 | 34 | import org.springframework.beans.factory.annotation.Autowired;
|
| 35 | +import org.springframework.data.geo.Box; |
35 | 36 | import org.springframework.data.mongodb.MongoDbFactory;
|
36 | 37 | import org.springframework.data.mongodb.core.MongoTemplate;
|
37 | 38 | import org.springframework.data.mongodb.core.convert.DbRefResolver;
|
|
50 | 51 | * Integration test for {@link MongoTemplate}'s Map-Reduce operations
|
51 | 52 | *
|
52 | 53 | * @author Mark Pollack
|
| 54 | + * @author Thomas Darimont |
53 | 55 | */
|
54 | 56 | @RunWith(SpringJUnit4ClassRunner.class)
|
55 | 57 | @ContextConfiguration("classpath:infrastructure.xml")
|
@@ -276,6 +278,31 @@ public void testMapReduceExcludeQuery() {
|
276 | 278 |
|
277 | 279 | }
|
278 | 280 |
|
| 281 | + /** |
| 282 | + * @see DATAMONGO-938 |
| 283 | + */ |
| 284 | + @Test |
| 285 | + public void mapReduceShouldUseQueryMapper() { |
| 286 | + |
| 287 | + DBCollection c = mongoTemplate.getDb().getCollection("jmrWithGeo"); |
| 288 | + |
| 289 | + c.save(new BasicDBObject("x", new String[] { "a", "b" }).append("loc", new double[] { 0, 0 })); |
| 290 | + c.save(new BasicDBObject("x", new String[] { "b", "c" }).append("loc", new double[] { 0, 0 })); |
| 291 | + c.save(new BasicDBObject("x", new String[] { "c", "d" }).append("loc", new double[] { 0, 0 })); |
| 292 | + |
| 293 | + Query query = new Query(where("x").ne(new String[] { "a", "b" }).and("loc") |
| 294 | + .within(new Box(new double[] { 0, 0 }, new double[] { 1, 1 }))); |
| 295 | + |
| 296 | + MapReduceResults<ValueObject> results = template.mapReduce(query, "jmrWithGeo", mapFunction, reduceFunction, |
| 297 | + ValueObject.class); |
| 298 | + |
| 299 | + Map<String, Float> m = copyToMap(results); |
| 300 | + assertEquals(3, m.size()); |
| 301 | + assertEquals(1, m.get("b").intValue()); |
| 302 | + assertEquals(2, m.get("c").intValue()); |
| 303 | + assertEquals(1, m.get("d").intValue()); |
| 304 | + } |
| 305 | + |
279 | 306 | private void performMapReduce(boolean inline, boolean withQuery) {
|
280 | 307 | createMapReduceData();
|
281 | 308 | MapReduceResults<ValueObject> results;
|
|
0 commit comments