Browse Source

Clean up tests.

pull/48/head
Kalle Stenflo 10 years ago
parent
commit
3386f1ab28
  1. 7
      json-path-assert/src/test/java/com/jayway/jsonassert/JsonAssertTest.java
  2. 51
      json-path/src/main/java/com/jayway/jsonpath/internal/compiler/PredicatePathToken.java
  3. 1
      json-path/src/test/java/com/jayway/jsonpath/old/ArraySlicingTest.java
  4. 78
      json-path/src/test/java/com/jayway/jsonpath/old/DeepScanTest.java
  5. 84
      json-path/src/test/java/com/jayway/jsonpath/old/DocumentationPageTests.java
  6. 100
      json-path/src/test/java/com/jayway/jsonpath/old/FilterTest.java
  7. 123
      json-path/src/test/java/com/jayway/jsonpath/old/HelpTest.java
  8. 4
      json-path/src/test/java/com/jayway/jsonpath/old/IssuesTest.java
  9. 116
      json-path/src/test/java/com/jayway/jsonpath/old/JsonPathFilterTest.java
  10. 8
      json-path/src/test/java/com/jayway/jsonpath/old/internal/ScanPathTokenTest.java
  11. 41
      json-path/src/test/java/com/jayway/jsonpath/old/reader/ReadConfigurationTest.java

7
json-path-assert/src/test/java/com/jayway/jsonassert/JsonAssertTest.java

