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());
}
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());
}
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"));
}
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);
}
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;
}
Aggregations