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 10:17:49 UTC
svn commit: r1362402 - 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 08:17:48 2012
New Revision: 1362402
URL: http://svn.apache.org/viewvc?rev=1362402&view=rev
Log:
AXIOM-432: Increased test coverage of ParentNode#replaceChild.
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildFirst.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildNotFound.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildNullNewChild.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildSingle.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildWithAncestor.java (with props)
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/TestReplaceChild.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=1362402&r1=1362401&r2=1362402&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 08:17:48 2012
@@ -94,6 +94,11 @@ 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.TestReplaceChild(dbf));
+ addTest(new org.apache.axiom.ts.dom.element.TestReplaceChildFirst(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/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/TestReplaceChild.java?rev=1362402&r1=1362401&r2=1362402&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/TestReplaceChild.java Tue Jul 17 08:17:48 2012
@@ -23,8 +23,13 @@ import javax.xml.parsers.DocumentBuilder
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 not the first child.
+ */
public class TestReplaceChild extends DOMTestCase {
public TestReplaceChild(DocumentBuilderFactory dbf) {
super(dbf);
Added: 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=1362402&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildFirst.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildFirst.java Tue Jul 17 08:17:48 2012
@@ -0,0 +1,52 @@
+/*
+ * 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 first child (which uses a different code path in DOOM).
+ */
+public class TestReplaceChildFirst extends DOMTestCase {
+ public TestReplaceChildFirst(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, child1);
+ NodeList children = parent.getChildNodes();
+ assertEquals(2, children.getLength());
+ assertSame(replacementChild, children.item(0));
+ assertSame(child2, children.item(1));
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildFirst.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildNotFound.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/TestReplaceChildNotFound.java?rev=1362402&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildNotFound.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildNotFound.java Tue Jul 17 08:17:48 2012
@@ -0,0 +1,52 @@
+/*
+ * 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.DOMException;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.Text;
+
+/**
+ * Tests the behavior of {@link Node#replaceChild(Node, Node)} if <code>oldChild</code> is not a
+ * child.
+ */
+public class TestReplaceChildNotFound extends DOMTestCase {
+ public TestReplaceChildNotFound(DocumentBuilderFactory dbf) {
+ super(dbf);
+ }
+
+ protected void runTest() throws Throwable {
+ Document document = dbf.newDocumentBuilder().newDocument();
+ Element root = document.createElementNS(null, "root");
+ root.appendChild(document.createElementNS(null, "child"));
+ Text node1 = document.createTextNode("test1");
+ Text node2 = document.createTextNode("test2");
+ try {
+ root.replaceChild(node2, node1);
+ fail("Expected DOMException");
+ } catch (DOMException ex) {
+ assertEquals(DOMException.NOT_FOUND_ERR, ex.code);
+ }
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildNotFound.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildNullNewChild.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/TestReplaceChildNullNewChild.java?rev=1362402&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildNullNewChild.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildNullNewChild.java Tue Jul 17 08:17:48 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;
+
+/**
+ * Tests the behavior of {@link Node#replaceChild(Node, Node)} if <code>newChild</code> is
+ * <code>null</code>. In this case an exception should be thrown. Note that the DOM doesn't specify
+ * the exception to throw; Xerces throws a {@link NullPointerException}.
+ */
+public class TestReplaceChildNullNewChild extends DOMTestCase {
+ public TestReplaceChildNullNewChild(DocumentBuilderFactory dbf) {
+ super(dbf);
+ }
+
+ protected void runTest() throws Throwable {
+ Document document = dbf.newDocumentBuilder().newDocument();
+ Element root = document.createElementNS(null, "root");
+ Element child = document.createElementNS(null, "child");
+ root.appendChild(child);
+ try {
+ root.replaceChild(null, child);
+ fail("Expected exception");
+ } catch (Exception ex) {
+ // Expected
+ }
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildNullNewChild.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: 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=1362402&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildSingle.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildSingle.java Tue Jul 17 08:17:48 2012
@@ -0,0 +1,49 @@
+/*
+ * 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 only child.
+ */
+public class TestReplaceChildSingle extends DOMTestCase {
+ public TestReplaceChildSingle(DocumentBuilderFactory dbf) {
+ super(dbf);
+ }
+
+ protected void runTest() throws Throwable {
+ Document doc = dbf.newDocumentBuilder().newDocument();
+ 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);
+ NodeList children = parent.getChildNodes();
+ assertEquals(1, children.getLength());
+ assertSame(newChild, children.item(0));
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildSingle.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: 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/TestReplaceChildWithAncestor.java?rev=1362402&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildWithAncestor.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildWithAncestor.java Tue Jul 17 08:17:48 2012
@@ -0,0 +1,52 @@
+/*
+ * 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.DOMException;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+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) {
+ super(dbf);
+ }
+
+ protected void runTest() throws Throwable {
+ Document document = dbf.newDocumentBuilder().newDocument();
+ Element ancestor = document.createElementNS(null, "ancestor");
+ Element element = document.createElementNS(null, "element");
+ ancestor.appendChild(element);
+ Element child = document.createElementNS(null, "child");
+ element.appendChild(child);
+ try {
+ element.replaceChild(ancestor, child);
+ fail("Expected DOMException");
+ } catch (DOMException ex) {
+ assertEquals(DOMException.HIERARCHY_REQUEST_ERR, ex.code);
+ }
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildWithAncestor.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=1362402&r1=1362401&r2=1362402&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 08:17:48 2012
@@ -375,7 +375,7 @@ public abstract class ParentNode extends
NodeImpl oldDomChild = (NodeImpl) oldChild;
if (newChild == null) {
- return this.removeChild(oldChild);
+ throw new IllegalArgumentException("newChild can't be null");
}
if (isAncestorOrSelf(newChild)) {