ConfigMain { public int execute(String[] args) { if (args.length < 1 || !commandMap.containsKey(args[0].toLowerCase())) { printUsage(); return ERR_INVALID_ARGS; } return commandMap.get(args[0].toLowerCase()).function.apply(args); } ConfigMain();  ConfigMain(PathInputStreamFactory pathInputStreamFactory, PathOutputStreamFactory pathOutputStreamFactory); static void main(String[] args); static void printValidateUsage(); int validate(String[] args); static void printTransformUsage(); static void printUpgradeUsage(); static ConfigSchema transformTemplateToSchema(InputStream source); static ConfigSchema transformVersionedFlowSnapshotToSchema(InputStream source); static ConfigSchema transformVersionedFlowSnapshotToSchema(VersionedFlowSnapshot versionedFlowSnapshot); int upgrade(String[] args); T loadAndPrintValidationErrors(InputStream inputStream, BiFunction<ConfigSchema, Boolean, T> resultHandler); int transform(String[] args); int execute(String[] args); Map<String, Command> createCommandMap(); void printUsage(); static final int ERR_INVALID_ARGS; static final int ERR_UNABLE_TO_OPEN_OUTPUT; static final int ERR_UNABLE_TO_OPEN_INPUT; static final int ERR_UNABLE_TO_READ_TEMPLATE; static final int ERR_UNABLE_TO_PARSE_CONFIG; static final int ERR_INVALID_CONFIG; static final int ERR_UNABLE_TO_CLOSE_CONFIG; static final int ERR_UNABLE_TO_SAVE_CONFIG; static final int SUCCESS; static final String TRANSFORM; static final String TRANSFORM_VFS; static final String VALIDATE; static final String UPGRADE; static final String THERE_ARE_VALIDATION_ERRORS_WITH_THE_TEMPLATE_STILL_OUTPUTTING_YAML_BUT_IT_WILL_NEED_TO_BE_EDITED; }
@Test public void testExecuteNoArgs() { assertEquals(ConfigMain.ERR_INVALID_ARGS, configMain.execute(new String[0])); }
@Test public void testExecuteInvalidCommand() { assertEquals(ConfigMain.ERR_INVALID_ARGS, configMain.execute(new String[]{"badCommand"})); }
@Test public void testValidateInvalidCommand() { assertEquals(ConfigMain.ERR_INVALID_ARGS, configMain.execute(new String[]{ConfigMain.VALIDATE})); }
@Test public void testValidateErrorOpeningInput() throws FileNotFoundException { when(pathInputStreamFactory.create(testInput)).thenThrow(new FileNotFoundException()); assertEquals(ConfigMain.ERR_UNABLE_TO_OPEN_INPUT, configMain.execute(new String[]{ConfigMain.VALIDATE, testInput})); }
@Test public void testValidateUnableToParseConfig() throws FileNotFoundException { when(pathInputStreamFactory.create(testInput)).thenReturn(new ByteArrayInputStream("!@#$%^&".getBytes(Charsets.UTF_8))); assertEquals(ConfigMain.ERR_UNABLE_TO_PARSE_CONFIG, configMain.execute(new String[]{ConfigMain.VALIDATE, testInput})); }
@Test public void testValidateInvalidConfig() throws FileNotFoundException { when(pathInputStreamFactory.create(testInput)).thenAnswer(invocation -> ConfigMainTest.class.getClassLoader().getResourceAsStream("config-malformed-field.yml")); assertEquals(ConfigMain.ERR_INVALID_CONFIG, configMain.execute(new String[]{ConfigMain.VALIDATE, testInput})); }
@Test public void testTransformInvalidCommand() { assertEquals(ConfigMain.ERR_INVALID_ARGS, configMain.execute(new String[]{ConfigMain.TRANSFORM})); }
@Test public void testValidateSuccess() throws FileNotFoundException { when(pathInputStreamFactory.create(testInput)).thenAnswer(invocation -> ConfigMainTest.class.getClassLoader().getResourceAsStream("config.yml")); assertEquals(SUCCESS, configMain.execute(new String[]{ConfigMain.VALIDATE, testInput})); }
@Test public void testValidateV1Success() throws FileNotFoundException { when(pathInputStreamFactory.create(testInput)).thenAnswer(invocation -> ConfigMainTest.class.getClassLoader().getResourceAsStream("config-v1.yml")); assertEquals(SUCCESS, configMain.execute(new String[]{ConfigMain.VALIDATE, testInput})); }
@Test public void testTransformErrorOpeningInput() throws FileNotFoundException { when(pathInputStreamFactory.create(testInput)).thenThrow(new FileNotFoundException()); assertEquals(ConfigMain.ERR_UNABLE_TO_OPEN_INPUT, configMain.execute(new String[]{ConfigMain.TRANSFORM, testInput, testOutput})); }
@Test public void testTransformErrorOpeningOutput() throws FileNotFoundException { when(pathInputStreamFactory.create(testInput)).thenAnswer(invocation -> ConfigMainTest.class.getClassLoader().getResourceAsStream("CsvToJson.xml")); when(pathOutputStreamFactory.create(testOutput)).thenThrow(new FileNotFoundException()); assertEquals(ConfigMain.ERR_UNABLE_TO_OPEN_OUTPUT, configMain.execute(new String[]{ConfigMain.TRANSFORM, testInput, testOutput})); }
@Test public void testTransformErrorReadingTemplate() throws FileNotFoundException { when(pathInputStreamFactory.create(testInput)).thenAnswer(invocation -> new ByteArrayInputStream("malformed xml".getBytes(Charsets.UTF_8))); assertEquals(ConfigMain.ERR_UNABLE_TO_READ_TEMPLATE, configMain.execute(new String[]{ConfigMain.TRANSFORM, testInput, testOutput})); }
@Test public void testTransformErrorTransformingTemplate() throws FileNotFoundException { when(pathInputStreamFactory.create(testInput)).thenAnswer(invocation -> new LimitedInputStream(ConfigMainTest.class.getClassLoader().getResourceAsStream("TemplateWithFunnel.xml"), 25)); assertEquals(ConfigMain.ERR_UNABLE_TO_READ_TEMPLATE, configMain.execute(new String[]{ConfigMain.TRANSFORM, testInput, testOutput})); }
@Test public void testTransformSuccess() throws FileNotFoundException { when(pathInputStreamFactory.create(testInput)).thenAnswer(invocation -> ConfigMainTest.class.getClassLoader().getResourceAsStream("CsvToJson.xml")); when(pathOutputStreamFactory.create(testOutput)).thenAnswer(invocation -> new ByteArrayOutputStream()); assertEquals(SUCCESS, configMain.execute(new String[]{ConfigMain.TRANSFORM, testInput, testOutput})); }
@Test public void testUpgradeInputFileNotFoundException() throws FileNotFoundException { when(pathInputStreamFactory.create(testInput)).thenThrow(new FileNotFoundException()); assertEquals(ConfigMain.ERR_UNABLE_TO_OPEN_INPUT, configMain.execute(new String[]{ConfigMain.UPGRADE, testInput, testOutput})); }
@Test public void testUpgradeCantLoadSchema() throws FileNotFoundException { when(pathInputStreamFactory.create(testInput)).thenReturn(new InputStream() { @Override public int read() throws IOException { throw new IOException(); } }); assertEquals(ConfigMain.ERR_UNABLE_TO_PARSE_CONFIG, configMain.execute(new String[]{ConfigMain.UPGRADE, testInput, testOutput})); }
@Test public void testUpgradeOutputFileNotFoundException() throws FileNotFoundException { when(pathInputStreamFactory.create(testInput)).thenReturn(getClass().getClassLoader().getResourceAsStream("CsvToJson-v1.yml")); when(pathOutputStreamFactory.create(testOutput)).thenThrow(new FileNotFoundException()); assertEquals(ConfigMain.ERR_UNABLE_TO_OPEN_OUTPUT, configMain.execute(new String[]{ConfigMain.UPGRADE, testInput, testOutput})); }
@Test public void testUpgradeCantSaveSchema() throws FileNotFoundException { when(pathInputStreamFactory.create(testInput)).thenReturn(getClass().getClassLoader().getResourceAsStream("CsvToJson-v1.yml")); when(pathOutputStreamFactory.create(testOutput)).thenReturn(new OutputStream() { @Override public void write(int b) throws IOException { throw new IOException(); } }); assertEquals(ConfigMain.ERR_UNABLE_TO_SAVE_CONFIG, configMain.execute(new String[]{ConfigMain.UPGRADE, testInput, testOutput})); }
@Test public void testUpgradeInvalidArgs() { assertEquals(ConfigMain.ERR_INVALID_ARGS, configMain.execute(new String[]{ConfigMain.UPGRADE})); }