@Test public void testCpl() throws Exception { String[] argsCplImp = new String[]{ "--cpl", ImpUtils.getCorrectCpl().getName(), "--imp", ImpUtils.getImpFolder().getAbsolutePath() }; String[] argsCplNoImp = new String[]{ "--cpl", ImpUtils.getCorrectCpl().getName() }; String[] argsNoCplNoImp = new String[]{ }; ImfUtilityInputParameters inputParametersCplImp = new FakeInputParameters( CliFactory.parseArguments(ImfUtilityCmdLineArgs.class, argsCplImp), new FakeDefaultTools()); ImfUtilityInputParameters inputParametersCplNoImp = new FakeInputParameters( CliFactory.parseArguments(ImfUtilityCmdLineArgs.class, argsCplNoImp), new FakeDefaultTools()); ImfUtilityInputParameters inputParametersNoCplNoImp = new FakeInputParameters( CliFactory.parseArguments(ImfUtilityCmdLineArgs.class, argsNoCplNoImp), new FakeDefaultTools()); assertEquals(ImpUtils.getCorrectCpl(), inputParametersCplImp.getCplFile()); assertEquals(new File(ImpUtils.getCorrectCpl().getName()), inputParametersCplNoImp.getCplFile()); assertNull(inputParametersNoCplNoImp.getCplFile()); }
@Test public void testCmdLineWorkingDir() { String[] argsWorkingDir = new String[]{ "-w", TemplateParameterContextCreator.getWorkingDir().getAbsolutePath() }; String[] argsNoWorkingDir = new String[]{ }; ImfUtilityInputParameters inputParametersWorkingDir = new FakeInputParameters( CliFactory.parseArguments(ImfUtilityCmdLineArgs.class, argsWorkingDir), new FakeDefaultTools()); ImfUtilityInputParameters inputParametersNoWorkingDir = new FakeInputParameters( CliFactory.parseArguments(ImfUtilityCmdLineArgs.class, argsNoWorkingDir), new FakeDefaultTools()); assertEquals(TemplateParameterContextCreator.getWorkingDir(), inputParametersWorkingDir.getWorkingDirFile()); assertNull(inputParametersNoWorkingDir.getWorkingDirFile()); }
@Test public void testImpFolder() throws Exception { String[] argsImp = new String[]{ "--imp", ImpUtils.getImpFolder().getAbsolutePath() }; String[] argsNoImp = new String[]{}; ImfUtilityInputParameters inputParametersImp = new FakeInputParameters( CliFactory.parseArguments(ImfUtilityCmdLineArgs.class, argsImp), new FakeDefaultTools()); ImfUtilityInputParameters inputParametersNoImp = new FakeInputParameters( CliFactory.parseArguments(ImfUtilityCmdLineArgs.class, argsNoImp), new FakeDefaultTools()); assertEquals(ImpUtils.getImpFolder(), inputParametersImp.getImpDirectoryFile()); assertNull(inputParametersNoImp.getImpDirectoryFile()); }
@Test public void testConfigXml() { String[] argsConfig = new String[]{ "-c", ConfigUtils.getCorrectConfigXmlPath() }; String[] argsNoConfig = new String[]{}; ImfUtilityInputParameters inputParametersConfig = new FakeInputParameters( CliFactory.parseArguments(ImfUtilityCmdLineArgs.class, argsConfig), new FakeDefaultTools()); ImfUtilityInputParameters inputParametersNoConfig = new FakeInputParameters( CliFactory.parseArguments(ImfUtilityCmdLineArgs.class, argsNoConfig), new FakeDefaultTools()); assertEquals(new File(ConfigUtils.getCorrectConfigXmlPath()), inputParametersConfig.getConfigFile()); assertNull(inputParametersNoConfig.getConfigFile()); }
@Test(expected = ArgumentValidationException.class) public void testValidateImpNotExistentFolder() throws Exception { String[] args = new String[]{ "--imp", "someFolder", "--cpl", ImpUtils.getCorrectCpl().getName(), "-w", TemplateParameterContextCreator.getWorkingDir().getAbsolutePath() }; ImfUtilityInputParameters inputParameters = new FakeInputParameters( CliFactory.parseArguments(ImfUtilityCmdLineArgs.class, args), new FakeDefaultTools()); ImfUtilityInputParametersValidator.validateInputParameters(inputParameters); }
@Test(expected = ArgumentValidationException.class) public void testValidateConfigNotExistentFile() throws Exception { String[] args = new String[]{ "-c", "someFile" }; ImfUtilityInputParameters inputParameters = new FakeInputParameters( CliFactory.parseArguments(ImfUtilityCmdLineArgs.class, args), new FakeDefaultTools()); ImfUtilityInputParametersValidator.validateCmdLineArguments(inputParameters); }
@Test(expected = ArgumentValidationException.class) public void testValidateConfigNotSpecified() throws Exception { String[] args = new String[]{}; ImfUtilityInputParameters inputParameters = new FakeInputParameters( CliFactory.parseArguments(ImfUtilityCmdLineArgs.class, args), new FakeDefaultTools()); ImfUtilityInputParametersValidator.validateCmdLineArguments(inputParameters); }
@Test public void testCmdLineCplReplacesDefault() throws Exception { String[] args = new String[]{ "--cpl", ImpUtils.getCorrectCpl().getName(), "--imp", ImpUtils.getImpFolder().getAbsolutePath() }; ImfUtilityInputParameters inputParameters = new FakeInputParameters( CliFactory.parseArguments(ImfUtilityCmdLineArgs.class, args), new FakeDefaultTools()); inputParameters.setDefaultCpl("defaultCpl"); assertEquals(ImpUtils.getCorrectCpl(), inputParameters.getCplFile()); }
@Test public void testCmdLineImpReplacesDefault() throws Exception { String[] args = new String[]{ "--imp", ImpUtils.getImpFolder().getAbsolutePath() }; ImfUtilityInputParameters inputParameters = new FakeInputParameters( CliFactory.parseArguments(ImfUtilityCmdLineArgs.class, args), new FakeDefaultTools()); inputParameters.setDefaultImp("defaultImp"); assertEquals(ImpUtils.getImpFolder(), inputParameters.getImpDirectoryFile()); }
@Test(expected = ArgumentValidationException.class) public void testValidateCplNotExistentFile() throws Exception { String[] args = new String[]{ "--imp", ImpUtils.getImpFolder().getAbsolutePath(), "--cpl", "someFile", "-w", TemplateParameterContextCreator.getWorkingDir().getAbsolutePath() }; ImfUtilityInputParameters inputParameters = new FakeInputParameters( CliFactory.parseArguments(ImfUtilityCmdLineArgs.class, args), new FakeDefaultTools()); ImfUtilityInputParametersValidator.validateInputParameters(inputParameters); }
@Test public void testValidateConfigCorrect() throws Exception { @SuppressWarnings("ConstantConditions") String[] args = new String[]{ "-c", ConfigUtils.getCorrectConfigXmlFile().getAbsolutePath() }; ImfUtilityInputParameters inputParameters = new FakeInputParameters( CliFactory.parseArguments(ImfUtilityCmdLineArgs.class, args), new FakeDefaultTools()); ImfUtilityInputParametersValidator.validateCmdLineArguments(inputParameters); }
@Test public void testDefaultImpFolder() throws Exception { String[] args = new String[]{}; ImfUtilityInputParameters inputParameters = new FakeInputParameters( CliFactory.parseArguments(ImfUtilityCmdLineArgs.class, args), new FakeDefaultTools()); inputParameters.setDefaultImp("defaultImp"); assertEquals(new File("defaultImp"), inputParameters.getImpDirectoryFile()); }
@Test public void testDefaultWorkingDir() { String[] args = new String[]{}; ImfUtilityInputParameters inputParameters = new FakeInputParameters( CliFactory.parseArguments(ImfUtilityCmdLineArgs.class, args), new FakeDefaultTools()); inputParameters.setDefaultWorkingDir("defaultWorkingDir"); assertEquals(new File("defaultWorkingDir"), inputParameters.getWorkingDirFile()); }
@Test public void tesCmdLineWorkingDirReplacesDefault() { String[] args = new String[]{ "-w", TemplateParameterContextCreator.getWorkingDir().getAbsolutePath() }; ImfUtilityInputParameters inputParameters = new FakeInputParameters( CliFactory.parseArguments(ImfUtilityCmdLineArgs.class, args), new FakeDefaultTools()); inputParameters.setDefaultWorkingDir("defaultWorkingDir"); assertEquals(TemplateParameterContextCreator.getWorkingDir(), inputParameters.getWorkingDirFile()); }
@Test(expected = ArgumentValidationException.class) public void testValidateImpNotSpecified() throws Exception { String[] args = new String[]{ "--cpl", ImpUtils.getCorrectCpl().getName(), "-w", TemplateParameterContextCreator.getWorkingDir().getAbsolutePath() }; ImfUtilityInputParameters inputParameters = new FakeInputParameters( CliFactory.parseArguments(ImfUtilityCmdLineArgs.class, args), new FakeDefaultTools()); ImfUtilityInputParametersValidator.validateInputParameters(inputParameters); }
@Test public void testValidateInputParamsCorrectAbsoluteCpl() throws Exception { String[] args = new String[]{ "--imp", ImpUtils.getImpFolder().getAbsolutePath(), "--cpl", ImpUtils.getCorrectCpl().getAbsolutePath(), "-w", TemplateParameterContextCreator.getWorkingDir().getAbsolutePath() }; ImfUtilityInputParameters inputParameters = new FakeInputParameters( CliFactory.parseArguments(ImfUtilityCmdLineArgs.class, args), new FakeDefaultTools()); ImfUtilityInputParametersValidator.validateInputParameters(inputParameters); }
@Test public void testDefaultCpl() throws Exception { String[] args = new String[]{}; ImfUtilityInputParameters inputParameters = new FakeInputParameters( CliFactory.parseArguments(ImfUtilityCmdLineArgs.class, args), new FakeDefaultTools()); inputParameters.setDefaultImp("defaultImp"); inputParameters.setDefaultCpl("defaultCpl"); assertEquals(new File("defaultImp", "defaultCpl"), inputParameters.getCplFile()); }
@Test(expected = ArgumentValidationException.class) public void testValidateWorkingDirNotSpecified() throws Exception { String[] args = new String[]{ "--imp", ImpUtils.getImpFolder().getAbsolutePath(), "--cpl", ImpUtils.getCorrectCpl().getName() }; ImfUtilityInputParameters inputParameters = new FakeInputParameters( CliFactory.parseArguments(ImfUtilityCmdLineArgs.class, args), new FakeDefaultTools()); ImfUtilityInputParametersValidator.validateInputParameters(inputParameters); }
@Test(expected = ArgumentValidationException.class) public void testValidateCplNotSpecified() throws Exception { String[] args = new String[]{ "--imp", ImpUtils.getImpFolder().getAbsolutePath(), "-w", TemplateParameterContextCreator.getWorkingDir().getAbsolutePath() }; ImfUtilityInputParameters inputParameters = new FakeInputParameters( CliFactory.parseArguments(ImfUtilityCmdLineArgs.class, args), new FakeDefaultTools()); ImfUtilityInputParametersValidator.validateInputParameters(inputParameters); }
@Test public void testValidateInputParamsCorrectRelativeCpl() throws Exception { String[] args = new String[]{ "--imp", ImpUtils.getImpFolder().getAbsolutePath(), "--cpl", ImpUtils.getCorrectCpl().getName(), "-w", TemplateParameterContextCreator.getWorkingDir().getAbsolutePath() }; ImfUtilityInputParameters inputParameters = new FakeInputParameters( CliFactory.parseArguments(ImfUtilityCmdLineArgs.class, args), new FakeDefaultTools()); ImfUtilityInputParametersValidator.validateInputParameters(inputParameters); }