Author: oheger
Date: Thu Apr 26 06:12:30 2012
New Revision: 1330666
URL: http://svn.apache.org/viewvc?rev=1330666&view=rev
Log:
[CONFIGURATION-495] HierarchicalConfiguration.setProperty() now handles lists
and arrays correctly if delimiter parsing is disabled.
Modified:
commons/proper/configuration/trunk/src/changes/changes.xml
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/HierarchicalConfiguration.java
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestPropertiesConfiguration.java
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestXMLConfiguration.java
Modified: commons/proper/configuration/trunk/src/changes/changes.xml
URL:
http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/changes/changes.xml?rev=1330666&r1=1330665&r2=1330666&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/changes/changes.xml (original)
+++ commons/proper/configuration/trunk/src/changes/changes.xml Thu Apr 26
06:12:30 2012
@@ -27,6 +27,10 @@
<body>
<release version="1.9" date="in SVN"
description="TBD">
+ <action dev="oheger" type="fix" issue="CONFIGURATION-495">
+ List properties can now be set correctly on a HierarchicalConfiguration
+ if delimiter parsing is disabled.
+ </action>
<action dev="oheger" type="fix" issue="CONFIGURATION-487">
DataConfiguration.get() now also works with String properties and if no
data type conversion is required.
Modified:
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/HierarchicalConfiguration.java
URL:
http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/HierarchicalConfiguration.java?rev=1330666&r1=1330665&r2=1330666&view=diff
==============================================================================
---
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/HierarchicalConfiguration.java
(original)
+++
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/HierarchicalConfiguration.java
Thu Apr 26 06:12:30 2012
@@ -739,7 +739,7 @@ public class HierarchicalConfiguration e
// Update the existing nodes for this property
Iterator<ConfigurationNode> itNodes = fetchNodeList(key).iterator();
Iterator<?> itValues;
- if (!isDelimiterParsingDisabled())
+ if (!isDelimiterParsingDisabled() || !(value instanceof String))
{
itValues = PropertyConverter.toIterator(value, getListDelimiter());
}
Modified:
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestPropertiesConfiguration.java
URL:
http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestPropertiesConfiguration.java?rev=1330666&r1=1330665&r2=1330666&view=diff
==============================================================================
---
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestPropertiesConfiguration.java
(original)
+++
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestPropertiesConfiguration.java
Thu Apr 26 06:12:30 2012
@@ -44,6 +44,7 @@ import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandler;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
@@ -1058,6 +1059,25 @@ public class TestPropertiesConfiguration
}
/**
+ * Tests whether a list property is handled correctly if delimiter parsing
+ * is disabled. This test is related to CONFIGURATION-495.
+ */
+ @Test
+ public void testSetPropertyListWithDelimiterParsingDisabled()
+ throws ConfigurationException
+ {
+ String prop = "delimiterListProp";
+ conf.setDelimiterParsingDisabled(true);
+ List<String> list = Arrays.asList("val", "val2", "val3");
+ conf.setProperty(prop, list);
+ conf.setFile(testSavePropertiesFile);
+ conf.save();
+ conf.clear();
+ conf.load();
+ assertEquals("Wrong list property", list, conf.getProperty(prop));
+ }
+
+ /**
* Helper method for testing the content of a list with elements that
* contain backslashes.
*
Modified:
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestXMLConfiguration.java
URL:
http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestXMLConfiguration.java?rev=1330666&r1=1330665&r2=1330666&view=diff
==============================================================================
---
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestXMLConfiguration.java
(original)
+++
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestXMLConfiguration.java
Thu Apr 26 06:12:30 2012
@@ -34,6 +34,7 @@ import java.io.StringReader;
import java.io.StringWriter;
import java.net.URL;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
@@ -1849,6 +1850,44 @@ public class TestXMLConfiguration
}
/**
+ * Tests whether list properties are set correctly if delimiter
+ * parsing is disabled. This test is related to CONFIGURATION-495.
+ */
+ @Test
+ public void testSetPropertyListWithDelimiterParsingDisabled()
+ throws ConfigurationException
+ {
+ String prop = "delimiterListProp";
+ conf.setDelimiterParsingDisabled(true);
+ List<String> list = Arrays.asList("val", "val2", "val3");
+ conf.setProperty(prop, list);
+ conf.setFile(testSaveFile);
+ conf.save();
+ conf.clear();
+ conf.load();
+ assertEquals("Wrong list property", list, conf.getProperty(prop));
+ }
+
+ /**
+ * Tests whether list properties are added correctly if delimiter parsing
is
+ * disabled. This test is related to CONFIGURATION-495.
+ */
+ @Test
+ public void testAddPropertyListWithDelimiterParsingDisabled()
+ throws ConfigurationException
+ {
+ String prop = "delimiterListProp";
+ conf.setDelimiterParsingDisabled(true);
+ List<String> list = Arrays.asList("val", "val2", "val3");
+ conf.addProperty(prop, list);
+ conf.setFile(testSaveFile);
+ conf.save();
+ conf.clear();
+ conf.load();
+ assertEquals("Wrong list property", list, conf.getProperty(prop));
+ }
+
+ /**
* Prepares a configuration object for testing a reload operation.
*
* @return the initialized configuration