commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1580608 - in /commons/proper/configuration/branches/immutableNodes/src: main/java/org/apache/commons/configuration/INIConfiguration.java test/java/org/apache/commons/configuration/TestINIConfiguration.java
Date Sun, 23 Mar 2014 20:38:23 GMT
Author: oheger
Date: Sun Mar 23 20:38:23 2014
New Revision: 1580608

URL: http://svn.apache.org/r1580608
Log:
getSection() now returns a SubnodeConfiguration.

Added some tests which ensure that the sub configurations are actually
connected to their parent.

Modified:
    commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/INIConfiguration.java
    commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/TestINIConfiguration.java

Modified: commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/INIConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/INIConfiguration.java?rev=1580608&r1=1580607&r2=1580608&view=diff
==============================================================================
--- commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/INIConfiguration.java
(original)
+++ commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/INIConfiguration.java
Sun Mar 23 20:38:23 2014
@@ -832,7 +832,7 @@ public class INIConfiguration extends Ba
      * @return a configuration containing only the properties of the specified
      *         section
      */
-    public HierarchicalConfiguration<ImmutableNode> getSection(String name)
+    public SubnodeConfiguration getSection(String name)
     {
         if (name == null)
         {
@@ -843,7 +843,7 @@ public class INIConfiguration extends Ba
         {
             try
             {
-                return configurationAt(name);
+                return (SubnodeConfiguration) configurationAt(name, true);
             }
             catch (ConfigurationRuntimeException iex)
             {

Modified: commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/TestINIConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/TestINIConfiguration.java?rev=1580608&r1=1580607&r2=1580608&view=diff
==============================================================================
--- commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/TestINIConfiguration.java
(original)
+++ commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/TestINIConfiguration.java
Sun Mar 23 20:38:23 2014
@@ -504,6 +504,20 @@ public class TestINIConfiguration
     }
 
     /**
+     * Tests whether the sub configuration for the global section is connected
+     * to its parent.
+     */
+    @Test
+    public void testGlobalSectionConnected() throws ConfigurationException
+    {
+        INIConfiguration config = setUpConfig(INI_DATA_GLOBAL);
+        HierarchicalConfiguration<ImmutableNode> sub = config.getSection(null);
+        config.setProperty("globalVar", "changed");
+        assertEquals("Wrong value in sub", "changed",
+                sub.getString("globalVar"));
+    }
+
+    /**
      * Tests whether the specified configuration contains exactly the expected
      * sections.
      *
@@ -607,12 +621,28 @@ public class TestINIConfiguration
     public void testGetSectionExisting() throws ConfigurationException
     {
         INIConfiguration config = setUpConfig(INI_DATA);
-        HierarchicalConfiguration<ImmutableNode> section = config.getSection("section1");
+        HierarchicalConfiguration<ImmutableNode> section =
+                config.getSection("section1");
         assertEquals("Wrong value of var1", "foo", section.getString("var1"));
         assertEquals("Wrong value of var2", "451", section.getString("var2"));
     }
 
     /**
+     * Tests whether the sub configuration returned by getSection() is connected
+     * to the parent.
+     */
+    @Test
+    public void testGetSectionConnected() throws ConfigurationException
+    {
+        INIConfiguration config = setUpConfig(INI_DATA);
+        HierarchicalConfiguration<ImmutableNode> section =
+                config.getSection("section1");
+        section.setProperty("var1", "foo2");
+        assertEquals("Not connected to parent", "foo2",
+                config.getString("section1.var1"));
+    }
+
+    /**
      * Tests querying the properties of a section that was merged from two
      * sections with the same name.
      */
@@ -1039,8 +1069,7 @@ public class TestINIConfiguration
             throws ConfigurationException
     {
         INIConfiguration config = setUpConfig(INI_DATA_GLOBAL);
-        SubnodeConfiguration sub =
-                (SubnodeConfiguration) config.getSection(null);
+        SubnodeConfiguration sub = config.getSection(null);
         NodeHandler<ImmutableNode> handler = sub.getModel().getNodeHandler();
         assertTrue("Sections not filtered",
                 handler.getChildren(sub.getRootNode(), "section1").isEmpty());
@@ -1055,8 +1084,7 @@ public class TestINIConfiguration
             throws ConfigurationException
     {
         INIConfiguration config = setUpConfig(INI_DATA_GLOBAL);
-        SubnodeConfiguration sub =
-                (SubnodeConfiguration) config.getSection(null);
+        SubnodeConfiguration sub = config.getSection(null);
         NodeHandler<ImmutableNode> handler = sub.getModel().getNodeHandler();
         assertEquals("Wrong number of children", 1,
                 handler.getChildrenCount(handler.getRootNode(), null));
@@ -1071,8 +1099,7 @@ public class TestINIConfiguration
             throws ConfigurationException
     {
         INIConfiguration config = setUpConfig(INI_DATA_GLOBAL);
-        SubnodeConfiguration sub =
-                (SubnodeConfiguration) config.getSection(null);
+        SubnodeConfiguration sub = config.getSection(null);
         NodeHandler<ImmutableNode> handler = sub.getModel().getNodeHandler();
         ImmutableNode child = handler.getChild(handler.getRootNode(), 0);
         assertEquals("Wrong child", "globalVar", child.getNodeName());
@@ -1096,8 +1123,7 @@ public class TestINIConfiguration
             throws ConfigurationException
     {
         INIConfiguration config = setUpConfig(INI_DATA_GLOBAL);
-        SubnodeConfiguration sub =
-                (SubnodeConfiguration) config.getSection(null);
+        SubnodeConfiguration sub = config.getSection(null);
         NodeHandler<ImmutableNode> handler = sub.getModel().getNodeHandler();
         List<ImmutableNode> children = handler.getRootNode().getChildren();
         assertEquals("Wrong index", 0,



Mime
View raw message