org.apache.commons.configuration2.convert.DefaultListDelimiterHandler Java Examples

The following examples show how to use org.apache.commons.configuration2.convert.DefaultListDelimiterHandler. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestCombinedConfigurationBuilder.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
/**
 * 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());
}
 
Example #2
Source File: TestFileBasedConfigurationBuilder.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
/**
 * Tests whether HomeDirectoryLocationStrategy can be properly initialized
 * and that it shouldn't throw {@code ConfigurationException} when
 * everything is correctly in place. Without the code fix for
 * <a href="https://issues.apache.org/jira/browse/CONFIGURATION-634">CONFIGURATION-634</a>,
 * this test will throw {@code ConfigurationException}
 * @throws IOException              Shouldn't happen
 * @throws ConfigurationException   Shouldn't happen
 */
@Test
public void testFileBasedConfigurationBuilderWithHomeDirectoryLocationStrategy()
        throws IOException, ConfigurationException
{
    final String folderName = "test";
    final String fileName = "sample.properties";
    folder.newFolder(folderName);
    folder.newFile(folderName + File.separatorChar + fileName);
    final FileBasedConfigurationBuilder<FileBasedConfiguration> homeDirConfigurationBuilder =
            new FileBasedConfigurationBuilder<>(
                    PropertiesConfiguration.class);
    final PropertiesBuilderParameters homeDirProperties =
            new Parameters().properties();
    final HomeDirectoryLocationStrategy strategy =
            new HomeDirectoryLocationStrategy(
                    folder.getRoot().getAbsolutePath(), true);
    final FileBasedConfigurationBuilder<FileBasedConfiguration> builder =
            homeDirConfigurationBuilder.configure(homeDirProperties
                    .setLocationStrategy(strategy).setBasePath(folderName)
                    .setListDelimiterHandler(
                            new DefaultListDelimiterHandler(','))
                    .setFileName(fileName));
    builder.getConfiguration();
}
 
Example #3
Source File: TestBaseConfigurationBuilderProvider.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a configuration object describing a configuration source.
 *
 * @param reload a flag whether reload operations are supported
 * @return the configuration object
 */
private HierarchicalConfiguration<?> setUpConfig(final boolean reload)
{
    final HierarchicalConfiguration<?> config = new BaseHierarchicalConfiguration();
    config.addProperty(CombinedConfigurationBuilder.ATTR_RELOAD,
            Boolean.valueOf(reload));
    config.addProperty("[@throwExceptionOnMissing]", Boolean.TRUE);
    config.addProperty("[@path]",
            ConfigurationAssert.getTestFile("test.properties")
                    .getAbsolutePath());
    config.addProperty("listDelimiterHandler[@config-class]",
            DefaultListDelimiterHandler.class.getName());
    config.addProperty(
            "listDelimiterHandler.config-constrarg[@config-value]", ";");
    return config;
}
 
Example #4
Source File: TestBaseConfigurationBuilderProvider.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
/**
 * Helper method for setting up a builder and checking properties of the
 * created configuration object.
 *
 * @param reload a flag whether reloading is supported
 * @return the builder created by the provider
 * @throws ConfigurationException if an error occurs
 */
private ConfigurationBuilder<? extends Configuration> checkBuilder(
        final boolean reload) throws ConfigurationException
{
    final HierarchicalConfiguration<?> declConfig = setUpConfig(reload);
    final ConfigurationDeclaration decl = createDeclaration(declConfig);
    final ConfigurationBuilder<? extends Configuration> builder =
            createProvider().getConfigurationBuilder(decl);
    final Configuration config = builder.getConfiguration();
    assertEquals("Wrong configuration class",
            PropertiesConfiguration.class, config.getClass());
    final PropertiesConfiguration pconfig = (PropertiesConfiguration) config;
    assertTrue("Wrong exception flag",
            pconfig.isThrowExceptionOnMissing());
    final DefaultListDelimiterHandler listHandler =
            (DefaultListDelimiterHandler) pconfig.getListDelimiterHandler();
    assertEquals("Wrong list delimiter", ';', listHandler.getDelimiter());
    assertTrue("Configuration not loaded",
            pconfig.getBoolean("configuration.loaded"));
    return builder;
}
 
