DATAMONGO-1871 - Polishing.

Migrate test to AssertJ.

Original pull request: #533.
This commit is contained in:
Mark Paluch
2018-02-14 10:56:30 +01:00
parent cec6526543
commit 6a20ddf5a2

View File

@@ -15,12 +15,10 @@
*/ */
package org.springframework.data.mongodb.core.aggregation; package org.springframework.data.mongodb.core.aggregation;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.springframework.data.mongodb.core.DocumentTestUtils.*; import static org.springframework.data.mongodb.core.DocumentTestUtils.*;
import static org.springframework.data.mongodb.core.aggregation.Aggregation.*; import static org.springframework.data.mongodb.core.aggregation.Aggregation.*;
import static org.springframework.data.mongodb.core.query.Criteria.*; import static org.springframework.data.mongodb.core.query.Criteria.*;
import static org.springframework.data.mongodb.test.util.IsBsonObject.*; import static org.springframework.data.mongodb.test.util.Assertions.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@@ -118,10 +116,9 @@ public class AggregationUnitTests {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Document unwind = ((List<Document>) agg.get("pipeline")).get(0); Document unwind = ((List<Document>) agg.get("pipeline")).get(0);
assertThat((Document) unwind.get("$unwind"), assertThat(unwind.get("$unwind", Document.class)). //
isBsonObject(). // containsEntry("includeArrayIndex", "x"). //
containing("includeArrayIndex", "x").// containsEntry("preserveNullAndEmptyArrays", true);
containing("preserveNullAndEmptyArrays", true));
} }
@Test // DATAMONGO-1391 @Test // DATAMONGO-1391
@@ -132,8 +129,9 @@ public class AggregationUnitTests {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Document unwind = ((List<Document>) agg.get("pipeline")).get(0); Document unwind = ((List<Document>) agg.get("pipeline")).get(0);
assertThat(unwind, assertThat(unwind) //
isBsonObject().notContaining("includeArrayIndex").containing("preserveNullAndEmptyArrays", true)); .doesNotContainKey("$unwind.includeArrayIndex") //
.containsEntry("$unwind.preserveNullAndEmptyArrays", true);
} }
@Test // DATAMONGO-1550 @Test // DATAMONGO-1550
@@ -145,7 +143,7 @@ public class AggregationUnitTests {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Document unwind = ((List<Document>) agg.get("pipeline")).get(0); Document unwind = ((List<Document>) agg.get("pipeline")).get(0);
assertThat(unwind, isBsonObject().containing("$replaceRoot.newRoot", new Document("field", "value"))); assertThat(unwind).containsEntry("$replaceRoot.newRoot", new Document("field", "value"));
} }
@Test // DATAMONGO-753 @Test // DATAMONGO-753
@@ -170,8 +168,8 @@ public class AggregationUnitTests {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Document secondProjection = ((List<Document>) agg.get("pipeline")).get(2); Document secondProjection = ((List<Document>) agg.get("pipeline")).get(2);
Document fields = getAsDocument(secondProjection, "$project"); Document fields = getAsDocument(secondProjection, "$project");
assertThat(fields.get("aCnt"), is((Object) 1)); assertThat(fields.get("aCnt")).isEqualTo(1);
assertThat(fields.get("a"), is((Object) "$_id.a")); assertThat(fields.get("a")).isEqualTo("$_id.a");
} }
@Test // DATAMONGO-791 @Test // DATAMONGO-791
@@ -187,14 +185,14 @@ public class AggregationUnitTests {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Document secondProjection = ((List<Document>) agg.get("pipeline")).get(2); Document secondProjection = ((List<Document>) agg.get("pipeline")).get(2);
Document fields = getAsDocument(secondProjection, "$project"); Document fields = getAsDocument(secondProjection, "$project");
assertThat(fields.get("aCnt"), is((Object) 1)); assertThat(fields.get("aCnt")).isEqualTo(1);
assertThat(fields.get("a"), is((Object) "$_id.a")); assertThat(fields.get("a")).isEqualTo("$_id.a");
} }
@Test // DATAMONGO-791 @Test // DATAMONGO-791
public void allowTypedAggregationOperationsToBePassedAsIterable() { public void allowTypedAggregationOperationsToBePassedAsIterable() {
List<AggregationOperation> ops = new ArrayList<AggregationOperation>(); List<AggregationOperation> ops = new ArrayList<>();
ops.add(project("a")); ops.add(project("a"));
ops.add(group("a").count().as("aCnt")); ops.add(group("a").count().as("aCnt"));
ops.add(project("aCnt", "a")); ops.add(project("aCnt", "a"));
@@ -204,8 +202,8 @@ public class AggregationUnitTests {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Document secondProjection = ((List<Document>) agg.get("pipeline")).get(2); Document secondProjection = ((List<Document>) agg.get("pipeline")).get(2);
Document fields = getAsDocument(secondProjection, "$project"); Document fields = getAsDocument(secondProjection, "$project");
assertThat(fields.get("aCnt"), is((Object) 1)); assertThat(fields.get("aCnt")).isEqualTo((Object) 1);
assertThat(fields.get("a"), is((Object) "$_id.a")); assertThat(fields.get("a")).isEqualTo((Object) "$_id.a");
} }
@Test // DATAMONGO-838 @Test // DATAMONGO-838
@@ -219,7 +217,7 @@ public class AggregationUnitTests {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Document secondProjection = ((List<Document>) agg.get("pipeline")).get(1); Document secondProjection = ((List<Document>) agg.get("pipeline")).get(1);
Document fields = getAsDocument(secondProjection, "$group"); Document fields = getAsDocument(secondProjection, "$group");
assertThat(fields.get("foosum"), is((Object) new Document("$sum", "$foo"))); assertThat(fields.get("foosum")).isEqualTo(new Document("$sum", "$foo"));
} }
@Test // DATAMONGO-908 @Test // DATAMONGO-908
@@ -231,13 +229,13 @@ public class AggregationUnitTests {
group("cmsParameterId", "rules.ruleType").count().as("totol") // group("cmsParameterId", "rules.ruleType").count().as("totol") //
).toDocument("foo", Aggregation.DEFAULT_CONTEXT); ).toDocument("foo", Aggregation.DEFAULT_CONTEXT);
assertThat(agg, is(notNullValue())); assertThat(agg).isNotNull();
Document group = ((List<Document>) agg.get("pipeline")).get(2); Document group = ((List<Document>) agg.get("pipeline")).get(2);
Document fields = getAsDocument(group, "$group"); Document fields = getAsDocument(group, "$group");
Document id = getAsDocument(fields, "_id"); Document id = getAsDocument(fields, "_id");
assertThat(id.get("ruleType"), is((Object) "$rules.ruleType")); assertThat(id.get("ruleType")).isEqualTo("$rules.ruleType");
} }
@Test // DATAMONGO-1585 @Test // DATAMONGO-1585
@@ -248,11 +246,12 @@ public class AggregationUnitTests {
sort(Direction.ASC, "cmsParameterId", "titles") // sort(Direction.ASC, "cmsParameterId", "titles") //
).toDocument("foo", Aggregation.DEFAULT_CONTEXT); ).toDocument("foo", Aggregation.DEFAULT_CONTEXT);
assertThat(agg, is(notNullValue())); assertThat(agg).isNotNull();
Document sort = ((List<Document>) agg.get("pipeline")).get(1); Document sort = ((List<Document>) agg.get("pipeline")).get(1);
assertThat(getAsDocument(sort, "$sort"), is(Document.parse("{ \"_id.cmsParameterId\" : 1 , \"titles\" : 1}"))); assertThat(getAsDocument(sort, "$sort"))
.isEqualTo(Document.parse("{ \"_id.cmsParameterId\" : 1 , \"titles\" : 1}"));
} }
@Test // DATAMONGO-1585 @Test // DATAMONGO-1585
@@ -265,14 +264,13 @@ public class AggregationUnitTests {
sort(Direction.ASC, "cmsParameterId", "titles", "alias") // sort(Direction.ASC, "cmsParameterId", "titles", "alias") //
).toDocument("foo", Aggregation.DEFAULT_CONTEXT); ).toDocument("foo", Aggregation.DEFAULT_CONTEXT);
assertThat(agg, is(notNullValue())); assertThat(agg).isNotNull();
Document sort = ((List<Document>) agg.get("pipeline")).get(1); Document sort = ((List<Document>) agg.get("pipeline")).get(1);
assertThat(getAsDocument(sort, "$sort"), assertThat(getAsDocument(sort, "$sort")).containsEntry("cmsParameterId", 1) //
isBsonObject().containing("cmsParameterId", 1) // .containsEntry("titles", 1) //
.containing("titles", 1) // .containsEntry("alias", 1);
.containing("alias", 1));
} }
@Test // DATAMONGO-924 @Test // DATAMONGO-924
@@ -284,10 +282,10 @@ public class AggregationUnitTests {
).toDocument("foo", Aggregation.DEFAULT_CONTEXT); ).toDocument("foo", Aggregation.DEFAULT_CONTEXT);
Document projection0 = extractPipelineElement(agg, 0, "$project"); Document projection0 = extractPipelineElement(agg, 0, "$project");
assertThat(projection0, is((Document) new Document("ba", "$foo.bar"))); assertThat(projection0).isEqualTo(new Document("ba", "$foo.bar"));
Document projection1 = extractPipelineElement(agg, 1, "$project"); Document projection1 = extractPipelineElement(agg, 1, "$project");
assertThat(projection1, is((Document) new Document("b", "$ba"))); assertThat(projection1).isEqualTo(new Document("b", "$ba"));
} }
@Test // DATAMONGO-960 @Test // DATAMONGO-960
@@ -297,8 +295,8 @@ public class AggregationUnitTests {
project().and("a").as("aa") // project().and("a").as("aa") //
).toDocument("foo", Aggregation.DEFAULT_CONTEXT); ).toDocument("foo", Aggregation.DEFAULT_CONTEXT);
assertThat(agg, assertThat(agg).isEqualTo(
is(Document.parse("{ \"aggregate\" : \"foo\" , \"pipeline\" : [ { \"$project\" : { \"aa\" : \"$a\"}}]}"))); Document.parse("{ \"aggregate\" : \"foo\" , \"pipeline\" : [ { \"$project\" : { \"aa\" : \"$a\"}}]}"));
} }
@Test // DATAMONGO-960 @Test // DATAMONGO-960
@@ -313,13 +311,12 @@ public class AggregationUnitTests {
.withOptions(aggregationOptions) // .withOptions(aggregationOptions) //
.toDocument("foo", Aggregation.DEFAULT_CONTEXT); .toDocument("foo", Aggregation.DEFAULT_CONTEXT);
assertThat(agg, assertThat(agg).isEqualTo(Document.parse("{ \"aggregate\" : \"foo\" , " //
is(Document.parse("{ \"aggregate\" : \"foo\" , " //
+ "\"pipeline\" : [ { \"$project\" : { \"aa\" : \"$a\"}}] , " // + "\"pipeline\" : [ { \"$project\" : { \"aa\" : \"$a\"}}] , " //
+ "\"allowDiskUse\" : true , " // + "\"allowDiskUse\" : true , " //
+ "\"explain\" : true , " // + "\"explain\" : true , " //
+ "\"cursor\" : { \"foo\" : 1}}") // + "\"cursor\" : { \"foo\" : 1}}") //
)); );
} }
@Test // DATAMONGO-954, DATAMONGO-1585 @Test // DATAMONGO-954, DATAMONGO-1585
@@ -334,13 +331,13 @@ public class AggregationUnitTests {
).toDocument("foo", Aggregation.DEFAULT_CONTEXT); ).toDocument("foo", Aggregation.DEFAULT_CONTEXT);
Document projection0 = extractPipelineElement(agg, 0, "$project"); Document projection0 = extractPipelineElement(agg, 0, "$project");
assertThat(projection0, is((Document) new Document("someKey", 1).append("a1", "$a").append("a2", "$$CURRENT.a"))); assertThat(projection0).isEqualTo(new Document("someKey", 1).append("a1", "$a").append("a2", "$$CURRENT.a"));
Document sort = extractPipelineElement(agg, 1, "$sort"); Document sort = extractPipelineElement(agg, 1, "$sort");
assertThat(sort, is((Document) new Document("a1", -1))); assertThat(sort).isEqualTo(new Document("a1", -1));
Document group = extractPipelineElement(agg, 2, "$group"); Document group = extractPipelineElement(agg, 2, "$group");
assertThat(group, is((Document) new Document("_id", "$someKey").append("doc", new Document("$first", "$$ROOT")))); assertThat(group).isEqualTo(new Document("_id", "$someKey").append("doc", new Document("$first", "$$ROOT")));
} }
@Test // DATAMONGO-1254 @Test // DATAMONGO-1254
@@ -354,7 +351,7 @@ public class AggregationUnitTests {
).toDocument("foo", Aggregation.DEFAULT_CONTEXT); ).toDocument("foo", Aggregation.DEFAULT_CONTEXT);
Document group = extractPipelineElement(agg, 1, "$group"); Document group = extractPipelineElement(agg, 1, "$group");
assertThat(getAsDocument(group, "count"), is(new Document().append("$sum", "$tags_count"))); assertThat(getAsDocument(group, "count")).isEqualTo(new Document().append("$sum", "$tags_count"));
} }
@Test // DATAMONGO-1254 @Test // DATAMONGO-1254
@@ -368,7 +365,7 @@ public class AggregationUnitTests {
).toDocument("foo", Aggregation.DEFAULT_CONTEXT); ).toDocument("foo", Aggregation.DEFAULT_CONTEXT);
Document group = extractPipelineElement(agg, 1, "$group"); Document group = extractPipelineElement(agg, 1, "$group");
assertThat(getAsDocument(group, "count"), is(new Document().append("$sum", "$tags_count"))); assertThat(getAsDocument(group, "count")).isEqualTo(new Document().append("$sum", "$tags_count"));
} }
@Test // DATAMONGO-861 @Test // DATAMONGO-861
@@ -384,9 +381,9 @@ public class AggregationUnitTests {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Document secondProjection = ((List<Document>) agg.get("pipeline")).get(1); Document secondProjection = ((List<Document>) agg.get("pipeline")).get(1);
Document fields = getAsDocument(secondProjection, "$group"); Document fields = getAsDocument(secondProjection, "$group");
assertThat(getAsDocument(fields, "foosum"), isBsonObject().containing("$first")); assertThat(getAsDocument(fields, "foosum")).containsKey("$first");
assertThat(getAsDocument(fields, "foosum"), isBsonObject().containing("$first.$cond.then", "$answer")); assertThat(getAsDocument(fields, "foosum")).containsEntry("$first.$cond.then", "$answer");
assertThat(getAsDocument(fields, "foosum"), isBsonObject().containing("$first.$cond.else", "no-answer")); assertThat(getAsDocument(fields, "foosum")).containsEntry("$first.$cond.else", "no-answer");
} }
@Test // DATAMONGO-861 @Test // DATAMONGO-861
@@ -405,15 +402,14 @@ public class AggregationUnitTests {
.append("then", "bright") // .append("then", "bright") //
.append("else", "dark"); .append("else", "dark");
assertThat(getAsDocument(project, "color"), isBsonObject().containing("$cond", expectedCondition)); assertThat(getAsDocument(project, "color")).containsEntry("$cond", expectedCondition);
} }
@Test // DATAMONGO-861 @Test // DATAMONGO-861
public void shouldRenderProjectionConditionalCorrectly() { public void shouldRenderProjectionConditionalCorrectly() {
Document agg = Aggregation.newAggregation(// Document agg = Aggregation.newAggregation(//
project().and("color") project().and("color").applyCondition(ConditionalOperators.Cond.newBuilder() //
.applyCondition(ConditionalOperators.Cond.newBuilder() //
.when("isYellow") // .when("isYellow") //
.then("bright") // .then("bright") //
.otherwise("dark"))) .otherwise("dark")))
@@ -425,14 +421,13 @@ public class AggregationUnitTests {
.append("then", "bright") // .append("then", "bright") //
.append("else", "dark"); .append("else", "dark");
assertThat(getAsDocument(project, "color"), isBsonObject().containing("$cond", expectedCondition)); assertThat(getAsDocument(project, "color")).containsEntry("$cond", expectedCondition);
} }
@Test // DATAMONGO-861 @Test // DATAMONGO-861
public void shouldRenderProjectionConditionalWithCriteriaCorrectly() { public void shouldRenderProjectionConditionalWithCriteriaCorrectly() {
Document agg = Aggregation Document agg = Aggregation.newAggregation(project()//
.newAggregation(project()//
.and("color")// .and("color")//
.applyCondition(ConditionalOperators.Cond.newBuilder().when(Criteria.where("key").gt(5)) // .applyCondition(ConditionalOperators.Cond.newBuilder().when(Criteria.where("key").gt(5)) //
.then("bright").otherwise("dark"))) // .then("bright").otherwise("dark"))) //
@@ -444,16 +439,14 @@ public class AggregationUnitTests {
.append("then", "bright") // .append("then", "bright") //
.append("else", "dark"); .append("else", "dark");
assertThat(getAsDocument(project, "color"), isBsonObject().containing("$cond", expectedCondition)); assertThat(getAsDocument(project, "color")).containsEntry("$cond", expectedCondition);
} }
@Test // DATAMONGO-861 @Test // DATAMONGO-861
public void referencingProjectionAliasesShouldRenderProjectionConditionalWithFieldReferenceCorrectly() { public void referencingProjectionAliasesShouldRenderProjectionConditionalWithFieldReferenceCorrectly() {
Document agg = Aggregation Document agg = Aggregation.newAggregation(//
.newAggregation(// project().and("color").as("chroma"), project().and("luminosity") //
project().and("color").as("chroma"),
project().and("luminosity") //
.applyCondition(ConditionalOperators // .applyCondition(ConditionalOperators //
.when("chroma") // .when("chroma") //
.thenValueOf("bright") // .thenValueOf("bright") //
@@ -466,18 +459,15 @@ public class AggregationUnitTests {
.append("then", "bright") // .append("then", "bright") //
.append("else", "dark"); .append("else", "dark");
assertThat(getAsDocument(project, "luminosity"), isBsonObject().containing("$cond", expectedCondition)); assertThat(getAsDocument(project, "luminosity")).containsEntry("$cond", expectedCondition);
} }
@Test // DATAMONGO-861 @Test // DATAMONGO-861
public void referencingProjectionAliasesShouldRenderProjectionConditionalWithCriteriaReferenceCorrectly() { public void referencingProjectionAliasesShouldRenderProjectionConditionalWithCriteriaReferenceCorrectly() {
Document agg = Aggregation Document agg = Aggregation.newAggregation(//
.newAggregation(// project().and("color").as("chroma"), project().and("luminosity") //
project().and("color").as("chroma"), .applyCondition(ConditionalOperators.Cond.newBuilder().when(Criteria.where("chroma") //
project().and("luminosity") //
.applyCondition(ConditionalOperators.Cond.newBuilder()
.when(Criteria.where("chroma") //
.is(100)) // .is(100)) //
.then("bright").otherwise("dark"))) // .then("bright").otherwise("dark"))) //
.toDocument("foo", Aggregation.DEFAULT_CONTEXT); .toDocument("foo", Aggregation.DEFAULT_CONTEXT);
@@ -488,14 +478,13 @@ public class AggregationUnitTests {
.append("then", "bright") // .append("then", "bright") //
.append("else", "dark"); .append("else", "dark");
assertThat(getAsDocument(project, "luminosity"), isBsonObject().containing("$cond", expectedCondition)); assertThat(getAsDocument(project, "luminosity")).containsEntry("$cond", expectedCondition);
} }
@Test // DATAMONGO-861 @Test // DATAMONGO-861
public void shouldRenderProjectionIfNullWithFieldReferenceCorrectly() { public void shouldRenderProjectionIfNullWithFieldReferenceCorrectly() {
Document agg = Aggregation Document agg = Aggregation.newAggregation(//
.newAggregation(//
project().and("color"), // project().and("color"), //
project().and("luminosity") // project().and("luminosity") //
.applyCondition(ConditionalOperators // .applyCondition(ConditionalOperators //
@@ -505,39 +494,34 @@ public class AggregationUnitTests {
Document project = extractPipelineElement(agg, 1, "$project"); Document project = extractPipelineElement(agg, 1, "$project");
assertThat(getAsDocument(project, "luminosity"), assertThat(getAsDocument(project, "luminosity")).containsEntry("$ifNull", Arrays.asList("$chroma", "unknown"));
isBsonObject().containing("$ifNull", Arrays.<Object> asList("$chroma", "unknown")));
} }
@Test // DATAMONGO-861 @Test // DATAMONGO-861
public void shouldRenderProjectionIfNullWithFallbackFieldReferenceCorrectly() { public void shouldRenderProjectionIfNullWithFallbackFieldReferenceCorrectly() {
Document agg = Aggregation Document agg = Aggregation.newAggregation(//
.newAggregation(// project("fallback").and("color").as("chroma"), project().and("luminosity") //
project("fallback").and("color").as("chroma"),
project().and("luminosity") //
.applyCondition(ConditionalOperators.ifNull("chroma") // .applyCondition(ConditionalOperators.ifNull("chroma") //
.thenValueOf("fallback"))) // .thenValueOf("fallback"))) //
.toDocument("foo", Aggregation.DEFAULT_CONTEXT); .toDocument("foo", Aggregation.DEFAULT_CONTEXT);
Document project = extractPipelineElement(agg, 1, "$project"); Document project = extractPipelineElement(agg, 1, "$project");
assertThat(getAsDocument(project, "luminosity"), assertThat(getAsDocument(project, "luminosity")).containsEntry("$ifNull", Arrays.asList("$chroma", "$fallback"));
isBsonObject().containing("$ifNull", Arrays.asList("$chroma", "$fallback")));
} }
@Test // DATAMONGO-1552 @Test // DATAMONGO-1552
public void shouldHonorDefaultCountField() { public void shouldHonorDefaultCountField() {
Document agg = Aggregation Document agg = Aggregation.newAggregation(//
.newAggregation(//
bucket("year"), // bucket("year"), //
project("count")) // project("count")) //
.toDocument("foo", Aggregation.DEFAULT_CONTEXT); .toDocument("foo", Aggregation.DEFAULT_CONTEXT);
Document project = extractPipelineElement(agg, 1, "$project"); Document project = extractPipelineElement(agg, 1, "$project");
assertThat(project, isBsonObject().containing("count", 1)); assertThat(project).containsEntry("count", 1);
} }
@Test // DATAMONGO-1533 @Test // DATAMONGO-1533
@@ -551,11 +535,11 @@ public class AggregationUnitTests {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Document secondProjection = ((List<Document>) agg.get("pipeline")).get(1); Document secondProjection = ((List<Document>) agg.get("pipeline")).get(1);
Document fields = getAsDocument(secondProjection, "$group"); Document fields = getAsDocument(secondProjection, "$group");
assertThat(getAsDocument(fields, "foosum"), isBsonObject().containing("$first")); assertThat(getAsDocument(fields, "foosum")).containsKey("$first");
assertThat(getAsDocument(fields, "foosum"), assertThat(getAsDocument(fields, "foosum")).containsEntry("$first.$cond.if",
isBsonObject().containing("$first.$cond.if", new Document("$gte", new Document("$a", 42)))); new Document("$gte", Arrays.asList("$a", 42)));
assertThat(getAsDocument(fields, "foosum"), isBsonObject().containing("$first.$cond.then", "answer")); assertThat(getAsDocument(fields, "foosum")).containsEntry("$first.$cond.then", "answer");
assertThat(getAsDocument(fields, "foosum"), isBsonObject().containing("$first.$cond.else", "no-answer")); assertThat(getAsDocument(fields, "foosum")).containsEntry("$first.$cond.else", "no-answer");
} }
@Test // DATAMONGO-1756 @Test // DATAMONGO-1756
@@ -564,8 +548,8 @@ public class AggregationUnitTests {
Document agg = newAggregation(project().and("value1.value").plus("value2.value").as("val")).toDocument("collection", Document agg = newAggregation(project().and("value1.value").plus("value2.value").as("val")).toDocument("collection",
Aggregation.DEFAULT_CONTEXT); Aggregation.DEFAULT_CONTEXT);
assertThat(extractPipelineElement(agg, 0, "$project"), Document expected = new Document("val", new Document("$add", Arrays.asList("$value1.value", "$value2.value")));
is(equalTo(new Document("val", new Document("$add", Arrays.asList("$value1.value", "$value2.value")))))); assertThat(extractPipelineElement(agg, 0, "$project")).isEqualTo(expected);
} }
@Test // DATAMONGO-1871 @Test // DATAMONGO-1871
@@ -582,7 +566,7 @@ public class AggregationUnitTests {
Document $project = extractPipelineElement(agg.toDocument("collection-1", Aggregation.DEFAULT_CONTEXT), 0, Document $project = extractPipelineElement(agg.toDocument("collection-1", Aggregation.DEFAULT_CONTEXT), 0,
"$project"); "$project");
assertThat($project.containsKey("plts.ests"), is(true)); assertThat($project.containsKey("plts.ests")).isTrue();
} }
private Document extractPipelineElement(Document agg, int index, String operation) { private Document extractPipelineElement(Document agg, int index, String operation) {