Search in sources :

Example 11 with Variable

use of org.batfish.datamodel.questions.Question.InstanceData.Variable in project batfish by batfish.

the class ClientTest method testValidateNodeNotAllowedValue.

@Test
public void testValidateNodeNotAllowedValue() throws IOException {
    String parameterName = "boolean";
    JsonNode invalidNode = _mapper.readTree("false");
    Question.InstanceData.Variable variable = new Question.InstanceData.Variable();
    variable.setType(BOOLEAN);
    SortedSet<String> allowedValues = new TreeSet<>();
    allowedValues.add("true");
    variable.setAllowedValues(allowedValues);
    _thrown.expect(BatfishException.class);
    _thrown.expectMessage(String.format("Invalid value: false, allowed values are: %s", allowedValues));
    Client.validateNode(invalidNode, variable, parameterName);
}
Also used : Variable(org.batfish.datamodel.questions.Question.InstanceData.Variable) TreeSet(java.util.TreeSet) Variable(org.batfish.datamodel.questions.Question.InstanceData.Variable) JsonNode(com.fasterxml.jackson.databind.JsonNode) Question(org.batfish.datamodel.questions.Question) Test(org.junit.Test)

Example 12 with Variable

use of org.batfish.datamodel.questions.Question.InstanceData.Variable in project batfish by batfish.

the class ClientTest method testValidProtocolValue.

@Test
public void testValidProtocolValue() throws IOException {
    JsonNode prefixRangeNode = _mapper.readTree("\"tcp\"");
    Question.InstanceData.Variable variable = new Question.InstanceData.Variable();
    variable.setType(PROTOCOL);
    Client.validateType(prefixRangeNode, variable);
}
Also used : Variable(org.batfish.datamodel.questions.Question.InstanceData.Variable) Variable(org.batfish.datamodel.questions.Question.InstanceData.Variable) JsonNode(com.fasterxml.jackson.databind.JsonNode) Question(org.batfish.datamodel.questions.Question) Test(org.junit.Test)

Example 13 with Variable

use of org.batfish.datamodel.questions.Question.InstanceData.Variable in project batfish by batfish.

the class ClientTest method testValidFloatValue.

@Test
public void testValidFloatValue() {
    Float floatValue = 15.0f;
    JsonNode floatNode = _mapper.valueToTree(floatValue);
    Question.InstanceData.Variable variable = new Question.InstanceData.Variable();
    variable.setType(FLOAT);
    Client.validateType(floatNode, variable);
}
Also used : Variable(org.batfish.datamodel.questions.Question.InstanceData.Variable) Variable(org.batfish.datamodel.questions.Question.InstanceData.Variable) JsonNode(com.fasterxml.jackson.databind.JsonNode) Question(org.batfish.datamodel.questions.Question) Test(org.junit.Test)

Example 14 with Variable

use of org.batfish.datamodel.questions.Question.InstanceData.Variable in project batfish by batfish.

the class ClientTest method testValidIntegerValue.

@Test
public void testValidIntegerValue() throws IOException {
    JsonNode integerNode = _mapper.readTree("15");
    Question.InstanceData.Variable variable = new Question.InstanceData.Variable();
    variable.setType(INTEGER);
    Client.validateType(integerNode, variable);
}
Also used : Variable(org.batfish.datamodel.questions.Question.InstanceData.Variable) Variable(org.batfish.datamodel.questions.Question.InstanceData.Variable) JsonNode(com.fasterxml.jackson.databind.JsonNode) Question(org.batfish.datamodel.questions.Question) Test(org.junit.Test)

Example 15 with Variable

use of org.batfish.datamodel.questions.Question.InstanceData.Variable in project batfish by batfish.

the class ClientTest method testUnsatisfiedMinElementInput.

@Test
public void testUnsatisfiedMinElementInput() throws IOException {
    Map<String, JsonNode> parameters = new HashMap<>();
    Map<String, Question.InstanceData.Variable> variables = new HashMap<>();
    JsonNode jsonArray = _mapper.readTree("[\"action1\", \"action2\"]");
    parameters.put("actions", jsonArray);
    Variable actionsVariable = new Variable();
    actionsVariable.setType(STRING);
    actionsVariable.setMinElements(5);
    variables.put("actions", actionsVariable);
    _thrown.expect(BatfishException.class);
    String errorMessage = String.format("Invalid value for parameter actions: %s. Expecting a " + "JSON array of at least 5 elements", jsonArray);
    _thrown.expectMessage(equalTo(errorMessage));
    Client.validateAndSet(parameters, variables);
}
Also used : Variable(org.batfish.datamodel.questions.Question.InstanceData.Variable) HashMap(java.util.HashMap) JsonNode(com.fasterxml.jackson.databind.JsonNode) Question(org.batfish.datamodel.questions.Question) Test(org.junit.Test)

Aggregations

Variable (org.batfish.datamodel.questions.Question.InstanceData.Variable)30 JsonNode (com.fasterxml.jackson.databind.JsonNode)25 Question (org.batfish.datamodel.questions.Question)24 Test (org.junit.Test)23 BatfishException (org.batfish.common.BatfishException)6 JSONObject (org.codehaus.jettison.json.JSONObject)3 IOException (java.io.IOException)2 TreeSet (java.util.TreeSet)2 JSONException (org.codehaus.jettison.json.JSONException)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Path (java.nio.file.Path)1 HashMap (java.util.HashMap)1 PatternSyntaxException (java.util.regex.PatternSyntaxException)1 WorkItem (org.batfish.common.WorkItem)1 BatfishObjectMapper (org.batfish.common.util.BatfishObjectMapper)1 Ip (org.batfish.datamodel.Ip)1 IpWildcard (org.batfish.datamodel.IpWildcard)1 SubRange (org.batfish.datamodel.SubRange)1