Tabnine Logo
Variable
Code IndexAdd Tabnine to your IDE (free)

How to use
Variable
in
org.batfish.datamodel.questions

Best Java code snippets using org.batfish.datamodel.questions.Variable (Showing top 20 results out of 315)

origin: batfish/batfish

@Test
public void testProvideOptionalParameterWithValue() throws IOException {
 Map<String, Variable> variables = new HashMap<>();
 Variable integerVariable = new Variable();
 integerVariable.setOptional(true);
 integerVariable.setValue(_mapper.readTree("3"));
 variables.put("integer", integerVariable);
 Client.checkVariableState(variables);
}
origin: batfish/batfish

   "No variable named: '" + parameterName + "' in supplied question template");
if (variable.getMinElements() != null) {
 if (!value.isArray() || value.size() < variable.getMinElements()) {
  throw new BatfishException(
    String.format(
        + "Expecting a JSON array of at least %d "
        + "elements",
      parameterName, value, variable.getMinElements()));
variable.setValue(value);
origin: batfish/batfish

/**
 * Verify that every non-optional variable has value assigned to it.
 *
 * @throws BatfishException when there exists a missing parameter: it is not optional in {@code
 *     variable}, but the user failed to provide it.
 */
static void checkVariableState(Map<String, Variable> variables) throws BatfishException {
 for (Entry<String, Variable> e : variables.entrySet()) {
  String variableName = e.getKey();
  Variable variable = e.getValue();
  if (!variable.getOptional() && variable.getValue() == null) {
   throw new BatfishException(String.format("Missing parameter: %s", variableName));
  }
 }
}
origin: batfish/batfish

@Test
public void testSatisfiedMinLengthValue() throws IOException {
 String longString = "\"long enough\"";
 Variable variable = new Variable();
 variable.setMinLength(8);
 variable.setType(STRING);
 Client.validateType(_mapper.readTree(longString), variable);
}
origin: batfish/batfish

@Test
public void testValidBgpSessionStatusValue() throws IOException {
 JsonNode sessionStatusNode = _mapper.readTree("\"sessionStatus\"");
 Variable variable = new Variable();
 variable.setType(BGP_SESSION_STATUS);
 Client.validateType(sessionStatusNode, variable);
}
origin: batfish/batfish

@Test
public void testEquals() throws IOException {
 Variable variable = new Variable();
 variable.setType(Type.INTEGER);
 Variable initialInstance = clone(variable);
 EqualsTester equalsTester = new EqualsTester();
 equalsTester.addEqualityGroup(initialInstance, initialInstance).addEqualityGroup(new Object());
 variable.setDescription("description");
 equalsTester.addEqualityGroup(clone(variable));
 variable.setDisplayName("display name");
 equalsTester.addEqualityGroup(clone(variable));
 variable.setFields(ImmutableMap.of("f", new Field()));
 equalsTester.addEqualityGroup(clone(variable));
 variable.setLongDescription("long description");
 equalsTester.addEqualityGroup(clone(variable));
 variable.setMinElements(1);
 equalsTester.addEqualityGroup(clone(variable));
 variable.setMinLength(1);
 equalsTester.addEqualityGroup(clone(variable));
 variable.setOptional(true);
 equalsTester.addEqualityGroup(clone(variable));
 variable.setType(Type.BOOLEAN);
 equalsTester.addEqualityGroup(clone(variable));
 variable.setValue(BooleanNode.TRUE);
 equalsTester.addEqualityGroup(clone(variable));
 variable.setValues(ImmutableList.of());
 equalsTester.addEqualityGroup(clone(variable));
 equalsTester.testEquals();
}
origin: batfish/batfish

String varName = e.getKey();
Variable variable = e.getValue();
JsonNode value = variable.getValue();
 if (variable.getOptional()) {
  recursivelyRemoveOptionalVar(jobj, varName);
if (variable.getType() == Variable.Type.QUESTION) {
 if (variable.getMinElements() != null) {
  if (!value.isArray()) {
   throw new IllegalArgumentException("Expecting JSON array for array type");
String varName = e.getKey();
Variable variable = e.getValue();
JsonNode value = variable.getValue();
String valueJsonString = new ObjectMapper().writeValueAsString(value);
boolean stringType = variable.getType().getStringType();
boolean setType = variable.getMinElements() != null;
if (value != null) {
 String topLevelVarNameRegex = Pattern.quote("\"${" + varName + "}\"");
origin: batfish/batfish

@Test
public void testValidateValidNode() throws IOException {
 String parameterName = "boolean";
 JsonNode invalidNode = _mapper.readTree("false");
 Variable variable = new Variable();
 variable.setType(BOOLEAN);
 List<AllowedValue> allowedValues = ImmutableList.of(new AllowedValue("false", "description"));
 variable.setValues(allowedValues);
 Client.validateNode(invalidNode, variable, parameterName);
}
origin: batfish/batfish

@Test
public void testSatisfiedMinElementInput() throws IOException {
 Map<String, JsonNode> parameters = new HashMap<>();
 Map<String, Variable> variables = new HashMap<>();
 String jsonArray =
   "[\"action1\", \"action2\", \"action3\", " + "\"action4\", \"action5\", \"action6\"]";
 parameters.put("actions", _mapper.readTree(jsonArray));
 Variable actionsVariable = new Variable();
 actionsVariable.setType(STRING);
 actionsVariable.setMinElements(5);
 variables.put("actions", actionsVariable);
 Client.validateAndSet(parameters, variables);
}
origin: batfish/batfish

@Test
public void testProvideNonOptionalParameterWithValue() throws IOException {
 Map<String, Variable> variables = new HashMap<>();
 Variable integerVariable = new Variable();
 integerVariable.setValue(_mapper.readTree("3"));
 variables.put("integer", integerVariable);
 Client.checkVariableState(variables);
}
origin: batfish/batfish

@Test
public void testMissingOptionalParameterNoValue() {
 Map<String, Variable> variables = new HashMap<>();
 Variable integerVariable = new Variable();
 integerVariable.setOptional(true);
 Client.checkVariableState(variables);
}
origin: batfish/batfish

@Test
public void testUnsatisfiedMinLengthValue() throws IOException {
 String shortString = "\"short\"";
 Variable variable = new Variable();
 variable.setMinLength(8);
 _thrown.expect(BatfishException.class);
 _thrown.expectMessage(equalTo("Must be at least 8 characters in length"));
 Client.validateType(_mapper.readTree(shortString), variable);
}
origin: batfish/batfish

@Test
public void testSerializationFields()
  throws JsonParseException, JsonMappingException, JsonProcessingException, IOException {
 Variable variable = new Variable();
 String fieldName = "f1";
 Field field = new Field();
 field.setOptional(true);
 variable.setFields(ImmutableMap.of(fieldName, field));
 // fields survive serialization cyle intact
 assertThat(
   BatfishObjectMapper.mapper()
     .readValue(BatfishObjectMapper.writeString(variable), Variable.class)
     .getFields()
     .get(fieldName)
     .getOptional(),
   equalTo(true));
}
origin: batfish/batfish

int minLength = variable.getMinLength() == null ? 0 : variable.getMinLength();
if (value.isTextual() && value.textValue().length() < minLength) {
 throw new BatfishException(
   String.format("Must be at least %s characters in length", minLength));
Variable.Type expectedType = variable.getType();
switch (expectedType) {
 case ADDRESS_BOOK:
origin: batfish/batfish

@Test
public void testMissingNonOptionalParameterNoValue() {
 Map<String, Variable> variables = new HashMap<>();
 Variable integerVariable = new Variable();
 variables.put("integer", integerVariable);
 _thrown.expect(BatfishException.class);
 String errorMessage = "Missing parameter: integer";
 _thrown.expectMessage(equalTo(errorMessage));
 Client.checkVariableState(variables);
}
origin: batfish/batfish

@Test
public void testValidInterfaceValue() throws IOException {
 JsonNode interfaceNode = _mapper.readTree("\"interfaceName\"");
 Variable variable = new Variable();
 variable.setType(INTERFACE);
 Client.validateType(interfaceNode, variable);
}
origin: batfish/batfish

@Test
public void testValidateNodeNotAllowedValue() throws IOException {
 String parameterName = "boolean";
 JsonNode invalidNode = _mapper.readTree("false");
 Variable variable = new Variable();
 variable.setType(BOOLEAN);
 List<AllowedValue> allowedValues = ImmutableList.of(new AllowedValue("true", "description"));
 variable.setValues(allowedValues);
 _thrown.expect(BatfishException.class);
 _thrown.expectMessage(
   String.format("Invalid value: false, allowed values are: %s", allowedValues));
 Client.validateNode(invalidNode, variable, parameterName);
}
origin: batfish/batfish

@Test
public void testUnsatisfiedMinElementInput() throws IOException {
 Map<String, JsonNode> parameters = new HashMap<>();
 Map<String, 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);
}
origin: batfish/batfish

 /**
  * Test that translating an InstanceData object to JSON and using that JSON to create a new
  * InstanceData object produces an object equal to the original instance
  */
 @Test
 public void testJsonSerialization() throws IOException {
  InstanceData instanceData = new InstanceData();
  instanceData.setInstanceName("instanceName");
  instanceData.setDescription("The description");
  instanceData.setLongDescription("The long description");
  instanceData.setOrderedVariableNames(ImmutableList.of("b", "a"));
  instanceData.setTags(new TreeSet<>(Arrays.asList("tag1", "tag2")));
  instanceData.setVariables(ImmutableSortedMap.of("v", new Variable()));
  assertThat(clone(instanceData), equalTo(instanceData));
 }
}
origin: batfish/batfish

@Test
public void testValidRoutingProtocolSpecValue() throws IOException {
 JsonNode rpsNode = _mapper.readTree("\"all\"");
 Variable variable = new Variable();
 variable.setType(ROUTING_PROTOCOL_SPEC);
 Client.validateType(rpsNode, variable);
}
org.batfish.datamodel.questionsVariable

Most used methods

  • setValue
  • <init>
  • getMinElements
  • getOptional
  • getType
  • getValue
  • setMinElements
  • setMinLength
  • setOptional
  • setType
  • setValues
  • getDescription
  • setValues,
  • getDescription,
  • getFields,
  • getMinLength,
  • getValues,
  • setDescription,
  • setDisplayName,
  • setFields,
  • setLongDescription

Popular in Java

  • Start an intent from android
  • setScale (BigDecimal)
  • onCreateOptionsMenu (Activity)
  • findViewById (Activity)
  • Pointer (com.sun.jna)
    An abstraction for a native pointer data type. A Pointer instance represents, on the Java side, a na
  • InputStreamReader (java.io)
    A class for turning a byte stream into a character stream. Data read from the source input stream is
  • RandomAccessFile (java.io)
    Allows reading from and writing to a file in a random-access manner. This is different from the uni-
  • SortedSet (java.util)
    SortedSet is a Set which iterates over its elements in a sorted order. The order is determined eithe
  • TreeSet (java.util)
    TreeSet is an implementation of SortedSet. All optional operations (adding and removing) are support
  • Manifest (java.util.jar)
    The Manifest class is used to obtain attribute information for a JarFile and its entries.
  • Best IntelliJ plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now