congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
ConfigBuilder
Code IndexAdd Tabnine to your IDE (free)

How to use
ConfigBuilder
in
org.chorusbdd.chorus.handlerconfig.configproperty

Best Java code snippets using org.chorusbdd.chorus.handlerconfig.configproperty.ConfigBuilder (Showing top 17 results out of 315)

origin: Chorus-bdd/Chorus

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;
}
origin: Chorus-bdd/Chorus

public <C> C buildConfig(Class<C> configClass, Properties properties) throws ConfigBuilderException {
  Map<String, HandlerConfigProperty> configPropertiesByName = configPropertyParser.getConfigPropertiesByName(configClass);
  C configInstance;
  try {
    configInstance = configClass.newInstance();
  } catch (Exception e) {
    throw new ConfigBuilderException("Failed to instantiate config class " + configClass.getSimpleName() + " - " + e.getClass().getSimpleName(), e);
  }
  
  //iterate sorted by field name for consistent/deterministic behaviour
  List<String> props = configPropertiesByName.keySet().stream().sorted().collect(Collectors.toList());
    
  for ( String configPropertyName : props) {
    log.debug("Processing config property " + configPropertyName);
    
    HandlerConfigPropertyImpl configProperty = (HandlerConfigPropertyImpl)configPropertiesByName.get(configPropertyName);
    String propertyValue = properties.getProperty(configPropertyName);
    setValueForConfigProperty(configInstance, configPropertyName, configProperty, propertyValue);
  }
  
  warnOnUnusedProperties(properties, configPropertiesByName);
  runClassLevelValidation(configClass, configInstance);
  
  return configInstance;
}
origin: Chorus-bdd/Chorus

@Test
public void testUnvalidatedConfigSettersCanAcceptEmptyStringAsValidPropertyValue() throws ConfigBuilderException {
  Properties p = new Properties();
  p.setProperty("stringProperty", "");
  ConfigClassWithUnvalidatedStringProperty c = configBuilder.buildConfig(ConfigClassWithUnvalidatedStringProperty.class, p);
  assertEquals("", c.stringProperty);
}
origin: Chorus-bdd/Chorus

validate(configPropertyName, propertyValue, configProperty.getValidationPattern());
convertedValue = applyConverterFunction(configPropertyName, configProperty, propertyValue);
origin: Chorus-bdd/Chorus

@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);
}
origin: Chorus-bdd/Chorus

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;
}
origin: Chorus-bdd/Chorus

@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());
  }
}
origin: Chorus-bdd/Chorus

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;
}
origin: Chorus-bdd/Chorus

@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());
  }
}
origin: Chorus-bdd/Chorus

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;
}
origin: Chorus-bdd/Chorus

@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());
}
origin: Chorus-bdd/Chorus

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;
}
origin: Chorus-bdd/Chorus

@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());
  }
}
origin: Chorus-bdd/Chorus

properties.put(ProcessConfig.MAINCLASS_PROPERTY, mainClass);
ProcessConfig config = new ConfigBuilder().buildConfig(ProcessConfig.class, properties);
JavaProcessCommandLineBuilder javaProcessCommandLineBuilder = new JavaProcessCommandLineBuilder(
  new File(System.getProperty("user.dir")),
origin: Chorus-bdd/Chorus

@Test
public void testADefaultValueIsUsedIfIDoNotProvideAValue() throws ConfigBuilderException {
  Properties p = new Properties();
  ConfigClassWithSimpleProperty c = configBuilder.buildConfig(ConfigClassWithSimpleProperty.class, p);
  assertEquals("My Default Value", c.getStringProperty());
}

origin: Chorus-bdd/Chorus

@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);
}
origin: Chorus-bdd/Chorus

@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);
}
org.chorusbdd.chorus.handlerconfig.configpropertyConfigBuilder

Javadoc

Build an instance of a config class from a Properties object The properties object will have its contents validated against the annotated properties of the config class

Most used methods

  • buildConfig
  • <init>
  • applyConverterFunction
  • runClassLevelValidation
  • setValueForConfigProperty
  • validate
  • warnOnUnusedProperties

Popular in Java

  • Parsing JSON documents to java classes using gson
  • getApplicationContext (Context)
  • requestLocationUpdates (LocationManager)
  • scheduleAtFixedRate (ScheduledExecutorService)
  • InputStreamReader (java.io)
    A class for turning a byte stream into a character stream. Data read from the source input stream is
  • HttpURLConnection (java.net)
    An URLConnection for HTTP (RFC 2616 [http://tools.ietf.org/html/rfc2616]) used to send and receive d
  • Socket (java.net)
    Provides a client-side TCP socket.
  • SocketTimeoutException (java.net)
    This exception is thrown when a timeout expired on a socket read or accept operation.
  • BasicDataSource (org.apache.commons.dbcp)
    Basic implementation of javax.sql.DataSource that is configured via JavaBeans properties. This is no
  • SAXParseException (org.xml.sax)
    Encapsulate an XML parse error or warning.> This module, both source code and documentation, is in t
  • CodeWhisperer alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now