@Test public void testJsonPathNotBooleanSuffix() throws IOException { String invalidJsonPath = "{\"path\" : \"I am path.\", \"suffix\" : \"I " + "am suffix.\"}"; _thrown.expect(BatfishException.class); _thrown.expectMessage( equalTo( String.format("'suffix' element of %s must be a JSON boolean", JSON_PATH.getName()))); Client.validateJsonPath(_mapper.readTree(invalidJsonPath)); }
@Test public void testNotStringPath() throws IOException { String invalidJsonPath = "{\"path\" : 1}"; _thrown.expect(BatfishException.class); _thrown.expectMessage( equalTo(String.format("'path' element of %s must be a JSON string", JSON_PATH.getName()))); Client.validateJsonPath(_mapper.readTree(invalidJsonPath)); }
@Test public void testEmptyJsonPathRegex() { _thrown.expect(BatfishException.class); _thrown.expectMessage( equalTo(String.format("A Batfish %s must start with \"/\"", JSON_PATH_REGEX.getName()))); Client.validateJsonPathRegex(""); }
@Test public void testUnStringInputWhenExpectString() throws IOException { String input = "10"; String expectedMessage = String.format("A Batfish %s must be a JSON string", STRING.getName()); validateTypeWithInvalidInput(input, expectedMessage, STRING); }
@Test public void testInvalidJsonPathRegexValue() throws IOException { String input = "\"/pathRegex\""; Type expectedType = JSON_PATH_REGEX; String expectedMessage = String.format("A Batfish %s must end in either \"/\" or \"/i\"", JSON_PATH_REGEX.getName()); validateTypeWithInvalidInput(input, expectedMessage, expectedType); }
@Test public void testInvalidInteriorJavaRegex() { String invalidJavaRegex = "/...{\\\\Q8\\\\E}/"; _thrown.expect(BatfishException.class); _thrown.expectMessage( equalTo( String.format( "Invalid %s at interior of %s", JAVA_REGEX.getName(), JSON_PATH_REGEX.getName()))); Client.validateJsonPathRegex(invalidJavaRegex); }
@Test public void testNonStringPrefixValue() throws IOException { String input = "10"; Type expectedType = PREFIX; String expectedMessage = String.format("A Batfish %s must be a JSON string", expectedType.getName()); validateTypeWithInvalidInput(input, expectedMessage, expectedType); }
@Test public void testInvalidJsonPathValue() throws IOException { String input = "{\"variable\" : \"I am variable\"}"; Type expectedType = JSON_PATH; String expectedMessage = String.format("Missing 'path' element of %s", JSON_PATH.getName()); validateTypeWithInvalidInput(input, expectedMessage, expectedType); }
@Test public void testInvalidIpsecSessionStatusValue() throws IOException { String input = "5"; Type expectedType = IPSEC_SESSION_STATUS; String expectedMessage = String.format("A Batfish %s must be a JSON string", expectedType.getName()); validateTypeWithInvalidInput(input, expectedMessage, expectedType); }
@Test public void testInvalidIpProtocolValue() throws IOException { String input = "\"invalid\""; Type expectedType = IP_PROTOCOL; String expectedMessage = String.format("Unknown %s string", expectedType.getName()); validateTypeWithInvalidInput(input, expectedMessage, expectedType); }
@Test public void testInvalidIntegerValue() throws IOException { String input = "1.5"; Type expectedType = INTEGER; String expectedMessage = String.format("It is not a valid JSON %s value", INTEGER.getName()); validateTypeWithInvalidInput(input, expectedMessage, expectedType); }
@Test public void testInvalidBgpSessionStatusValue() throws IOException { String input = "5"; Type expectedType = BGP_SESSION_STATUS; String expectedMessage = String.format("A Batfish %s must be a JSON string", expectedType.getName()); validateTypeWithInvalidInput(input, expectedMessage, expectedType); }
@Test public void testInvalidAddressBookValue() throws IOException { String input = "5"; Type expectedType = ADDRESS_BOOK; String expectedMessage = String.format("A Batfish %s must be a JSON string", expectedType.getName()); validateTypeWithInvalidInput(input, expectedMessage, expectedType); }
@Test public void testNonStringProtocolValue() throws IOException { String input = "10"; Type expectedType = PROTOCOL; String expectedMessage = String.format("A Batfish %s must be a JSON string", expectedType.getName()); validateTypeWithInvalidInput(input, expectedMessage, expectedType); }
@Test public void testNonStringOrIntSubRangeValue() throws IOException { String input = "false"; Type expectedType = SUBRANGE; String expectedMessage = String.format("A Batfish %s must be a JSON string or integer", expectedType.getName()); validateTypeWithInvalidInput(input, expectedMessage, expectedType); }
@Test public void testInvalidNodeRoleDimensionValue() throws IOException { String input = "5"; Type expectedType = NODE_ROLE_DIMENSION; String expectedMessage = String.format("A Batfish %s must be a JSON string", expectedType.getName()); validateTypeWithInvalidInput(input, expectedMessage, expectedType); }
@Test public void testInvalidLongValue() throws IOException { String input = "\"string\""; Type expectedType = LONG; String expectedMessage = String.format("It is not a valid JSON %s value", LONG.getName()); validateTypeWithInvalidInput(input, expectedMessage, expectedType); }
@Test public void testInvalidFloatValue() throws IOException { String input = "\"string\""; Type expectedType = FLOAT; String expectedMessage = String.format("It is not a valid JSON %s value", FLOAT.getName()); validateTypeWithInvalidInput(input, expectedMessage, expectedType); }
@Test public void testInvalidDoubleValue() throws IOException { String input = "\"string\""; Type expectedType = DOUBLE; String expectedMessage = String.format("It is not a valid JSON %s value", DOUBLE.getName()); validateTypeWithInvalidInput(input, expectedMessage, expectedType); }
@Test public void testInvalidAddressGroupValue() throws IOException { String input = "5"; Type expectedType = ADDRESS_GROUP; String expectedMessage = String.format("A Batfish %s must be a JSON string", expectedType.getName()); validateTypeWithInvalidInput(input, expectedMessage, expectedType); }