Search in sources :

Example 16 with AbstractConfiguration

use of org.apache.commons.configuration2.AbstractConfiguration in project commons-configuration by apache.

the class TestAbstractConfigurationBasicFeatures method testSetParentInterpolatorExistingInterpolator.

/**
 * Tests whether a parent {@code ConfigurationInterpolator} can be set if already a {@code ConfigurationInterpolator} is
 * available.
 */
@Test
public void testSetParentInterpolatorExistingInterpolator() {
    final ConfigurationInterpolator parent = EasyMock.createMock(ConfigurationInterpolator.class);
    EasyMock.replay(parent);
    final AbstractConfiguration config = new TestConfigurationImpl(new PropertiesConfiguration());
    final ConfigurationInterpolator ci = config.getInterpolator();
    config.setParentInterpolator(parent);
    assertSame("Parent was not set", parent, config.getInterpolator().getParentInterpolator());
    assertSame("Interpolator was changed", ci, config.getInterpolator());
}
Also used : ConfigurationInterpolator(org.apache.commons.configuration2.interpol.ConfigurationInterpolator) Test(org.junit.Test)

Example 17 with AbstractConfiguration

use of org.apache.commons.configuration2.AbstractConfiguration in project commons-configuration by apache.

the class TestAbstractConfigurationBasicFeatures method testSetParentInterpolatorNoInterpolator.

/**
 * Tests whether a parent {@code ConfigurationInterpolator} can be set if currently no {@code ConfigurationInterpolator}
 * is available.
 */
@Test
public void testSetParentInterpolatorNoInterpolator() {
    final ConfigurationInterpolator parent = EasyMock.createMock(ConfigurationInterpolator.class);
    EasyMock.replay(parent);
    final AbstractConfiguration config = new TestConfigurationImpl(new PropertiesConfiguration());
    config.setInterpolator(null);
    config.setParentInterpolator(parent);
    assertSame("Parent was not set", parent, config.getInterpolator().getParentInterpolator());
}
Also used : ConfigurationInterpolator(org.apache.commons.configuration2.interpol.ConfigurationInterpolator) Test(org.junit.Test)

Example 18 with AbstractConfiguration

use of org.apache.commons.configuration2.AbstractConfiguration in project commons-configuration by apache.

the class InterpolationTestHelper method testGetInterpolator.

/**
 * Tests accessing and manipulating the interpolator object.
 *
 * @param config the configuration to test
 */
public static void testGetInterpolator(final AbstractConfiguration config) {
    config.addProperty("var", "${echo:testVar}");
    final ConfigurationInterpolator interpol = config.getInterpolator();
    interpol.registerLookup("echo", varName -> "Value of variable " + varName);
    assertEquals("Wrong value of echo variable", "Value of variable testVar", config.getString("var"));
}
Also used : ConfigurationInterpolator(org.apache.commons.configuration2.interpol.ConfigurationInterpolator)

Example 19 with AbstractConfiguration

use of org.apache.commons.configuration2.AbstractConfiguration in project bitflyer4j by after-the-sunrise.

the class Bitflyer4jFactory method createInstance.

/**
 * Create a new instance of the {@link Bitflyer4j} with instance specific properties.
 * A new instance is created for each invocation.
 *
 * @param properties Instance specific properties.
 * @return New instance.
 */
