Search in sources :

Example 11 with AbstractConfiguration

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

the class TestPropertyListConfigurationEvents method createConfiguration.

@Override
protected AbstractConfiguration createConfiguration() {
    try {
        final PropertyListConfiguration c = new PropertyListConfiguration();
        new FileHandler(c).load(TEST_FILE);
        return c;
    } catch (final ConfigurationException cex) {
        throw new ConfigurationRuntimeException(cex);
    }
}
Also used : ConfigurationRuntimeException(org.apache.commons.configuration2.ex.ConfigurationRuntimeException) ConfigurationException(org.apache.commons.configuration2.ex.ConfigurationException) FileHandler(org.apache.commons.configuration2.io.FileHandler)

Example 12 with AbstractConfiguration

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

the class TestXMLPropertyListConfigurationEvents method createConfiguration.

@Override
protected AbstractConfiguration createConfiguration() {
    try {
        final XMLPropertyListConfiguration c = new XMLPropertyListConfiguration();
        new FileHandler(c).load(TEST_FILE);
        return c;
    } catch (final ConfigurationException cex) {
        throw new ConfigurationRuntimeException(cex);
    }
}
Also used : ConfigurationRuntimeException(org.apache.commons.configuration2.ex.ConfigurationRuntimeException) ConfigurationException(org.apache.commons.configuration2.ex.ConfigurationException) FileHandler(org.apache.commons.configuration2.io.FileHandler)

Example 13 with AbstractConfiguration

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

the class TestAbstractConfiguration method testSetLogger.

/**
 * Tests accessing the configuration's logger.
 */
@Test
public void testSetLogger() {
    final AbstractConfiguration config = getEmptyConfiguration();
    assertNotNull("Default logger is null", config.getLogger());
    final ConfigurationLogger log = new ConfigurationLogger(config.getClass());
    config.setLogger(log);
    assertSame("Logger was not set", log, config.getLogger());
}
Also used : ConfigurationLogger(org.apache.commons.configuration2.io.ConfigurationLogger) Test(org.junit.Test)

Example 14 with AbstractConfiguration

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

the class TestAbstractConfigurationBasicFeatures method testSetPrefixLookupsExistingInterpolator.

/**
 * Tests whether prefix lookups can be added to an existing {@code ConfigurationInterpolator}.
 */
@Test
public void testSetPrefixLookupsExistingInterpolator() {
    final Lookup look = EasyMock.createMock(Lookup.class);
    EasyMock.replay(look);
    final AbstractConfiguration config = new TestConfigurationImpl(new PropertiesConfiguration());
    final int count = config.getInterpolator().getLookups().size();
    final Map<String, Lookup> lookups = new HashMap<>();
    lookups.put("test", look);
    config.setPrefixLookups(lookups);
    final Map<String, Lookup> lookups2 = config.getInterpolator().getLookups();
    assertEquals("Not added", count + 1, lookups2.size());
    assertSame("Not found", look, lookups2.get("test"));
}
Also used : HashMap(java.util.HashMap) Lookup(org.apache.commons.configuration2.interpol.Lookup) Test(org.junit.Test)

Example 15 with AbstractConfiguration

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

the class TestAbstractConfigurationBasicFeatures method testSetPrefixLookupsNoInterpolator.

/**
 * Tests whether prefix lookups can be added if no {@code ConfigurationInterpolator} exists yet.
 */
@Test
public void testSetPrefixLookupsNoInterpolator() {
    final Lookup look = EasyMock.createMock(Lookup.class);
    EasyMock.replay(look);
    final AbstractConfiguration config = new TestConfigurationImpl(new PropertiesConfiguration());
    config.setInterpolator(null);
    config.setPrefixLookups(Collections.singletonMap("test", look));
    final Map<String, Lookup> lookups = config.getInterpolator().getLookups();
    assertEquals("Wrong number of lookups", 1, lookups.size());
    assertSame("Not found", look, lookups.get("test"));
}
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