use of com.jayway.jsonpath.JsonPath in project batfish by batfish.
the class JsonPathTest method testTwoNtpServersPresent.
@Test
public void testTwoNtpServersPresent() {
String path = "$.nodes[*][?(!([\"1.2.3.4\", \"5.6.7.8\"] 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(0));
}
use of com.jayway.jsonpath.JsonPath in project batfish by batfish.
the class JsonPathTest method testPath2.
@Test
public void testPath2() {
JsonPath jsonPath = JsonPath.compile("$.nodes[*][?(@.interfaces['Management1'].prefix)].vendorFamily.cisco.ntp.servers[*]" + "[?(@.vrf!='mgmt')]");
assertThat(jsonPath, not(equalTo(nullValue())));
}
use of com.jayway.jsonpath.JsonPath in project TOSCAna by StuPro-TOSCAna.
the class TransformationControllerTest method getInputsTest.
@Test
public void getInputsTest() throws Exception {
preInitNonCreationTests();
MvcResult result = mvc.perform(get(INPUTS_VALID_URL)).andDo(print()).andExpect(status().is(200)).andExpect(content().contentType(DEFAULT_CHARSET_HAL_JSON)).andExpect(jsonPath("$.inputs").isArray()).andExpect(jsonPath("$.inputs").isNotEmpty()).andExpect(jsonPath("$.inputs[0].key").isString()).andExpect(jsonPath("$.inputs[0].type").isString()).andExpect(jsonPath("$.inputs[0].description").isString()).andExpect(jsonPath("$.inputs[0].required").isBoolean()).andExpect(jsonPath("$.links[0].rel").value("self")).andExpect(jsonPath("$.links[0].href").value("http://localhost/api/csars/kubernetes-cluster/transformations/p-a/inputs")).andReturn();
MockHttpServletResponse response = result.getResponse();
String responseJson = new String(response.getContentAsByteArray());
String[] values = JsonPath.parse(responseJson).read("$.inputs[*].value", String[].class);
long nullCount = Arrays.asList(values).stream().filter(Objects::isNull).count();
long testCount = Arrays.asList(values).stream().filter(e -> e != null && e.equals(INPUT_TEST_DEFAULT_VALUE)).count();
assertEquals(8, nullCount);
assertEquals(1, testCount);
}
use of com.jayway.jsonpath.JsonPath in project pentaho-kettle by pentaho.
the class FastJsonReader method evalCombinedResult.
private List<List<?>> evalCombinedResult() throws JsonInputException {
int lastSize = -1;
String prevPath = null;
List<List<?>> results = new ArrayList<>(compiledJsonPaths.length);
int i = 0;
for (JsonPath path : compiledJsonPaths) {
List<Object> result = getReadContext().read(path);
if (result.size() != lastSize && lastSize > 0 && !result.isEmpty()) {
throw new JsonInputException(BaseMessages.getString(PKG, "JsonInput.Error.BadStructure", result.size(), inputFields[i].getPath(), prevPath, lastSize));
}
if (!isIgnoreMissingPath() && (isAllNull(result) || result.isEmpty())) {
throw new JsonInputException(BaseMessages.getString(PKG, "JsonReader.Error.CanNotFindPath", inputFields[i].getPath()));
}
results.add(result);
lastSize = result.size();
prevPath = inputFields[i].getPath();
i++;
}
return results;
}
use of com.jayway.jsonpath.JsonPath in project bender by Nextdoor.
the class JsonPathProvider method delete.
public static void delete(Object json, String pathStr) {
JsonPath path = getPath(pathStr);
path.delete(json, CONFIG);
}
Aggregations