Package org.apache.commons.configuration

Examples of org.apache.commons.configuration.AbstractConfiguration


    {
      // String
      // fileName=FilenameUtils.separatorsToSystem("C:\\init\\MOBILEguard\\yajsw/lib/jvmstat/*.jar");
      // System.out.println("FileName: "+fileName);
      CompositeConfiguration compConfig = new CompositeConfiguration();
      AbstractConfiguration configuraton = new BaseConfiguration();
      compConfig.addConfiguration(new EnvironmentConfiguration());
      configuraton.setProperty("wrapper.java.classpath.1", "${VERSANT_ROOT}/lib/jvi.*jar");
      configuraton.setProperty("wrapper.java.classpath.2", "${GROOVY_HOME}/lib/*.jar");
      compConfig.addConfiguration(configuraton);
      System.out.println("Configuration: " + ConfigurationConverter.getProperties(compConfig));
      System.out.println("subset: " + ConfigurationConverter.getProperties(compConfig.subset("wrapper.java")));

      // Collection files=FileUtils.getFiles("../..",
View Full Code Here


   
   
    @Test
    public void testAddorUpdatePropertyWithColonDelimiter(){
        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); // the config is not set again. when the value is still not changed.
       config.setProperty("test.host1", "test1:test12");
        // changing the new object value , the config.setProperty should be called again.
        dynamicPropertyUpdater.addOrChangeProperty("test.host1", "test1.test12", config);
        assertEquals("test1.test12",config.getProperty("test.host1"));
       assertEquals(3, MyListener.count);
    }
View Full Code Here

public class PropertyListenerTest {
   
    @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);
    }
View Full Code Here

        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");
View Full Code Here

    @Test
    public void testContainerConfiguration() {
        ConcurrentCompositeConfiguration config = new ConcurrentCompositeConfiguration();
        assertEquals(0, config.getIndexOfContainerConfiguration());
        Configuration originalContainerConfig = config.getContainerConfiguration();
        AbstractConfiguration config1= new BaseConfiguration();
        config.addConfiguration(config1, "base");
        assertEquals(1, config.getIndexOfContainerConfiguration());
        config.setContainerConfigurationIndex(0);
        assertEquals(0, config.getIndexOfContainerConfiguration());
        assertEquals(2, config.getNumberOfConfigurations());
        AbstractConfiguration config2 = new ConcurrentMapConfiguration();
        config.addConfigurationAtIndex(config2, "new", 1);
        AbstractConfiguration config3 = new ConcurrentMapConfiguration();
        config.setContainerConfiguration(config3, "new container", 2);
        assertEquals(config3, config.getContainerConfiguration());
        try {
            config.setContainerConfigurationIndex(4);
            fail("expect IndexOutOfBoundsException");
        } catch (IndexOutOfBoundsException e) {  
            assertNotNull(e);
        }
        try {
            config.addConfigurationAtIndex(new BaseConfiguration(), "ignore", 5);
            fail("expect IndexOutOfBoundsException");
        } catch (IndexOutOfBoundsException e) {           
            assertNotNull(e);
        }
        List<AbstractConfiguration> list = config.getConfigurations();
        assertEquals(originalContainerConfig, list.get(0));
        assertEquals(config2, list.get(1));
        assertEquals(config3, list.get(2));
        assertEquals(config1, list.get(3));
        assertEquals(4, list.size());
        config.removeConfiguration(config1);
        assertFalse(config.getConfigurationNames().contains("base"));
        assertFalse(config.getConfigurations().contains(config1));
        config.removeConfigurationAt(1);
        assertFalse(config.getConfigurationNames().contains("new"));
        assertFalse(config.getConfigurations().contains(config2));
        AbstractConfiguration config4 = new ConcurrentMapConfiguration();
        config.addConfiguration(config4, "another container");
        config.removeConfiguration("another container");
        assertFalse(config.getConfigurationNames().contains("another container"));
        assertFalse(config.getConfigurations().contains(config4));
    }