@ -49,6 +49,11 @@ public class JsonAssertTest {
}
@Test(expected = AssertionError.class)
public void has_path() throws Exception {
with(JSON).assertNotDefined("$.store.bicycle[?(@.color == 'red' )]");
}
@Test(expected = AssertionError.class)
public void failed_error_message() throws Exception {
@ -57,7 +62,6 @@ public class JsonAssertTest {
}
@Test
//@Ignore //TODO: finalize behaviour
public void links_document() throws Exception {
with(getResourceAsStream("links.json")).assertEquals("count", 2)
@ -70,7 +74,6 @@ public class JsonAssertTest {
@Test
//@Ignore //TODO: finalize behaviour
public void a_document_can_be_expected_not_to_contain_a_path() throws Exception {
with(JSON).assertNotDefined("$.store.bicycle.cool");
}

51
json-path/src/main/java/com/jayway/jsonpath/internal/compiler/PredicatePathToken.java

@ -22,14 +22,14 @@ public class PredicatePathToken extends PathToken {
"[?,?,?,?,?]"
};
private final Collection<Predicate> filters;
private final Collection<Predicate> predicates;
public PredicatePathToken(Predicate filter) {
this.filters = asList(filter);
this.predicates = asList(filter);
}
public PredicatePathToken(Collection<Predicate> filters) {
this.filters = filters;
public PredicatePathToken(Collection<Predicate> predicates) {
this.predicates = predicates;
}
@Override
@ -58,37 +58,44 @@ public class PredicatePathToken extends PathToken {
}
public boolean accept(final Object obj, final Configuration configuration) {
boolean accept = true;
Predicate.PredicateContext ctx = new PredicateContextImpl(obj, configuration);
Predicate.PredicateContext ctx = new Predicate.PredicateContext() {
@Override
public Object target() {
return obj;
for (Predicate predicate : predicates) {
if (!predicate.apply (ctx)) {
return false;
}
}
return true;
}
@Override
public Configuration configuration() {
return configuration;
public String getPathFragment() {
return FRAGMENTS[predicates.size() - 1];
}
};
for (Predicate filter : filters) {
if (!filter.apply (ctx)) {
accept = false;
break;
}
@Override
boolean isTokenDefinite() {
return false;
}
return accept;
private static class PredicateContextImpl implements Predicate.PredicateContext {
private final Object obj;
private final Configuration configuration;
private PredicateContextImpl(Object obj, Configuration configuration) {
this.obj = obj;
this.configuration = configuration;
}
@Override
public String getPathFragment() {
return FRAGMENTS[filters.size() - 1];
public Object target() {
return obj;
}
@Override
boolean isTokenDefinite() {
return false;
public Configuration configuration() {
return configuration;
}
}
}

1
json-path/src/test/java/com/jayway/jsonpath/old/ArraySlicingTest.java

@ -59,7 +59,6 @@ public class ArraySlicingTest {
assertThat(result, Matchers.contains(1));
}
//@Test(expected = IndexOutOfBoundsException.class)
@Test
public void get_between_index_out_of_bounds(){
List<Integer> result = JsonPath.read(JSON_ARRAY, "$[1:15]");

78
json-path/src/test/java/com/jayway/jsonpath/old/DeepScanTest.java

@ -1,78 +0,0 @@
package com.jayway.jsonpath.old;
import com.jayway.jsonpath.Option;
import com.jayway.jsonpath.spi.json.JsonProvider;
import com.jayway.jsonpath.spi.json.JsonProviderFactory;
import java.util.Collections;
import java.util.Set;
public class DeepScanTest {
private static final String DOCUMENT = "{\n" +
" \"store\":{\n" +
" \"book\":[\n" +
" {\n" +
" \"category\":\"reference\",\n" +
" \"author\":\"Nigel Rees\",\n" +
" \"title\":\"Sayings of the Century\",\n" +
" \"price\":8.95\n" +
" },\n" +
" {\n" +
" \"category\":\"fiction\",\n" +
" \"author\":\"Evelyn Waugh\",\n" +
" \"title\":\"Sword of Honour\",\n" +
" \"price\":12.99\n" +
" },\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" +
"}";
private static final JsonProvider prov = JsonProviderFactory.createProvider();
private static final Set<Option> opts = Collections.emptySet();
/*
@Test
public void correct_path() {
System.out.println(DOCUMENT);
System.out.println(PathEvaluator.evaluate("$.store..", DOCUMENT, prov, opts));
}
@Test
public void a_string_property_can_be_scanned_for() {
PathEvaluationResult result = PathEvaluator.evaluate("$.store..category", DOCUMENT, prov, opts);
assertThat(result.getPathList(), hasItems("$['store']['book'][0]['category']", "$['store']['book'][1]['category']", "$['store']['book'][2]['category']"));
assertThat(result.getResultList(), hasItems(
Matchers.<Object>is("reference"),
Matchers.<Object>is("fiction"),
Matchers.<Object>is("fiction")));
System.out.println(result.toString());
}
@Test
public void a_path_can_end_with_deep_scan() {
String json = "{\"items\":[1, 3, 5, 7, 8, 13, 20]}";
//System.out.println( JsonPath.read(json, "$.."));
System.out.println(PathEvaluator.evaluate("$..", json, prov, opts).toString());
}
*/
}

84
json-path/src/test/java/com/jayway/jsonpath/old/DocumentationPageTests.java

@ -1,84 +0,0 @@
package com.jayway.jsonpath.old;
import com.jayway.jsonpath.JsonPath;
import org.junit.Test;
public class DocumentationPageTests {
public static final String JSON = "{ \n" +
" \"store\": {\n" +
" \"book\": [ \n" +
" { \n" +
" \"category\": \"reference\",\n" +
" \"author\": \"Nigel Rees\",\n" +
" \"title\": \"Sayings of the Century\",\n" +
" \"price\": 8.95\n" +
" },\n" +
" { \n" +
" \"category\": \"fiction\",\n" +
" \"author\": \"Evelyn Waugh\",\n" +
" \"title\": \"Sword of Honour\",\n" +
" \"price\": 12.99\n" +
" },\n" +
" { \n" +
" \"category\": \"fiction\",\n" +
" \"author\": \"Herman Melville\",\n" +
" \"title\": \"Moby Dick\",\n" +
" \"isbn\": \"0-553-21311-3\",\n" +
" \"price\": 8.99\n" +
" },\n" +
" { \n" +
" \"category\": null,\n" +
" \"author\": \"J. R. R. Tolkien\",\n" +
" \"title\": \"The Lord of the Rings\",\n" +
" \"isbn\": \"0-395-19395-8\",\n" +
" \"price\": 22.99,\n" +
" \"edition\": {\n" +
" \"release-date\": \"2013-01-22\"\n" +
" }\n" +
" }\n" +
" ],\n" +
" \"bicycle\": {\n" +
" \"color\": \"red\",\n" +
" \"price\": 19.95\n" +
" }\n" +
" }\n" +
"}";
@Test
public void test_1() {
System.out.println(JsonPath.read(JSON, "$.store.bicycle"));
}
@Test
public void test_2() {
System.out.println(JsonPath.read(JSON, "$.store.book[0]"));
}
@Test
public void test_3() {
System.out.println(JsonPath.read(JSON, "$.store.book[*].author"));
}
@Test
public void test_4() {
System.out.println(JsonPath.read(JSON, "$.store.book[-2:].author"));
}
@Test
public void test_5() {
System.out.println(JsonPath.read(JSON, "$.store.book[1:3].author"));
}
@Test
public void test_6() {
System.out.println(JsonPath.read(JSON, "$.store.book[0]['author', 'category']"));
}
@Test
public void test_7() {
System.out.println(JsonPath.read(JSON, "$..price"));
}
}

100
json-path/src/test/java/com/jayway/jsonpath/old/FilterTest.java

@ -5,6 +5,7 @@ import com.jayway.jsonpath.Configuration;
import com.jayway.jsonpath.Filter;
import com.jayway.jsonpath.InvalidCriteriaException;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.Predicate;
import com.jayway.jsonpath.spi.json.JsonProvider;
import com.jayway.jsonpath.spi.json.JsonProviderFactory;
import org.junit.Test;
@ -284,12 +285,6 @@ public class FilterTest extends BaseTest {
assertThat((String)JsonPath.read(jocksInTexas1, "[0].first-name"), is("Jock"));
assertThat((String)JsonPath.read(jocksInTexas1, "[0].last-name"), is("Ewing"));
System.out.println("res1" + jocksInTexas1);
System.out.println("res2" + jocksInTexas2);
System.out.println("done");
}
//-------------------------------------------------
@ -316,65 +311,12 @@ public class FilterTest extends BaseTest {
}
/*
@Test
public void filters_can_be_extended_with_new_criteria() throws Exception {
Map<String, Object> check = new HashMap<String, Object>();
check.put("string", "foo");
check.put("string_null", null);
check.put("int", 10);
check.put("long", 1L);
check.put("double", 1.12D);
Filter filter = filter(where("string").is("foo").and("int").lt(11));
assertTrue(filter.apply(createPredicateContext(check)));
filter.addCriteria(where("long").ne(1L));
assertFalse(filter.apply(createPredicateContext(check)));
}
*/
/*
@Test
public void filters_criteria_can_be_refined() throws Exception {
Map<String, Object> check = new HashMap<String, Object>();
check.put("string", "foo");
check.put("string_null", null);
check.put("int", 10);
check.put("long", 1L);
check.put("double", 1.12D);
Filter filter = filter(where("string").is("foo"));
assertTrue(filter.apply(createPredicateContext(check)));
Criteria criteria = where("string").is("not eq");
filter.addCriteria(criteria);
assertFalse(filter.apply(createPredicateContext(check)));
filter = filter(where("string").is("foo").and("string").is("not eq"));
assertFalse(filter.apply(createPredicateContext(check)));
filter = filter(where("string").is("foo").and("string").is("foo"));
assertTrue(filter.apply(createPredicateContext(check)));
}
*/
@Test
public void arrays_of_maps_can_be_filtered() throws Exception {
/*
Map<String, Object> rootGrandChild_A = new HashMap<String, Object>();
rootGrandChild_A.put("name", "rootGrandChild_A");
@ -401,10 +343,10 @@ public class FilterTest extends BaseTest {
root.put("children", asList(rootChild_A, rootChild_B, rootChild_C));
Filter customFilter = new Filter.FilterAdapter<Map<String, Object>>() {
Predicate customFilter = new Predicate () {
@Override
public boolean apply(createPredicateContext(check)Map<String, Object> map) {
if (map.getValue("name").equals("rootGrandChild_A")) {
public boolean apply(PredicateContext ctx) {
if (ctx.configuration().getProvider().getMapValue(ctx.target(), "name").equals("rootGrandChild_A")) {
return true;
}
return false;
@ -414,55 +356,33 @@ public class FilterTest extends BaseTest {
Filter rootChildFilter = filter(where("name").regex(Pattern.compile("rootChild_[A|B]")));
Filter rootGrandChildFilter = filter(where("name").regex(Pattern.compile("rootGrandChild_[A|B]")));
//TODO: breaking v2 (solved by [?,?])
//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());
*/
}
@Test
public void arrays_of_objects_can_be_filtered() throws Exception {
/*
Map<String, Object> doc = new HashMap<String, Object>();
doc.put("items", asList(1, 2, 3));
Filter customFilter = new Filter.FilterAdapter() {
Predicate customFilter = new Predicate() {
@Override
public boolean apply(createPredicateContext(check)Object o, Configuration configuration) {
return 1 == (Integer) o;
public boolean apply(PredicateContext ctx) {
return 1 == (Integer)ctx.target();
}
};
List<Integer> res = JsonPath.read(doc, "$.items[?]", customFilter);
assertEquals(1, res.getValue(0).intValue());
*/
assertEquals(1, res.get(0).intValue());
}
@Test
public void filters_can_contain_json_path_expressions() throws Exception {
System.out.println(DOCUMENT);
Object doc = JsonProviderFactory.createProvider().parse(DOCUMENT);
assertFalse(filter(where("$.store.bicycle.color").ne("red")).apply(createPredicateContext(doc)));
/*
assertFalse(filter(where("store..price").gt(10)).apply(doc, conf));
assertFalse(filter(where("$.store..price").gte(100)).apply(doc, conf));
assertTrue(filter(where("$.store..category").ne("fiction")).apply(doc, conf));
assertTrue(filter(where("$.store.bicycle.color").ne("blue")).apply(doc, conf));
assertTrue(filter(where("$.store..color").exists(true)).apply(doc, conf));
assertTrue(filter(where("$.store..color").regex(Pattern.compile("^r.d$"))).apply(doc, conf));
assertTrue(filter(where("$.store..color").type(String.class)).apply(doc, conf));
assertTrue(filter(where("$.store..price").is(12.99)).apply(doc, conf));
assertFalse(filter(where("$.store..price").is(13.99)).apply(doc, conf));
assertFalse(filter(where("$.store..flavor").exists(true)).apply(doc, conf));
*/
}
@Test
@ -494,11 +414,9 @@ public class FilterTest extends BaseTest {
List<Map<String, Object>> result = JsonPath.read(doc, "$.fields[?]", filter(where("errors").notEmpty()));
assertEquals(1, result.size());
System.out.println(result);
List<Map<String, Object>> result2 = JsonPath.read(doc, "$.fields[?]", filter(where("name").notEmpty()));
assertEquals(2, result2.size());
System.out.println(result2);
}
@Test(expected = InvalidCriteriaException.class)

123
json-path/src/test/java/com/jayway/jsonpath/old/HelpTest.java

@ -1,123 +0,0 @@
package com.jayway.jsonpath.old;
import com.jayway.jsonpath.JsonPath;
import org.junit.Test;
import java.util.List;
import static org.hamcrest.Matchers.hasItems;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
public class HelpTest {
public static final String JSON = "{\n" +
" \"destination_addresses\" : [\n" +
" \"Rua do Dom António José Cordeiro 48, 3800-012 Aveiro, Portugal\",\n" +
" \"Rua do Dom António José Cordeiro 48, 3800-012 Aveiro, Portugal\"\n" +
" ],\n" +
" \"origin_addresses\" : [ \"N109, 3800, Portugal\" ],\n" +
" \"rows\" : [\n" +
" {\n" +
" \"elements\" : [\n" +
" {\n" +
" \"distance\" : {\n" +
" \"text\" : \"0.4 km\",\n" +
" \"value\" : 427\n" +
" },\n" +
" \"duration\" : {\n" +
" \"text\" : \"1 min\",\n" +
" \"value\" : 58\n" +
" },\n" +
" \"status\" : \"OK\"\n" +
" },\n" +
" {\n" +
" \"distance\" : {\n" +
" \"text\" : \"5.0 km\",\n" +
" \"value\" : 427\n" +
" },\n" +
" \"duration\" : {\n" +
" \"text\" : \"1 min\",\n" +
" \"value\" : 58\n" +
" },\n" +
" \"status\" : \"OK\"\n" +
" }\n" +
" ]\n" +
" }\n" +
" ],\n" +
" \"status\" : \"OK\"\n" +
"}";
private static final String JSON2 = "{\n" +
" \"error\": null,\n" +
" \"contents\": [\n" +
" {\n" +
" \"groupType\": \"series\",\n" +
" \"instanceId\": \"grp://15\",\n" +
" \"id\": \"prg://16\",\n" +
" \"type\": \"group\",\n" +
" \"media\": [\n" +
" {\n" +
" \"classification\": \"urn:1.2.3\",\n" +
" \"uri\": \"http://yahoo.com/1.png\",\n" +
" \"mimeType\": \"application/octet-stream\"\n" +
" }\n" +
" ]\n" +
" },\n" +
" {\n" +
" \"groupType\": \"series\",\n" +
" \"instanceId\": \"grp://15\",\n" +
" \"extra\": 1,\n" +
" \"id\": \"prg://16\",\n" +
" \"type\": \"group\",\n" +
" \"media\": [\n" +
" {\n" +
" \"classification\": \"urn:1.2.3\",\n" +
" \"uri\": \"http://yahoo.com/1.png\",\n" +
" \"mimeType\": \"application/octet-stream\"\n" +
" }\n" +
" ]\n" +
" }\n" +
" ],\n" +
" \"header\": {\n" +
" \"total\": 1\n" +
" }\n" +
"}";
@Test
public void sample_one_a(){
System.out.println(JsonPath.read(JSON2, "$.['error', 'header']"));
System.out.println(JsonPath.read(JSON2, "$.contents[*].['groupType', 'type', 'extra']"));
}
@Test
public void sample_one_b(){
System.out.println(JsonPath.read(JSON2, "$.['error', 'header']"));
System.out.println(JsonPath.read(JSON2, "$.contents[*].['groupType', 'type']"));
}
@Test
public void sample_one(){
List<String> addresses = JsonPath.read(JSON, "$.destination_addresses[*]");
assertThat(addresses, hasItems("Rua do Dom António José Cordeiro 48, 3800-012 Aveiro, Portugal"));
}
@Test
public void sample_two(){
String text = JsonPath.read(JSON, "$.rows[0].elements[1].distance.text");
assertEquals("5.0 km", text);
}
@Test
public void sample_two_b(){
String text = JsonPath.read(JSON, "$.rows[0].elements[1].distance.text");
assertEquals("5.0 km", text);
}
@Test
public void sample_three(){
List<String> allDistanceTexts = JsonPath.read(JSON, "$.rows[0].elements[*].distance.text");
assertThat(allDistanceTexts, hasItems("0.4 km", "5.0 km"));
}
}

4
json-path/src/test/java/com/jayway/jsonpath/old/IssuesTest.java

@ -121,7 +121,6 @@ public class IssuesTest {
Object o = JsonPath.read(is, "$.project.field[*].@key");
//Object o = JsonPath.read(is, "$.project.template[?(@.@key == 'foo')].field[*].@key");
System.out.println(o);
is.close();
} catch (Exception e) {
@ -230,11 +229,10 @@ public class IssuesTest {
@Test(expected = PathNotFoundException.class)
public void issue_22() throws Exception {
//Configuration configuration = Configuration.builder().options(Option.THROW_ON_MISSING_PROPERTY).build();
Configuration configuration = Configuration.defaultConfiguration();
String json = "{\"a\":{\"b\":1,\"c\":2}}";
System.out.println(JsonPath.parse(json, configuration).read("a.d"));
JsonPath.parse(json, configuration).read("a.d");
}
@Test
public void issue_22c() throws Exception {

116
json-path/src/test/java/com/jayway/jsonpath/old/JsonPathFilterTest.java

@ -1,116 +0,0 @@
package com.jayway.jsonpath.old;
public class JsonPathFilterTest {
public final static String DOCUMENT =
"{ \"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" +
" \"foo:bar\": \"fooBar\",\n" +
" \"dot.notation\": \"new\"\n" +
" }\n" +
" }\n" +
"}";
/*
@Test
public void arrays_of_maps_can_be_filtered() throws Exception {
Map<String, Object> rootGrandChild_A = new HashMap<String, Object>();
rootGrandChild_A.put("name", "rootGrandChild_A");
Map<String, Object> rootGrandChild_B = new HashMap<String, Object>();
rootGrandChild_B.put("name", "rootGrandChild_B");
Map<String, Object> rootGrandChild_C = new HashMap<String, Object>();
rootGrandChild_C.put("name", "rootGrandChild_C");
Map<String, Object> rootChild_A = new HashMap<String, Object>();
rootChild_A.put("name", "rootChild_A");
rootChild_A.put("children", asList(rootGrandChild_A, rootGrandChild_B, rootGrandChild_C));
Map<String, Object> rootChild_B = new HashMap<String, Object>();
rootChild_B.put("name", "rootChild_B");
rootChild_B.put("children", asList(rootGrandChild_A, rootGrandChild_B, rootGrandChild_C));
Map<String, Object> rootChild_C = new HashMap<String, Object>();
rootChild_C.put("name", "rootChild_C");
rootChild_C.put("children", asList(rootGrandChild_A, rootGrandChild_B, rootGrandChild_C));
Map<String, Object> root = new HashMap<String, Object>();
root.put("children", asList(rootChild_A, rootChild_B, rootChild_C));
Filter customFilter = new Filter.FilterAdapter<Map<String, Object>>() {
@Override
public boolean accept(Map<String, Object> map) {
if(map.getValue("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]")));
//TODO: breaking v2 solved by [?,?]
//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());
}
@Test
public void arrays_of_objects_can_be_filtered() throws Exception {
Map<String, Object> doc = new HashMap<String, Object>();
doc.put("items", asList(1, 2, 3));
Filter customFilter = new Filter.FilterAdapter<Integer>(){
@Override
public boolean accept(Integer o) {
return 1 == o;
}
};
List<Integer> res = JsonPath.read(doc, "$.items[?]", customFilter);
assertEquals(1, res.getValue(0).intValue());
}
*/
}

8
json-path/src/test/java/com/jayway/jsonpath/old/internal/ScanPathTokenTest.java

@ -1,6 +1,7 @@
package com.jayway.jsonpath.old.internal;
import com.jayway.jsonpath.Configuration;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.internal.PathCompiler;
import com.jayway.jsonpath.spi.json.JsonProviderFactory;
import org.junit.Test;
@ -87,6 +88,13 @@ public class ScanPathTokenTest {
" }"
);
@Test
public void a_root_scan() {
Object o = JsonPath.read(DOCUMENT, "$..");
}
@Test
public void a_document_can_be_scanned_for_property() {

41
json-path/src/test/java/com/jayway/jsonpath/old/reader/ReadConfigurationTest.java

@ -1,41 +0,0 @@
package com.jayway.jsonpath.old.reader;
import com.jayway.jsonpath.Configuration;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.spi.json.JsonProvider;
import com.jayway.jsonpath.spi.json.JsonProviderFactory;
import org.junit.Test;
public class ReadConfigurationTest {
private static JsonProvider provider = JsonProviderFactory.createProvider();
@Test
public void fluent() {
Configuration configuration = Configuration.defaultConfiguration();
Configuration configuration2 = Configuration.builder()
.jsonProvider(JsonProviderFactory.createProvider())
.build();
//.options(Option.THROW_ON_MISSING_PROPERTY).build();
JsonProvider jsonProvider = JsonProviderFactory.createProvider();
JsonPath.using(configuration).parse("{}").read("$");
JsonPath.using(jsonProvider).parse("{}").read("$");
JsonPath.parse("{}").read("$");
JsonPath.parse("{}", configuration).read("$");
JsonPath.using(configuration).parse("{}").read("$");
/*
Object updatedJsonModel = JsonPath.parse("{...}")
.write("$['store'][1]['name']", "new name")
.write("$.store[1].age", 43)
.getValue();
*/
}
}
Loading…
Cancel
Save