Search in sources :

Example 46 with AbstractConfiguration

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);
}
Also used : AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) Configuration(org.apache.commons.configuration.Configuration) EnvironmentConfiguration(org.apache.commons.configuration.EnvironmentConfiguration) AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) SystemConfiguration(org.apache.commons.configuration.SystemConfiguration) Properties(java.util.Properties)

Example 47 with AbstractConfiguration

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"));
}
Also used : AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) Test(org.junit.Test)

Example 48 with AbstractConfiguration

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);
    }
}
Also used : AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) BaseConfiguration(org.apache.commons.configuration.BaseConfiguration) Test(org.junit.Test)

Example 49 with AbstractConfiguration

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);
}
Also used : AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) Test(org.junit.Test)

Example 50 with AbstractConfiguration

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);
}
Also used : AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) ConcurrentCompositeConfiguration(com.netflix.config.ConcurrentCompositeConfiguration) ExpandedConfigurationListenerAdapter(com.netflix.config.ExpandedConfigurationListenerAdapter) Test(org.junit.Test)

Aggregations

AbstractConfiguration (org.apache.commons.configuration.AbstractConfiguration)80 Test (org.junit.Test)29 ConcurrentCompositeConfiguration (com.netflix.config.ConcurrentCompositeConfiguration)18 BeforeClass (org.junit.BeforeClass)10 Configuration (org.apache.commons.configuration.Configuration)9 URI (java.net.URI)6 BaseConfiguration (org.apache.commons.configuration.BaseConfiguration)6 HttpRequest (com.netflix.client.http.HttpRequest)5 ArrayList (java.util.ArrayList)5 DynamicConfiguration (com.netflix.config.DynamicConfiguration)4 EnvironmentConfiguration (org.apache.commons.configuration.EnvironmentConfiguration)4 SystemConfiguration (org.apache.commons.configuration.SystemConfiguration)4 HttpResponse (com.netflix.client.http.HttpResponse)3 ConcurrentMapConfiguration (com.netflix.config.ConcurrentMapConfiguration)3 ExpandedConfigurationListenerAdapter (com.netflix.config.ExpandedConfigurationListenerAdapter)3 LinkedHashMap (java.util.LinkedHashMap)3 Properties (java.util.Properties)3 AggregatedConfiguration (com.netflix.config.AggregatedConfiguration)2 ConfigurationManager (com.netflix.config.ConfigurationManager)2 DynamicURLConfiguration (com.netflix.config.DynamicURLConfiguration)2