You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by yo...@apache.org on 2015/03/13 14:18:51 UTC
svn commit: r1666440 - in /lucene/dev/branches/branch_5x: ./ solr/
solr/test-framework/
solr/test-framework/src/java/org/apache/solr/JSONTestUtil.java
Author: yonik
Date: Fri Mar 13 13:18:50 2015
New Revision: 1666440
URL: http://svn.apache.org/r1666440
Log:
tests: give json matching tests a way to fail on repeated keys instead of overwriting with the last key
Modified:
lucene/dev/branches/branch_5x/ (props changed)
lucene/dev/branches/branch_5x/solr/ (props changed)
lucene/dev/branches/branch_5x/solr/test-framework/ (props changed)
lucene/dev/branches/branch_5x/solr/test-framework/src/java/org/apache/solr/JSONTestUtil.java
Modified: lucene/dev/branches/branch_5x/solr/test-framework/src/java/org/apache/solr/JSONTestUtil.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/test-framework/src/java/org/apache/solr/JSONTestUtil.java?rev=1666440&r1=1666439&r2=1666440&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/test-framework/src/java/org/apache/solr/JSONTestUtil.java (original)
+++ lucene/dev/branches/branch_5x/solr/test-framework/src/java/org/apache/solr/JSONTestUtil.java Fri Mar 13 13:18:50 2015
@@ -17,9 +17,11 @@
package org.apache.solr;
+import org.noggit.JSONParser;
import org.noggit.ObjectBuilder;
import org.apache.solr.common.util.StrUtils;
+import java.io.IOException;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -31,6 +33,7 @@ public class JSONTestUtil {
* Default delta used in numeric equality comparisons for floats and doubles.
*/
public final static double DEFAULT_DELTA = 1e-5;
+ public static boolean failRepeatedKeys = false;
/**
* comparison using default delta
@@ -78,11 +81,25 @@ public class JSONTestUtil {
* @param delta tollerance allowed in comparing float/double values
*/
public static String match(String path, String input, String expected, double delta) throws Exception {
- Object inputObj = ObjectBuilder.fromJSON(input);
- Object expectObj = ObjectBuilder.fromJSON(expected);
+ Object inputObj = failRepeatedKeys ? new NoDupsObjectBuilder(new JSONParser(input)).getVal() : ObjectBuilder.fromJSON(input);
+ Object expectObj = failRepeatedKeys ? new NoDupsObjectBuilder(new JSONParser(expected)).getVal() : ObjectBuilder.fromJSON(expected);
return matchObj(path, inputObj, expectObj, delta);
}
+ static class NoDupsObjectBuilder extends ObjectBuilder {
+ public NoDupsObjectBuilder(JSONParser parser) throws IOException {
+ super(parser);
+ }
+
+ @Override
+ public void addKeyVal(Object map, Object key, Object val) throws IOException {
+ Object prev = ((Map<Object, Object>) map).put(key, val);
+ if (prev != null) {
+ throw new RuntimeException("REPEATED JSON OBJECT KEY: key=" + key + " prevValue=" + prev + " thisValue" + val);
+ }
+ }
+ }
+
/**
* @param path JSON path expression
* @param input JSON Structure
@@ -243,7 +260,7 @@ class CollectionTester {
if (a >= expectedList.size() || b >=v.size()) {
popPath();
- setErr("List size mismatch (expected: " + expectedList.size() + ", got: " + v.size() + ")");
+ setErr("List size mismatch");
return false;
}