Search in sources :

Example 41 with JsonPath

use of com.jayway.jsonpath.JsonPath in project batfish by batfish.

the class JsonPathTest method testPath3.

@Test
public void testPath3() {
    JsonPath jsonPath = JsonPath.compile("$.nodes[*][?(!@.ntpServers)]");
    assertThat(jsonPath, not(equalTo(nullValue())));
}
Also used : JsonPath(com.jayway.jsonpath.JsonPath) Test(org.junit.Test)

Example 42 with JsonPath

use of com.jayway.jsonpath.JsonPath in project batfish by batfish.

the class JsonPathTest method testOneNtpServerPresentViolation.

@Test
public void testOneNtpServerPresentViolation() {
    String path = "$.nodes[*][?(!([\"9.9.9.9\"] subsetof @.ntpServers))].ntpServers";
    JsonPath jsonPath = JsonPath.compile(path);
    ArrayNode prefixes = null;
    try {
        prefixes = jsonPath.read(_oneNtpServerNodesAnswerJsonObject, _prefixConfiguration);
    } catch (PathNotFoundException e) {
        prefixes = JsonNodeFactory.instance.arrayNode();
    }
    assertThat(prefixes, not(equalTo(nullValue())));
    assertThat(prefixes.size(), equalTo(1));
}
Also used : ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) PathNotFoundException(com.jayway.jsonpath.PathNotFoundException) JsonPath(com.jayway.jsonpath.JsonPath) Test(org.junit.Test)

Example 43 with JsonPath

use of com.jayway.jsonpath.JsonPath in project batfish by batfish.

the class JsonPathTest method testOneNtpServerSanctioned.

@Test
public void testOneNtpServerSanctioned() {
    String path = "$.nodes[*].ntpServers[?(@ nin [\"1.2.3.4\"])]";
    JsonPath jsonPath = JsonPath.compile(path);
    ArrayNode prefixes = null;
    try {
        prefixes = jsonPath.read(_oneNtpServerNodesAnswerJsonObject, _prefixConfiguration);
    } catch (PathNotFoundException e) {
        prefixes = JsonNodeFactory.instance.arrayNode();
    }
    assertThat(prefixes, not(equalTo(nullValue())));
    assertThat(prefixes.size(), equalTo(0));
}
Also used : ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) PathNotFoundException(com.jayway.jsonpath.PathNotFoundException) JsonPath(com.jayway.jsonpath.JsonPath) Test(org.junit.Test)

Example 44 with JsonPath

use of com.jayway.jsonpath.JsonPath in project batfish by batfish.

the class JsonPathTest method testTwoNtpServersPresentViolation.

@Test
public void testTwoNtpServersPresentViolation() {
    String path = "$.nodes[*][?(!([\"1.2.3.4\", \"9.9.9.9\"] subsetof @.ntpServers))].ntpServers";
    JsonPath jsonPath = JsonPath.compile(path);
    ArrayNode prefixes = null;
    try {
        prefixes = jsonPath.read(_twoNtpServersNodesAnswerJsonObject, _prefixConfiguration);
    } catch (PathNotFoundException e) {
        prefixes = JsonNodeFactory.instance.arrayNode();
    }
    assertThat(prefixes, not(equalTo(nullValue())));
    assertThat(prefixes.size(), equalTo(1));
}
Also used : ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) PathNotFoundException(com.jayway.jsonpath.PathNotFoundException) JsonPath(com.jayway.jsonpath.JsonPath) Test(org.junit.Test)

Example 45 with JsonPath

use of com.jayway.jsonpath.JsonPath in project JsonPath by json-path.

the class IssuesTest method github_89.

@Test(expected = PathNotFoundException.class)
public void github_89() {
    com.google.gson.JsonObject json = new JsonObject();
    json.addProperty("foo", "bar");
    JsonPath path = JsonPath.compile("$.foo");
    String object = path.read(json);
}
Also used : JsonObject(com.google.gson.JsonObject) JsonObject(com.google.gson.JsonObject) JsonPath(com.jayway.jsonpath.JsonPath) BaseTest(com.jayway.jsonpath.BaseTest) Test(org.junit.Test)

Aggregations

JsonPath (com.jayway.jsonpath.JsonPath)61 Test (org.junit.Test)34 PathNotFoundException (com.jayway.jsonpath.PathNotFoundException)13 BaseTest (com.jayway.jsonpath.BaseTest)12 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)9 ArrayList (java.util.ArrayList)9 LinkedHashMap (java.util.LinkedHashMap)8 List (java.util.List)8 Map (java.util.Map)8 DocumentContext (com.jayway.jsonpath.DocumentContext)6 IOException (java.io.IOException)6 ComponentLog (org.apache.nifi.logging.ComponentLog)6 File (java.io.File)5 Arrays (java.util.Arrays)5 HashMap (java.util.HashMap)5 Collectors (java.util.stream.Collectors)5 DataType (org.apache.nifi.serialization.record.DataType)5 RecordField (org.apache.nifi.serialization.record.RecordField)5 Assert.assertEquals (org.junit.Assert.assertEquals)5 Assert.assertTrue (org.junit.Assert.assertTrue)5