Browse Source
The raw result for a map-reduce operation might contain a complex element containing the output collection in case the original request configured an output database as option. Adapted the parsing of the output collection to accommodate both scenarios (plain String value as well as DBObject wrapper).1.0.x
2 changed files with 129 additions and 33 deletions
@ -0,0 +1,59 @@
@@ -0,0 +1,59 @@
|
||||
/* |
||||
* Copyright 2012 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package org.springframework.data.mongodb.core.mapreduce; |
||||
|
||||
import static org.hamcrest.CoreMatchers.*; |
||||
import static org.junit.Assert.*; |
||||
|
||||
import java.util.Collections; |
||||
|
||||
import org.junit.Test; |
||||
|
||||
import com.mongodb.BasicDBObject; |
||||
import com.mongodb.DBObject; |
||||
|
||||
/** |
||||
* Unit tests for {@link MapReduceResults}. |
||||
* |
||||
* @author Oliver Gierke |
||||
*/ |
||||
public class MapReduceResultsUnitTests { |
||||
|
||||
/** |
||||
* @see DATAMONGO-428 |
||||
*/ |
||||
@Test |
||||
public void resolvesOutputCollectionForPlainResult() { |
||||
|
||||
DBObject rawResult = new BasicDBObject("result", "FOO"); |
||||
MapReduceResults<Object> results = new MapReduceResults<Object>(Collections.emptyList(), rawResult); |
||||
|
||||
assertThat(results.getOutputCollection(), is("FOO")); |
||||
} |
||||
|
||||
/** |
||||
* @see DATAMONGO-428 |
||||
*/ |
||||
@Test |
||||
public void resolvesOutputCollectionForDBObjectResult() { |
||||
|
||||
DBObject rawResult = new BasicDBObject("result", new BasicDBObject("collection", "FOO")); |
||||
MapReduceResults<Object> results = new MapReduceResults<Object>(Collections.emptyList(), rawResult); |
||||
|
||||
assertThat(results.getOutputCollection(), is("FOO")); |
||||
} |
||||
|
||||
} |
||||
Loading…
Reference in new issue