Java Code Examples for com.typesafe.config.ConfigFactory#parseResourcesAnySyntax()

The following examples show how to use com.typesafe.config.ConfigFactory#parseResourcesAnySyntax() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HoconConfigSourceProvider.java    From smallrye-config with Apache License 2.0 4 votes vote down vote up
static ConfigSource getConfigSource(ClassLoader classLoader, String resource, int ordinal) {
    final Config config = ConfigFactory.parseResourcesAnySyntax(classLoader, resource,
            ConfigParseOptions.defaults().setClassLoader(classLoader).setSyntax(ConfigSyntax.CONF));
    return new HoconConfigSource(config, resource, ordinal);
}
 
Example 2
Source File: ServiceSpecificEnvironmentConfigSupplier.java    From ditto with Eclipse Public License 2.0 4 votes vote down vote up
private Config getConfigFromResource(final HostingEnvironment hostingEnvironment) {
    return ConfigFactory.parseResourcesAnySyntax(getResourceBasename(hostingEnvironment));
}
 
Example 3
Source File: RawConfigSupplier.java    From ditto with Eclipse Public License 2.0 4 votes vote down vote up
private Config getServiceSpecificBaseConfig() {
    return ConfigFactory.parseResourcesAnySyntax(serviceName);
}
 
Example 4
Source File: RawConfigSupplier.java    From ditto with Eclipse Public License 2.0 4 votes vote down vote up
private static Config getCommonDittoServicesConfig() {
    return ConfigFactory.parseResourcesAnySyntax(DITTO_BASE_CONFIG_NAME);
}
 
Example 5
Source File: StreamsConfiguratorTest.java    From streams with Apache License 2.0 4 votes vote down vote up
/**
 * Test that custom config file includes and internal references work as expected.
 *
 * @throws Exception
 */
@Test
public void testResolve() throws Exception {

  Config overrides = ConfigFactory.parseResourcesAnySyntax("testResolve.conf");

  StreamsConfigurator.addConfig(overrides);

  Config withOverride = StreamsConfigurator.getConfig();

  assert( withOverride.getString("message") != null);

  assert( withOverride.getConfig("evenmore").getString("message") != null);

  assert( withOverride.getString("samemessage") != null);

}
 
Example 6
Source File: StreamsConfiguratorTest.java    From streams with Apache License 2.0 4 votes vote down vote up
/**
 * Test that a class which uses a configuration class with StreamsConfiguration
 * as an ancestor can use a typed StreamsConfigurator and detectCustomConfiguration
 * to populate its fields using ComponentConfigurators automatically, using a
 * a custom Configuration.
 *
 * @throws Exception
 */
@Test
public void testDetectCustomStreamsConfigurationProvideConfig() throws Exception {

  Config base = StreamsConfigurator.getConfig();

  Config overrides = ConfigFactory.parseResourcesAnySyntax("custom.conf");

  Config combined = overrides.withFallback(base);

  StreamsConfigurator<StreamsConfigurationForTesting> configurator = new StreamsConfigurator<>(StreamsConfigurationForTesting.class);

  StreamsConfigurationForTesting customPojo = configurator.detectCustomConfiguration(combined);

  verifyCustomStreamsConfiguration(customPojo);

}
 
Example 7
Source File: StreamsConfiguratorTest.java    From streams with Apache License 2.0 4 votes vote down vote up
/**
 * Test that a class which uses a configuration class with StreamsConfiguration
 * as an ancestor can use a typed StreamsConfigurator and detectCustomConfiguration
 * to populate its fields using ComponentConfigurators automatically, sourced using
 * a provided child path.
 *
 * @throws Exception
 */
@Test
public void testDetectCustomStreamsConfigurationProvidePath() throws Exception {

  String testPath = "childPath";

  Config base = StreamsConfigurator.getConfig();

  Config overrides = ConfigFactory.parseResourcesAnySyntax("customChild.conf");

  Config combined = overrides.withFallback(base);

  StreamsConfigurator<StreamsConfigurationForTesting> configurator = new StreamsConfigurator<>(StreamsConfigurationForTesting.class);

  StreamsConfigurationForTesting customPojo = configurator.detectCustomConfiguration(combined, testPath);

  verifyCustomStreamsConfiguration(customPojo);
}
 
