@Test public void testArgWithNoValues() throws InterpreterPropertyException { propertyMap = new HashMap<>(); Map<ConfigurationProperty, List<String>> parsedArgs = new CommandLineParser(TestConfigProperty.getAll()).parseProperties(propertyMap, TEST_ARGS); Assert.assertTrue("-showErrors flag not found", parsedArgs.containsKey(TestConfigProperty.SHOW_ERRORS)); }
@Test public void testPathsWithHyphens() throws InterpreterPropertyException { Map<ConfigurationProperty, List<String>> parsedArgs = new CommandLineParser(TestConfigProperty.getAll()).parseProperties(propertyMap, TEST_PATH_ARG_WITH_INLINE_HYPHEN); Assert.assertTrue("-h flag not found", parsedArgs.containsKey(TestConfigProperty.HANDLER_PACKAGES)); Assert.assertEquals("Not equal to handlers.package-name-with-hyphens-", "handlers.package-name-with-hyphens-", parsedArgs.get(TestConfigProperty.HANDLER_PACKAGES).get(0)); Assert.assertTrue("-f flag not found", parsedArgs.containsKey(TestConfigProperty.FEATURE_PATHS)); Assert.assertEquals("Not equal to test.with-hyphen.dir", "test.with-hyphen.dir", parsedArgs.get(TestConfigProperty.FEATURE_PATHS).get(0)); }
@Test public void testArgWithSingleValue() throws InterpreterPropertyException { Map<ConfigurationProperty, List<String>> parsedArgs = new CommandLineParser(TestConfigProperty.getAll()).parseProperties(propertyMap, TEST_ARGS); List<String> fValues = parsedArgs.get(TestConfigProperty.FEATURE_PATHS); Assert.assertEquals("incorrect nunber of -f args found", 1, fValues.size()); }
@Test public void testValueOfWithSingleArg() throws InterpreterPropertyException { Map<ConfigurationProperty, List<String>> parsedArgs = new CommandLineParser(TestConfigProperty.getAll()).parseProperties(propertyMap, TEST_ARGS); List<String> fValues = parsedArgs.get(TestConfigProperty.FEATURE_PATHS); Assert.assertEquals("incorrect value for -f arg found", "file1", fValues.get(0)); }
@Test public void testArgWithMultipleValues() throws InterpreterPropertyException { Map<ConfigurationProperty, List<String>> parsedArgs = new CommandLineParser(TestConfigProperty.getAll()).parseProperties(propertyMap, TEST_ARGS); Assert.assertTrue("-h flag not found", parsedArgs.containsKey(TestConfigProperty.HANDLER_PACKAGES)); Assert.assertEquals("wrong number of values found for -h flag", 2, parsedArgs.get(TestConfigProperty.HANDLER_PACKAGES).size()); }
@Test public void mandatoryPropertyMustBeSet() { System.clearProperty(TestConfigProperty.FEATURE_PATHS.getSystemProperty()); //in case set String[] switches = new String[] { "-d" }; ConfigReader c = new ConfigReader(TestConfigProperty.getAll(), switches); try { c.readConfiguration(); } catch (InterpreterPropertyException e) { assertTrue(e.getMessage().contains("Mandatory property featurePaths was not set")); return; } fail("Must require mandatory -f property value"); }
@Test public void testADefaultValueDoesNotGetSetIfNoDefaultDefined() throws InterpreterPropertyException { String[] switches = new String[] { "-f", "./features", "-h", "org.chorusbdd.chorus" }; ConfigReader c = new ConfigReader(TestConfigProperty.getAll(), switches); c.readConfiguration(); assertTrue(! c.isSet(TestConfigProperty.TAG_EXPRESSION)); }
@Test public void testBooleanSwitchWithValue() throws InterpreterPropertyException { String[] switches = new String[] { "-f", "./features", "-h", "org.chorusbdd.chorus", "-dryrun", "true" }; ConfigReader c = new ConfigReader(TestConfigProperty.getAll(), switches); c.readConfiguration(); assertTrue(c.isTrue(TestConfigProperty.DRY_RUN)); assertTrue(c.isSet(TestConfigProperty.DRY_RUN)); }
@Test public void testDefaultValueGetsSetIfAvailable() throws InterpreterPropertyException { String[] switches = new String[] { "-f", "./features", "-h", "org.chorusbdd.chorus" }; ConfigReader c = new ConfigReader(TestConfigProperty.getAll(), switches); c.readConfiguration(); assertTrue(! c.isTrue(TestConfigProperty.DRY_RUN)); assertTrue(c.isSet(TestConfigProperty.DRY_RUN)); }
@Test public void testBooleanSwitchUsingShortName() throws InterpreterPropertyException { String[] switches = new String[] { "-f", "./features", "-h", "org.chorusbdd.chorus", "-d" }; ConfigReader c = new ConfigReader(TestConfigProperty.getAll(), switches); c.readConfiguration(); assertTrue(c.isTrue(TestConfigProperty.DRY_RUN)); assertTrue(c.isSet(TestConfigProperty.DRY_RUN)); }
@Test public void testBooleanSwitchCanBeSetFalse() throws InterpreterPropertyException { String[] switches = new String[] { "-f", "./features", "-h", "org.chorusbdd.chorus", "-dryrun", "false" }; ConfigReader c = new ConfigReader(TestConfigProperty.getAll(), switches); c.readConfiguration(); assertTrue(! c.isTrue(TestConfigProperty.DRY_RUN)); assertTrue(c.isSet(TestConfigProperty.DRY_RUN)); }
@Test public void testBooleanSwitchWithoutValue() throws InterpreterPropertyException { String[] switches = new String[] { "-f", "./features", "-h", "org.chorusbdd.chorus", "-dryrun" }; ConfigReader c = new ConfigReader(TestConfigProperty.getAll(), switches); c.readConfiguration(); assertTrue(c.isTrue(TestConfigProperty.DRY_RUN)); assertTrue(c.isSet(TestConfigProperty.DRY_RUN)); }