Browse Source

add some tests

pull/16/head
Jochen Berger 11 years ago
parent
commit
03e97890dc
  1. 38
      json-path/src/test/java/com/jayway/jsonpath/FilterTest.java

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

@ -1,5 +1,7 @@
package com.jayway.jsonpath;
import net.minidev.json.parser.JSONParser;
import org.junit.Test;
import java.util.Collections;
@ -382,5 +384,41 @@ public class FilterTest {
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{
where("$.store.*").size(4);
fail("This should have thrown an exception");
} catch(IllegalArgumentException e){
}
try{
where("$.store.*").in("foo");
fail("This should have thrown an exception");
} catch(IllegalArgumentException e){
}
}
}

Loading…
Cancel
Save