diff --git a/json-path-assert/pom.xml b/json-path-assert/pom.xml index 4febfadc..bae633d3 100644 --- a/json-path-assert/pom.xml +++ b/json-path-assert/pom.xml @@ -19,5 +19,21 @@ json-path ${project.version} + + + junit + junit + test + + + + com.googlecode.json-simple + json-simple + + + + org.hamcrest + hamcrest-all + diff --git a/json-path-assert/src/main/java/com/jayway/jsonassert/JsonAssert.java b/json-path-assert/src/main/java/com/jayway/jsonassert/JsonAssert.java new file mode 100644 index 00000000..d55eb299 --- /dev/null +++ b/json-path-assert/src/main/java/com/jayway/jsonassert/JsonAssert.java @@ -0,0 +1,66 @@ +package com.jayway.jsonassert; + + +import com.jayway.jsonassert.impl.JsonAsserterImpl; +import org.json.simple.parser.JSONParser; + +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.text.ParseException; + +/** + * User: kalle stenflo + * Date: 1/24/11 + * Time: 9:31 PM + */ +public class JsonAssert { + + private static final JSONParser JSON_PARSER = new JSONParser(); + + /** + * Creates a JSONAsserter + * + * @param json the JSON document to create a JSONAsserter for + * @return a JSON asserter initialized with the provided document + * @throws ParseException when the given JSON could not be parsed + */ + public static JsonAsserter with(String json) throws ParseException { + try { + return new JsonAsserterImpl(JSON_PARSER.parse(json)); + } catch (org.json.simple.parser.ParseException e) { + throw new ParseException(json, e.getPosition()); + } + } + + /** + * Creates a JSONAsserter + * + * @param reader the reader of the json document + * @return a JSON asserter initialized with the provided document + * @throws ParseException when the given JSON could not be parsed + */ + public static JsonAsserter with(Reader reader) throws ParseException, IOException { + try { + return new JsonAsserterImpl(JSON_PARSER.parse(reader)); + } catch (org.json.simple.parser.ParseException e) { + throw new ParseException(e.toString(), e.getPosition()); + } finally { + reader.close(); + } + } + + /** + * Creates a JSONAsserter + * + * @param is the input stream + * @return a JSON asserter initialized with the provided document + * @throws ParseException when the given JSON could not be parsed + */ + public static JsonAsserter with(InputStream is) throws ParseException, IOException { + Reader reader = new InputStreamReader(is); + return with(reader); + } + +} diff --git a/json-path/src/main/java/com/jayway/jsonassert/JsonAsserter.java b/json-path-assert/src/main/java/com/jayway/jsonassert/JsonAsserter.java similarity index 93% rename from json-path/src/main/java/com/jayway/jsonassert/JsonAsserter.java rename to json-path-assert/src/main/java/com/jayway/jsonassert/JsonAsserter.java index 27b28c3f..0f0024ab 100644 --- a/json-path/src/main/java/com/jayway/jsonassert/JsonAsserter.java +++ b/json-path-assert/src/main/java/com/jayway/jsonassert/JsonAsserter.java @@ -9,13 +9,6 @@ import org.hamcrest.Matcher; */ public interface JsonAsserter { - /** - * Gives access to the {@link JsonPath} used to base the assertions on - * - * @return the underlying reader - */ - JsonPath reader(); - /** * Asserts that object specified by path satisfies the condition specified by matcher. * If not, an AssertionError is thrown with information about the matcher diff --git a/json-path/src/main/java/com/jayway/jsonassert/impl/JsonAsserterImpl.java b/json-path-assert/src/main/java/com/jayway/jsonassert/impl/JsonAsserterImpl.java similarity index 66% rename from json-path/src/main/java/com/jayway/jsonassert/impl/JsonAsserterImpl.java rename to json-path-assert/src/main/java/com/jayway/jsonassert/impl/JsonAsserterImpl.java index 80c9a5c3..111bd247 100644 --- a/json-path/src/main/java/com/jayway/jsonassert/impl/JsonAsserterImpl.java +++ b/json-path-assert/src/main/java/com/jayway/jsonassert/impl/JsonAsserterImpl.java @@ -2,10 +2,14 @@ package com.jayway.jsonassert.impl; import com.jayway.jsonassert.JsonAsserter; -import com.jayway.jsonassert.JsonPath; +import com.jayway.jsonpath.JsonPath; +import com.jayway.jsonpath.PathUtil; import org.hamcrest.Matcher; import org.hamcrest.MatcherAssert; +import java.text.ParseException; +import java.util.List; + import static org.hamcrest.Matchers.*; /** @@ -15,31 +19,34 @@ import static org.hamcrest.Matchers.*; */ public class JsonAsserterImpl implements JsonAsserter { - private final JsonPath reader; + + + private final Object jsonObject; /** * Instantiates a new JSONAsserter * - * @param reader initialized with the JSON document to be asserted upon + * @param jsonObject the object to make asserts on */ - public JsonAsserterImpl(JsonPath reader) { - this.reader = reader; + public JsonAsserterImpl(Object jsonObject) { + this.jsonObject = jsonObject; } - /** - * {@inheritDoc} - */ - public JsonPath reader() { - return reader; - } + /** * {@inheritDoc} */ @SuppressWarnings("unchecked") public JsonAsserter assertThat(String path, Matcher matcher) { - MatcherAssert.assertThat((T) reader.get(path), matcher); + + if(PathUtil.isPathDefinite(path)){ + MatcherAssert.assertThat(JsonPath.readOne(jsonObject, path), matcher); + } + else { + MatcherAssert.assertThat((T) JsonPath.read(jsonObject, path), matcher); + } return this; } diff --git a/json-path-assert/src/test/java/com/jayway/jsonassert/JsonAssertTest.java b/json-path-assert/src/test/java/com/jayway/jsonassert/JsonAssertTest.java new file mode 100644 index 00000000..dc6802d4 --- /dev/null +++ b/json-path-assert/src/test/java/com/jayway/jsonassert/JsonAssertTest.java @@ -0,0 +1,115 @@ +package com.jayway.jsonassert; + +import org.junit.Test; + +import static com.jayway.jsonassert.JsonAssert.with; +import static org.hamcrest.Matchers.*; + +/** + * User: kalle stenflo + * Date: 1/21/11 + * Time: 4:04 PM + */ +public class JsonAssertTest { + + public final static String JSON = + "{ \"store\": {\n" + + " \"book\": [ \n" + + " { \"category\": \"reference\",\n" + + " \"author\": \"Nigel Rees\",\n" + + " \"title\": \"Sayings of the Century\",\n" + + " \"price\": 8.95\n" + + " },\n" + + " { \"category\": \"fiction\",\n" + + " \"author\": \"Evelyn Waugh\",\n" + + " \"title\": \"Sword of Honour\",\n" + + " \"price\": 12.99\n" + + " },\n" + + " { \"category\": \"fiction\",\n" + + " \"author\": \"Herman Melville\",\n" + + " \"title\": \"Moby Dick\",\n" + + " \"isbn\": \"0-553-21311-3\",\n" + + " \"price\": 8.99\n" + + " },\n" + + " { \"category\": \"fiction\",\n" + + " \"author\": \"J. R. R. Tolkien\",\n" + + " \"title\": \"The Lord of the Rings\",\n" + + " \"isbn\": \"0-395-19395-8\",\n" + + " \"price\": 22.99\n" + + " }\n" + + " ],\n" + + " \"bicycle\": {\n" + + " \"color\": \"red\",\n" + + " \"price\": 19.95\n" + + " }\n" + + " }\n" + + "}"; + + @Test + public void a_path_can_be_asserted_with_matcher() throws Exception { + + with(JSON).assertThat("$.store.bicycle.color", equalTo("red")) + .assertThat("$.store.bicycle.price", equalTo(19.95D)); + } + + @Test + public void list_content_can_be_asserted_with_matcher() throws Exception { + + with(JSON).assertThat("$..book[*].author", hasItems("Nigel Rees", "Evelyn Waugh", "Herman Melville", "J. R. R. Tolkien")); + } + + @Test + public void map_content_can_be_asserted_with_matcher() throws Exception { + + with(JSON).assertThat("$.store.book[0]", hasEntry("category", "reference")) + .assertThat("$.store.book[0]", hasEntry("title", "Sayings of the Century")); + } + + @Test + public void a_path_can_be_asserted_equal_to() throws Exception { + + with(JSON).assertEquals("$.store.book[0].title", "Sayings of the Century") + .assertThat("$.store.book[0].title", equalTo("Sayings of the Century")); + } + + + /* + @Test + public void a_sub_document_can_asserted_on__by_path() throws Exception { + JsonAssert.with(TEST_DOCUMENT).assertThat("subDocument.subField", is(equalTo("sub-field"))); + } + + @Test + public void a_path_can_be_asserted_equal_to() throws Exception { + + JsonAssert.with(TEST_DOCUMENT).assertEquals("stringField", "string-field"); + } + + @Test + public void a_path_can_be_asserted_is_null() throws Exception { + + JsonAssert.with(TEST_DOCUMENT).assertNull("nullField"); + } + + @Test(expected = AssertionError.class) + public void failed_assert_throws() throws Exception { + + JsonAssert.with(TEST_DOCUMENT).assertThat("stringField", equalTo("SOME CRAP")); + } + + @Test + public void multiple_asserts_can_be_chained() throws Exception { + + JsonAssert.with(TEST_DOCUMENT) + .assertThat("stringField", equalTo("string-field")) + .assertThat("numberField", is(notNullValue())) + .and() + .assertNull("nullField") + .and() + .assertEquals("stringField", "string-field"); + + } + */ + + +} diff --git a/json-path/pom.xml b/json-path/pom.xml index 96952770..06ac6556 100644 --- a/json-path/pom.xml +++ b/json-path/pom.xml @@ -30,20 +30,11 @@ http://maven.apache.org - - commons-jxpath - commons-jxpath - - com.googlecode.json-simple json-simple - - org.hamcrest - hamcrest-all - commons-lang @@ -59,5 +50,10 @@ test + + org.hamcrest + hamcrest-all + + diff --git a/json-path/src/main/java/com/jayway/jsonassert/JsonAssert.java b/json-path/src/main/java/com/jayway/jsonassert/JsonAssert.java deleted file mode 100644 index a171378d..00000000 --- a/json-path/src/main/java/com/jayway/jsonassert/JsonAssert.java +++ /dev/null @@ -1,84 +0,0 @@ -package com.jayway.jsonassert; - -import com.jayway.jsonassert.impl.JsonAsserterImpl; -import com.jayway.jsonassert.impl.JsonPathImpl; - -import java.io.IOException; -import java.io.Reader; -import java.text.ParseException; - -/** - * User: kalle stenflo - * Date: 1/24/11 - * Time: 9:31 PM - */ -public class JsonAssert { - - /** - * Creates a JSONReader - * - * @param jsonDoc the json document to read - * @return a new reader - * @throws ParseException - */ - public static JsonPath parse(String jsonDoc) throws ParseException { - return JsonPathImpl.parse(jsonDoc); - } - - /** - * Creates a JSONReader - * - * @param reader he json document to read - * @return a new reader - * @throws ParseException document could not pe parsed - * @throws IOException - */ - public static JsonPath parse(Reader reader) throws ParseException, IOException { - return parse(reader, false); - } - - /** - * Creates a JSONReader - * - * @param reader he json document to read - * @return a new reader - * @throws ParseException document could not pe parsed - * @throws IOException - */ - public static JsonPath parse(Reader reader, boolean closeReader) throws ParseException, IOException { - JsonPath jsonReader = null; - try { - jsonReader = JsonPathImpl.parse(reader); - } finally { - if(closeReader){ - try { - reader.close(); - } catch (IOException ignore) {} - } - } - return jsonReader; - } - - /** - * Creates a JSONAsserter - * - * @param json the JSON document to create a JSONAsserter for - * @return a JSON asserter initialized with the provided document - * @throws ParseException when the given JSON could not be parsed - */ - public static JsonAsserter with(String json) throws ParseException { - return new JsonAsserterImpl(JsonPathImpl.parse(json)); - } - - /** - * Creates a JSONAsserter - * - * @param reader the reader of the json document - * @return a JSON asserter initialized with the provided document - * @throws ParseException when the given JSON could not be parsed - */ - public static JsonAsserter with(Reader reader) throws ParseException, IOException { - return new JsonAsserterImpl(JsonPathImpl.parse(reader)); - } - -} 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 26188ea3..3586ea10 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/JsonPath.java +++ b/json-path/src/main/java/com/jayway/jsonpath/JsonPath.java @@ -50,7 +50,7 @@ public class JsonPath { return path.read(json); } - public static List read(Object json, String jsonPath) throws java.text.ParseException { + public static List read(Object json, String jsonPath) { JsonPath path = compile(jsonPath); return path.read(json); @@ -68,7 +68,7 @@ public class JsonPath { return (T) result.get(0); } - public static T readOne(Object json, String jsonPath) throws java.text.ParseException { + public static T readOne(Object json, String jsonPath) { JsonPath path = compile(jsonPath); List result = read(json, jsonPath); diff --git a/json-path/src/main/java/com/jayway/jsonpath/PathItem.java b/json-path/src/main/java/com/jayway/jsonpath/PathItem.java deleted file mode 100644 index df3b29a6..00000000 --- a/json-path/src/main/java/com/jayway/jsonpath/PathItem.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.jayway.jsonpath; - -/** - * Created by IntelliJ IDEA. - * User: kallestenflo - * Date: 2/2/11 - * Time: 2:33 PM - */ -public class PathItem { - - private final String path; - - private final Object target; - - public PathItem(String path, Object target) { - this.path = path; - this.target = target; - } - - public String getPath() { - return path; - } - - public Object getTarget() { - return target; - } - - -} diff --git a/json-path/src/main/java/com/jayway/jsonpath/PathUtil.java b/json-path/src/main/java/com/jayway/jsonpath/PathUtil.java index c83be718..d29d4041 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/PathUtil.java +++ b/json-path/src/main/java/com/jayway/jsonpath/PathUtil.java @@ -14,6 +14,10 @@ import java.util.List; */ public class PathUtil { + public static boolean isPathDefinite(String jsonPath) { + return !jsonPath.replaceAll("\"[^\"\\\\\\n\r]*\"", "").matches(".*(\\.\\.|\\*|\\[[\\\\/]|\\?|,|:|>|\\(|<|=|\\+).*"); + } + public static boolean isContainer(Object obj) { return (isArray(obj) || isDocument(obj)); } @@ -50,7 +54,7 @@ public class PathUtil { String[] split = jsonPath.split("\\."); for (int i = 0; i < split.length; i++) { - if(split[i].trim().isEmpty()){ + if (split[i].trim().isEmpty()) { continue; } fragments.add(split[i].replace("@", "@.").replace("~", "..")); diff --git a/json-path/src/main/java/com/jayway/jsonpath/filter/ListFilter.java b/json-path/src/main/java/com/jayway/jsonpath/filter/ListFilter.java index 7227de35..7048bb98 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/filter/ListFilter.java +++ b/json-path/src/main/java/com/jayway/jsonpath/filter/ListFilter.java @@ -2,7 +2,11 @@ package com.jayway.jsonpath.filter; import com.jayway.jsonpath.PathUtil; import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import javax.script.ScriptEngine; +import javax.script.ScriptEngineManager; +import javax.script.ScriptException; import java.util.LinkedList; import java.util.List; import java.util.regex.Matcher; @@ -16,6 +20,8 @@ import java.util.regex.Pattern; */ public class ListFilter extends JsonPathFilterBase { + private static ScriptEngine SCRIPT_ENGINE = new ScriptEngineManager().getEngineByName("js"); + private static final Pattern LIST_INDEX_PATTERN = Pattern.compile("\\[(\\s?\\d+\\s?,?)+\\]"); private static final Pattern LIST_PULL_PATTERN = Pattern.compile("\\[\\s?:(\\d+)\\s?\\]"); //[ :2 ] private static final Pattern LIST_WILDCARD_PATTERN = Pattern.compile("\\[\\*\\]"); @@ -23,6 +29,7 @@ public class ListFilter extends JsonPathFilterBase { private static final Pattern LIST_TAIL_PATTERN_LONG = Pattern.compile("\\[\\s*\\(\\s*@\\.length\\s*-\\s*(\\d+)\\s*\\)\\s*\\]"); private static final Pattern LIST_TAIL_PATTERN = Pattern.compile("(" + LIST_TAIL_PATTERN_SHORT.pattern() + "|" + LIST_TAIL_PATTERN_LONG.pattern() + ")"); private static final Pattern LIST_ITEM_HAS_PROPERTY_PATTERN = Pattern.compile("\\[\\s?\\?\\s?\\(\\s?@\\.(\\w+)\\s?\\)\\s?\\]"); + private static final Pattern LIST_ITEM_MATCHES_EVAL = Pattern.compile("\\[\\s?\\?\\s?\\(\\s?@.(\\w+)\\s?([=<>]+)\\s?(.*)\\s?\\)\\s?\\]"); //[ ?( @.title< 'ko' ) ] private final String pathFragment; @@ -42,13 +49,30 @@ public class ListFilter extends JsonPathFilterBase { return filterByListTailIndex(items); } else if (LIST_PULL_PATTERN.matcher(pathFragment).matches()) { return filterByPullIndex(items); - } else if (LIST_ITEM_HAS_PROPERTY_PATTERN.matcher(pathFragment).matches()){ + } else if (LIST_ITEM_HAS_PROPERTY_PATTERN.matcher(pathFragment).matches()) { return filterByItemProperty(items); } + else if (LIST_ITEM_MATCHES_EVAL.matcher(pathFragment).matches()) { + return filterByItemEvalMatch(items); + } return result; } + private List filterByItemEvalMatch(List items) { + List result = new JSONArray(); + + for (Object current : items) { + for (Object item : PathUtil.toArray(current)) { + if(isEvalMatch(item)){ + result.add(item); + } + } + } + return result; + } + + private List filterByItemProperty(List items) { List result = new JSONArray(); @@ -114,7 +138,52 @@ public class ListFilter extends JsonPathFilterBase { return result; } - private String getFilterProperty(){ + private boolean isEvalMatch(Object check) { + Matcher matcher = LIST_ITEM_MATCHES_EVAL.matcher(pathFragment); + + if (matcher.matches()) { + String property = matcher.group(1); + String operator = matcher.group(2); + String expected = matcher.group(3); + + if(!PathUtil.isDocument(check)){ + return false; + } + JSONObject obj = PathUtil.toDocument(check); + + if(!obj.containsKey(property)){ + return false; + } + + Object propertyValue = obj.get(property); + + if(PathUtil.isContainer(propertyValue)){ + return false; + } + + + if(propertyValue instanceof String){ + propertyValue = "'" + propertyValue + "'"; + } + + if(operator.trim().equals("=")){ + operator = "==="; + } + + + String expression = propertyValue + " " + operator + " " + expected; + System.out.println("EVAL" + expression); + + try { + return (Boolean) SCRIPT_ENGINE.eval(expression); + } catch (ScriptException e) { + return false; + } + } + return false; + } + + private String getFilterProperty() { Matcher matcher = LIST_ITEM_HAS_PROPERTY_PATTERN.matcher(pathFragment); if (matcher.matches()) { return matcher.group(1); diff --git a/json-path/src/test/java/com/jayway/ScriptTest.java b/json-path/src/test/java/com/jayway/ScriptTest.java new file mode 100644 index 00000000..5d4ae10e --- /dev/null +++ b/json-path/src/test/java/com/jayway/ScriptTest.java @@ -0,0 +1,25 @@ +package com.jayway; + +import org.junit.Test; + +import javax.script.ScriptEngine; +import javax.script.ScriptEngineManager; + +/** + * Created by IntelliJ IDEA. + * User: kallestenflo + * Date: 2/3/11 + * Time: 8:52 PM + */ +public class ScriptTest { + + + @Test + public void script() throws Exception { + ScriptEngineManager manager = new ScriptEngineManager(); + ScriptEngine engine = manager.getEngineByName("js"); + + System.out.println(engine.eval("1 === 2")); + System.out.println(engine.eval("'APA' === 'APA'").getClass()); + } +} diff --git a/json-path/src/test/java/com/jayway/jsonassert/JsonAssertTest.java b/json-path/src/test/java/com/jayway/jsonassert/JsonAssertTest.java deleted file mode 100644 index 55b08f93..00000000 --- a/json-path/src/test/java/com/jayway/jsonassert/JsonAssertTest.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.jayway.jsonassert; - -import org.junit.Test; - -import static org.hamcrest.Matchers.*; - -/** - * User: kalle stenflo - * Date: 1/21/11 - * Time: 4:04 PM - */ -public class JsonAssertTest { - - private static String TEST_DOCUMENT = "{ \"nullField\" : null \"stringField\" : \"string-field\" , \"numberField\" : 1234 , \"booleanField\" : true , \"subDocument\" : {\"subField\" : \"sub-field\"} , \"stringList\" : [\"ONE\", \"TWO\"], \"objectList\" : [{\"subField\" : \"sub-field-0\"}, {\"subField\" : \"sub-field-1\"}], \"listList\" : [[\"0.0\", \"0.1\"], [\"1.0\", \"1.1\"]], }"; - - - @Test - public void a_path_can_be_asserted_with_matcher() throws Exception { - - JsonAssert.with(TEST_DOCUMENT).assertThat("stringField", equalTo("string-field")); - } - - @Test - public void list_content_can_be_asserted_with_matcher() throws Exception { - - JsonAssert.with(TEST_DOCUMENT).assertThat("stringList", hasItems("ONE", "TWO")); - } - - @Test - public void map_content_can_be_asserted_with_matcher() throws Exception { - - JsonAssert.with(TEST_DOCUMENT).assertThat("subDocument", hasEntry("subField", "sub-field")); - } - - @Test - public void a_sub_document_can_asserted_on__by_path() throws Exception { - JsonAssert.with(TEST_DOCUMENT).assertThat("subDocument.subField", is(equalTo("sub-field"))); - } - - @Test - public void a_path_can_be_asserted_equal_to() throws Exception { - - JsonAssert.with(TEST_DOCUMENT).assertEquals("stringField", "string-field"); - } - - @Test - public void a_path_can_be_asserted_is_null() throws Exception { - - JsonAssert.with(TEST_DOCUMENT).assertNull("nullField"); - } - - @Test(expected = AssertionError.class) - public void failed_assert_throws() throws Exception { - - JsonAssert.with(TEST_DOCUMENT).assertThat("stringField", equalTo("SOME CRAP")); - } - - @Test - public void multiple_asserts_can_be_chained() throws Exception { - - JsonAssert.with(TEST_DOCUMENT) - .assertThat("stringField", equalTo("string-field")) - .assertThat("numberField", is(notNullValue())) - .and() - .assertNull("nullField") - .and() - .assertEquals("stringField", "string-field"); - - } - - -} 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 c1e7bd39..c4bf9449 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/JsonPathTest.java +++ b/json-path/src/test/java/com/jayway/jsonpath/JsonPathTest.java @@ -123,7 +123,6 @@ public class JsonPathTest { assertThat(JsonPath.read(DOCUMENT, "$.store.book[0,1].author"), hasItems("Nigel Rees", "Evelyn Waugh")); assertTrue(JsonPath.read(DOCUMENT, "$.store.book[0,1].author").size() == 2); } - @Test public void read_store_book_pull_first_2() throws Exception { @@ -131,6 +130,7 @@ public class JsonPathTest { assertTrue(JsonPath.read(DOCUMENT, "$.store.book[:2].author").size() == 2); } + @Test public void read_store_book_filter_by_isbn() throws Exception { @@ -138,6 +138,16 @@ public class JsonPathTest { assertTrue(JsonPath.read(DOCUMENT, "$.store.book[?(@.isbn)].isbn").size() == 2); } + @Test + public void all_books_cheapier_than_10() throws Exception { + + assertThat(JsonPath.read(DOCUMENT, "$.store.book[?(@.price < 10)].title"), hasItems("Sayings of the Century", "Moby Dick")); + + + assertThat(JsonPath.read(DOCUMENT, "$.store.book[?(@.category = 'reference')].title"), hasItems("Sayings of the Century")); + + } + @Test public void all_members_of_all_documents() throws Exception { diff --git a/json-path/src/test/java/com/jayway/jsonpath/PathUtilTest.java b/json-path/src/test/java/com/jayway/jsonpath/PathUtilTest.java new file mode 100644 index 00000000..a609e8d4 --- /dev/null +++ b/json-path/src/test/java/com/jayway/jsonpath/PathUtilTest.java @@ -0,0 +1,22 @@ +package com.jayway.jsonpath; + +import org.junit.Test; + +import static org.junit.Assert.assertFalse; + +/** + * Created by IntelliJ IDEA. + * User: kallestenflo + * Date: 2/3/11 + * Time: 9:58 PM + */ +public class PathUtilTest { + + + @Test + public void wildcard_is_not_definite() throws Exception { + assertFalse(PathUtil.isPathDefinite("$..book[0]")); + } + + +} diff --git a/pom.xml b/pom.xml index f44cf5d2..6d52cdc6 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,9 @@ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ~ See the License for the specific language governing permissions and ~ limitations under the License. - --> + --> + 4.0.0 org.sonatype.oss @@ -24,9 +26,9 @@ json-path-parent pom 1.0-SNAPSHOT - http://code.google.com/p/rest-assured + http://code.google.com/p/json-path json-path-parent-pom - Java DSL for easy testing and reading of JSON data + Java JsonPath implementation 2011 GitHub Issue Tracking @@ -56,23 +58,23 @@ UTF-8 - http://github.com/jayway/json-assert/tree/${scm.branch} - scm:git:git://github.com/jayway/json-assert.git - scm:git:ssh://git@github.com/jayway/json-assert.git + http://github.com/jayway/JsonPath/tree/${scm.branch} + scm:git:git://github.com/jayway/JsonPath.git + scm:git:ssh://git@github.com/jayway/JsonPath.git - json-assert mailing-list - http://groups.google.com/group/rest-assured/topics + JsonPath mailing-list + http://groups.google.com/group/json-path/topics json-path examples - json-path-assert - + json-path-assert + @@ -129,12 +131,6 @@ - - commons-jxpath - commons-jxpath - 1.3 - - com.googlecode.json-simple json-simple