Example #5
Source File: TestCombinedConfiguration.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
/**
 * Tests using a conversion expression engine for child configurations with
 * strange keys. This test is related to CONFIGURATION-336.
 */
@Test
public void testConversionExpressionEngine()
{
    final PropertiesConfiguration child = new PropertiesConfiguration();
    child.setListDelimiterHandler(new DefaultListDelimiterHandler(','));
    child.addProperty("test(a)", "1,2,3");
    config.addConfiguration(child);
    final DefaultExpressionEngine engineQuery =
            new DefaultExpressionEngine(
                    new DefaultExpressionEngineSymbols.Builder(
                            DefaultExpressionEngineSymbols.DEFAULT_SYMBOLS)
                            .setIndexStart("<").setIndexEnd(">").create());
    config.setExpressionEngine(engineQuery);
    final DefaultExpressionEngine engineConvert =
            new DefaultExpressionEngine(
                    new DefaultExpressionEngineSymbols.Builder(
                            DefaultExpressionEngineSymbols.DEFAULT_SYMBOLS)
                            .setIndexStart("[").setIndexEnd("]").create());
    config.setConversionExpressionEngine(engineConvert);
    assertEquals("Wrong property 1", "1", config.getString("test(a)<0>"));
    assertEquals("Wrong property 2", "2", config.getString("test(a)<1>"));
    assertEquals("Wrong property 3", "3", config.getString("test(a)<2>"));
}
 
Example #6
Source File: TestSubsetConfiguration.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
/**
 * Tests whether a list delimiter handler is used correctly.
 */
@Test
public void testListDelimiterHandling()
{
    final BaseConfiguration config = new BaseConfiguration();
    final Configuration subset = config.subset("prefix");
    config.setListDelimiterHandler(new DefaultListDelimiterHandler('/'));
    subset.addProperty("list", "a/b/c");
    assertEquals("Wrong size of list", 3, config.getList("prefix.list")
            .size());

    ((AbstractConfiguration) subset)
            .setListDelimiterHandler(new DefaultListDelimiterHandler(';'));
    subset.addProperty("list2", "a;b;c");
    assertEquals("Wrong size of list2", 3, config.getList("prefix.list2")
            .size());
}
 
Example #7
Source File: TestCompositeConfiguration.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
/**
 * 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());
}
 
Example #8
Source File: TestCombinedConfigurationBuilder.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
/**
 * 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());
}
 
Example #9
Source File: ScriptFilterTest.java    From engine with GNU General Public License v3.0 6 votes vote down vote up
private SiteContext createSiteContext(ContentStoreService storeService) throws Exception {
    SiteContext siteContext = spy(new SiteContext());
    ScriptFactory scriptFactory = createScriptFactory(siteContext);

    XMLConfiguration config =
        ConfigUtils.readXmlConfiguration(new ClassPathResource("config/site-config.xml"), ',', null);
    config.setListDelimiterHandler(new DefaultListDelimiterHandler(','));

    when(siteContext.getSiteName()).thenReturn("default");
    when(siteContext.getContext()).thenReturn(mock(Context.class));
    when(siteContext.getStoreService()).thenReturn(storeService);
    when(siteContext.getConfig()).thenReturn(config);
    when(siteContext.getScriptFactory()).thenReturn(scriptFactory);
    when(siteContext.getCacheTemplate()).thenReturn(cacheTemplate);

    return siteContext;
}
 
Example #10
Source File: TestAbstractConfigurationBasicFeatures.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
/**
 * Tests escaping the variable marker, so that no interpolation will be
 * performed.
 */
@Test
public void testInterpolateEscape()
{
    final AbstractConfiguration config = new TestConfigurationImpl(
            new PropertiesConfiguration());
    config.setListDelimiterHandler(new DefaultListDelimiterHandler(','));
    config
            .addProperty(
                    "mypath",
                    "$${DB2UNIVERSAL_JDBC_DRIVER_PATH}/db2jcc.jar\\,$${DB2UNIVERSAL_JDBC_DRIVER_PATH}/db2jcc_license_cu.jar");
    assertEquals(
            "Wrong interpolated value",
            "${DB2UNIVERSAL_JDBC_DRIVER_PATH}/db2jcc.jar,${DB2UNIVERSAL_JDBC_DRIVER_PATH}/db2jcc_license_cu.jar",
            config.getString("mypath"));
}
 
