use of org.apache.commons.configuration.AbstractConfiguration in project archaius by Netflix.
the class ConfigurationManager method loadAppOverrideProperties.
public static void loadAppOverrideProperties(String appConfigName) throws IOException {
AbstractConfiguration config = getConfigInstance();
Properties props = loadCascadedProperties(appConfigName);
if (config instanceof AggregatedConfiguration) {
AggregatedConfiguration aggregated = (AggregatedConfiguration) config;
Configuration appConfig = aggregated.getConfiguration(APPLICATION_PROPERTIES);
if (appConfig != null) {
ConfigurationUtils.loadProperties(props, appConfig);
return;
}
}
// The configuration instance is not an aggregated configuration or it does
// not have designated configuration for application properties - just add
// the properties using config.setProperty()
ConfigurationUtils.loadProperties(props, config);
}
use of org.apache.commons.configuration.AbstractConfiguration in project archaius by Netflix.
the class ConcurrentCompositeConfigurationTest method testProperties.
@Test
public void testProperties() {
ConcurrentCompositeConfiguration config = new ConcurrentCompositeConfiguration();
DynamicPropertyFactory factory = DynamicPropertyFactory.initWithConfigurationSource(config);
DynamicStringProperty prop1 = factory.getStringProperty("prop1", null);
DynamicStringProperty prop2 = factory.getStringProperty("prop2", null);
DynamicStringProperty prop3 = factory.getStringProperty("prop3", null);
DynamicStringProperty prop4 = factory.getStringProperty("prop4", null);
AbstractConfiguration containerConfig = new ConcurrentMapConfiguration();
containerConfig.addProperty("prop1", "prop1");
containerConfig.addProperty("prop2", "prop2");
AbstractConfiguration baseConfig = new ConcurrentMapConfiguration();
baseConfig.addProperty("prop3", "prop3");
baseConfig.addProperty("prop1", "prop1FromBase");
// make container configuration the highest priority
config.setContainerConfiguration(containerConfig, "container configuration", 0);
config.addConfiguration(baseConfig, "base configuration");
assertEquals("prop1", config.getProperty("prop1"));
assertEquals("prop1", prop1.get());
assertEquals("prop2", prop2.get());
assertEquals("prop3", prop3.get());
containerConfig.setProperty("prop1", "newvalue");
assertEquals("newvalue", prop1.get());
assertEquals("newvalue", config.getProperty("prop1"));
baseConfig.addProperty("prop4", "prop4");
assertEquals("prop4", config.getProperty("prop4"));
assertEquals("prop4", prop4.get());
baseConfig.setProperty("prop1", "newvaluefrombase");
assertEquals("newvalue", prop1.get());
containerConfig.clearProperty("prop1");
assertEquals("newvaluefrombase", config.getProperty("prop1"));
assertEquals("newvaluefrombase", prop1.get());
config.setOverrideProperty("prop2", "overridden");
config.setProperty("prop2", "fromContainer");
assertEquals("overridden", config.getProperty("prop2"));
assertEquals("overridden", prop2.get());
config.clearOverrideProperty("prop2");
assertEquals("fromContainer", prop2.get());
assertEquals("fromContainer", config.getProperty("prop2"));
config.setProperty("prop3", "fromContainer");
assertEquals("fromContainer", prop3.get());
assertEquals("fromContainer", config.getProperty("prop3"));
config.clearProperty("prop3");
assertEquals("prop3", prop3.get());
assertEquals("prop3", config.getProperty("prop3"));
}
use of org.apache.commons.configuration.AbstractConfiguration in project archaius by Netflix.
the class TestConfigurationFactory method testConfigurationFactory.
@Test
public void testConfigurationFactory() {
Object configSource = DynamicPropertyFactory.getInstance().getBackingConfigurationSource();
AbstractConfiguration config = ConfigurationManager.getConfigInstance();
assertTrue(ConfigurationManager.isConfigurationInstalled());
assertTrue(configSource == config);
assertTrue(config == TestConfigurationFactory.getInstance());
try {
DynamicPropertyFactory.initWithConfigurationSource(new BaseConfiguration());
fail("IllegalStateException expected");
} catch (IllegalStateException e) {
assertNotNull(e);
}
}
use of org.apache.commons.configuration.AbstractConfiguration in project archaius by Netflix.
the class MyListener method testAddPropertyListener.
@Test
public void testAddPropertyListener() {
AbstractConfiguration config = ConfigurationManager.getConfigInstance();
config.addConfigurationListener(new ExpandedConfigurationListenerAdapter(new MyListener()));
// config.addConfigurationListener(new MyListener());
config.setProperty("xyz", "abcc");
assertEquals(1, MyListener.count);
}
use of org.apache.commons.configuration.AbstractConfiguration in project archaius by Netflix.
the class DynamicPropertyUpdaterTest method testAddorChangeProperty.
@Test
public void testAddorChangeProperty() {
AbstractConfiguration.setDefaultListDelimiter(',');
AbstractConfiguration config = new ConcurrentCompositeConfiguration();
config.addConfigurationListener(new ExpandedConfigurationListenerAdapter(new MyListener()));
MyListener.resetCount();
config.setProperty("test.host", "test,test1,test2");
assertEquals(1, MyListener.count);
dynamicPropertyUpdater.addOrChangeProperty("test.host", "test,test1,test2", config);
assertEquals(3, ((CopyOnWriteArrayList) (config.getProperty("test.host"))).size());
assertTrue(((CopyOnWriteArrayList) (config.getProperty("test.host"))).contains("test"));
assertTrue(((CopyOnWriteArrayList) (config.getProperty("test.host"))).contains("test1"));
assertTrue(((CopyOnWriteArrayList) (config.getProperty("test.host"))).contains("test2"));
assertEquals(1, MyListener.count);
dynamicPropertyUpdater.addOrChangeProperty("test.host", "test,test1,test2", config);
assertEquals(3, ((CopyOnWriteArrayList) (config.getProperty("test.host"))).size());
assertTrue(((CopyOnWriteArrayList) (config.getProperty("test.host"))).contains("test"));
assertTrue(((CopyOnWriteArrayList) (config.getProperty("test.host"))).contains("test1"));
assertTrue(((CopyOnWriteArrayList) (config.getProperty("test.host"))).contains("test2"));
assertEquals(1, MyListener.count);
dynamicPropertyUpdater.addOrChangeProperty("test.host", "test,test1", config);
assertEquals(2, ((CopyOnWriteArrayList) (config.getProperty("test.host"))).size());
assertTrue(((CopyOnWriteArrayList) (config.getProperty("test.host"))).contains("test"));
assertTrue(((CopyOnWriteArrayList) (config.getProperty("test.host"))).contains("test1"));
assertEquals(2, MyListener.count);
dynamicPropertyUpdater.addOrChangeProperty("test.host1", "test1,test12", config);
assertEquals(2, ((CopyOnWriteArrayList) (config.getProperty("test.host1"))).size());
assertTrue(((CopyOnWriteArrayList) (config.getProperty("test.host1"))).contains("test1"));
assertTrue(((CopyOnWriteArrayList) (config.getProperty("test.host1"))).contains("test12"));
assertEquals(3, MyListener.count);
config.setProperty("test.host1", "test1.test12");
dynamicPropertyUpdater.addOrChangeProperty("test.host1", "test1.test12", config);
assertEquals("test1.test12", config.getProperty("test.host1"));
assertEquals(4, MyListener.count);
}
Aggregations