commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r640458 - in /commons/proper/configuration/trunk: src/java/org/apache/commons/configuration/ src/test/org/apache/commons/configuration/ xdocs/
Date Mon, 24 Mar 2008 16:30:48 GMT
Author: oheger
Date: Mon Mar 24 09:30:44 2008
New Revision: 640458

URL: http://svn.apache.org/viewvc?rev=640458&view=rev
Log:
CONFIGURATION-318: Take the name of the root element into account when creating an XMLConfiguration
using the copy constructor

Modified:
    commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/XMLConfiguration.java
    commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestHierarchicalConfigurationXMLReader.java
    commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestXMLConfiguration.java
    commons/proper/configuration/trunk/xdocs/changes.xml

Modified: commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/XMLConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/XMLConfiguration.java?rev=640458&r1=640457&r2=640458&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/XMLConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/XMLConfiguration.java
Mon Mar 24 09:30:44 2008
@@ -279,6 +279,7 @@
                     + "cannot be changed when loaded from an XML document!");
         }
         rootElementName = name;
+        getRootNode().setName(name);
     }
 
     /**
@@ -422,6 +423,7 @@
         }
 
         constructHierarchy(getRoot(), document.getDocumentElement(), elemRefs);
+        getRootNode().setName(document.getDocumentElement().getNodeName());
         if (elemRefs)
         {
             getRoot().setReference(document.getDocumentElement());

Modified: commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestHierarchicalConfigurationXMLReader.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestHierarchicalConfigurationXMLReader.java?rev=640458&r1=640457&r2=640458&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestHierarchicalConfigurationXMLReader.java
(original)
+++ commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestHierarchicalConfigurationXMLReader.java
Mon Mar 24 09:30:44 2008
@@ -67,7 +67,7 @@
         Node root = ((Document) result.getNode()).getDocumentElement();
         JXPathContext ctx = JXPathContext.newContext(root);
 
-        assertEquals("Wrong name of root element", "config", root.getNodeName());
+        assertEquals("Wrong name of root element", "database", root.getNodeName());
         assertEquals("Wrong number of children of root", 1, ctx.selectNodes(
                 "/*").size());
         assertEquals("Wrong number of tables", 2, ctx.selectNodes(

Modified: commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestXMLConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestXMLConfiguration.java?rev=640458&r1=640457&r2=640458&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestXMLConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestXMLConfiguration.java
Mon Mar 24 09:30:44 2008
@@ -1326,6 +1326,45 @@
     }
 
     /**
+     * Tests whether the name of the root element is copied when a configuration
+     * is created using the copy constructor.
+     */
+    public void testCopyRootName() throws ConfigurationException
+    {
+        final String rootName = "rootElement";
+        final String xml = "<" + rootName + "><test>true</test></" +
rootName
+                + ">";
+        conf.clear();
+        conf.load(new StringReader(xml));
+        XMLConfiguration copy = new XMLConfiguration(conf);
+        assertEquals("Wrong name of root element", rootName, copy
+                .getRootElementName());
+        copy.save(testSaveConf);
+        copy = new XMLConfiguration(testSaveConf);
+        assertEquals("Wrong name of root element after save", rootName, copy
+                .getRootElementName());
+    }
+
+    /**
+     * Tests whether the name of the root element is copied for a configuration
+     * for which not yet a document exists.
+     */
+    public void testCopyRootNameNoDocument() throws ConfigurationException
+    {
+        final String rootName = "rootElement";
+        conf = new XMLConfiguration();
+        conf.setRootElementName(rootName);
+        conf.setProperty("test", Boolean.TRUE);
+        XMLConfiguration copy = new XMLConfiguration(conf);
+        assertEquals("Wrong name of root element", rootName, copy
+                .getRootElementName());
+        copy.save(testSaveConf);
+        copy = new XMLConfiguration(testSaveConf);
+        assertEquals("Wrong name of root element after save", rootName, copy
+                .getRootElementName());
+    }
+
+    /**
      * Prepares a configuration object for testing a reload operation.
      *
      * @return the initialized configuration

Modified: commons/proper/configuration/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/xdocs/changes.xml?rev=640458&r1=640457&r2=640458&view=diff
==============================================================================
--- commons/proper/configuration/trunk/xdocs/changes.xml (original)
+++ commons/proper/configuration/trunk/xdocs/changes.xml Mon Mar 24 09:30:44 2008
@@ -23,6 +23,10 @@
 
   <body>
     <release version="1.6" date="in SVN" description="">
+      <action dev="oheger" type="fix" issue="CONFIGURATION-318">
+        When an XMLConfiguration is created using the copy constructor, the name
+        of the root element is now preserved.
+      </action>
       <action dev="oheger" type="fix" issue="CONFIGURATION-316">
         Changing the text of the root element of an XMLConfiguration had no
         effect when the configuration was saved. This has been fixed.



Mime
View raw message