use of org.batfish.question.jsonpath.JsonPathQuestionPlugin.JsonPathQuestion in project batfish by batfish.
the class JsonPathQuestionPluginTest method configureTemplateTest.
@Test
public void configureTemplateTest() throws IOException {
ObjectMapper mapper = BatfishObjectMapper.mapper();
Set<JsonPathException> oldExceptions = Collections.singleton(new JsonPathException(Collections.singletonList("old"), null));
JsonPathAssertion oldAssertion = new JsonPathAssertion(JsonPathAssertionType.equals, mapper.readValue("[true]", JsonNode.class));
JsonPathQuery query = new JsonPathQuery("ll", false, null, null, oldExceptions, oldAssertion);
JsonPathQuestion oldQuestion = new JsonPathQuestion();
oldQuestion.setPaths(Collections.singletonList(query));
Set<JsonPathException> newExceptions = Collections.singleton(new JsonPathException(Collections.singletonList("new"), null));
JsonPathAssertion newAssertion = new JsonPathAssertion(JsonPathAssertionType.equals, mapper.readValue("[false]", JsonNode.class));
JsonPathQuestion newQuestion = (JsonPathQuestion) oldQuestion.configureTemplate(mapper.writeValueAsString(newExceptions), mapper.writeValueAsString(newAssertion));
// the exceptions and assertion of the newQuestion should be the new values
assertThat(newQuestion.getPaths().get(0).getExceptions(), equalTo(newExceptions));
assertThat(newQuestion.getPaths().get(0).getAssertion(), equalTo(newAssertion));
}
use of org.batfish.question.jsonpath.JsonPathQuestionPlugin.JsonPathQuestion in project batfish by batfish.
the class JsonPathQuestionPluginTest method configureTemplateTestNullValues.
@Test
public void configureTemplateTestNullValues() throws IOException {
ObjectMapper mapper = BatfishObjectMapper.mapper();
Set<JsonPathException> oldExceptions = Collections.singleton(new JsonPathException(Collections.singletonList("old"), null));
JsonPathAssertion oldAssertion = new JsonPathAssertion(JsonPathAssertionType.equals, mapper.readValue("[true]", JsonNode.class));
JsonPathQuery query = new JsonPathQuery("ll", false, null, null, oldExceptions, oldAssertion);
JsonPathQuestion oldQuestion = new JsonPathQuestion();
oldQuestion.setPaths(Collections.singletonList(query));
Set<JsonPathException> newExceptions = Collections.singleton(new JsonPathException(Collections.singletonList("new"), null));
JsonPathQuestion nullAssertionQuestion = (JsonPathQuestion) oldQuestion.configureTemplate(mapper.writeValueAsString(newExceptions), null);
JsonPathAssertion newAssertion = new JsonPathAssertion(JsonPathAssertionType.equals, mapper.readValue("[false]", JsonNode.class));
JsonPathQuestion nullExceptionQuestion = (JsonPathQuestion) oldQuestion.configureTemplate(null, mapper.writeValueAsString(newAssertion));
// check if null values retained the original values
assertThat(nullAssertionQuestion.getPaths().get(0).getAssertion(), equalTo(oldAssertion));
assertThat(nullExceptionQuestion.getPaths().get(0).getExceptions(), equalTo(oldExceptions));
}
use of org.batfish.question.jsonpath.JsonPathQuestionPlugin.JsonPathQuestion in project batfish by batfish.
the class InferPoliciesQuestionPlugin method makeQuestionWithHints.
private static JsonPathQuestion makeQuestionWithHints(AbstractRoleConsistencyQuestion roleQ) {
JsonPathQuestion ret = new JsonPathQuestion();
ret.setInnerQuestion(roleQ);
JsonPathQuery path = new JsonPathQuery("$.answers[?(@.outliers)]", true);
path.setDisplayHints(getDisplayHintsForQuestion(roleQ));
ret.setPaths(Collections.singletonList(path));
InstanceData instance = new InstanceData();
instance.setInstanceName(getInstanceNameForQuestion(roleQ));
ret.setInstance(instance);
return ret;
}
Aggregations