Search in sources :

Example 1 with ListDelimiterHandler

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"));
}
Also used : DefaultListDelimiterHandler(org.apache.commons.configuration2.convert.DefaultListDelimiterHandler) ArrayList(java.util.ArrayList) FileBasedBuilderParametersImpl(org.apache.commons.configuration2.builder.FileBasedBuilderParametersImpl) BasicBuilderParameters(org.apache.commons.configuration2.builder.BasicBuilderParameters) ListDelimiterHandler(org.apache.commons.configuration2.convert.ListDelimiterHandler) DefaultListDelimiterHandler(org.apache.commons.configuration2.convert.DefaultListDelimiterHandler) Test(org.junit.Test)

Example 2 with 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());
}
Also used : DefaultListDelimiterHandler(org.apache.commons.configuration2.convert.DefaultListDelimiterHandler) CombinedConfiguration(org.apache.commons.configuration2.CombinedConfiguration) DynamicCombinedConfiguration(org.apache.commons.configuration2.DynamicCombinedConfiguration) XMLBuilderParametersImpl(org.apache.commons.configuration2.builder.XMLBuilderParametersImpl) File(java.io.File) ListDelimiterHandler(org.apache.commons.configuration2.convert.ListDelimiterHandler) DefaultListDelimiterHandler(org.apache.commons.configuration2.convert.DefaultListDelimiterHandler) ConfigurationDecoder(org.apache.commons.configuration2.ConfigurationDecoder) Test(org.junit.Test)

Example 3 with ListDelimiterHandler

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());
}
Also used : DefaultListDelimiterHandler(org.apache.commons.configuration2.convert.DefaultListDelimiterHandler) CombinedConfiguration(org.apache.commons.configuration2.CombinedConfiguration) DynamicCombinedConfiguration(org.apache.commons.configuration2.DynamicCombinedConfiguration) XMLBuilderParametersImpl(org.apache.commons.configuration2.builder.XMLBuilderParametersImpl) File(java.io.File) ListDelimiterHandler(org.apache.commons.configuration2.convert.ListDelimiterHandler) DefaultListDelimiterHandler(org.apache.commons.configuration2.convert.DefaultListDelimiterHandler) Test(org.junit.Test)

Example 4 with ListDelimiterHandler

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);
    }
}
Also used : ListDelimiterHandler(org.apache.commons.configuration2.convert.ListDelimiterHandler) DisabledListDelimiterHandler(org.apache.commons.configuration2.convert.DisabledListDelimiterHandler)

Example 5 with ListDelimiterHandler

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

ListDelimiterHandler (org.apache.commons.configuration2.convert.ListDelimiterHandler)17 DefaultListDelimiterHandler (org.apache.commons.configuration2.convert.DefaultListDelimiterHandler)16 Test (org.junit.Test)12 File (java.io.File)5 FileHandler (org.apache.commons.configuration2.io.FileHandler)4 DisabledListDelimiterHandler (org.apache.commons.configuration2.convert.DisabledListDelimiterHandler)3 LegacyListDelimiterHandler (org.apache.commons.configuration2.convert.LegacyListDelimiterHandler)3 IOException (java.io.IOException)2 StringReader (java.io.StringReader)2 ArrayList (java.util.ArrayList)2 CombinedConfiguration (org.apache.commons.configuration2.CombinedConfiguration)2 ConfigurationDecoder (org.apache.commons.configuration2.ConfigurationDecoder)2 DynamicCombinedConfiguration (org.apache.commons.configuration2.DynamicCombinedConfiguration)2 XMLBuilderParametersImpl (org.apache.commons.configuration2.builder.XMLBuilderParametersImpl)2 ConfigurationLogger (org.apache.commons.configuration2.io.ConfigurationLogger)2 Before (org.junit.Before)2 BufferedReader (java.io.BufferedReader)1 FileReader (java.io.FileReader)1 FileWriter (java.io.FileWriter)1 Reader (java.io.Reader)1