View Full Code Here

    }

    @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());
View Full Code Here

        longProp = propertyFactory.getLongProperty("dprops1", Long.MAX_VALUE, new Runnable() {
            public void run() {
                propertyChanged = true;
            }
        });
        AbstractConfiguration newConfig = new ConcurrentMapConfiguration();
        DynamicStringProperty prop = propertyFactory.getStringProperty("abc", "default");
        newConfig.setProperty("abc", "nondefault");
        newConfig.setProperty("dprops1", "0");
        DynamicPropertyFactory.initWithConfigurationSource(newConfig);
        Thread.sleep(2000);
        assertEquals("nondefault", prop.get());
        assertEquals(0, longProp.get());
        assertTrue(newConfig == ConfigurationManager.getConfigInstance());
View Full Code Here

     * @throws InterruptedException
     */
    @Test
    public void testUpdateProperties() throws InterruptedException {
        AbstractConfiguration.setDefaultListDelimiter(',');
        AbstractConfiguration config  = new ConcurrentCompositeConfiguration();
        config.addConfigurationListener(new ExpandedConfigurationListenerAdapter(new MyListener()));
        MyListener.resetCount();
        config.setProperty("test", "host,host1,host2");
        config.setProperty("test12", "host12");
        Map<String,Object> added = Maps.newHashMap();
        added.put("test.host","test,test1");
        Map<String,Object> changed = Maps.newHashMap();
        changed.put("test","host,host1");
        changed.put("test.host","");
        dynamicPropertyUpdater.updateProperties(WatchedUpdateResult.createIncremental(added, changed, null), config, false);
        assertEquals("",config.getProperty("test.host"));
        assertEquals(2,((CopyOnWriteArrayList)(config.getProperty("test"))).size());
        assertTrue(((CopyOnWriteArrayList)(config.getProperty("test"))).contains("host"));
        assertTrue(((CopyOnWriteArrayList)(config.getProperty("test"))).contains("host1"));
        assertEquals(5, MyListener.count);
    }
View Full Code Here

 
    @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);
    }
View Full Code Here

        } catch (IOException e) {
            LOG.error(String.format("Exception loading properties file - %s, Explorers application may not work correctly ",
                     propertiesFileName));
        }

        AbstractConfiguration configuration = ConfigurationManager.getConfigInstance();

        environmentName     = configuration.getString(PROPERTY_ENVIRONMENT_NAME);
        currentRegion       = configuration.getString(PROPERTY_CURRENT_REGION);
        applicationVersion  = (String) configuration.getProperty(PROPERTY_APPLICATION_VERSION);
        applicationName     = (String) configuration.getProperty(PROPERTY_APPLICATION_NAME);
        isLocal             = configuration.getBoolean(PROPERTY_IS_LOCAL, false);
        homePageUrl         = configuration.getString(PROPERTY_HOME_PAGE);
        defaultPort         = configuration.getShort(PROPERTY_DEFAULT_PORT, (short) 8080);
        dataCenter          = configuration.getString(PROPERTY_DATA_CENTER);
        defaultExplorerName = configuration.getString(PROPERTY_DEFAULT_EXPLORER);

        try {
            Iterator<String> dcKeySet = configuration.getKeys(PROPERTIES_PREFIX + ".dc");
            while (dcKeySet.hasNext()) {
                String dcKey = dcKeySet.next();
                String key  = StringUtils.substringBefore(dcKey, ".");
                String attr = StringUtils.substringAfter (dcKey,  ".");

                CrossLink link = links.get(key);
                if (link == null) {
                    link = new CrossLink();
                    links.put(key,  link);
                }

                BeanUtils.setProperty(link, attr, configuration.getProperty(dcKey));
            }
        } catch (Exception e) {
            LOG.error("Exception in constructing links map ", e);
            throw new RuntimeException(e);
        }
View Full Code Here

TOP

Related Classes of org.apache.commons.configuration.AbstractConfiguration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.