commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1585194 - in /commons/proper/configuration/branches/immutableNodes/src: main/java/org/apache/commons/configuration/XMLConfiguration.java test/java/org/apache/commons/configuration/TestXMLConfiguration.java
Date Sat, 05 Apr 2014 19:50:39 GMT
Author: oheger
Date: Sat Apr  5 19:50:39 2014
New Revision: 1585194

URL: http://svn.apache.org/r1585194
Log:
XMLConfiguration now calls the new mergeRoot() method.

Fixed all remaining failing test cases.

Modified:
    commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/XMLConfiguration.java
    commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/TestXMLConfiguration.java

Modified: commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/XMLConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/XMLConfiguration.java?rev=1585194&r1=1585193&r2=1585194&view=diff
==============================================================================
--- commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/XMLConfiguration.java
(original)
+++ commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/XMLConfiguration.java
Sat Apr  5 19:50:39 2014
@@ -258,7 +258,9 @@ public class XMLConfiguration extends Ba
     public XMLConfiguration(HierarchicalConfiguration<ImmutableNode> c)
     {
         super(c);
-        rootElementName = getRootNode().getNodeName();
+        rootElementName =
+                (c != null) ? c.getRootElementName() : getRootNode()
+                        .getNodeName();
         setLogger(LogFactory.getLog(XMLConfiguration.class));
     }
 
@@ -556,18 +558,16 @@ public class XMLConfiguration extends Ba
         MutableObject<String> rootValue = new MutableObject<String>();
         Map<ImmutableNode, Object> elemRefMap =
                 elemRefs ? new HashMap<ImmutableNode, Object>() : null;
-        constructHierarchy(rootBuilder, rootValue,
-                document.getDocumentElement(), elemRefMap, true, 0);
-        ImmutableNode top = rootBuilder.value(rootValue.getValue()).create();
-        // TODO handle merge of root node
-        getModel().addNodes(null, top.getChildren(), this);
-
-        if (elemRefs)
-        {
-            // TODO set references in atomic operation
-            elemRefMap.put(getRootNode(), docHelper);
-            getSubConfigurationParentModel().addReferences(elemRefMap);
-        }
+        Map<String, String> attributes =
+                constructHierarchy(rootBuilder, rootValue,
+                        document.getDocumentElement(), elemRefMap, true, 0);
+        attributes.remove(ATTR_SPACE_INTERNAL);
+        ImmutableNode top =
+                rootBuilder.value(rootValue.getValue())
+                        .addAttributes(attributes).create();
+        getSubConfigurationParentModel().mergeRoot(top,
+                document.getDocumentElement().getTagName(), elemRefMap,
+                elemRefs ? docHelper : null, this);
     }
 
     /**

Modified: commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/TestXMLConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/TestXMLConfiguration.java?rev=1585194&r1=1585193&r2=1585194&view=diff
==============================================================================
--- commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/TestXMLConfiguration.java
(original)
+++ commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/TestXMLConfiguration.java
Sat Apr  5 19:50:39 2014
@@ -344,8 +344,8 @@ public class TestXMLConfiguration
         conf.setProperty("foo[@bar]", "value");
         assertEquals("foo[@bar]", "value", conf.getProperty("foo[@bar]"));
 
-        conf.setProperty("name1","value1");
-        assertEquals("value1",conf.getProperty("name1"));
+        conf.setProperty("name1", "value1");
+        assertEquals("value1", conf.getProperty("name1"));
     }
 
     /**
@@ -924,8 +924,8 @@ public class TestXMLConfiguration
 
         StringWriter out = new StringWriter();
         handler.save(out);
-        assertTrue("Encoding was not written to file", out.toString().indexOf(
-                "encoding=\"" + ENCODING + "\"") >= 0);
+        assertThat("Encoding was not written to file", out.toString(),
+                containsString("encoding=\"" + ENCODING + "\""));
     }
 
     /**
@@ -942,8 +942,8 @@ public class TestXMLConfiguration
 
         StringWriter out = new StringWriter();
         handler.save(out);
-        assertTrue("Encoding was written to file", out.toString().indexOf(
-                "encoding=\"UTF-") >= 0);
+        assertThat("Encoding was written to file", out.toString(),
+                containsString("encoding=\"UTF-"));
     }
 
     /**
@@ -959,7 +959,8 @@ public class TestXMLConfiguration
         assertEquals("Wrong system ID", SYSTEM_ID, conf.getSystemID());
         StringWriter out = new StringWriter();
         new FileHandler(conf).save(out);
-        assertTrue("Did not find DOCTYPE", out.toString().indexOf(DOCTYPE) >= 0);
+        assertThat("Did not find DOCTYPE", out.toString(),
+                containsString(DOCTYPE));
     }
 
     /**
@@ -1336,7 +1337,8 @@ public class TestXMLConfiguration
     public void testSaveAfterCreateWithCopyConstructor()
             throws ConfigurationException
     {
-        HierarchicalConfiguration hc = conf.configurationAt("element2");
+        HierarchicalConfiguration<ImmutableNode> hc =
+                conf.configurationAt("element2");
         conf = new XMLConfiguration(hc);
         saveTestConfig();
         XMLConfiguration checkConfig = checkSavedConfig();
@@ -1387,6 +1389,18 @@ public class TestXMLConfiguration
     }
 
     /**
+     * Tests the copy constructor for null input.
+     */
+    @Test
+    public void testCopyNull()
+    {
+        conf = new XMLConfiguration(null);
+        assertTrue("Not empty", conf.isEmpty());
+        assertEquals("Wrong root element name", "configuration",
+                conf.getRootElementName());
+    }
+
+    /**
      * Tests whether spaces are preserved when the xml:space attribute is set.
      */
     @Test
@@ -1522,8 +1536,8 @@ public class TestXMLConfiguration
         StringWriter writer = new StringWriter();
         new FileHandler(conf).save(writer);
         String content = writer.toString();
-        assertTrue("Path not found: " + content,
-                content.indexOf("<path>C:\\Temp</path>") >= 0);
+        assertThat("Path not found: ", content,
+                containsString("<path>C:\\Temp</path>"));
         saveTestConfig();
         XMLConfiguration conf2 = new XMLConfiguration();
         load(conf2, testSaveConf.getAbsolutePath());
@@ -1628,18 +1642,6 @@ public class TestXMLConfiguration
     }
 
     /**
-     * Tests whether access to the document is synchronized.
-     */
-    @Test
-    public void testGetDocumentSynchronized()
-    {
-        SynchronizerTestImpl sync = new SynchronizerTestImpl();
-        conf.setSynchronizer(sync);
-        assertNotNull("No document", conf.getDocument());
-        sync.verify(Methods.BEGIN_READ, Methods.END_READ);
-    }
-
-    /**
      * Removes the test output file if it exists.
      */
     private void removeTestFile()



Mime
View raw message