@Test public void appendPropertyMayBeSetFromMultipleSources() throws InterpreterPropertyException { ConfigurationProperty propertyWithMinValues = new TestProperty(TestConfigProperty.HANDLER_PACKAGES) { public PropertySourceMode getPropertySourceMode() { return PropertySourceMode.APPEND; } }; try { System.setProperty("chorusHandlerPackages", "secondvalue"); ConfigReader c = new ConfigReader(Collections.singletonList(propertyWithMinValues), new String[] { "-h", "onevalue" }); c.readConfiguration(); List<String> values = c.getValues(propertyWithMinValues); assertEquals("property value count", 2, values.size()); } finally { System.clearProperty("chorusHandlerPackages"); } }
@Test public void testCannotSetLessThanMinimumValues() { ConfigurationProperty propertyWithMinValues = new TestProperty(TestConfigProperty.HANDLER_PACKAGES) { public int getMinValueCount() { return 2; } }; ConfigReader c = new ConfigReader(Collections.singletonList(propertyWithMinValues), new String[] { "-h", "onevalue" }); try { c.readConfiguration(); } catch (InterpreterPropertyException e) { assertTrue("contains At Least 2", e.getMessage().contains("At least 2 value(s) must be supplied")); return; } fail("Must complain when less than min vals set"); }
@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 testCannotSetMoreThanMaxValues() { ConfigurationProperty propertyWithMinValues = new TestProperty(TestConfigProperty.HANDLER_PACKAGES) { public int getMaxValueCount() { return 1; } }; ConfigReader c = new ConfigReader(Collections.singletonList(propertyWithMinValues), new String[] { "-h", "onevalue", "twovalues" }); try { c.readConfiguration(); } catch (InterpreterPropertyException e) { assertTrue("contains At Most 1", e.getMessage().contains("At most 1 value(s) must be supplied")); return; } fail("Must complain when more than max vals set"); }
@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 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 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)); }
@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)); }