Example 8
Source File: ComponentConfiguratorTest.java    From streams with Apache License 2.0 4 votes vote down vote up
/**
 * Test that ComponentConfiguration.detectConfiguration() picks up properties defined
 * on a package parent path.
 *
 * @throws Exception
 */
@Test
public void testDetectConfigurationCompoundPath() throws Exception {

  Config testConfig = ConfigFactory.parseResourcesAnySyntax("packagePath.conf");

  StreamsConfigurator.setConfig(testConfig);

  ComponentConfigurator<ComponentConfiguration> configurator = new ComponentConfigurator<>(ComponentConfiguration.class);

  ComponentConfiguration configuredPojo = configurator.detectConfiguration("org.apache.streams.config");

  Assert.assertThat(configuredPojo, is(notNullValue()));

  Assert.assertThat(configuredPojo.getInClasses(), is(notNullValue()));
  Assert.assertThat(configuredPojo.getInClasses().size(), is(greaterThan(0)));

  Assert.assertThat(configuredPojo.getOutClasses(), is(notNullValue()));
  Assert.assertThat(configuredPojo.getOutClasses().size(), is(greaterThan(0)));

}
 
Example 9
Source File: ComponentConfiguratorTest.java    From streams with Apache License 2.0 4 votes vote down vote up
/**
 * Test that ComponentConfiguration.detectConfiguration() picks up properties defined
 * on the class simple name with no path.
 *
 * @throws Exception
 */
@Test
public void testDetectConfigurationSimpleClassName() throws Exception {

  Config testConfig = ConfigFactory.parseResourcesAnySyntax("simpleClassName.conf");

  StreamsConfigurator.setConfig(testConfig);

  ComponentConfigurator<ComponentConfiguration> configurator = new ComponentConfigurator<>(ComponentConfiguration.class);

  ComponentConfiguration configuredPojo = configurator.detectConfiguration();

  Assert.assertThat(configuredPojo, is(notNullValue()));

  Assert.assertThat(configuredPojo.getInClasses(), is(notNullValue()));
  Assert.assertThat(configuredPojo.getInClasses().size(), is(greaterThan(0)));
  Assert.assertThat(configuredPojo.getInClasses().get(0), equalTo("java.lang.Object"));

  Assert.assertThat(configuredPojo.getOutClasses(), is(notNullValue()));
  Assert.assertThat(configuredPojo.getOutClasses().size(), is(greaterThan(0)));
  Assert.assertThat(configuredPojo.getOutClasses().get(0), equalTo("java.lang.Object"));

}
 
Example 10
Source File: ComponentConfiguratorTest.java    From streams with Apache License 2.0 4 votes vote down vote up
/**
 * Test that ComponentConfiguration.detectConfiguration() picks up properties defined
 * on the class canonical name.
 *
 * @throws Exception
 */
@Test
public void testDetectConfigurationCanonicalClassName() throws Exception {

  Config testConfig = ConfigFactory.parseResourcesAnySyntax("canonicalClassName.conf");

  StreamsConfigurator.setConfig(testConfig);

  ComponentConfigurator<ComponentConfiguration> configurator = new ComponentConfigurator<>(ComponentConfiguration.class);

  ComponentConfiguration configuredPojo = configurator.detectConfiguration();

  Assert.assertThat(configuredPojo, is(notNullValue()));

  Assert.assertThat(configuredPojo.getInClasses(), is(notNullValue()));
  Assert.assertThat(configuredPojo.getInClasses().size(), is(greaterThan(0)));
  Assert.assertThat(configuredPojo.getInClasses().get(0), equalTo("java.lang.Object"));

  Assert.assertThat(configuredPojo.getOutClasses(), is(notNullValue()));
  Assert.assertThat(configuredPojo.getOutClasses().size(), is(greaterThan(0)));
  Assert.assertThat(configuredPojo.getOutClasses().get(0), equalTo("java.lang.Object"));

}
 
