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/09/14 20:15:52 UTC
svn commit: r1384874 - 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/d...
Author: veithen
Date: Fri Sep 14 18:15:51 2012
New Revision: 1384874
URL: http://svn.apache.org/viewvc?rev=1384874&view=rev
Log:
AXIOM-432: Added more test cases and assertions for Node#replaceChild and fixed several issues.
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/ReplaceChildTestCase.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/element/TestReplaceChildFirstIncomplete.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/element/TestReplaceChildMiddleIncomplete.java
- copied, changed from r1384847, webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/element/TestReplaceChildIncomplete.java
Removed:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/element/TestReplaceChildIncomplete.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/TestReplaceChildFirst.java
webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildFirstWithDocumentFragment.java
webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildLast.java
webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildLastWithDocumentFragment.java
webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildMiddle.java
webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildMiddleWithDocumentFragment.java
webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildSingle.java
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ParentNode.java
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/OMDOMTestSuiteBuilder.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=1384874&r1=1384873&r2=1384874&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 Fri Sep 14 18:15:51 2012
@@ -126,15 +126,19 @@ public class DOMTestSuiteBuilder extends
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.TestReplaceChildCyclic(dbf));
- addTest(new org.apache.axiom.ts.dom.element.TestReplaceChildFirst(dbf));
+ addTest(new org.apache.axiom.ts.dom.element.TestReplaceChildFirst(dbf, false));
+ addTest(new org.apache.axiom.ts.dom.element.TestReplaceChildFirst(dbf, true));
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.TestReplaceChildLast(dbf, false));
+ addTest(new org.apache.axiom.ts.dom.element.TestReplaceChildLast(dbf, true));
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.TestReplaceChildMiddle(dbf, false));
+ addTest(new org.apache.axiom.ts.dom.element.TestReplaceChildMiddle(dbf, true));
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.TestReplaceChildSingle(dbf, false));
+ addTest(new org.apache.axiom.ts.dom.element.TestReplaceChildSingle(dbf, true));
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));
Added: webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/ReplaceChildTestCase.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/ReplaceChildTestCase.java?rev=1384874&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/ReplaceChildTestCase.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/ReplaceChildTestCase.java Fri Sep 14 18:15:51 2012
@@ -0,0 +1,50 @@
+/*
+ * 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;
+
+public abstract class ReplaceChildTestCase extends DOMTestCase {
+ private final boolean newChildHasSiblings;
+
+ public ReplaceChildTestCase(DocumentBuilderFactory dbf, boolean newChildHasSiblings) {
+ super(dbf);
+ this.newChildHasSiblings = newChildHasSiblings;
+ addTestProperty("newChildHasSiblings", String.valueOf(newChildHasSiblings));
+ }
+
+ protected final void runTest() throws Throwable {
+ Document doc = dbf.newDocumentBuilder().newDocument();
+ Element newChild = doc.createElementNS(null, "newChild");
+ if (newChildHasSiblings) {
+ Element parent = doc.createElementNS(null, "parent");
+ parent.appendChild(doc.createComment("previous sibling"));
+ parent.appendChild(newChild);
+ parent.appendChild(doc.createComment("next sibling"));
+ }
+ runTest(doc, newChild);
+ }
+
+ protected abstract void runTest(Document doc, Node newChild);
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/ReplaceChildTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
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=1384874&r1=1384873&r2=1384874&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 Fri Sep 14 18:15:51 2012
@@ -20,7 +20,6 @@ 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;
@@ -30,28 +29,26 @@ 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 first child (which uses a different code path in DOOM).
*/
-public class TestReplaceChildFirst extends DOMTestCase {
- public TestReplaceChildFirst(DocumentBuilderFactory dbf) {
- super(dbf);
+public class TestReplaceChildFirst extends ReplaceChildTestCase {
+ public TestReplaceChildFirst(DocumentBuilderFactory dbf, boolean newChildHasSiblings) {
+ super(dbf, newChildHasSiblings);
}
- protected void runTest() throws Throwable {
- Document doc = dbf.newDocumentBuilder().newDocument();
+ protected void runTest(Document doc, Node newChild) {
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, child1);
- assertSame(replacementChild, parent.getFirstChild());
+ parent.replaceChild(newChild, child1);
+ assertSame(newChild, parent.getFirstChild());
assertSame(child2, parent.getLastChild());
- assertNull(replacementChild.getPreviousSibling());
- assertSame(child2, replacementChild.getNextSibling());
- assertSame(replacementChild, child2.getPreviousSibling());
+ assertNull(newChild.getPreviousSibling());
+ assertSame(child2, newChild.getNextSibling());
+ assertSame(newChild, child2.getPreviousSibling());
NodeList children = parent.getChildNodes();
assertEquals(2, children.getLength());
- assertSame(replacementChild, children.item(0));
+ assertSame(newChild, children.item(0));
assertSame(child2, children.item(1));
}
}
Modified: 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=1384874&r1=1384873&r2=1384874&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildFirstWithDocumentFragment.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildFirstWithDocumentFragment.java Fri Sep 14 18:15:51 2012
@@ -66,5 +66,8 @@ public class TestReplaceChildFirstWithDo
assertNull(fragment.getFirstChild());
assertNull(fragment.getLastChild());
assertEquals(0, fragment.getChildNodes().getLength());
+
+ assertSame(x, element.getFirstChild());
+ assertSame(b, element.getLastChild());
}
}
Modified: 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=1384874&r1=1384873&r2=1384874&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildLast.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildLast.java Fri Sep 14 18:15:51 2012
@@ -20,7 +20,6 @@ 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;
@@ -30,28 +29,26 @@ 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);
+public class TestReplaceChildLast extends ReplaceChildTestCase {
+ public TestReplaceChildLast(DocumentBuilderFactory dbf, boolean newChildHasSiblings) {
+ super(dbf, newChildHasSiblings);
}
- protected void runTest() throws Throwable {
- Document doc = dbf.newDocumentBuilder().newDocument();
+ protected void runTest(Document doc, Node newChild) {
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);
+ parent.replaceChild(newChild, child2);
assertSame(child1, parent.getFirstChild());
- assertSame(replacementChild, parent.getLastChild());
- assertSame(child1, replacementChild.getPreviousSibling());
- assertNull(replacementChild.getNextSibling());
- assertSame(replacementChild, child1.getNextSibling());
+ assertSame(newChild, parent.getLastChild());
+ assertSame(child1, newChild.getPreviousSibling());
+ assertNull(newChild.getNextSibling());
+ assertSame(newChild, child1.getNextSibling());
NodeList children = parent.getChildNodes();
assertEquals(2, children.getLength());
assertSame(child1, children.item(0));
- assertSame(replacementChild, children.item(1));
+ assertSame(newChild, children.item(1));
}
}
Modified: 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=1384874&r1=1384873&r2=1384874&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildLastWithDocumentFragment.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildLastWithDocumentFragment.java Fri Sep 14 18:15:51 2012
@@ -66,5 +66,8 @@ public class TestReplaceChildLastWithDoc
assertNull(fragment.getFirstChild());
assertNull(fragment.getLastChild());
assertEquals(0, fragment.getChildNodes().getLength());
+
+ assertSame(a, element.getFirstChild());
+ assertSame(y, element.getLastChild());
}
}
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildMiddle.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?rev=1384874&r1=1384873&r2=1384874&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildMiddle.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildMiddle.java Fri Sep 14 18:15:51 2012
@@ -20,7 +20,6 @@ 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;
@@ -30,13 +29,12 @@ 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 neither the first nor the last child.
*/
-public class TestReplaceChildMiddle extends DOMTestCase {
- public TestReplaceChildMiddle(DocumentBuilderFactory dbf) {
- super(dbf);
+public class TestReplaceChildMiddle extends ReplaceChildTestCase {
+ public TestReplaceChildMiddle(DocumentBuilderFactory dbf, boolean newChildHasSiblings) {
+ super(dbf, newChildHasSiblings);
}
- protected void runTest() throws Throwable {
- Document doc = dbf.newDocumentBuilder().newDocument();
+ protected void runTest(Document doc, Node newChild) {
Element parent = doc.createElementNS(null, "parent");
Element child1 = doc.createElementNS(null, "child1");
Element child2 = doc.createElementNS(null, "child2");
@@ -44,12 +42,11 @@ public class TestReplaceChildMiddle exte
parent.appendChild(child1);
parent.appendChild(child2);
parent.appendChild(child3);
- Element replacementChild = doc.createElementNS(null, "replacement");
- parent.replaceChild(replacementChild, child2);
+ parent.replaceChild(newChild, child2);
NodeList children = parent.getChildNodes();
assertEquals(3, children.getLength());
assertSame(child1, children.item(0));
- assertSame(replacementChild, children.item(1));
+ assertSame(newChild, children.item(1));
assertSame(child3, children.item(2));
}
}
Modified: 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=1384874&r1=1384873&r2=1384874&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildMiddleWithDocumentFragment.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildMiddleWithDocumentFragment.java Fri Sep 14 18:15:51 2012
@@ -69,5 +69,8 @@ public class TestReplaceChildMiddleWithD
assertNull(fragment.getFirstChild());
assertNull(fragment.getLastChild());
assertEquals(0, fragment.getChildNodes().getLength());
+
+ assertSame(a, element.getFirstChild());
+ assertSame(c, element.getLastChild());
}
}
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildSingle.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/TestReplaceChildSingle.java?rev=1384874&r1=1384873&r2=1384874&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildSingle.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildSingle.java Fri Sep 14 18:15:51 2012
@@ -20,7 +20,6 @@ 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;
@@ -30,18 +29,18 @@ 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 only child.
*/
-public class TestReplaceChildSingle extends DOMTestCase {
- public TestReplaceChildSingle(DocumentBuilderFactory dbf) {
- super(dbf);
+public class TestReplaceChildSingle extends ReplaceChildTestCase {
+ public TestReplaceChildSingle(DocumentBuilderFactory dbf, boolean newChildHasSiblings) {
+ super(dbf, newChildHasSiblings);
}
- protected void runTest() throws Throwable {
- Document doc = dbf.newDocumentBuilder().newDocument();
+ protected void runTest(Document doc, Node newChild) {
Element parent = doc.createElementNS(null, "parent");
Element oldChild = doc.createElementNS(null, "oldChild");
parent.appendChild(oldChild);
- Element newChild = doc.createElementNS(null, "newChild");
parent.replaceChild(newChild, oldChild);
+ assertSame(newChild, parent.getFirstChild());
+ assertSame(newChild, parent.getLastChild());
NodeList children = parent.getChildNodes();
assertEquals(1, children.getLength());
assertSame(newChild, children.item(0));
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=1384874&r1=1384873&r2=1384874&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 Fri Sep 14 18:15:51 2012
@@ -376,7 +376,7 @@ public abstract class ParentNode extends
boolean found = false;
while (!found && children.hasNext()) {
NodeImpl tempNode = (NodeImpl) children.next();
- if (tempNode.equals(oldChild)) {
+ if (tempNode == oldChild) {
NodeImpl head; // The first child to insert
NodeImpl tail; // The last child to insert
@@ -401,37 +401,25 @@ public abstract class ParentNode extends
newDomChild.setParent(this, true);
}
- if (this.firstChild == oldDomChild) {
-
- if (this.firstChild.internalGetNextSibling() != null) {
- this.firstChild.internalGetNextSibling().internalSetPreviousSibling(tail);
- tail.internalSetNextSibling(this.firstChild.internalGetNextSibling());
- }
-
- //Cleanup the current first child
- this.firstChild.setParent(null, true);
- this.firstChild.internalSetNextSibling(null);
-
- //Set the new first child
+ // We use getNextSibling here to force bulding the node if necessary
+ NodeImpl nextSibling = (NodeImpl)oldDomChild.getNextSibling();
+ NodeImpl previousSibling = oldDomChild.internalGetPreviousSibling();
+
+ tail.internalSetNextSibling(nextSibling);
+ head.internalSetPreviousSibling(previousSibling);
+
+ if (previousSibling != null) {
+ previousSibling.internalSetNextSibling(head);
+ } else {
this.firstChild = head;
-
+ }
+ if (nextSibling != null) {
+ nextSibling.internalSetPreviousSibling(tail);
} 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;
- }
-
+ this.lastChild = tail;
}
-
+
found = true;
// remove the old child's references to this tree
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/OMDOMTestSuiteBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/OMDOMTestSuiteBuilder.java?rev=1384874&r1=1384873&r2=1384874&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/OMDOMTestSuiteBuilder.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/OMDOMTestSuiteBuilder.java Fri Sep 14 18:15:51 2012
@@ -50,7 +50,8 @@ public class OMDOMTestSuiteBuilder exten
addTest(new org.apache.axiom.ts.omdom.element.TestRemoveAttribute(metaFactory));
addTest(new org.apache.axiom.ts.omdom.element.TestRemoveAttributeNSNamespaceDeclaration(metaFactory));
addTest(new org.apache.axiom.ts.omdom.element.TestRemoveChildIncomplete(metaFactory));
- addTest(new org.apache.axiom.ts.omdom.element.TestReplaceChildIncomplete(metaFactory));
+ addTest(new org.apache.axiom.ts.omdom.element.TestReplaceChildFirstIncomplete(metaFactory));
+ addTest(new org.apache.axiom.ts.omdom.element.TestReplaceChildMiddleIncomplete(metaFactory));
addTest(new org.apache.axiom.ts.omdom.factory.TestCreateOMAttribute(metaFactory));
addTest(new org.apache.axiom.ts.omdom.factory.TestCreateOMTextCDATASection(metaFactory));
addTest(new org.apache.axiom.ts.omdom.factory.TestCreateOMTextCDATASectionWithParent(metaFactory));
Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/element/TestReplaceChildFirstIncomplete.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/element/TestReplaceChildFirstIncomplete.java?rev=1384874&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/element/TestReplaceChildFirstIncomplete.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/element/TestReplaceChildFirstIncomplete.java Fri Sep 14 18:15:51 2012
@@ -0,0 +1,72 @@
+/*
+ * 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.omdom.element;
+
+import java.io.StringReader;
+
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMXMLBuilderFactory;
+import org.apache.axiom.ts.AxiomTestCase;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * Tests the behavior of {@link Node#replaceChild(Node, Node)} on an element that has not been built
+ * completely. This test covers the case where the child being replaced is the first child.
+ */
+public class TestReplaceChildFirstIncomplete extends AxiomTestCase {
+ public TestReplaceChildFirstIncomplete(OMMetaFactory metaFactory) {
+ super(metaFactory);
+ }
+
+ protected void runTest() throws Throwable {
+ OMFactory factory = metaFactory.getOMFactory();
+ Element element = (Element)OMXMLBuilderFactory.createOMBuilder(factory,
+ new StringReader("<root><a/><b/><c/></root>")).getDocumentElement();
+ Element a = (Element)element.getFirstChild();
+ Element a2 = element.getOwnerDocument().createElementNS(null, "a2");
+ element.replaceChild(a2, a);
+ Element b = (Element)a2.getNextSibling();
+ assertNotNull(b);
+ Element c = (Element)b.getNextSibling();
+ assertNotNull(c);
+ // Check the other sibling relations
+ assertNull(a2.getPreviousSibling());
+ assertSame(a2, b.getPreviousSibling());
+ assertSame(b, c.getPreviousSibling());
+ assertNull(c.getNextSibling());
+ // Check parent-child relations
+ assertSame(a2, element.getFirstChild());
+ assertSame(c, element.getLastChild());
+ assertSame(element, a2.getParentNode());
+ assertSame(element, b.getParentNode());
+ assertSame(element, c.getParentNode());
+ NodeList children = element.getChildNodes();
+ assertEquals(3, children.getLength());
+ assertSame(a2, children.item(0));
+ assertSame(b, children.item(1));
+ assertSame(c, children.item(2));
+ // Check that a has been detached properly
+ assertNull(a.getPreviousSibling());
+ assertNull(a.getNextSibling());
+ assertNull(a.getParentNode());
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/element/TestReplaceChildFirstIncomplete.java
------------------------------------------------------------------------------
svn:eol-style = native
Copied: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/element/TestReplaceChildMiddleIncomplete.java (from r1384847, webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/element/TestReplaceChildIncomplete.java)
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/element/TestReplaceChildMiddleIncomplete.java?p2=webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/element/TestReplaceChildMiddleIncomplete.java&p1=webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/element/TestReplaceChildIncomplete.java&r1=1384847&r2=1384874&rev=1384874&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/element/TestReplaceChildIncomplete.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/element/TestReplaceChildMiddleIncomplete.java Fri Sep 14 18:15:51 2012
@@ -30,11 +30,12 @@ import org.w3c.dom.NodeList;
/**
* Tests the behavior of {@link Node#replaceChild(Node, Node)} on an element that has not been built
- * completely. This is a regression test for <a
+ * completely. This test covers the case where the child being replaced is neither the first nor the
+ * last child. This is a regression test for <a
* href="https://issues.apache.org/jira/browse/AXIOM-432">AXIOM-432</a>.
*/
-public class TestReplaceChildIncomplete extends AxiomTestCase {
- public TestReplaceChildIncomplete(OMMetaFactory metaFactory) {
+public class TestReplaceChildMiddleIncomplete extends AxiomTestCase {
+ public TestReplaceChildMiddleIncomplete(OMMetaFactory metaFactory) {
super(metaFactory);
}
@@ -58,6 +59,8 @@ public class TestReplaceChildIncomplete
assertSame(b2, c.getPreviousSibling());
assertNull(c.getNextSibling());
// Check parent-child relations
+ assertSame(a, element.getFirstChild());
+ assertSame(c, element.getLastChild());
assertSame(element, a.getParentNode());
assertSame(element, b2.getParentNode());
assertSame(element, c.getParentNode());