@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); }
static void validateJsonPathRegex(String jsonPathRegex) throws BatfishException { if (!jsonPathRegex.startsWith("/")) { throw new BatfishException( String.format( "A Batfish %s must start with \"/\"", Variable.Type.JSON_PATH_REGEX.getName())); } if (!(jsonPathRegex.endsWith("/") || jsonPathRegex.endsWith("/i"))) { throw new BatfishException( String.format( "A Batfish %s must end in either \"/\" or \"/i\"", Variable.Type.JSON_PATH_REGEX.getName())); } String innerPath = ""; if (jsonPathRegex.lastIndexOf('/') > 0) { innerPath = jsonPathRegex.substring(1, jsonPathRegex.lastIndexOf('/')); } try { Pattern.compile(innerPath); } catch (PatternSyntaxException e) { throw new BatfishException( String.format( "Invalid %s at interior of %s", Variable.Type.JAVA_REGEX.getName(), Variable.Type.JSON_PATH_REGEX.getName()), e); } }
Client extends AbstractClient implements IClient { static void validateJsonPathRegex(String jsonPathRegex) throws BatfishException { if (!jsonPathRegex.startsWith("/")) { throw new BatfishException( String.format( "A Batfish %s must start with \"/\"", Variable.Type.JSON_PATH_REGEX.getName())); } if (!(jsonPathRegex.endsWith("/") || jsonPathRegex.endsWith("/i"))) { throw new BatfishException( String.format( "A Batfish %s must end in either \"/\" or \"/i\"", Variable.Type.JSON_PATH_REGEX.getName())); } String innerPath = ""; if (jsonPathRegex.lastIndexOf('/') > 0) { innerPath = jsonPathRegex.substring(1, jsonPathRegex.lastIndexOf('/')); } try { Pattern.compile(innerPath); } catch (PatternSyntaxException e) { throw new BatfishException( String.format( "Invalid %s at interior of %s", Variable.Type.JAVA_REGEX.getName(), Variable.Type.JSON_PATH_REGEX.getName()), e); } } }
Client extends AbstractClient implements IClient { static void validateJsonPathRegex(String jsonPathRegex) throws BatfishException { if (!jsonPathRegex.startsWith("/")) { throw new BatfishException( String.format( "A Batfish %s must start with \"/\"", Variable.Type.JSON_PATH_REGEX.getName())); } if (!(jsonPathRegex.endsWith("/") || jsonPathRegex.endsWith("/i"))) { throw new BatfishException( String.format( "A Batfish %s must end in either \"/\" or \"/i\"", Variable.Type.JSON_PATH_REGEX.getName())); } String innerPath = ""; if (jsonPathRegex.lastIndexOf('/') > 0) { innerPath = jsonPathRegex.substring(1, jsonPathRegex.lastIndexOf('/')); } try { Pattern.compile(innerPath); } catch (PatternSyntaxException e) { throw new BatfishException( String.format( "Invalid %s at interior of %s", Variable.Type.JAVA_REGEX.getName(), Variable.Type.JSON_PATH_REGEX.getName()), e); } } Client(Settings settings);  Client(String[] args); }
Client extends AbstractClient implements IClient { static void validateJsonPathRegex(String jsonPathRegex) throws BatfishException { if (!jsonPathRegex.startsWith("/")) { throw new BatfishException( String.format( "A Batfish %s must start with \"/\"", Variable.Type.JSON_PATH_REGEX.getName())); } if (!(jsonPathRegex.endsWith("/") || jsonPathRegex.endsWith("/i"))) { throw new BatfishException( String.format( "A Batfish %s must end in either \"/\" or \"/i\"", Variable.Type.JSON_PATH_REGEX.getName())); } String innerPath = ""; if (jsonPathRegex.lastIndexOf('/') > 0) { innerPath = jsonPathRegex.substring(1, jsonPathRegex.lastIndexOf('/')); } try { Pattern.compile(innerPath); } catch (PatternSyntaxException e) { throw new BatfishException( String.format( "Invalid %s at interior of %s", Variable.Type.JAVA_REGEX.getName(), Variable.Type.JSON_PATH_REGEX.getName()), e); } } Client(Settings settings);  Client(String[] args); @Override BatfishLogger getLogger(); Settings getSettings(); void run(List<String> initialCommands); }
Client extends AbstractClient implements IClient { static void validateJsonPathRegex(String jsonPathRegex) throws BatfishException { if (!jsonPathRegex.startsWith("/")) { throw new BatfishException( String.format( "A Batfish %s must start with \"/\"", Variable.Type.JSON_PATH_REGEX.getName())); } if (!(jsonPathRegex.endsWith("/") || jsonPathRegex.endsWith("/i"))) { throw new BatfishException( String.format( "A Batfish %s must end in either \"/\" or \"/i\"", Variable.Type.JSON_PATH_REGEX.getName())); } String innerPath = ""; if (jsonPathRegex.lastIndexOf('/') > 0) { innerPath = jsonPathRegex.substring(1, jsonPathRegex.lastIndexOf('/')); } try { Pattern.compile(innerPath); } catch (PatternSyntaxException e) { throw new BatfishException( String.format( "Invalid %s at interior of %s", Variable.Type.JAVA_REGEX.getName(), Variable.Type.JSON_PATH_REGEX.getName()), e); } } Client(Settings settings);  Client(String[] args); @Override BatfishLogger getLogger(); Settings getSettings(); void run(List<String> initialCommands);  }