Search in sources :

Example 6 with AbstractConfiguration

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

the class TestServletConfiguration method getConfiguration.

@Override
protected AbstractConfiguration getConfiguration() {
    final MockServletConfig config = new MockServletConfig();
    config.setInitParameter("key1", "value1");
    config.setInitParameter("key2", "value2");
    config.setInitParameter("list", "value1, value2");
    config.setInitParameter("listesc", "value1\\,value2");
    final Servlet servlet = new HttpServlet() {

        /**
         * Serial version UID.
         */
        private static final long serialVersionUID = 1L;

        @Override
        public ServletConfig getServletConfig() {
            return config;
        }
    };
    final ServletConfiguration servletConfiguration = new ServletConfiguration(servlet);
    servletConfiguration.setListDelimiterHandler(new DefaultListDelimiterHandler(','));
    return servletConfiguration;
}
Also used : DefaultListDelimiterHandler(org.apache.commons.configuration2.convert.DefaultListDelimiterHandler) HttpServlet(javax.servlet.http.HttpServlet) MockServletConfig(com.mockobjects.servlet.MockServletConfig) HttpServlet(javax.servlet.http.HttpServlet) Servlet(javax.servlet.Servlet)

Example 7 with AbstractConfiguration

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

the class TestServletFilterConfiguration method getConfiguration.

@Override
protected AbstractConfiguration getConfiguration() {
    final MockFilterConfig config = new MockFilterConfig();
    config.setInitParameter("key1", "value1");
    config.setInitParameter("key2", "value2");
    config.setInitParameter("list", "value1, value2");
    config.setInitParameter("listesc", "value1\\,value2");
    final ServletFilterConfiguration resultConfig = new ServletFilterConfiguration(config);
    resultConfig.setListDelimiterHandler(new DefaultListDelimiterHandler(','));
    return resultConfig;
}
Also used : DefaultListDelimiterHandler(org.apache.commons.configuration2.convert.DefaultListDelimiterHandler)

Example 8 with AbstractConfiguration

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

the class TestSubsetConfiguration method testLocalLookupsInInterpolatorAreInherited.

@Test
public void testLocalLookupsInInterpolatorAreInherited() {
    final BaseConfiguration config = new BaseConfiguration();
    final ConfigurationInterpolator interpolator = config.getInterpolator();
    interpolator.registerLookup("brackets", key -> "(" + key + ")");
    config.setProperty("prefix.var", "${brackets:x}");
    final AbstractConfiguration subset = (AbstractConfiguration) config.subset("prefix");
    assertEquals("Local lookup was not inherited", "(x)", subset.getString("var", ""));
}
Also used : ConfigurationInterpolator(org.apache.commons.configuration2.interpol.ConfigurationInterpolator) Test(org.junit.Test)

Example 9 with AbstractConfiguration

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

the class TestSubsetConfiguration method testSetListDelimiterHandlerInParent.

/**
 * Tests whether the list delimiter handler is also set for the parent configuration.
 */
@Test
public void testSetListDelimiterHandlerInParent() {
    final BaseConfiguration config = new BaseConfiguration();
    final AbstractConfiguration subset = (AbstractConfiguration) config.subset("prefix");
    final ListDelimiterHandler listHandler = new DefaultListDelimiterHandler(',');
    subset.setListDelimiterHandler(listHandler);
    assertSame("Handler not passed to parent", listHandler, config.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 10 with AbstractConfiguration

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

the class TestSubsetConfiguration method testSetListDelimiterHandlerParentNotSupported.

/**
 * Tests the case that the parent configuration is not derived from AbstractConfiguration and thus does not support a
 * list delimiter handler.
 */
@Test
public void testSetListDelimiterHandlerParentNotSupported() {
    final Configuration config = EasyMock.createNiceMock(Configuration.class);
    EasyMock.replay(config);
    final SubsetConfiguration subset = new SubsetConfiguration(config, "prefix");
    final ListDelimiterHandler listHandler = new DefaultListDelimiterHandler(',');
    subset.setListDelimiterHandler(listHandler);
    assertSame("List delimiter handler not set", 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)

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