Example #11
Source File: TestMultiWrapDynaBean.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
/**
 * 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"));
}
 
Example #12
Source File: TestConfigurationConverter.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
@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"));
}
 
Example #13
Source File: TestSubnodeConfiguration.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
/**
 * Tests manipulating the list delimiter handler. This object is derived
 * from the parent.
 */
@Test
public void testSetListDelimiterHandler()
{
    final ListDelimiterHandler handler1 = new DefaultListDelimiterHandler('/');
    final ListDelimiterHandler handler2 = new DefaultListDelimiterHandler(';');
    parent.setListDelimiterHandler(handler1);
    setUpSubnodeConfig();
    parent.setListDelimiterHandler(handler2);
    assertEquals("List delimiter handler not obtained from parent",
            handler1, config.getListDelimiterHandler());
    config.addProperty("newProp", "test1,test2/test3");
    assertEquals("List was incorrectly splitted", "test1,test2",
            parent.getString("tables.table(0).newProp"));
    config.setListDelimiterHandler(DisabledListDelimiterHandler.INSTANCE);
    assertEquals("List delimiter changed on parent", handler2,
            parent.getListDelimiterHandler());
}
 
Example #14
Source File: TestServletConfiguration.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #15
Source File: TestServletRequestConfiguration.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a new servlet request configuration that is backed by the passed
 * in configuration.
 *
 * @param base the configuration with the underlying values
 * @return the servlet request configuration
 */
private ServletRequestConfiguration createConfiguration(final Configuration base)
{
    final ServletRequest request = new MockHttpServletRequest()
    {
        @Override
        public String[] getParameterValues(final String key)
        {
            return base.getStringArray(key);
        }

        @Override
        public Map<?, ?> getParameterMap()
        {
            return new ConfigurationMap(base);
        }
    };

    final ServletRequestConfiguration config = new ServletRequestConfiguration(request);
    config.setListDelimiterHandler(new DefaultListDelimiterHandler(','));
    return config;
}
 
Example #16
Source File: Elepy.java    From elepy with Apache License 2.0 6 votes vote down vote up
public Elepy withProperties(URL url) {
    try {

        Parameters params = new Parameters();
        FileBasedConfigurationBuilder<PropertiesConfiguration> builder =
                new FileBasedConfigurationBuilder<>(PropertiesConfiguration.class)
                        .configure(params.properties()
                                .setURL(url)
                                .setListDelimiterHandler(new DefaultListDelimiterHandler(',')));
        var propertyConfig = builder.getConfiguration();

        propertyConfiguration.addConfiguration(
                propertyConfig
        );
    } catch (ConfigurationException e) {
        throw new ElepyConfigException("Failed to load properties", e);
    }
    return this;
}
 
Example #17
Source File: TestSubsetConfiguration.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetList()
{
    final BaseConfiguration conf = new BaseConfiguration();
    conf.setListDelimiterHandler(new DefaultListDelimiterHandler(','));
    conf.setProperty("test.abc", "value0,value1");
    conf.addProperty("test.abc", "value3");

    final Configuration subset = new SubsetConfiguration(conf, "test", ".");
    final List<Object> list = subset.getList("abc", new ArrayList<>());
    assertEquals(3, list.size());
}
 
Example #18
Source File: TestINIConfiguration.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
/**
 * Tests whether the configuration deals correctly with list delimiters.
 */
@Test
public void testListDelimiterHandling() throws ConfigurationException
{
    final INIConfiguration config = new INIConfiguration();
    config.setListDelimiterHandler(new DefaultListDelimiterHandler(','));
    config.addProperty("list", "a,b,c");
    config.addProperty("listesc", "3\\,1415");
    final String output = saveToString(config);
    final INIConfiguration config2 = setUpConfig(output);
    assertEquals("Wrong list size", 3, config2.getList("list").size());
    assertEquals("Wrong list element", "b", config2.getList("list").get(1));
    assertEquals("Wrong escaped list element", "3,1415",
            config2.getString("listesc"));
}
 
Example #19
Source File: TestINIConfiguration.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a INIConfiguration object that is initialized from
 * the given data.
 *
 * @param data the data of the configuration (an ini file as string)
 * @return the initialized configuration
 * @throws ConfigurationException if an error occurs
 */
