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);
}
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());
}
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"));
}
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;
}
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);
}
Aggregations