Example 11
Source File: ComponentConfiguratorTest.java    From streams with Apache License 2.0 4 votes vote down vote up
/**
 * Test that ComponentConfiguration.detectConfiguration() picks up properties defined
 * from multiple levels of class ancestry in the right order.
 *
 * @throws Exception
 */
@Test
public void testDetectConfigurationClassHierarchy() throws Exception {

  Config testConfig = ConfigFactory.parseResourcesAnySyntax("classHierarchy.conf");

  StreamsConfigurator.setConfig(testConfig);

  ComponentConfigurator<ComponentConfigurationForTestingNumberTwo> configurator = new ComponentConfigurator(ComponentConfigurationForTestingNumberTwo.class);

  ComponentConfiguration configuredPojo = configurator.detectConfiguration();

  Assert.assertThat(configuredPojo, is(notNullValue()));

  Assert.assertThat(configuredPojo.getInClasses(), is(notNullValue()));
  Assert.assertThat(configuredPojo.getInClasses().size(), is(greaterThan(0)));
  Assert.assertThat(configuredPojo.getInClasses().get(0), equalTo("java.lang.Integer"));

  Assert.assertThat(configuredPojo.getOutClasses(), is(notNullValue()));
  Assert.assertThat(configuredPojo.getOutClasses().size(), is(greaterThan(0)));
  Assert.assertThat(configuredPojo.getOutClasses().get(0), equalTo("java.lang.Float"));

}
 
Example 12
Source File: ComponentConfiguratorTest.java    From streams with Apache License 2.0 4 votes vote down vote up
/**
 * Test that ComponentConfiguration.detectConfiguration() picks up properties defined
 * from multiple levels of package hierarchy in the right order.
 *
 * @throws Exception
 */
@Test
public void testDetectConfigurationPackageHierarchy() throws Exception {

  Config testConfig = ConfigFactory.parseResourcesAnySyntax("packageHierarchy.conf");

  StreamsConfigurator.setConfig(testConfig);

  ComponentConfigurator<ComponentConfiguration> configurator = new ComponentConfigurator(ComponentConfiguration.class);

  ComponentConfiguration configuredPojo = configurator.detectConfiguration();

  Assert.assertThat(configuredPojo, is(notNullValue()));

  Assert.assertThat(configuredPojo.getInClasses(), is(notNullValue()));
  Assert.assertThat(configuredPojo.getInClasses().size(), is(greaterThan(0)));
  Assert.assertThat(configuredPojo.getInClasses().get(0), equalTo("java.lang.Integer"));

  Assert.assertThat(configuredPojo.getOutClasses(), is(notNullValue()));
  Assert.assertThat(configuredPojo.getOutClasses().size(), is(greaterThan(0)));
  Assert.assertThat(configuredPojo.getOutClasses().get(0), equalTo("java.lang.Float"));

}
 
Example 13
Source File: StreamsConfiguratorTest.java    From streams with Apache License 2.0 3 votes vote down vote up
/**
 * Test that a class which uses a configuration class with StreamsConfiguration
 * as an ancestor can use a typed StreamsConfigurator and detectCustomConfiguration
 * to populate its fields using ComponentConfigurators automatically.
 *
 * @throws Exception
 */
@Test
public void testDetectCustomStreamsConfiguration() throws Exception {

  Config overrides = ConfigFactory.parseResourcesAnySyntax("custom.conf");

  StreamsConfigurator.addConfig(overrides);

  StreamsConfigurator<StreamsConfigurationForTesting> configurator = new StreamsConfigurator<>(StreamsConfigurationForTesting.class);

  StreamsConfigurationForTesting customPojo = configurator.detectCustomConfiguration();

  verifyCustomStreamsConfiguration(customPojo);

}
 
Example 14
Source File: FileBasedConfigSupplier.java    From ditto with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Returns an instance of {@code FileBasedConfigSupplier}.
 *
 * @param resourceBaseName the name of the resource.
 * @return the instance.
 */
static FileBasedConfigSupplier fromResource(final String resourceBaseName) {
    final Config initialConfig = ConfigFactory.parseResourcesAnySyntax(resourceBaseName);
    return new FileBasedConfigSupplier(initialConfig);
}