use of com.jayway.jsonpath.JsonPath in project batfish by batfish.
the class Environment method computePath.
public ArrayNode computePath(String path) {
ArrayNode pathResult = _pathCache.get(path);
if (pathResult == null) {
JsonPath jsonPath = JsonPath.compile(path);
try {
pathResult = jsonPath.read(_jsonObject, _configuration);
} catch (PathNotFoundException e) {
pathResult = JsonNodeFactory.instance.arrayNode();
} catch (Exception e) {
throw new BatfishException("Error reading JSON path: " + path, e);
}
_pathCache.put(path, pathResult);
}
return pathResult;
}
use of com.jayway.jsonpath.JsonPath in project batfish by batfish.
the class JsonPathTest method testTwoNtpServersSanctionedViolation.
@Test
public void testTwoNtpServersSanctionedViolation() {
String path = "$.nodes[*].ntpServers[?(@ nin [\"9.9.9.9\", \"5.6.7.8\"])]";
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));
}
use of com.jayway.jsonpath.JsonPath in project batfish by batfish.
the class JsonPathTest method testOneNtpServerSanctionedViolation.
@Test
public void testOneNtpServerSanctionedViolation() {
String path = "$.nodes[*].ntpServers[?(@ nin [\"9.9.9.9\"])]";
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));
}
use of com.jayway.jsonpath.JsonPath in project batfish by batfish.
the class JsonPathTest method testPath1.
@Test
public void testPath1() {
JsonPath jsonPath = JsonPath.compile("$.nodes[*][?(@.interfaces['Management1'].prefix)].vendorFamily.cisco.logging" + "[?(@.sourceInterface!='Management1')]");
assertThat(jsonPath, not(equalTo(nullValue())));
}
use of com.jayway.jsonpath.JsonPath in project batfish by batfish.
the class JsonPathTest method testTwoNtpServersSanctioned.
@Test
public void testTwoNtpServersSanctioned() {
String path = "$.nodes[*].ntpServers[?(@ nin [\"1.2.3.4\", \"5.6.7.8\"])]";
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(0));
}
Aggregations