use of com.jayway.jsonpath.Filter in project JsonPath by jayway.
the class FilterTest method filters_can_be_combined.
//-------------------------------------------------
//
// Single filter tests
//
//-------------------------------------------------
@Test
public void filters_can_be_combined() 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 shouldMarch = filter(where("string").is("foo").and("int").lt(11));
Filter shouldNotMarch = filter(where("string").is("foo").and("int").gt(11));
assertTrue(shouldMarch.apply(createPredicateContext(check)));
assertFalse(shouldNotMarch.apply(createPredicateContext(check)));
}
use of com.jayway.jsonpath.Filter in project JsonPath by jayway.
the class FilterTest method contains_filter_evaluates_on_string.
@Test
public void contains_filter_evaluates_on_string() {
String json = "{\n" + "\"store\": {\n" + " \"book\": [\n" + " {\n" + " \"category\": \"reference\",\n" + " \"title\": \"Sayings of the Century\",\n" + " \"price\": 8.95\n" + " },\n" + " {\n" + " \"category\": \"fiction\",\n" + " \"title\": \"Sword of Honour\",\n" + " \"price\": 12.99\n" + " }\n" + " ]\n" + " }\n" + "}";
Filter filter = filter(where("category").contains("fic"));
List<String> result = JsonPath.parse(json).read("$.store.book[?].title", filter);
Assertions.assertThat(result).containsExactly("Sword of Honour");
}
use of com.jayway.jsonpath.Filter in project JsonPath by jayway.
the class IssuesTest method issue_129.
@Test
public void issue_129() throws Exception {
final Map<String, Integer> match = new HashMap<String, Integer>();
match.put("a", 1);
match.put("b", 2);
Map<String, Integer> noMatch = new HashMap<String, Integer>();
noMatch.put("a", -1);
noMatch.put("b", -2);
Filter orig = filter(where("a").eq(1).and("b").eq(2));
String filterAsString = orig.toString();
Filter parsed = Filter.parse(filterAsString);
assertThat(orig.apply(createPredicateContext(match))).isTrue();
assertThat(parsed.apply(createPredicateContext(match))).isTrue();
assertThat(orig.apply(createPredicateContext(noMatch))).isFalse();
assertThat(parsed.apply(createPredicateContext(noMatch))).isFalse();
}
Aggregations