You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by se...@apache.org on 2019/05/09 00:46:51 UTC

[calcite] branch master updated: Mongo adapter. Mongo checker validates only first line of the Bson query in tests

This is an automated email from the ASF dual-hosted git repository.

sereda pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/master by this push:
     new b15c8c9  Mongo adapter. Mongo checker validates only first line of the Bson query in tests
b15c8c9 is described below

commit b15c8c9baccf05e1bf16b1e268d4edfac90bbf03
Author: Andrei Sereda <25...@users.noreply.github.com>
AuthorDate: Wed May 8 20:20:40 2019 -0400

    Mongo adapter. Mongo checker validates only first line of the Bson query in tests
    
    `BsonDocument.parse()` is more lenient with input and this omission was not noticed before
---
 .../calcite/adapter/mongodb/MongoAdapterTest.java  | 28 +++++++++++++++-------
 1 file changed, 20 insertions(+), 8 deletions(-)

diff --git a/mongodb/src/test/java/org/apache/calcite/adapter/mongodb/MongoAdapterTest.java b/mongodb/src/test/java/org/apache/calcite/adapter/mongodb/MongoAdapterTest.java
index 306846d..c62fe35 100644
--- a/mongodb/src/test/java/org/apache/calcite/adapter/mongodb/MongoAdapterTest.java
+++ b/mongodb/src/test/java/org/apache/calcite/adapter/mongodb/MongoAdapterTest.java
@@ -53,11 +53,13 @@ import java.sql.SQLException;
 import java.time.Instant;
 import java.time.LocalDate;
 import java.time.ZoneOffset;
+import java.util.Arrays;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 import java.util.Objects;
 import java.util.function.Consumer;
+import java.util.function.Function;
 import java.util.stream.Collectors;
 
 /**
@@ -753,20 +755,30 @@ public class MongoAdapterTest implements SchemaFactory {
         return;
       }
 
-      final BsonDocument expectedBson = BsonDocument.parse(String.join(",", expected));
-      final BsonDocument actualBson = BsonDocument.parse(((List<?>) actual.get(0))
+      // comparing list of Bsons (expected and actual)
+      final List<BsonDocument> expectedBsons = Arrays.stream(expected).map(BsonDocument::parse)
+          .collect(Collectors.toList());
+
+      final List<BsonDocument> actualBsons =  ((List<?>) actual.get(0))
           .stream()
           .map(Objects::toString)
-          .collect(Collectors.joining("\n")));
+          .map(BsonDocument::parse)
+          .collect(Collectors.toList());
 
       // compare Bson (not string) representation
-      if (!expectedBson.equals(actualBson)) {
+      if (!expectedBsons.equals(actualBsons)) {
         final JsonWriterSettings settings = JsonWriterSettings.builder().indent(true).build();
+        // outputs Bson in pretty Json format (with new lines)
+        // so output is human friendly in IDE diff tool
+        final Function<List<BsonDocument>, String> prettyFn = bsons -> bsons.stream()
+            .map(b -> b.toJson(settings)).collect(Collectors.joining("\n"));
+
         // used to pretty print Assertion error
-        Assert.assertEquals("expected and actual Mongo queries do not match",
-            expectedBson.toJson(settings),
-            actualBson.toJson(settings));
-        Assert.fail("Should have failed previously because (expected != actual) is already known");
+        Assert.assertEquals("expected and actual Mongo queries (pipelines) do not match",
+            prettyFn.apply(expectedBsons),
+            prettyFn.apply(actualBsons));
+
+        Assert.fail("Should have failed previously because expected != actual is known to be true");
       }
     };
   }