private static INIConfiguration setUpConfig(final String data)
        throws ConfigurationException
{
    final INIConfiguration instance = new INIConfiguration();
    instance.setListDelimiterHandler(new DefaultListDelimiterHandler(','));
    load(instance, data);
    return instance;
}
 
Example #20
Source File: TestCombinedConfigurationBuilder.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
/**
 * Prepares a parameters object for a test for properties inheritance.
 * @param params the {@code Parameters} object
 * @return the builder parameters
 */
private static XMLBuilderParameters prepareParamsForInheritanceTest(final Parameters params) {
    final DefaultExpressionEngineSymbols symbols = new DefaultExpressionEngineSymbols.Builder(
            DefaultExpressionEngineSymbols.DEFAULT_SYMBOLS)
            .setPropertyDelimiter("/").create();
    final DefaultExpressionEngine engine = new DefaultExpressionEngine(symbols);
    final DefaultListDelimiterHandler listDelimiterHandler = new DefaultListDelimiterHandler(',');
    return params.xml()
            .setExpressionEngine(engine)
            .setListDelimiterHandler(listDelimiterHandler).setFile(TEST_FILE);
}
 
Example #21
Source File: TestConfigurationConverter.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
/**
 * Tests a conversion to Properties if the list delimiter handler supports
 * list joining.
 */
@Test
public void testConfigurationToPropertiesListDelimiterHandler()
{
    final BaseConfiguration config = createTestConfiguration();
    config.setListDelimiterHandler(new DefaultListDelimiterHandler(';'));
    final Properties props = ConfigurationConverter.getProperties(config);
    assertEquals("'array' property", "item 1;item 2", props.getProperty("array"));
}
 
Example #22
Source File: TestCombinedConfigurationBuilder.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method for testing the attributes of a combined configuration
 * created by the builder.
 *
 * @param cc the configuration to be checked
 */
private static void checkCombinedConfigAttrs(final CombinedConfiguration cc)
{
    final ListDelimiterHandler handler = cc.getListDelimiterHandler();
    assertTrue("Wrong delimiter handler: " + handler,
            handler instanceof DefaultListDelimiterHandler);
    assertEquals("Wrong list delimiter character", ',',
            ((DefaultListDelimiterHandler) handler).getDelimiter());
}
 
Example #23
Source File: TestBasicBuilderParameters.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
/**
 * Tests whether properties can be inherited from another parameters map.
 */
@Test
public void testInheritFrom()
{
    final BeanHelper beanHelper = new BeanHelper();
    final ConfigurationDecoder decoder =
            EasyMock.createMock(ConfigurationDecoder.class);
    final ConversionHandler conversionHandler = new DefaultConversionHandler();
    final ListDelimiterHandler listDelimiterHandler =
            new DefaultListDelimiterHandler('#');
    final ConfigurationLogger logger = new ConfigurationLogger("test");
    final Synchronizer synchronizer = new ReadWriteSynchronizer();
    params.setBeanHelper(beanHelper).setConfigurationDecoder(decoder)
            .setConversionHandler(conversionHandler)
            .setListDelimiterHandler(listDelimiterHandler).setLogger(logger)
            .setSynchronizer(synchronizer).setThrowExceptionOnMissing(true);
    final BasicBuilderParameters p2 = new BasicBuilderParameters();

    p2.inheritFrom(params.getParameters());
    final Map<String, Object> parameters = p2.getParameters();
    assertEquals("Bean helper not set", beanHelper,
            parameters.get("config-BeanHelper"));
    assertEquals("Decoder not set", decoder,
            parameters.get("configurationDecoder"));
    assertEquals("Conversion handler not set", conversionHandler,
            parameters.get("conversionHandler"));
    assertEquals("Delimiter handler not set", listDelimiterHandler,
            parameters.get("listDelimiterHandler"));
    assertEquals("Logger not set", logger, parameters.get("logger"));
    assertEquals("Synchronizer not set", synchronizer,
            parameters.get("synchronizer"));
    assertEquals("Exception flag not set", Boolean.TRUE,
            parameters.get("throwExceptionOnMissing"));
}
 
