private WebSocketsConfig getWebSocketsConfig(String configName, Properties webSocketsProperties) { WebSocketsConfigBean config; try { config = new ConfigBuilder().buildConfig(WebSocketsConfigBean.class, webSocketsProperties); } catch (ConfigBuilderException e) { throw new ChorusException(String.format("Invalid config '%s'. %s", configName, e.getMessage())); } config.setConfigName(configName); return config; }
private SeleniumConfig getSeleniumConfig(String configName, Properties remotingProperties) { SeleniumConfigBean config; try { config = new ConfigBuilder().buildConfig(SeleniumConfigBean.class, remotingProperties); } catch (ConfigBuilderException e) { throw new ChorusException(String.format("Invalid config '%s'. %s", configName, e.getMessage())); } config.setConfigName(configName); return config; }
private RemotingManagerConfig buildRemotingConfig(String configName, Properties remotingProperties) { RemotingConfig config; try { config = new ConfigBuilder().buildConfig(RemotingConfig.class, remotingProperties); } catch (ConfigBuilderException e) { throw new ChorusException(String.format("Invalid config '%s'. %s", configName, e.getMessage())); } config.setConfigName(configName); return config; }
private ProcessConfig buildProcessesConfig(String configName, Properties processProperties) { ProcessConfig config; try { config = new ConfigBuilder().buildConfig(ProcessConfig.class, processProperties); } catch (ConfigBuilderException e) { throw new ChorusException(String.format("Invalid config '%s'. %s", configName, e.getMessage())); } config.setConfigName(configName); return config; }
private SqlConfig getSqlConfig(String configName, Properties processProperties) { SqlConfigBean config; try { config = new ConfigBuilder().buildConfig(SqlConfigBean.class, processProperties); } catch (ConfigBuilderException e) { throw new ChorusException(String.format("Invalid config '%s'. %s", configName, e.getMessage())); } config.setConfigName(configName); return config; }
@Test public void testUnvalidatedConfigSettersCanAcceptEmptyStringAsValidPropertyValue() throws ConfigBuilderException { Properties p = new Properties(); p.setProperty("stringProperty", ""); ConfigClassWithUnvalidatedStringProperty c = configBuilder.buildConfig(ConfigClassWithUnvalidatedStringProperty.class, p); assertEquals("", c.stringProperty); }
@Test public void testConfigPropertiesWithEnumField() throws ConfigBuilderException { Properties p = new Properties(); p.setProperty("enumField", "feature"); p.setProperty("enumFieldCaseInsensitive", "ScEnArIo"); ConfigClassWithEnumTypes c = configBuilder.buildConfig(ConfigClassWithEnumTypes.class, p); assertEquals(Scope.FEATURE, c.scope); assertEquals(Scope.SCENARIO, c.scopeCaseInsensitive); }
@Test public void testAnEnumValueWhichCantBeMappedThrowsException() { Properties p = new Properties(); p.setProperty("enumField", "rgioergergerg"); try { ConfigClassWithEnumTypes c = configBuilder.buildConfig(ConfigClassWithEnumTypes.class, p); fail("Should throw exception"); } catch (Exception e) { assertEquals("Property enumField value 'rgioergergerg' does not match pattern '(?i)SCENARIO|FEATURE'", e.getMessage()); } }
@Test public void testValidationRulesAreAppliedToMyProvidedValue() { Properties p = new Properties(); p.setProperty("stringProperty", "This value will not validate"); try { configBuilder.buildConfig(ConfigClassWithSimpleProperty.class, p); fail("Should not validate"); } catch (Exception e) { assertEquals("Property stringProperty value 'This value will not validate' does not match pattern 'My.*'", e.getMessage()); } }
@Test public void testICanBuildABeanProvidingASimpleStringProperty() throws ConfigBuilderException { Properties p = new Properties(); p.setProperty("stringProperty", "My Provided Value"); ConfigClassWithSimpleProperty c = configBuilder.buildConfig(ConfigClassWithSimpleProperty.class, p); assertEquals("My Provided Value", c.getStringProperty()); }
@Test public void testAMandatoryPropertyMustBeProvidedIfADefaultDoesNotExist() { Properties p = new Properties(); try { configBuilder.buildConfig(ConfigClassPropertyWithNoDefault.class, p); fail("Should not validate"); } catch (Exception e) { assertEquals("Property stringProperty is mandatory but no value was provided", e.getMessage()); } }
@Test public void testADefaultValueIsUsedIfIDoNotProvideAValue() throws ConfigBuilderException { Properties p = new Properties(); ConfigClassWithSimpleProperty c = configBuilder.buildConfig(ConfigClassWithSimpleProperty.class, p); assertEquals("My Default Value", c.getStringProperty()); }
properties.put(ProcessConfig.MAINCLASS_PROPERTY, mainClass); ProcessConfig config = new ConfigBuilder().buildConfig(ProcessConfig.class, properties); JavaProcessCommandLineBuilder javaProcessCommandLineBuilder = new JavaProcessCommandLineBuilder( new File(System.getProperty("user.dir")),
@Test public void testConfigProperiesWithPrimitiveSetters() throws ConfigBuilderException { Properties p = new Properties(); p.setProperty("intProperty", "123"); p.setProperty("floatProperty", "234.5"); p.setProperty("longProperty", "345"); p.setProperty("doubleProperty", "456.7"); p.setProperty("booleanProperty", "true"); p.setProperty("charProperty", "X"); p.setProperty("shortProperty", "123"); ConfigClassPropertyWithPrimitivesSetters c = configBuilder.buildConfig(ConfigClassPropertyWithPrimitivesSetters.class, p); assertEquals( 123, c.intProperty); assertEquals( 234.5f, c.floatProperty, 0); assertEquals( 345, c.longProperty); assertEquals(456.7d, c.doubleProperty, 0); assertEquals( true, c.booleanProperty); assertEquals( 'X', c.charProperty); assertEquals( 123, c.shortProperty); }
@Test public void testConfigProperiesWithConversions() throws ConfigBuilderException { Properties p = new Properties(); p.setProperty("intProperty", "123"); p.setProperty("floatProperty", "234.5"); p.setProperty("longProperty", "345"); p.setProperty("doubleProperty", "456.7"); p.setProperty("booleanProperty", "true"); p.setProperty("charProperty", "X"); p.setProperty("shortProperty", "123"); ConfigClassPropertyWithConversions c = configBuilder.buildConfig(ConfigClassPropertyWithConversions.class, p); assertEquals( 123, c.intProperty); assertEquals( 234.5f, c.floatProperty, 0); assertEquals( 345, c.longProperty); assertEquals(456.7d, c.doubleProperty, 0); assertEquals( true, c.booleanProperty); assertEquals( 'X', c.charProperty); assertEquals( 123, c.shortProperty); }