commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1690811 - in /commons/proper/configuration/trunk/src: main/java/org/apache/commons/configuration2/ test/java/org/apache/commons/configuration2/ test/java/org/apache/commons/configuration2/tree/
Date Mon, 13 Jul 2015 20:18:22 GMT
Author: oheger
Date: Mon Jul 13 20:18:21 2015
New Revision: 1690811

URL: http://svn.apache.org/r1690811
Log:
[CONFIGURATION-604] Changed construction of hierarchical configuration.

The conversion of a flat configuration to a hierarchical one now uses copy()
rather than append(). This causes a slightly different structure of the
resulting configuration. Because append() adds new nodes on each invocation
the property keys "x.y.z" and "x.y" processed in this order generates two y
child nodes of x. With copy() only a single node is created. This is closer to
the original structure of the flat configuration and is less dependent on the
order of configuration keys.

Modified:
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/ConfigurationUtils.java
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestConfigurationUtils.java
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/tree/TestOverrideCombiner.java

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/ConfigurationUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/ConfigurationUtils.java?rev=1690811&r1=1690810&r2=1690811&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/ConfigurationUtils.java
(original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/ConfigurationUtils.java
Mon Jul 13 20:18:21 2015
@@ -262,7 +262,7 @@ public final class ConfigurationUtils
 
             // Per default, a DisabledListDelimiterHandler is set.
             // So list delimiters in property values are not an issue.
-            hc.append(conf);
+            hc.copy(conf);
             return hc;
         }
     }

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestConfigurationUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestConfigurationUtils.java?rev=1690811&r1=1690810&r2=1690811&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestConfigurationUtils.java
(original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestConfigurationUtils.java
Mon Jul 13 20:18:21 2015
@@ -31,6 +31,7 @@ import java.util.List;
 import java.util.Map;
 
 import junitx.framework.ListAssert;
+
 import org.apache.commons.configuration2.builder.XMLBuilderParametersImpl;
 import org.apache.commons.configuration2.convert.DefaultListDelimiterHandler;
 import org.apache.commons.configuration2.event.ConfigurationErrorEvent;
@@ -42,6 +43,7 @@ import org.apache.commons.configuration2
 import org.apache.commons.configuration2.tree.DefaultExpressionEngine;
 import org.apache.commons.configuration2.tree.DefaultExpressionEngineSymbols;
 import org.apache.commons.configuration2.tree.ExpressionEngine;
+import org.apache.commons.configuration2.tree.ImmutableNode;
 import org.easymock.EasyMock;
 import org.junit.After;
 import org.junit.Before;
@@ -91,7 +93,7 @@ public class TestConfigurationUtils
         assertEquals("String representation of a configuration", "two=2" , ConfigurationUtils.toString(config));
 
         config.setProperty("one","1");
-        assertEquals("String representation of a configuration", "two=2" + lineSeparator
+ "one=1" , ConfigurationUtils.toString(config));
+        assertEquals("String representation of a configuration", "two=2" + lineSeparator
+ "one=1", ConfigurationUtils.toString(config));
     }
 
     @Test
@@ -281,6 +283,26 @@ public class TestConfigurationUtils
     }
 
     /**
+     * Tests that the structure of the resulting hierarchical configuration
+     * does not depend on the order of properties in the source configuration.
+     * This test is related to CONFIGURATION-604.
+     */
+    @Test
+    public void testConvertToHierarchicalOrderOfProperties()
+    {
+        PropertiesConfiguration config = new PropertiesConfiguration();
+        config.addProperty("x.y.z", true);
+        config.addProperty("x.y", true);
+        @SuppressWarnings("unchecked")
+        HierarchicalConfiguration<ImmutableNode> hc =
+                (HierarchicalConfiguration<ImmutableNode>)
+                        ConfigurationUtils.convertToHierarchical(config);
+        ImmutableNode rootNode = hc.getNodeModel().getNodeHandler().getRootNode();
+        ImmutableNode nodeX = rootNode.getChildren().get(0);
+        assertEquals("Wrong number of children of x", 1, nodeX.getChildren().size());
+    }
+
+    /**
      * Tests cloning a configuration that supports this operation.
      */
     @Test

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/tree/TestOverrideCombiner.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/tree/TestOverrideCombiner.java?rev=1690811&r1=1690810&r2=1690811&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/tree/TestOverrideCombiner.java
(original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/tree/TestOverrideCombiner.java
Mon Jul 13 20:18:21 2015
@@ -18,11 +18,14 @@ package org.apache.commons.configuration
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 
 import java.util.List;
 
 import org.apache.commons.configuration2.BaseHierarchicalConfiguration;
+import org.apache.commons.configuration2.CombinedConfiguration;
 import org.apache.commons.configuration2.HierarchicalConfiguration;
+import org.apache.commons.configuration2.PropertiesConfiguration;
 import org.apache.commons.configuration2.ex.ConfigurationException;
 import org.junit.Test;
 
@@ -176,4 +179,36 @@ public class TestOverrideCombiner extend
         assertFalse("An attribute result", nds.get(0).isAttributeResult());
         return nds.get(0).getNode();
     }
+
+    /**
+     * Tests a combine operation of non-hierarchical properties. This test is
+     * related to CONFIGURATION-604.
+     */
+    @Test
+    public void testCombineProperties()
+    {
+        PropertiesConfiguration c1 = new PropertiesConfiguration();
+        c1.addProperty("x.y.simpleCase", false);
+        c1.addProperty("x.y.between", false);
+        c1.addProperty("x.y.isDistinctFrom",false);
+        c1.addProperty("x.y",false);
+        PropertiesConfiguration c2 = new PropertiesConfiguration();
+        c2.addProperty("x.y", true);
+        c2.addProperty("x.y.between",true);
+        c2.addProperty("x.y.comparison",true);
+        c2.addProperty("x.y.in",true);
+        c2.addProperty("x.y.isDistinctFrom",true);
+        c2.addProperty("x.y.simpleCase", true);
+
+        CombinedConfiguration config = new CombinedConfiguration(new OverrideCombiner());
+        config.addConfiguration(c1);
+        config.addConfiguration(c2);
+        assertFalse("Wrong value for x.y", config.getBoolean("x.y"));
+        assertFalse("Wrong value for x.y.between", config.getBoolean("x.y.between"));
+        assertFalse("Wrong value for x.y.isDistinctFrom", config.getBoolean("x.y.isDistinctFrom"));
+        assertFalse("Wrong value for x.y.simpleCase", config.getBoolean("x.y.simpleCase"));
+        assertTrue("Wrong value for x.y.in", config.getBoolean("x.y.in"));
+        assertTrue("Wrong value for x.y.comparison", config.getBoolean("x.y.comparison"));
+        assertEquals("Wrong size", 6, config.size());
+    }
 }



Mime
View raw message