Search in sources :

Example 1 with JsonPathQuestion

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));
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonPathQuestion(org.batfish.question.jsonpath.JsonPathQuestionPlugin.JsonPathQuestion) BatfishObjectMapper(org.batfish.common.util.BatfishObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 2 with JsonPathQuestion

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));
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonPathQuestion(org.batfish.question.jsonpath.JsonPathQuestionPlugin.JsonPathQuestion) BatfishObjectMapper(org.batfish.common.util.BatfishObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 3 with JsonPathQuestion

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;
}
Also used : InstanceData(org.batfish.datamodel.questions.Question.InstanceData) JsonPathQuery(org.batfish.question.jsonpath.JsonPathQuery) JsonPathQuestion(org.batfish.question.jsonpath.JsonPathQuestionPlugin.JsonPathQuestion)

Aggregations

JsonPathQuestion (org.batfish.question.jsonpath.JsonPathQuestionPlugin.JsonPathQuestion)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 BatfishObjectMapper (org.batfish.common.util.BatfishObjectMapper)2 Test (org.junit.Test)2 InstanceData (org.batfish.datamodel.questions.Question.InstanceData)1 JsonPathQuery (org.batfish.question.jsonpath.JsonPathQuery)1