From 77e18924f920bf0971f2982a5f8f67acde0ceec2 Mon Sep 17 00:00:00 2001 From: Kalle Stenflo Date: Wed, 28 Aug 2013 11:48:25 +0200 Subject: [PATCH] Added internal logging support. --- json-path-assert/pom.xml | 10 - json-path/pom.xml | 29 --- .../java/com/jayway/jsonpath/Criteria.java | 34 +++- .../java/com/jayway/jsonpath/JsonPath.java | 111 +++++----- .../com/jayway/jsonpath/internal/Log.java | 50 +++++ .../jayway/jsonpath/ExpressionEvalTest.java | 5 +- .../java/com/jayway/jsonpath/FilterTest.java | 190 ++++++++++-------- .../com/jayway/jsonpath/JsonPathTest.java | 17 ++ .../java/com/jayway/jsonpath/LogTest.java | 22 ++ .../internal/filter/ArrayEvalFilterTest.java | 2 + json-path/src/test/resources/logback-test.xml | 15 ++ pom.xml | 102 ++++++++-- 12 files changed, 395 insertions(+), 192 deletions(-) create mode 100644 json-path/src/main/java/com/jayway/jsonpath/internal/Log.java create mode 100644 json-path/src/test/java/com/jayway/jsonpath/LogTest.java create mode 100644 json-path/src/test/resources/logback-test.xml diff --git a/json-path-assert/pom.xml b/json-path-assert/pom.xml index 90f31315..7317e82d 100644 --- a/json-path-assert/pom.xml +++ b/json-path-assert/pom.xml @@ -31,11 +31,6 @@ ${project.version} - - net.minidev - json-smart - - org.hamcrest hamcrest-library @@ -46,10 +41,5 @@ hamcrest-core - - junit - junit - test - diff --git a/json-path/pom.xml b/json-path/pom.xml index 765ad701..84d775e1 100644 --- a/json-path/pom.xml +++ b/json-path/pom.xml @@ -26,8 +26,6 @@ json-path http://code.google.com/p/json-path/ - - net.minidev json-smart @@ -41,33 +39,6 @@ jackson-mapper-asl true - - - - - - - - - org.hamcrest - hamcrest-library - test - - - - junit - junit - test - - - - commons-io - commons-io - test - - - - diff --git a/json-path/src/main/java/com/jayway/jsonpath/Criteria.java b/json-path/src/main/java/com/jayway/jsonpath/Criteria.java index 84aa642f..2d35f620 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/Criteria.java +++ b/json-path/src/main/java/com/jayway/jsonpath/Criteria.java @@ -14,11 +14,13 @@ */ package com.jayway.jsonpath; +import com.jayway.jsonpath.spi.JsonProvider; +import org.apache.commons.lang3.Validate; + import java.util.*; import java.util.regex.Pattern; import static java.util.Arrays.asList; -import static org.apache.commons.lang3.Validate.notEmpty; import static org.apache.commons.lang3.Validate.notNull; /** @@ -40,6 +42,7 @@ public class Criteria { EXISTS, TYPE, REGEX, + NOT_EMPTY, OR } @@ -58,14 +61,14 @@ public class Criteria { private Criteria(String key) { - notEmpty(key, "key can not be null or empty"); + Validate.notEmpty(key, "key can not be null or empty"); this.criteriaChain = new ArrayList(); this.criteriaChain.add(this); this.key = JsonPath.compile(key); } private Criteria(List criteriaChain, String key) { - notEmpty(key, "key can not be null or empty"); + Validate.notEmpty(key, "key can not be null or empty"); this.criteriaChain = criteriaChain; this.criteriaChain.add(this); this.key = JsonPath.compile(key); @@ -226,6 +229,20 @@ public class Criteria { return (act.size() == exp); + } else if (CriteriaType.NOT_EMPTY.equals(key)) { + + if(actualVal == null){ + return false; + } + boolean empty = false; + if (actualVal instanceof Collection) { + empty = ((List) actualVal).isEmpty(); + } else if(actualVal instanceof String){ + empty = ((String) actualVal).isEmpty(); + } + + return !empty; + } else if (CriteriaType.EXISTS.equals(key)) { final boolean exp = (Boolean) expectedVal; @@ -506,6 +523,17 @@ public class Criteria { return this; } + /** + * The notEmpty operator checks that an array is not empty. + * + * @return + */ + public Criteria notEmpty() { + checkFilterCanBeApplied(CriteriaType.NOT_EMPTY); + criteria.put(CriteriaType.NOT_EMPTY, null); + return this; + } + /** * Check for existence (or lack thereof) of a field. * diff --git a/json-path/src/main/java/com/jayway/jsonpath/JsonPath.java b/json-path/src/main/java/com/jayway/jsonpath/JsonPath.java index e69cd649..1821525b 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/JsonPath.java +++ b/json-path/src/main/java/com/jayway/jsonpath/JsonPath.java @@ -16,6 +16,7 @@ package com.jayway.jsonpath; import com.jayway.jsonpath.internal.IOUtils; +import com.jayway.jsonpath.internal.Log; import com.jayway.jsonpath.internal.PathToken; import com.jayway.jsonpath.internal.PathTokenizer; import com.jayway.jsonpath.internal.filter.PathTokenFilter; @@ -98,37 +99,44 @@ import static org.apache.commons.lang3.Validate.*; */ public class JsonPath { - private static Pattern DEFINITE_PATH_PATTERN = Pattern.compile(".*(\\.\\.|\\*|\\[[\\\\/]|\\?|,|:\\s?\\]|\\[\\s?:|>|\\(|<|=|\\+).*"); + private static Pattern DEFINITE_PATH_PATTERN = Pattern.compile(".*(\\.\\.|\\*|\\[[\\\\/]|\\?|,|:\\s?]|\\[\\s?:|>|\\(|<|=|\\+).*"); + private static Pattern INVALID_PATH_PATTERN = Pattern.compile("[^\\?\\+=\\-\\*/!]\\("); + private PathTokenizer tokenizer; private LinkedList filters; - public JsonPath(String jsonPath, Filter[] filters) { - if (jsonPath == null || - jsonPath.trim().length() == 0 || - jsonPath.matches("[^\\?\\+\\=\\-\\*\\/\\!]\\(")) { + private JsonPath(String jsonPath, Filter[] filters) { + + notNull(jsonPath, "path can not be null"); + jsonPath = jsonPath.trim(); + notEmpty(jsonPath, "path can not be empty"); + if (INVALID_PATH_PATTERN.matcher(jsonPath).matches()) { throw new InvalidPathException("Invalid path"); } + int filterCountInPath = StringUtils.countMatches(jsonPath, "[?]"); isTrue(filterCountInPath == filters.length, "Filters in path ([?]) does not match provided filters."); this.tokenizer = new PathTokenizer(jsonPath); - //System.out.println(tokenizer.toString()); + if(Log.isDebugEnabled()){ + Log.debug("New JsonPath:\n{}", this.tokenizer.toString()); + } this.filters = new LinkedList(); this.filters.addAll(asList(filters)); } - PathTokenizer getTokenizer(){ + PathTokenizer getTokenizer() { return this.tokenizer; } - public JsonPath copy(){ + public JsonPath copy() { return new JsonPath(tokenizer.getPath(), filters.toArray(new Filter[0])); } @@ -199,7 +207,7 @@ public class JsonPath { * the {@link JsonProvider} * * @param jsonObject a container Object - * @param expected return type + * @param expected return type * @return list of objects matched by the given path */ @SuppressWarnings({"unchecked"}) @@ -213,8 +221,8 @@ public class JsonPath { * the {@link JsonProvider} * * @param jsonProvider JsonProvider to use - * @param jsonObject a container Object - * @param expected return type + * @param jsonObject a container Object + * @param expected return type * @return list of objects matched by the given path */ @SuppressWarnings({"unchecked"}) @@ -222,9 +230,9 @@ public class JsonPath { notNull(jsonProvider, "jsonProvider can not be null"); notNull(jsonObject, "json can not be null"); - if(this.getPath().equals("$")){ + if (this.getPath().equals("$")) { //This path only references the whole object. No need to do any work here... - return (T)jsonObject; + return (T) jsonObject; } if (!jsonProvider.isContainer(jsonObject)) { @@ -265,8 +273,8 @@ public class JsonPath { * Applies this JsonPath to the provided json string * * @param jsonProvider JsonProvider to use - * @param json a json string - * @param expected return type + * @param json a json string + * @param expected return type * @return list of objects matched by the given path */ @SuppressWarnings({"unchecked"}) @@ -294,8 +302,8 @@ public class JsonPath { * Applies this JsonPath to the provided json URL * * @param jsonProvider JsonProvider to use - * @param jsonURL url to read from - * @param expected return type + * @param jsonURL url to read from + * @param expected return type * @return list of objects matched by the given path * @throws IOException */ @@ -331,8 +339,8 @@ public class JsonPath { * Applies this JsonPath to the provided json file * * @param jsonProvider JsonProvider to use - * @param jsonFile file to read from - * @param expected return type + * @param jsonFile file to read from + * @param expected return type * @return list of objects matched by the given path * @throws IOException */ @@ -373,7 +381,7 @@ public class JsonPath { /** * Applies this JsonPath to the provided json input stream * - * @param jsonProvider JsonProvider to use + * @param jsonProvider JsonProvider to use * @param jsonInputStream input stream to read from * @param expected return type * @return list of objects matched by the given path @@ -401,7 +409,7 @@ public class JsonPath { * Compiles a JsonPath * * @param jsonPath to compile - * @param filters filters to be applied to the filter place holders [?] in the path + * @param filters filters to be applied to the filter place holders [?] in the path * @return compiled JsonPath */ public static JsonPath compile(String jsonPath, Filter... filters) { @@ -422,7 +430,7 @@ public class JsonPath { * * @param json a json string * @param jsonPath the json path - * @param filters filters to be applied to the filter place holders [?] in the path + * @param filters filters to be applied to the filter place holders [?] in the path * @param expected return type * @return list of objects matched by the given path */ @@ -436,10 +444,10 @@ public class JsonPath { * Creates a new JsonPath and applies it to the provided Json string * * @param jsonProvider JsonProvider to use - * @param json a json string - * @param jsonPath the json path - * @param filters filters to be applied to the filter place holders [?] in the path - * @param expected return type + * @param json a json string + * @param jsonPath the json path + * @param filters filters to be applied to the filter place holders [?] in the path + * @param expected return type * @return list of objects matched by the given path */ @SuppressWarnings({"unchecked"}) @@ -456,7 +464,7 @@ public class JsonPath { * * @param json a json object * @param jsonPath the json path - * @param filters filters to be applied to the filter place holders [?] in the path + * @param filters filters to be applied to the filter place holders [?] in the path * @param expected return type * @return list of objects matched by the given path */ @@ -464,14 +472,15 @@ public class JsonPath { public static T read(Object json, String jsonPath, Filter... filters) { return read(JsonProviderFactory.createProvider(), json, jsonPath, filters); } + /** * Creates a new JsonPath and applies it to the provided Json object * * @param jsonProvider JsonProvider to use - * @param json a json object - * @param jsonPath the json path - * @param filters filters to be applied to the filter place holders [?] in the path - * @param expected return type + * @param json a json object + * @param jsonPath the json path + * @param filters filters to be applied to the filter place holders [?] in the path + * @param expected return type * @return list of objects matched by the given path */ @SuppressWarnings({"unchecked"}) @@ -489,7 +498,7 @@ public class JsonPath { * * @param jsonURL url pointing to json doc * @param jsonPath the json path - * @param filters filters to be applied to the filter place holders [?] in the path + * @param filters filters to be applied to the filter place holders [?] in the path * @param expected return type * @return list of objects matched by the given path */ @@ -502,10 +511,10 @@ public class JsonPath { * Creates a new JsonPath and applies it to the provided Json object * * @param jsonProvider JsonProvider to use - * @param jsonURL url pointing to json doc - * @param jsonPath the json path - * @param filters filters to be applied to the filter place holders [?] in the path - * @param expected return type + * @param jsonURL url pointing to json doc + * @param jsonPath the json path + * @param filters filters to be applied to the filter place holders [?] in the path + * @param expected return type * @return list of objects matched by the given path */ @SuppressWarnings({"unchecked"}) @@ -520,9 +529,9 @@ public class JsonPath { /** * Creates a new JsonPath and applies it to the provided Json object * - * @param jsonFile json file + * @param jsonFile json file * @param jsonPath the json path - * @param filters filters to be applied to the filter place holders [?] in the path + * @param filters filters to be applied to the filter place holders [?] in the path * @param expected return type * @return list of objects matched by the given path */ @@ -535,10 +544,10 @@ public class JsonPath { * Creates a new JsonPath and applies it to the provided Json object * * @param jsonProvider JsonProvider to use - * @param jsonFile json file - * @param jsonPath the json path - * @param filters filters to be applied to the filter place holders [?] in the path - * @param expected return type + * @param jsonFile json file + * @param jsonPath the json path + * @param filters filters to be applied to the filter place holders [?] in the path + * @param expected return type * @return list of objects matched by the given path */ @SuppressWarnings({"unchecked"}) @@ -553,10 +562,10 @@ public class JsonPath { /** * Creates a new JsonPath and applies it to the provided Json object * - * @param jsonInputStream json input stream - * @param jsonPath the json path - * @param filters filters to be applied to the filter place holders [?] in the path - * @param expected return type + * @param jsonInputStream json input stream + * @param jsonPath the json path + * @param filters filters to be applied to the filter place holders [?] in the path + * @param expected return type * @return list of objects matched by the given path */ @SuppressWarnings({"unchecked"}) @@ -567,11 +576,11 @@ public class JsonPath { /** * Creates a new JsonPath and applies it to the provided Json object * - * @param jsonProvider JsonProvider to use - * @param jsonInputStream json input stream - * @param jsonPath the json path - * @param filters filters to be applied to the filter place holders [?] in the path - * @param expected return type + * @param jsonProvider JsonProvider to use + * @param jsonInputStream json input stream + * @param jsonPath the json path + * @param filters filters to be applied to the filter place holders [?] in the path + * @param expected return type * @return list of objects matched by the given path */ @SuppressWarnings({"unchecked"}) diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/Log.java b/json-path/src/main/java/com/jayway/jsonpath/internal/Log.java new file mode 100644 index 00000000..a37e68d9 --- /dev/null +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/Log.java @@ -0,0 +1,50 @@ +package com.jayway.jsonpath.internal; + +import org.apache.commons.lang3.StringUtils; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * User: kalle + * Date: 8/28/13 + * Time: 10:23 AM + */ +public final class Log { + + private Log() { + } + + private static boolean enabled = true; + + public static void enableDebug(){ + enabled = true; + } + + public static boolean isDebugEnabled(){ + return enabled; + } + + public static void debug(String msg, Object... args){ + if(enabled){ + + int argCount = StringUtils.countMatches(msg, "{}"); + + if(!(argCount == args.length)){ + throw new RuntimeException("Invalid debug statement."); + } + + StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace(); + + String cls = stackTraceElements[2].getClassName(); + + msg = msg.replaceFirst(Pattern.quote("{}"), "%s"); + + msg = String.format(msg, args); + + System.out.println("DEBUG [" + Thread.currentThread().getName() + "] " + cls + " " + msg); + } + + } + +} diff --git a/json-path/src/test/java/com/jayway/jsonpath/ExpressionEvalTest.java b/json-path/src/test/java/com/jayway/jsonpath/ExpressionEvalTest.java index fc101ad8..c79eb69b 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/ExpressionEvalTest.java +++ b/json-path/src/test/java/com/jayway/jsonpath/ExpressionEvalTest.java @@ -198,10 +198,7 @@ public class ExpressionEvalTest { result = JsonPath.read(DOCUMENT, "$.characters[?(@.offspring)]"); assertEquals(4, result.size()); - - - - } + } diff --git a/json-path/src/test/java/com/jayway/jsonpath/FilterTest.java b/json-path/src/test/java/com/jayway/jsonpath/FilterTest.java index 2ee3a0e2..6495bc9c 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/FilterTest.java +++ b/json-path/src/test/java/com/jayway/jsonpath/FilterTest.java @@ -1,7 +1,5 @@ package com.jayway.jsonpath; -import net.minidev.json.parser.JSONParser; - import org.junit.Test; import java.util.Collections; @@ -258,7 +256,7 @@ public class FilterTest { check.put("int", 10); check.put("long", 1L); check.put("double", 1.12D); - + Filter shouldMarch = filter(where("string").is("foo").and("int").lt(11)); Filter shouldNotMarch = filter(where("string").is("foo").and("int").gt(11)); @@ -318,107 +316,141 @@ public class FilterTest { @Test - public void arrays_of_maps_can_be_filtered() throws Exception { + public void arrays_of_maps_can_be_filtered() throws Exception { - Map rootGrandChild_A = new HashMap(); - rootGrandChild_A.put("name", "rootGrandChild_A"); + Map rootGrandChild_A = new HashMap(); + rootGrandChild_A.put("name", "rootGrandChild_A"); - Map rootGrandChild_B = new HashMap(); - rootGrandChild_B.put("name", "rootGrandChild_B"); + Map rootGrandChild_B = new HashMap(); + rootGrandChild_B.put("name", "rootGrandChild_B"); - Map rootGrandChild_C = new HashMap(); - rootGrandChild_C.put("name", "rootGrandChild_C"); + Map rootGrandChild_C = new HashMap(); + rootGrandChild_C.put("name", "rootGrandChild_C"); - Map rootChild_A = new HashMap(); - rootChild_A.put("name", "rootChild_A"); - rootChild_A.put("children", asList(rootGrandChild_A, rootGrandChild_B, rootGrandChild_C)); + Map rootChild_A = new HashMap(); + rootChild_A.put("name", "rootChild_A"); + rootChild_A.put("children", asList(rootGrandChild_A, rootGrandChild_B, rootGrandChild_C)); - Map rootChild_B = new HashMap(); - rootChild_B.put("name", "rootChild_B"); - rootChild_B.put("children", asList(rootGrandChild_A, rootGrandChild_B, rootGrandChild_C)); + Map rootChild_B = new HashMap(); + rootChild_B.put("name", "rootChild_B"); + rootChild_B.put("children", asList(rootGrandChild_A, rootGrandChild_B, rootGrandChild_C)); - Map rootChild_C = new HashMap(); - rootChild_C.put("name", "rootChild_C"); - rootChild_C.put("children", asList(rootGrandChild_A, rootGrandChild_B, rootGrandChild_C)); + Map rootChild_C = new HashMap(); + rootChild_C.put("name", "rootChild_C"); + rootChild_C.put("children", asList(rootGrandChild_A, rootGrandChild_B, rootGrandChild_C)); - Map root = new HashMap(); - root.put("children", asList(rootChild_A, rootChild_B, rootChild_C)); + Map root = new HashMap(); + root.put("children", asList(rootChild_A, rootChild_B, rootChild_C)); - - Filter customFilter = new Filter.FilterAdapter>() { - @Override - public boolean accept(Map map) { - if(map.get("name").equals("rootGrandChild_A")){ - return true; - } - return false; + Filter customFilter = new Filter.FilterAdapter>() { + @Override + public boolean accept(Map map) { + if (map.get("name").equals("rootGrandChild_A")) { + return true; } - }; + return false; + } + }; - Filter rootChildFilter = filter(where("name").regex(Pattern.compile("rootChild_[A|B]"))); - Filter rootGrandChildFilter = filter(where("name").regex(Pattern.compile("rootGrandChild_[A|B]"))); + Filter rootChildFilter = filter(where("name").regex(Pattern.compile("rootChild_[A|B]"))); + Filter rootGrandChildFilter = filter(where("name").regex(Pattern.compile("rootGrandChild_[A|B]"))); - List read = JsonPath.read(root, "children[?].children[?][?]", rootChildFilter, rootGrandChildFilter, customFilter); + List read = JsonPath.read(root, "children[?].children[?][?]", rootChildFilter, rootGrandChildFilter, customFilter); - System.out.println(read.size()); - } + System.out.println(read.size()); + } - @Test - public void arrays_of_objects_can_be_filtered() throws Exception { - Map doc = new HashMap(); - doc.put("items", asList(1, 2, 3)); + @Test + public void arrays_of_objects_can_be_filtered() throws Exception { + Map doc = new HashMap(); + doc.put("items", asList(1, 2, 3)); - Filter customFilter = new Filter.FilterAdapter(){ - @Override - public boolean accept(Object o) { - return 1 == (Integer)o; - } - }; + Filter customFilter = new Filter.FilterAdapter() { + @Override + public boolean accept(Object o) { + return 1 == (Integer) o; + } + }; - List res = JsonPath.read(doc, "$.items[?]", customFilter); + List res = JsonPath.read(doc, "$.items[?]", customFilter); - assertEquals(1, res.get(0).intValue()); - } - - @Test - public void filters_can_contain_json_path_expressions() throws Exception { - Object doc = JsonModel.model(DOCUMENT).getJsonObject(); - - assertTrue(filter(where("$.store..price").gt(10)).accept(doc)); - assertFalse(filter(where("$.store..price").gte(100)).accept(doc)); - assertTrue(filter(where("$.store..category").ne("fiction")).accept(doc)); - assertFalse(filter(where("$.store.bicycle.color").ne("red")).accept(doc)); - assertTrue(filter(where("$.store.bicycle.color").ne("blue")).accept(doc)); - assertTrue(filter(where("$.store..color").exists(true)).accept(doc)); - assertFalse(filter(where("$.store..flavor").exists(true)).accept(doc)); - assertTrue(filter(where("$.store..color").regex(Pattern.compile("^r.d$"))).accept(doc)); - assertTrue(filter(where("$.store..color").type(String.class)).accept(doc)); - assertTrue(filter(where("$.store..price").is(12.99)).accept(doc)); - assertFalse(filter(where("$.store..price").is(13.99)).accept(doc)); - - } - - @Test - public void collection_based_filters_cannot_be_applied_to_multi_level_expressions(){ - - try{ + assertEquals(1, res.get(0).intValue()); + } + + @Test + public void filters_can_contain_json_path_expressions() throws Exception { + Object doc = JsonModel.model(DOCUMENT).getJsonObject(); + + assertTrue(filter(where("$.store..price").gt(10)).accept(doc)); + assertFalse(filter(where("$.store..price").gte(100)).accept(doc)); + assertTrue(filter(where("$.store..category").ne("fiction")).accept(doc)); + assertFalse(filter(where("$.store.bicycle.color").ne("red")).accept(doc)); + assertTrue(filter(where("$.store.bicycle.color").ne("blue")).accept(doc)); + assertTrue(filter(where("$.store..color").exists(true)).accept(doc)); + assertFalse(filter(where("$.store..flavor").exists(true)).accept(doc)); + assertTrue(filter(where("$.store..color").regex(Pattern.compile("^r.d$"))).accept(doc)); + assertTrue(filter(where("$.store..color").type(String.class)).accept(doc)); + assertTrue(filter(where("$.store..price").is(12.99)).accept(doc)); + assertFalse(filter(where("$.store..price").is(13.99)).accept(doc)); + + } + + @Test + public void not_empty_filter_evaluates() { + + String json = "{\n" + + " \"fields\": [\n" + + " {\n" + + " \"errors\": [], \n" + + " \"name\": \"\", \n" + + " \"empty\": true \n" + + " }, \n" + + " {\n" + + " \"errors\": [], \n" + + " \"name\": \"foo\"\n" + + " }, \n" + + " {\n" + + " \"errors\": [\n" + + " \"first\", \n" + + " \"second\"\n" + + " ], \n" + + " \"name\": \"invalid\"\n" + + " }\n" + + " ]\n" + + "}\n"; + + Object doc = JsonModel.model(json).getJsonObject(); + + List> result = JsonPath.read(doc, "$.fields[?]", filter(where("errors").notEmpty())); + assertEquals(1, result.size()); + System.out.println(result); + + result = JsonPath.read(doc, "$.fields[?]", filter(where("name").notEmpty())); + assertEquals(2, result.size()); + System.out.println(result); + } + + @Test + public void collection_based_filters_cannot_be_applied_to_multi_level_expressions() { + + try { where("$.store.*").size(4); fail("This should have thrown an exception"); - } catch(IllegalArgumentException e){ - - } - - try{ + } catch (IllegalArgumentException e) { + + } + + try { where("$.store.*").in("foo"); fail("This should have thrown an exception"); - } catch(IllegalArgumentException e){ - - } + } catch (IllegalArgumentException e) { + } + } } diff --git a/json-path/src/test/java/com/jayway/jsonpath/JsonPathTest.java b/json-path/src/test/java/com/jayway/jsonpath/JsonPathTest.java index 341d7965..593d9914 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/JsonPathTest.java +++ b/json-path/src/test/java/com/jayway/jsonpath/JsonPathTest.java @@ -77,6 +77,23 @@ public class JsonPathTest { private final static String ARRAY_EXPAND = "[{\"parent\": \"ONE\", \"child\": {\"name\": \"NAME_ONE\"}}, [{\"parent\": \"TWO\", \"child\": {\"name\": \"NAME_TWO\"}}]]"; + @Test + public void bracket_notation_with_dots() { + String json = "{\n" + + " \"store\": {\n" + + " \"book\": [\n" + + " {\n" + + " \"author.name\": \"Nigel Rees\", \n" + + " \"category\": \"reference\", \n" + + " \"price\": 8.95, \n" + + " \"title\": \"Sayings of the Century\"\n" + + " }\n" + + " ]\n" + + " }\n" + + "}"; + + assertEquals("Nigel Rees", JsonPath.read(json, "$.store.book[0]['author.name']")); + } @Test public void null_object_in_path() { diff --git a/json-path/src/test/java/com/jayway/jsonpath/LogTest.java b/json-path/src/test/java/com/jayway/jsonpath/LogTest.java new file mode 100644 index 00000000..cd3b9b9b --- /dev/null +++ b/json-path/src/test/java/com/jayway/jsonpath/LogTest.java @@ -0,0 +1,22 @@ +package com.jayway.jsonpath; + +import com.jayway.jsonpath.internal.Log; +import org.junit.Test; + +/** + * User: kalle + * Date: 8/28/13 + * Time: 10:40 AM + */ +public class LogTest { + + + @Test + public void logger_expands_templates() { + + Log.enableDebug(); + + Log.debug("foo \n{}", "bar"); + + } +} diff --git a/json-path/src/test/java/com/jayway/jsonpath/internal/filter/ArrayEvalFilterTest.java b/json-path/src/test/java/com/jayway/jsonpath/internal/filter/ArrayEvalFilterTest.java index 80770dd5..562ad085 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/internal/filter/ArrayEvalFilterTest.java +++ b/json-path/src/test/java/com/jayway/jsonpath/internal/filter/ArrayEvalFilterTest.java @@ -14,6 +14,8 @@ public class ArrayEvalFilterTest { @Test public void condition_statements_can_be_parsed() { + assertEquals(new ArrayEvalFilter.ConditionStatement("@.length", ">", "0"), ArrayEvalFilter.createConditionStatement("[?(@.length>0)]")); + //int array assertEquals(new ArrayEvalFilter.ConditionStatement("@", "==", "5"), ArrayEvalFilter.createConditionStatement("[?(@==5)]")); assertEquals(new ArrayEvalFilter.ConditionStatement("@", "==", "5"), ArrayEvalFilter.createConditionStatement("[?(@ == 5)]")); diff --git a/json-path/src/test/resources/logback-test.xml b/json-path/src/test/resources/logback-test.xml new file mode 100644 index 00000000..5c536ae4 --- /dev/null +++ b/json-path/src/test/resources/logback-test.xml @@ -0,0 +1,15 @@ + + + myAppName + + + %-5level [%t] %logger{36} - %msg%n + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index f2f6ba63..20a3680a 100644 --- a/pom.xml +++ b/pom.xml @@ -55,6 +55,15 @@ master UTF-8 + + 1.7.5 + 1.0.13 + 4.10 + 2.4 + 3.1 + 1.3 + 1.9.11 + 1.2 http://github.com/jayway/JsonPath/tree/${scm.branch} @@ -65,7 +74,7 @@ JsonPath mailing-list - http://groups.google.com/group/json-path/topics + https://groups.google.com/forum/#!forum/jsonpath @@ -183,48 +192,109 @@ net.minidev json-smart - 1.2 + ${json-smart.version} org.apache.commons commons-lang3 - 3.1 + ${commons-lang.version} org.codehaus.jackson jackson-mapper-asl - true - 1.9.11 + ${jackson.version} org.hamcrest hamcrest-library - 1.3 + ${hamcrest.version} org.hamcrest hamcrest-core - 1.3 + ${hamcrest.version} - - junit - junit - 4.10 - test - - commons-io commons-io - 2.4 - test + ${commons-io.version} + + + + org.slf4j + slf4j-api + ${slf4j.version} + + + + ch.qos.logback + logback-classic + ${logback.version} + + + + junit + junit + ${junit.version} + + + + + + + + + commons-io + commons-io + test + + + + org.slf4j + slf4j-api + test + + + + ch.qos.logback + logback-classic + test + + + + org.hamcrest + hamcrest-core + test + + + + org.hamcrest + hamcrest-library + test + + + + junit + junit + test + + + \ No newline at end of file