Search in sources :

Example 36 with AbstractConfiguration

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

the class TestSubsetConfiguration method testListDelimiterHandling.

/**
 * Tests whether a list delimiter handler is used correctly.
 */
@Test
public void testListDelimiterHandling() {
    final BaseConfiguration config = new BaseConfiguration();
    final Configuration subset = config.subset("prefix");
    config.setListDelimiterHandler(new DefaultListDelimiterHandler('/'));
    subset.addProperty("list", "a/b/c");
    assertEquals("Wrong size of list", 3, config.getList("prefix.list").size());
    ((AbstractConfiguration) subset).setListDelimiterHandler(new DefaultListDelimiterHandler(';'));
    subset.addProperty("list2", "a;b;c");
    assertEquals("Wrong size of list2", 3, config.getList("prefix.list2").size());
}
Also used : DefaultListDelimiterHandler(org.apache.commons.configuration2.convert.DefaultListDelimiterHandler) Test(org.junit.Test)

Example 37 with AbstractConfiguration

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

the class TestSubsetConfiguration method testGetListDelimiterHandlerFromParent.

/**
 * Tests whether the list delimiter handler from the parent configuration is used.
 */
@Test
public void testGetListDelimiterHandlerFromParent() {
    final BaseConfiguration config = new BaseConfiguration();
    final AbstractConfiguration subset = (AbstractConfiguration) config.subset("prefix");
    final ListDelimiterHandler listHandler = new DefaultListDelimiterHandler(',');
    config.setListDelimiterHandler(listHandler);
    assertSame("Not list handler from parent", listHandler, subset.getListDelimiterHandler());
}
Also used : DefaultListDelimiterHandler(org.apache.commons.configuration2.convert.DefaultListDelimiterHandler) ListDelimiterHandler(org.apache.commons.configuration2.convert.ListDelimiterHandler) DefaultListDelimiterHandler(org.apache.commons.configuration2.convert.DefaultListDelimiterHandler) Test(org.junit.Test)

Example 38 with AbstractConfiguration

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

the class TestMapConfiguration method getConfiguration.

@Override
protected AbstractConfiguration getConfiguration() {
    final Map<String, Object> map = new HashMap<>();
    map.put(KEY, "value1");
    map.put("key2", "value2");
    map.put("list", "value1, value2");
    map.put("listesc", "value1\\,value2");
    final MapConfiguration config = new MapConfiguration(map);
    config.setListDelimiterHandler(new DefaultListDelimiterHandler(','));
    return config;
}
Also used : DefaultListDelimiterHandler(org.apache.commons.configuration2.convert.DefaultListDelimiterHandler) HashMap(java.util.HashMap)

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