Example #24
Source File: TestAbstractConfigurationBasicFeatures.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #25
Source File: TestAbstractConfigurationBasicFeatures.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
/**
 * Creates the source configuration for testing the copy() and append()
 * methods. This configuration contains keys with an odd index and values
 * starting with the prefix "src". There are also some list properties.
 *
 * @return the source configuration for copy operations
 */
private Configuration setUpSourceConfig()
{
    final BaseConfiguration config = new BaseConfiguration();
    config.setListDelimiterHandler(new DefaultListDelimiterHandler(','));
    for (int i = 1; i < PROP_COUNT; i += 2)
    {
        config.addProperty(KEY_PREFIX + i, "src" + i);
    }
    config.addProperty("list1", "1,2,3");
    config.addProperty("list2", "3\\,1415,9\\,81");
    return config;
}
 
Example #26
Source File: TestAbstractConfigurationBasicFeatures.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
/**
 * Tests whether the list delimiter is correctly handled if a configuration
 * is appended.
 */
@Test
public void testAppendDelimiterHandling()
{
    final BaseConfiguration srcConfig = new BaseConfiguration();
    final BaseConfiguration dstConfig = new BaseConfiguration();
    dstConfig.setListDelimiterHandler(new DefaultListDelimiterHandler(','));
    srcConfig.setProperty(KEY_PREFIX, "C:\\Temp\\,D:\\Data");
    dstConfig.append(srcConfig);
    assertEquals("Wrong property value", srcConfig.getString(KEY_PREFIX),
            dstConfig.getString(KEY_PREFIX));
}
 
Example #27
Source File: TestAbstractConfigurationBasicFeatures.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
/**
 * Tests whether list delimiters are correctly handled when copying a
 * configuration.
 */
@Test
public void testCopyDelimiterHandling()
{
    final BaseConfiguration srcConfig = new BaseConfiguration();
    final BaseConfiguration dstConfig = new BaseConfiguration();
    dstConfig.setListDelimiterHandler(new DefaultListDelimiterHandler(','));
    srcConfig.setProperty(KEY_PREFIX, "C:\\Temp\\,D:\\Data");
    dstConfig.copy(srcConfig);
    assertEquals("Wrong property value", srcConfig.getString(KEY_PREFIX),
            dstConfig.getString(KEY_PREFIX));
}
 
Example #28
Source File: TestConfigurationUtils.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
/**
 * Tests converting a configuration to a hierarchical one that contains a
 * property with multiple values. This test is related to CONFIGURATION-346.
 */
@Test
public void testConvertToHierarchicalMultiValues()
{
    final BaseConfiguration config = new BaseConfiguration();
    config.setListDelimiterHandler(new DefaultListDelimiterHandler(','));
    config.addProperty("test", "1,2,3");
    final HierarchicalConfiguration<?> hc = ConfigurationUtils
            .convertToHierarchical(config);
    assertEquals("Wrong value 1", 1, hc.getInt("test(0)"));
    assertEquals("Wrong value 2", 2, hc.getInt("test(1)"));
    assertEquals("Wrong value 3", 3, hc.getInt("test(2)"));
}
 
Example #29
Source File: TestConfigurationUtils.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
/**
 * Tests converting a configuration into a hierarchical one if some of its
 * properties contain escaped list delimiter characters.
 */
@Test
public void testConvertToHierarchicalDelimiters()
{
    final BaseConfiguration conf = new BaseConfiguration();
    conf.setListDelimiterHandler(new DefaultListDelimiterHandler(','));
    conf.addProperty("test.key", "1\\,2\\,3");
    assertEquals("Wrong property value", "1,2,3", conf
            .getString("test.key"));
    final HierarchicalConfiguration<?> hc = ConfigurationUtils
            .convertToHierarchical(conf);
    assertEquals("Escaped list delimiters not correctly handled", "1,2,3",
            hc.getString("test.key"));
}
 
Example #30
Source File: TestXMLListHandling.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
/**
 * Parses the specified string into an XML configuration.
 *
 * @param xml the XML to be parsed
 * @return the resulting configuration
 */
private static XMLConfiguration readFromString(final String xml)
        throws ConfigurationException
{
    final XMLConfiguration config = new XMLConfiguration();
    config.setListDelimiterHandler(new DefaultListDelimiterHandler(','));
    final FileHandler handler = new FileHandler(config);
    handler.load(new StringReader(xml));
    return config;
}