You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2012/07/17 19:37:13 UTC
svn commit: r1362582 - in /webservices/commons/trunk/modules/axiom/modules:
axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/
axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/
axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/
Author: veithen
Date: Tue Jul 17 17:37:13 2012
New Revision: 1362582
URL: http://svn.apache.org/viewvc?rev=1362582&view=rev
Log:
AXIOM-432: Further increased the test coverage of ParentNode#replaceChild and fixed a couple of issues that occur when newChild is a document fragment.
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildCyclic.java
- copied, changed from r1362402, webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildWithAncestor.java
webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildFirstWithDocumentFragment.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildLast.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildLastWithDocumentFragment.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildMiddle.java
- copied, changed from r1362402, webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChild.java
webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildMiddleWithDocumentFragment.java (with props)
Removed:
webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChild.java
webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildWithAncestor.java
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/DOMTestSuiteBuilder.java
webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestInsertBeforeWithDocumentFragment.java
webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildFirst.java
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ParentNode.java
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/DOMTestSuiteBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/DOMTestSuiteBuilder.java?rev=1362582&r1=1362581&r2=1362582&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/DOMTestSuiteBuilder.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/DOMTestSuiteBuilder.java Tue Jul 17 17:37:13 2012
@@ -93,12 +93,16 @@ public class DOMTestSuiteBuilder extends
addTest(new org.apache.axiom.ts.dom.element.TestRemoveFirstChild(dbf));
addTest(new org.apache.axiom.ts.dom.element.TestRemoveLastChild(dbf));
addTest(new org.apache.axiom.ts.dom.element.TestRemoveSingleChild(dbf));
- addTest(new org.apache.axiom.ts.dom.element.TestReplaceChild(dbf));
+ addTest(new org.apache.axiom.ts.dom.element.TestReplaceChildCyclic(dbf));
addTest(new org.apache.axiom.ts.dom.element.TestReplaceChildFirst(dbf));
+ addTest(new org.apache.axiom.ts.dom.element.TestReplaceChildFirstWithDocumentFragment(dbf));
+ addTest(new org.apache.axiom.ts.dom.element.TestReplaceChildLast(dbf));
+ addTest(new org.apache.axiom.ts.dom.element.TestReplaceChildLastWithDocumentFragment(dbf));
+ addTest(new org.apache.axiom.ts.dom.element.TestReplaceChildMiddle(dbf));
+ addTest(new org.apache.axiom.ts.dom.element.TestReplaceChildMiddleWithDocumentFragment(dbf));
addTest(new org.apache.axiom.ts.dom.element.TestReplaceChildNotFound(dbf));
addTest(new org.apache.axiom.ts.dom.element.TestReplaceChildNullNewChild(dbf));
addTest(new org.apache.axiom.ts.dom.element.TestReplaceChildSingle(dbf));
- addTest(new org.apache.axiom.ts.dom.element.TestReplaceChildWithAncestor(dbf));
addTest(new org.apache.axiom.ts.dom.element.TestReplaceChildWrongDocument(dbf));
addTest(new org.apache.axiom.ts.dom.element.TestSetAttributeNodeNSInUse(dbf));
addTest(new org.apache.axiom.ts.dom.element.TestSetAttributeNodeNSReplace(dbf));
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestInsertBeforeWithDocumentFragment.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestInsertBeforeWithDocumentFragment.java?rev=1362582&r1=1362581&r2=1362582&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestInsertBeforeWithDocumentFragment.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestInsertBeforeWithDocumentFragment.java Tue Jul 17 17:37:13 2012
@@ -59,5 +59,7 @@ public class TestInsertBeforeWithDocumen
assertSame(element, y.getParentNode());
assertNull(fragment.getFirstChild());
+ assertNull(fragment.getLastChild());
+ assertEquals(0, fragment.getChildNodes().getLength());
}
}
Copied: webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildCyclic.java (from r1362402, webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildWithAncestor.java)
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildCyclic.java?p2=webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildCyclic.java&p1=webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildWithAncestor.java&r1=1362402&r2=1362582&rev=1362582&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildWithAncestor.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildCyclic.java Tue Jul 17 17:37:13 2012
@@ -30,8 +30,8 @@ import org.w3c.dom.Node;
* Tests the behavior of {@link Node#replaceChild(Node, Node)} if an attempt is made to replace a
* child with an ancestor of the node, i.e. if the replacement would create a cycle.
*/
-public class TestReplaceChildWithAncestor extends DOMTestCase {
- public TestReplaceChildWithAncestor(DocumentBuilderFactory dbf) {
+public class TestReplaceChildCyclic extends DOMTestCase {
+ public TestReplaceChildCyclic(DocumentBuilderFactory dbf) {
super(dbf);
}
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildFirst.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildFirst.java?rev=1362582&r1=1362581&r2=1362582&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildFirst.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildFirst.java Tue Jul 17 17:37:13 2012
@@ -44,6 +44,11 @@ public class TestReplaceChildFirst exten
parent.appendChild(child2);
Element replacementChild = doc.createElementNS(null, "replacement");
parent.replaceChild(replacementChild, child1);
+ assertSame(replacementChild, parent.getFirstChild());
+ assertSame(child2, parent.getLastChild());
+ assertNull(replacementChild.getPreviousSibling());
+ assertSame(child2, replacementChild.getNextSibling());
+ assertSame(replacementChild, child2.getPreviousSibling());
NodeList children = parent.getChildNodes();
assertEquals(2, children.getLength());
assertSame(replacementChild, children.item(0));
Added: webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildFirstWithDocumentFragment.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildFirstWithDocumentFragment.java?rev=1362582&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildFirstWithDocumentFragment.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildFirstWithDocumentFragment.java Tue Jul 17 17:37:13 2012
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axiom.ts.dom.element;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.apache.axiom.ts.dom.DOMTestCase;
+import org.w3c.dom.Document;
+import org.w3c.dom.DocumentFragment;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * Tests the behavior of {@link Node#replaceChild(Node, Node)} when replacing a child by a
+ * {@link DocumentFragment}. This test covers the case where the child being replaced is the first
+ * child (which uses a different code path in DOOM).
+ */
+public class TestReplaceChildFirstWithDocumentFragment extends DOMTestCase {
+ public TestReplaceChildFirstWithDocumentFragment(DocumentBuilderFactory dbf) {
+ super(dbf);
+ }
+
+ protected void runTest() throws Throwable {
+ Document document = dbf.newDocumentBuilder().newDocument();
+
+ DocumentFragment fragment = document.createDocumentFragment();
+ Element x = document.createElementNS(null, "x");
+ Element y = document.createElementNS(null, "y");
+ fragment.appendChild(x);
+ fragment.appendChild(y);
+
+ Element element = document.createElementNS(null, "parent");
+ Element a = document.createElementNS(null, "a");
+ Element b = document.createElementNS(null, "b");
+ element.appendChild(a);
+ element.appendChild(b);
+
+ element.replaceChild(fragment, a);
+
+ NodeList children = element.getChildNodes();
+ assertEquals(3, children.getLength());
+ assertSame(x, children.item(0));
+ assertSame(y, children.item(1));
+ assertSame(b, children.item(2));
+
+ assertSame(element, x.getParentNode());
+ assertSame(element, y.getParentNode());
+
+ assertNull(fragment.getFirstChild());
+ assertNull(fragment.getLastChild());
+ assertEquals(0, fragment.getChildNodes().getLength());
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildFirstWithDocumentFragment.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildLast.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildLast.java?rev=1362582&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildLast.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildLast.java Tue Jul 17 17:37:13 2012
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axiom.ts.dom.element;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.apache.axiom.ts.dom.DOMTestCase;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * Tests the behavior of {@link Node#replaceChild(Node, Node)}. This test covers the case where the
+ * child being replaced is the last child (which uses a different code path in DOOM).
+ */
+public class TestReplaceChildLast extends DOMTestCase {
+ public TestReplaceChildLast(DocumentBuilderFactory dbf) {
+ super(dbf);
+ }
+
+ protected void runTest() throws Throwable {
+ Document doc = dbf.newDocumentBuilder().newDocument();
+ Element parent = doc.createElementNS(null, "parent");
+ Element child1 = doc.createElementNS(null, "child1");
+ Element child2 = doc.createElementNS(null, "child2");
+ parent.appendChild(child1);
+ parent.appendChild(child2);
+ Element replacementChild = doc.createElementNS(null, "replacement");
+ parent.replaceChild(replacementChild, child2);
+ assertSame(child1, parent.getFirstChild());
+ assertSame(replacementChild, parent.getLastChild());
+ assertSame(child1, replacementChild.getPreviousSibling());
+ assertNull(replacementChild.getNextSibling());
+ assertSame(replacementChild, child1.getNextSibling());
+ NodeList children = parent.getChildNodes();
+ assertEquals(2, children.getLength());
+ assertSame(child1, children.item(0));
+ assertSame(replacementChild, children.item(1));
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildLast.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildLastWithDocumentFragment.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildLastWithDocumentFragment.java?rev=1362582&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildLastWithDocumentFragment.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildLastWithDocumentFragment.java Tue Jul 17 17:37:13 2012
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axiom.ts.dom.element;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.apache.axiom.ts.dom.DOMTestCase;
+import org.w3c.dom.Document;
+import org.w3c.dom.DocumentFragment;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * Tests the behavior of {@link Node#replaceChild(Node, Node)} when replacing a child by a
+ * {@link DocumentFragment}. This test covers the case where the child being replaced is the first
+ * child (which uses a different code path in DOOM).
+ */
+public class TestReplaceChildLastWithDocumentFragment extends DOMTestCase {
+ public TestReplaceChildLastWithDocumentFragment(DocumentBuilderFactory dbf) {
+ super(dbf);
+ }
+
+ protected void runTest() throws Throwable {
+ Document document = dbf.newDocumentBuilder().newDocument();
+
+ DocumentFragment fragment = document.createDocumentFragment();
+ Element x = document.createElementNS(null, "x");
+ Element y = document.createElementNS(null, "y");
+ fragment.appendChild(x);
+ fragment.appendChild(y);
+
+ Element element = document.createElementNS(null, "parent");
+ Element a = document.createElementNS(null, "a");
+ Element b = document.createElementNS(null, "b");
+ element.appendChild(a);
+ element.appendChild(b);
+
+ element.replaceChild(fragment, b);
+
+ NodeList children = element.getChildNodes();
+ assertEquals(3, children.getLength());
+ assertSame(a, children.item(0));
+ assertSame(x, children.item(1));
+ assertSame(y, children.item(2));
+
+ assertSame(element, x.getParentNode());
+ assertSame(element, y.getParentNode());
+
+ assertNull(fragment.getFirstChild());
+ assertNull(fragment.getLastChild());
+ assertEquals(0, fragment.getChildNodes().getLength());
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildLastWithDocumentFragment.java
------------------------------------------------------------------------------
svn:eol-style = native
Copied: webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildMiddle.java (from r1362402, webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChild.java)
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildMiddle.java?p2=webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildMiddle.java&p1=webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChild.java&r1=1362402&r2=1362582&rev=1362582&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChild.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildMiddle.java Tue Jul 17 17:37:13 2012
@@ -28,10 +28,10 @@ import org.w3c.dom.NodeList;
/**
* Tests the behavior of {@link Node#replaceChild(Node, Node)}. This test covers the case where the
- * child being replaced is not the first child.
+ * child being replaced is neither the first nor the last child.
*/
-public class TestReplaceChild extends DOMTestCase {
- public TestReplaceChild(DocumentBuilderFactory dbf) {
+public class TestReplaceChildMiddle extends DOMTestCase {
+ public TestReplaceChildMiddle(DocumentBuilderFactory dbf) {
super(dbf);
}
Added: webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildMiddleWithDocumentFragment.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildMiddleWithDocumentFragment.java?rev=1362582&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildMiddleWithDocumentFragment.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildMiddleWithDocumentFragment.java Tue Jul 17 17:37:13 2012
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axiom.ts.dom.element;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.apache.axiom.ts.dom.DOMTestCase;
+import org.w3c.dom.Document;
+import org.w3c.dom.DocumentFragment;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * Tests the behavior of {@link Node#replaceChild(Node, Node)} when replacing a child by a
+ * {@link DocumentFragment}. This test covers the case where the child being replaced is neither the
+ * first nor the last child.
+ */
+public class TestReplaceChildMiddleWithDocumentFragment extends DOMTestCase {
+ public TestReplaceChildMiddleWithDocumentFragment(DocumentBuilderFactory dbf) {
+ super(dbf);
+ }
+
+ protected void runTest() throws Throwable {
+ Document document = dbf.newDocumentBuilder().newDocument();
+
+ DocumentFragment fragment = document.createDocumentFragment();
+ Element x = document.createElementNS(null, "x");
+ Element y = document.createElementNS(null, "y");
+ fragment.appendChild(x);
+ fragment.appendChild(y);
+
+ Element element = document.createElementNS(null, "parent");
+ Element a = document.createElementNS(null, "a");
+ Element b = document.createElementNS(null, "b");
+ Element c = document.createElementNS(null, "c");
+ element.appendChild(a);
+ element.appendChild(b);
+ element.appendChild(c);
+
+ element.replaceChild(fragment, b);
+
+ NodeList children = element.getChildNodes();
+ assertEquals(4, children.getLength());
+ assertSame(a, children.item(0));
+ assertSame(x, children.item(1));
+ assertSame(y, children.item(2));
+ assertSame(c, children.item(3));
+
+ assertSame(element, x.getParentNode());
+ assertSame(element, y.getParentNode());
+
+ assertNull(fragment.getFirstChild());
+ assertNull(fragment.getLastChild());
+ assertEquals(0, fragment.getChildNodes().getLength());
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildMiddleWithDocumentFragment.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ParentNode.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ParentNode.java?rev=1362582&r1=1362581&r2=1362582&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ParentNode.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ParentNode.java Tue Jul 17 17:37:13 2012
@@ -392,54 +392,61 @@ public abstract class ParentNode extends
while (!found && children.hasNext()) {
NodeImpl tempNode = (NodeImpl) children.next();
if (tempNode.equals(oldChild)) {
+ NodeImpl head; // The first child to insert
+ NodeImpl tail; // The last child to insert
+
if (newChild instanceof DocumentFragmentImpl) {
DocumentFragmentImpl docFrag =
(DocumentFragmentImpl) newDomChild;
- NodeImpl child = (NodeImpl) docFrag.getFirstChild();
- this.replaceChild(child, oldChild);
+ head = (NodeImpl)docFrag.getFirstChild();
+ tail = (NodeImpl)docFrag.getLastChild();
+ NodeImpl child = (NodeImpl) docFrag.getFirstChild();
//set the parent of all kids to me
while(child != null) {
child.setParent(this, true);
child = child.internalGetNextSibling();
}
- this.lastChild = (NodeImpl)docFrag.getLastChild();
-
+ docFrag.setFirstChild(null);
+ docFrag.setLastChild(null);
} else {
- if (this.firstChild == oldDomChild) {
+ head = newDomChild;
+ tail = newDomChild;
+ newDomChild.setParent(this, true);
+ }
+
+ if (this.firstChild == oldDomChild) {
- if (this.firstChild.internalGetNextSibling() != null) {
- this.firstChild.internalGetNextSibling().internalSetPreviousSibling(newDomChild);
- newDomChild.internalSetNextSibling(this.firstChild.internalGetNextSibling());
- }
-
- //Cleanup the current first child
- this.firstChild.setParent(null, true);
- this.firstChild.internalSetNextSibling(null);
-
- //Set the new first child
- this.firstChild = newDomChild;
-
+ if (this.firstChild.internalGetNextSibling() != null) {
+ this.firstChild.internalGetNextSibling().internalSetPreviousSibling(tail);
+ tail.internalSetNextSibling(this.firstChild.internalGetNextSibling());
+ }
- } else {
- // We use getNextSibling here to force bulding the node if necessary
- newDomChild.internalSetNextSibling((NodeImpl)oldDomChild.getNextSibling());
- newDomChild.internalSetPreviousSibling(oldDomChild.internalGetPreviousSibling());
-
- oldDomChild.internalGetPreviousSibling().internalSetNextSibling(newDomChild);
-
- // If the old child is not the last
- if (oldDomChild.internalGetNextSibling() != null) {
- oldDomChild.internalGetNextSibling().internalSetPreviousSibling(newDomChild);
- } else {
- this.lastChild = newDomChild;
- }
+ //Cleanup the current first child
+ this.firstChild.setParent(null, true);
+ this.firstChild.internalSetNextSibling(null);
+ //Set the new first child
+ this.firstChild = head;
+
+
+ } else {
+ // We use getNextSibling here to force bulding the node if necessary
+ tail.internalSetNextSibling((NodeImpl)oldDomChild.getNextSibling());
+ head.internalSetPreviousSibling(oldDomChild.internalGetPreviousSibling());
+
+ oldDomChild.internalGetPreviousSibling().internalSetNextSibling(head);
+
+ // If the old child is not the last
+ if (oldDomChild.internalGetNextSibling() != null) {
+ oldDomChild.internalGetNextSibling().internalSetPreviousSibling(tail);
+ } else {
+ this.lastChild = newDomChild;
}
- newDomChild.setParent(this, true);
}
+
found = true;
// remove the old child's references to this tree