public Bitflyer4j createInstance(Properties properties) {
    log.info("Creating instance.");
    final AbstractConfiguration conf = createConfiguration(properties);
    final Class<? extends RealtimeService> realtimeClass = getRealtimeType(conf);
    Module module = new AbstractModule() {

        @Override
        protected void configure() {
            bind(Configuration.class).toInstance(conf);
            bind(EventSource.class).toInstance(conf);
            bind(Gson.class).toProvider(GsonProvider.class).asEagerSingleton();
            bind(Socket.class).toProvider(SocketProvider.class).asEagerSingleton();
            bind(Environment.class).to(EnvironmentImpl.class).asEagerSingleton();
            bind(Throttler.class).to(ThrottlerImpl.class).asEagerSingleton();
            bind(ExecutorFactory.class).to(ExecutorFactoryImpl.class).asEagerSingleton();
            bind(HttpClient.class).to(HttpClientImpl.class).asEagerSingleton();
            bind(Bitflyer4j.class).to(Bitflyer4jImpl.class).asEagerSingleton();
            bind(MarketService.class).to(MarketServiceImpl.class).asEagerSingleton();
            bind(AccountService.class).to(AccountServiceImpl.class).asEagerSingleton();
            bind(OrderService.class).to(OrderServiceImpl.class).asEagerSingleton();
            bind(RealtimeService.class).to(realtimeClass).asEagerSingleton();
        }
    };
    return Guice.createInjector(module).getInstance(Bitflyer4j.class);
}
Also used : MapConfiguration(org.apache.commons.configuration2.MapConfiguration) CompositeConfiguration(org.apache.commons.configuration2.CompositeConfiguration) AbstractConfiguration(org.apache.commons.configuration2.AbstractConfiguration) Configuration(org.apache.commons.configuration2.Configuration) AccountServiceImpl(com.after_sunrise.cryptocurrency.bitflyer4j.service.impl.AccountServiceImpl) AbstractModule(com.google.inject.AbstractModule) AbstractConfiguration(org.apache.commons.configuration2.AbstractConfiguration) MarketServiceImpl(com.after_sunrise.cryptocurrency.bitflyer4j.service.impl.MarketServiceImpl) EventSource(org.apache.commons.configuration2.event.EventSource) OrderServiceImpl(com.after_sunrise.cryptocurrency.bitflyer4j.service.impl.OrderServiceImpl) Module(com.google.inject.Module) AbstractModule(com.google.inject.AbstractModule)

Example 20 with AbstractConfiguration

use of org.apache.commons.configuration2.AbstractConfiguration in project bitflyer4j by after-the-sunrise.

the class Bitflyer4jFactory method createConfiguration.

/**
 * Create a {@link Configuration} instance,
 * composed of multiple configurations which are enumerated in {@link ConfigurationType}.
 *
 * @return Composite configuration instance.
 */
@VisibleForTesting
AbstractConfiguration createConfiguration(Properties properties) {
    CompositeConfiguration composite = new CompositeConfiguration();
    ConfigurationType[] types = ConfigurationType.values();
    Arrays.stream(types).forEach(s -> s.get().ifPresent(composite::addConfiguration));
    Optional.ofNullable(properties).ifPresent(p -> composite.addConfiguration(new MapConfiguration(p)));
    return composite;
}
Also used : CompositeConfiguration(org.apache.commons.configuration2.CompositeConfiguration) MapConfiguration(org.apache.commons.configuration2.MapConfiguration) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

Test (org.junit.Test)19 DefaultListDelimiterHandler (org.apache.commons.configuration2.convert.DefaultListDelimiterHandler)13 AbstractConfiguration (org.apache.commons.configuration2.AbstractConfiguration)8 MapConfiguration (org.apache.commons.configuration2.MapConfiguration)6 ConfigurationInterpolator (org.apache.commons.configuration2.interpol.ConfigurationInterpolator)5 Lookup (org.apache.commons.configuration2.interpol.Lookup)5 Properties (java.util.Properties)4 BaseConfiguration (org.apache.commons.configuration2.BaseConfiguration)4 Configuration (org.apache.commons.configuration2.Configuration)4 PropertiesConfiguration (org.apache.commons.configuration2.PropertiesConfiguration)4 ListDelimiterHandler (org.apache.commons.configuration2.convert.ListDelimiterHandler)4 ConfigurationException (org.apache.commons.configuration2.ex.ConfigurationException)4 HugeConfig (com.baidu.hugegraph.config.HugeConfig)2 BaseUnitTest (com.baidu.hugegraph.unit.BaseUnitTest)2 MockServletConfig (com.mockobjects.servlet.MockServletConfig)2 HashMap (java.util.HashMap)2 Servlet (javax.servlet.Servlet)2 HttpServlet (javax.servlet.http.HttpServlet)2 CompositeConfiguration (org.apache.commons.configuration2.CompositeConfiguration)2 TestAbstractConfiguration (org.apache.commons.configuration2.TestAbstractConfiguration)2