|
29 | 29 | import org.junit.Test;
|
30 | 30 |
|
31 | 31 | import java.util.ArrayList;
|
| 32 | +import java.util.Collections; |
32 | 33 | import java.util.List;
|
33 | 34 |
|
| 35 | +import static com.mongodb.ClusterFixture.serverVersionAtLeast; |
34 | 36 | import static java.util.Arrays.asList;
|
35 | 37 | import static org.bson.codecs.configuration.CodecRegistries.fromProviders;
|
36 | 38 | import static org.hamcrest.CoreMatchers.is;
|
37 | 39 | import static org.junit.Assert.assertEquals;
|
38 | 40 | import static org.junit.Assert.assertNotNull;
|
39 | 41 | import static org.junit.Assert.assertThat;
|
| 42 | +import static org.junit.Assume.assumeTrue; |
40 | 43 |
|
41 | 44 | public class MongoCollectionTest extends DatabaseTestCase {
|
42 | 45 |
|
@@ -137,6 +140,26 @@ public void testMapReduceWithGenerics() {
|
137 | 140 | assertEquals(new Name("Sam", 1), result.get(1));
|
138 | 141 | }
|
139 | 142 |
|
| 143 | + @Test |
| 144 | + public void testAggregationToACollection() { |
| 145 | + assumeTrue(serverVersionAtLeast(asList(2, 6, 0))); |
| 146 | + |
| 147 | + // given |
| 148 | + List<Document> documents = asList(new Document("_id", 1), new Document("_id", 2)); |
| 149 | + |
| 150 | + getCollectionHelper().insertDocuments(new DocumentCodec(), documents); |
| 151 | + |
| 152 | + MongoCollection<Document> collection = database |
| 153 | + .getCollection(getCollectionName()); |
| 154 | + |
| 155 | + // when |
| 156 | + List<Document> result = collection.aggregate(Collections.singletonList(new Document("$out", "outCollection"))) |
| 157 | + .into(new ArrayList<Document>()); |
| 158 | + |
| 159 | + // then |
| 160 | + assertEquals(documents, result); |
| 161 | + } |
| 162 | + |
140 | 163 | // This is really a test that the default registry created in MongoClient and passed down to MongoCollection has been constructed
|
141 | 164 | // properly to handle DBRef encoding and decoding
|
142 | 165 | @Test
|
|
0 commit comments