Search in sources :

Example 26 with AbstractConfiguration

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

the class TestServletRequestConfiguration method getConfiguration.

@Override
protected AbstractConfiguration getConfiguration() {
    final Configuration configuration = new BaseConfiguration();
    configuration.setProperty("key1", "value1");
    configuration.setProperty("key2", "value2");
    configuration.addProperty("list", "value1");
    configuration.addProperty("list", "value2");
    configuration.addProperty("listesc", "value1\\,value2");
    return createConfiguration(configuration);
}
Also used : BaseConfiguration(org.apache.commons.configuration2.BaseConfiguration) TestAbstractConfiguration(org.apache.commons.configuration2.TestAbstractConfiguration) AbstractConfiguration(org.apache.commons.configuration2.AbstractConfiguration) Configuration(org.apache.commons.configuration2.Configuration) BaseConfiguration(org.apache.commons.configuration2.BaseConfiguration)

Example 27 with AbstractConfiguration

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

the class TestCompositeConfiguration method checkSetListDelimiterHandler.

/**
 * Helper method for testing whether the list delimiter is correctly handled.
 */
private void checkSetListDelimiterHandler() {
    cc.addProperty("test.list", "a/b/c");
    cc.addProperty("test.property", "a,b,c");
    assertEquals("Wrong number of list elements", 3, cc.getList("test.list").size());
    assertEquals("Wrong value of property", "a,b,c", cc.getString("test.property"));
    final AbstractConfiguration config = (AbstractConfiguration) cc.getInMemoryConfiguration();
    final DefaultListDelimiterHandler listHandler = (DefaultListDelimiterHandler) config.getListDelimiterHandler();
    assertEquals("Wrong list delimiter", '/', listHandler.getDelimiter());
}
Also used : DefaultListDelimiterHandler(org.apache.commons.configuration2.convert.DefaultListDelimiterHandler)

Example 28 with AbstractConfiguration

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

the class TestConfigurationConverter method testPropertiesToConfiguration.

@Test
public void testPropertiesToConfiguration() {
    final Properties props = new Properties();
    props.setProperty("string", "teststring");
    props.setProperty("int", "123");
    props.setProperty("list", "item 1, item 2");
    final AbstractConfiguration config = (AbstractConfiguration) ConfigurationConverter.getConfiguration(props);
    config.setListDelimiterHandler(new DefaultListDelimiterHandler(','));
    assertEquals("This returns 'teststring'", "teststring", config.getString("string"));
    final List<Object> item1 = config.getList("list");
    assertEquals("This returns 'item 1'", "item 1", item1.get(0));
    assertEquals("This returns 123", 123, config.getInt("int"));
}
Also used : DefaultListDelimiterHandler(org.apache.commons.configuration2.convert.DefaultListDelimiterHandler) Properties(java.util.Properties) Test(org.junit.Test)

Example 29 with AbstractConfiguration

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

the class TestAbstractConfigurationBasicFeatures method setUpDestConfig.

/**
 * Creates the destination configuration for testing the copy() and append() methods. This configuration contains keys
 * with a running index and corresponding values starting with the prefix "value".
 *
 * @return the destination configuration for copy operations
 */
private AbstractConfiguration setUpDestConfig() {
    final AbstractConfiguration config = new TestConfigurationImpl(new PropertiesConfiguration());
    config.setListDelimiterHandler(new DefaultListDelimiterHandler(','));
    for (int i = 0; i < PROP_COUNT; i++) {
        config.addProperty(KEY_PREFIX + i, "value" + i);
    }
    return config;
}
Also used : DefaultListDelimiterHandler(org.apache.commons.configuration2.convert.DefaultListDelimiterHandler)

Example 30 with AbstractConfiguration

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

the class TestAbstractConfigurationBasicFeatures method testSetDefaultLookupsExistingInterpolator.

/**
 * Tests whether default lookups can be added to an already existing {@code ConfigurationInterpolator}.
 */
@Test
public void testSetDefaultLookupsExistingInterpolator() {
    final Lookup look = EasyMock.createMock(Lookup.class);
    EasyMock.replay(look);
    final AbstractConfiguration config = new TestConfigurationImpl(new PropertiesConfiguration());
    config.getInterpolator().addDefaultLookup(new ConfigurationLookup(new PropertiesConfiguration()));
    config.setDefaultLookups(Collections.singleton(look));
    final List<Lookup> lookups = config.getInterpolator().getDefaultLookups();
    assertEquals("Wrong number of default lookups", 3, lookups.size());
    assertSame("Wrong lookup at 1", look, lookups.get(1));
    assertTrue("Wrong lookup at 2: " + lookups, lookups.get(2) instanceof ConfigurationLookup);
}
Also used : Lookup(org.apache.commons.configuration2.interpol.Lookup) Test(org.junit.Test)

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