use of org.apache.commons.configuration2.convert.ListDelimiterHandler in project commons-configuration by apache.
the class TestMultiWrapDynaBean method testOrderOfProperties.
/**
* Tests that the order of properties is relevant when adding beans to a MultiWrapDynaBean.
*/
@Test
public void testOrderOfProperties() throws Exception {
final Collection<Object> beans = new ArrayList<>();
params = new BasicBuilderParameters();
beans.add(params);
beans.add(new FileBasedBuilderParametersImpl());
for (int i = 0; i < 32; i++) {
beans.add(new BasicBuilderParameters());
}
final MultiWrapDynaBean bean = new MultiWrapDynaBean(beans);
final ListDelimiterHandler listHandler = new DefaultListDelimiterHandler('+');
PropertyUtils.setProperty(bean, "throwExceptionOnMissing", Boolean.TRUE);
PropertyUtils.setProperty(bean, "listDelimiterHandler", listHandler);
final Map<String, Object> map = params.getParameters();
assertEquals("Exception flag not set", Boolean.TRUE, map.get("throwExceptionOnMissing"));
assertEquals("List delimiter handler not set", listHandler, map.get("listDelimiterHandler"));
}
use of org.apache.commons.configuration2.convert.ListDelimiterHandler in project commons-configuration by apache.
the class TestCombinedConfigurationBuilder method testConfigurationBuilderProviderInheritBasicProperties.
/**
* Tests whether basic properties defined for the combined configuration are inherited by a child combined configuration
* builder.
*/
@Test
public void testConfigurationBuilderProviderInheritBasicProperties() throws ConfigurationException {
final File testFile = ConfigurationAssert.getTestFile("testCCCombinedChildBuilder.xml");
final ListDelimiterHandler listHandler = new DefaultListDelimiterHandler('*');
final ConfigurationDecoder decoder = EasyMock.createMock(ConfigurationDecoder.class);
builder.configure(new CombinedBuilderParametersImpl().setDefinitionBuilderParameters(new XMLBuilderParametersImpl().setFile(testFile)).setListDelimiterHandler(listHandler).setConfigurationDecoder(decoder));
final CombinedConfiguration cc = builder.getConfiguration();
final CombinedConfiguration cc2 = (CombinedConfiguration) cc.getConfiguration("subcc");
assertFalse("Wrong exception flag", cc2.isThrowExceptionOnMissing());
assertEquals("Wrong list delimiter handler", listHandler, cc2.getListDelimiterHandler());
assertEquals("Wrong decoder", decoder, cc2.getConfigurationDecoder());
}
use of org.apache.commons.configuration2.convert.ListDelimiterHandler in project commons-configuration by apache.
the class TestCombinedConfigurationBuilder method testCustomResultConfiguration.
/**
* Tests whether the resulting combined configuration can be customized.
*/
@Test
public void testCustomResultConfiguration() throws ConfigurationException {
final File testFile = ConfigurationAssert.getTestFile("testCCResultClass.xml");
final ListDelimiterHandler listHandler = new DefaultListDelimiterHandler('.');
builder.configure(new CombinedBuilderParametersImpl().setDefinitionBuilderParameters(new XMLBuilderParametersImpl().setFile(testFile)).setListDelimiterHandler(listHandler).setThrowExceptionOnMissing(false));
final CombinedConfiguration cc = builder.getConfiguration();
assertTrue("Wrong configuration class: " + cc.getClass(), cc instanceof CombinedConfigurationTestImpl);
assertTrue("Wrong exception flag", cc.isThrowExceptionOnMissing());
assertEquals("Wrong list delimiter handler", listHandler, cc.getListDelimiterHandler());
}
use of org.apache.commons.configuration2.convert.ListDelimiterHandler in project commons-configuration by apache.
the class DatabaseConfiguration method addPropertyInternal.
/**
* Adds a property to this configuration. This implementation temporarily disables list delimiter parsing, so that even
* if the value contains the list delimiter, only a single record is written into the managed table. The implementation
* of {@code getProperty()} takes care about delimiters. So list delimiters are fully supported by
* {@code DatabaseConfiguration}, but internally treated a bit differently.
*
* @param key the key of the new property
* @param value the value to be added
*/
@Override
protected void addPropertyInternal(final String key, final Object value) {
final ListDelimiterHandler oldHandler = getListDelimiterHandler();
try {
// temporarily disable delimiter parsing
setListDelimiterHandler(DisabledListDelimiterHandler.INSTANCE);
super.addPropertyInternal(key, value);
} finally {
setListDelimiterHandler(oldHandler);
}
}
use of org.apache.commons.configuration2.convert.ListDelimiterHandler 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());
}
Aggregations