Author: veithen
Date: Sun Dec 14 13:32:13 2008
New Revision: 726537
URL: http://svn.apache.org/viewvc?rev=726537&view=rev
Log:
Improved the DOM related tests so that test cases that only refer to the JAXP
and DOM APIs are executed twice: once against a standard DOM implementation
(Xerces) and once against DOOM. This allows us to cross-check the validity of
these tests, i.e. to check whether we are testing the right thing.
Corrected two test cases that failed with the standard DOM implementation, i.e.
where we were testing the wrong thing:
1) ElementImplTest#testGetElementsbyTagNameNS: The test incorrectly assumed
that the second argument to getElementsByTagNameNS is a qualified name (it is
the local name).
2) TextImplTest#testSplitText: The test didn't take into account that the new
node (with the remaining text) is inserted as the next sibling only if the
original node had a parent (which was not the case).
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/dom/DOMTestUtil.java
(with props)
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/dom/DocumentImplTest.java
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/dom/ElementImplTest.java
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/dom/TextImplTest.java
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/dom/DOMTestUtil.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/dom/DOMTestUtil.java?rev=726537&view=auto
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/dom/DOMTestUtil.java
(added)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/dom/DOMTestUtil.java
Sun Dec 14 13:32:13 2008
@@ -0,0 +1,51 @@
+/*
+ * 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.om.impl.dom;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import junit.framework.Assert;
+
+import org.apache.axiom.om.impl.dom.jaxp.DOOMDocumentBuilderFactory;
+import org.apache.xerces.jaxp.DocumentBuilderFactoryImpl;
+
+/**
+ * Utility to execute DOM tests.
+ * It executes test cases twice: once against a standard DOM implementation
+ * (Xerces) and once against DOOM. This allows us to cross-check the validity
+ * of these tests, i.e. to check whether we are testing the right thing.
+ */
+public class DOMTestUtil {
+ public interface Test {
+ void execute(DocumentBuilderFactory dbf) throws Exception;
+ }
+
+ private DOMTestUtil() {}
+
+ public static void execute(Test test) throws Exception {
+ try {
+ test.execute(new DocumentBuilderFactoryImpl());
+ } catch (Throwable ex) {
+ Assert.fail("Invalid test case; execution failed with standard DOM
implementation: "
+ + ex.getMessage());
+ }
+ test.execute(new DOOMDocumentBuilderFactory());
+ }
+}
Propchange:
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/dom/DOMTestUtil.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/dom/DocumentImplTest.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/dom/DocumentImplTest.java?rev=726537&r1=726536&r2=726537&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/dom/DocumentImplTest.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/dom/DocumentImplTest.java
Sun Dec 14 13:32:13 2008
@@ -19,9 +19,9 @@
package org.apache.axiom.om.impl.dom;
+import javax.xml.parsers.DocumentBuilderFactory;
+
import junit.framework.TestCase;
-import org.apache.axiom.om.impl.dom.factory.OMDOMFactory;
-import org.apache.axiom.om.impl.dom.jaxp.DOOMDocumentBuilderFactory;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -29,66 +29,76 @@
import org.w3c.dom.Text;
public class DocumentImplTest extends TestCase {
- public void testCreateElement() {
- String tagName = "LocalName";
- String namespace = "http://ws.apache.org/axis2/ns";
- OMDOMFactory fac = new OMDOMFactory();
- DocumentImpl doc = new DocumentImpl(fac);
- Element elem = doc.createElement(tagName);
-
- assertEquals("Local name misnatch", tagName, elem.getNodeName());
-
- elem = doc.createElementNS(namespace, "axis2:" + tagName);
- assertEquals("Local name misnatch", tagName, elem.getLocalName());
- assertEquals("Namespace misnatch", namespace, elem.getNamespaceURI());
-
+ public void testCreateElement() throws Exception {
+ DOMTestUtil.execute(new DOMTestUtil.Test() {
+ public void execute(DocumentBuilderFactory dbf) throws Exception {
+ String tagName = "LocalName";
+ String namespace = "http://ws.apache.org/axis2/ns";
+ Document doc = dbf.newDocumentBuilder().newDocument();
+ Element elem = doc.createElement(tagName);
+
+ assertEquals("Local name misnatch", tagName,
elem.getNodeName());
+
+ elem = doc.createElementNS(namespace, "axis2:" + tagName);
+ assertEquals("Local name misnatch", tagName,
elem.getLocalName());
+ assertEquals("Namespace misnatch", namespace,
elem.getNamespaceURI());
+ }
+ });
}
- public void testCreateAttribute() {
- String attrName = "attrIdentifier";
- String attrValue = "attrValue";
- String attrNs = "http://ws.apache.org/axis2/ns";
- String attrNsPrefix = "axis2";
-
- OMDOMFactory fac = new OMDOMFactory();
- DocumentImpl doc = new DocumentImpl(fac);
- Attr attr = doc.createAttribute(attrName);
-
- assertEquals("Attr name mismatch", attrName, attr.getName());
- assertNull("Namespace value should be null", attr.getNamespaceURI());
-
-
- attr = doc.createAttributeNS(attrNs, attrNsPrefix + ":" + attrName);
- assertEquals("Attr name mismatch", attrName, attr.getLocalName());
- assertNotNull("Namespace value should not be null",
attr.getNamespaceURI());
- assertEquals("NamsspaceURI mismatch", attrNs, attr.getNamespaceURI());
- assertEquals("namespace prefix mismatch", attrNsPrefix,
attr.getPrefix());
-
- attr.setValue(attrValue);
-
+ public void testCreateAttribute() throws Exception {
+ DOMTestUtil.execute(new DOMTestUtil.Test() {
+ public void execute(DocumentBuilderFactory dbf) throws Exception {
+ String attrName = "attrIdentifier";
+ String attrValue = "attrValue";
+ String attrNs = "http://ws.apache.org/axis2/ns";
+ String attrNsPrefix = "axis2";
+
+ Document doc = dbf.newDocumentBuilder().newDocument();
+ Attr attr = doc.createAttribute(attrName);
+
+ assertEquals("Attr name mismatch", attrName, attr.getName());
+ assertNull("Namespace value should be null",
attr.getNamespaceURI());
+
+
+ attr = doc.createAttributeNS(attrNs, attrNsPrefix + ":" +
attrName);
+ assertEquals("Attr name mismatch", attrName,
attr.getLocalName());
+ assertNotNull("Namespace value should not be null",
attr.getNamespaceURI());
+ assertEquals("NamsspaceURI mismatch", attrNs,
attr.getNamespaceURI());
+ assertEquals("namespace prefix mismatch", attrNsPrefix,
attr.getPrefix());
+
+ attr.setValue(attrValue);
+ }
+ });
}
- public void testCreateText() {
- String textValue = "temp text value";
-
- OMDOMFactory fac = new OMDOMFactory();
- DocumentImpl doc = new DocumentImpl(fac);
- Text txt = doc.createTextNode(textValue);
-
- assertEquals("Text value mismatch", textValue, txt.getData());
+ public void testCreateText() throws Exception {
+ DOMTestUtil.execute(new DOMTestUtil.Test() {
+ public void execute(DocumentBuilderFactory dbf) throws Exception {
+ String textValue = "temp text value";
+
+ Document doc = dbf.newDocumentBuilder().newDocument();
+ Text txt = doc.createTextNode(textValue);
+
+ assertEquals("Text value mismatch", textValue, txt.getData());
+ }
+ });
}
public void testDocumentSiblings() throws Exception {
- Document doc = new
DOOMDocumentBuilderFactory().newDocumentBuilder().newDocument();
- Element elem = doc.createElement("test");
- doc.appendChild(elem);
-
- Node node = doc.getNextSibling();
- assertNull("Document's next sibling has to be null", node);
- Node node2 = doc.getPreviousSibling();
- assertNull("Document's previous sibling has to be null", node2);
- Node node3 = doc.getParentNode();
- assertNull("Document's parent has to be null", node3);
+ DOMTestUtil.execute(new DOMTestUtil.Test() {
+ public void execute(DocumentBuilderFactory dbf) throws Exception {
+ Document doc = dbf.newDocumentBuilder().newDocument();
+ Element elem = doc.createElement("test");
+ doc.appendChild(elem);
+
+ Node node = doc.getNextSibling();
+ assertNull("Document's next sibling has to be null", node);
+ Node node2 = doc.getPreviousSibling();
+ assertNull("Document's previous sibling has to be null",
node2);
+ Node node3 = doc.getParentNode();
+ assertNull("Document's parent has to be null", node3);
+ }
+ });
}
-
}
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/dom/ElementImplTest.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/dom/ElementImplTest.java?rev=726537&r1=726536&r2=726537&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/dom/ElementImplTest.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/dom/ElementImplTest.java
Sun Dec 14 13:32:13 2008
@@ -30,6 +30,8 @@
import org.w3c.dom.Text;
import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilderFactory;
+
import java.io.ByteArrayOutputStream;
import java.util.Iterator;
@@ -94,72 +96,85 @@
}
public void testAppendChild() throws Exception {
- String elementName = "TestElem";
- String childElemName = "TestChildElem";
- String childTextValue = "text value of the child text node";
-
- //Apending am Element node
- Document doc = new
DOOMDocumentBuilderFactory().newDocumentBuilder().newDocument();
- Element elem = doc.createElement(elementName);
- Element childElem = doc.createElement(childElemName);
-
- elem.appendChild(childElem);
-
- Element addedChild = (Element) elem.getFirstChild();
- assertNotNull("Child Element node missing", addedChild);
- assertEquals("Incorre node object", childElem, addedChild);
-
- elem = doc.createElement(elementName);
- Text text = doc.createTextNode(childTextValue);
- elem.appendChild(text);
-
- Text addedTextnode = (Text) elem.getFirstChild();
- assertNotNull("Child Text node missing", addedTextnode);
- assertEquals("Incorrect node object", text, addedTextnode);
+ DOMTestUtil.execute(new DOMTestUtil.Test() {
+ public void execute(DocumentBuilderFactory dbf) throws Exception {
+ String elementName = "TestElem";
+ String childElemName = "TestChildElem";
+ String childTextValue = "text value of the child text node";
+
+ //Apending am Element node
+ Document doc = dbf.newDocumentBuilder().newDocument();
+ Element elem = doc.createElement(elementName);
+ Element childElem = doc.createElement(childElemName);
+
+ elem.appendChild(childElem);
+
+ Element addedChild = (Element) elem.getFirstChild();
+ assertNotNull("Child Element node missing", addedChild);
+ assertEquals("Incorre node object", childElem, addedChild);
+
+ elem = doc.createElement(elementName);
+ Text text = doc.createTextNode(childTextValue);
+ elem.appendChild(text);
+
+ Text addedTextnode = (Text) elem.getFirstChild();
+ assertNotNull("Child Text node missing", addedTextnode);
+ assertEquals("Incorrect node object", text, addedTextnode);
+ }
+ });
}
/** Testing the NodeList returned with the elements's children */
public void testGetElementsbyTagName() throws Exception {
- String childElementLN = "Child";
-
- Document doc = new
DOOMDocumentBuilderFactory().newDocumentBuilder().newDocument();
- Element docElem = doc.getDocumentElement();
- assertNull("The document element shoudl be null", docElem);
-
- docElem = doc.createElement("Test");
- docElem.appendChild(doc.createElement(childElementLN));
- docElem.appendChild(doc.createElement(childElementLN));
- docElem.appendChild(doc.createElement(childElementLN));
- docElem.appendChild(doc.createElement(childElementLN));
- docElem.appendChild(doc.createElement(childElementLN));
- docElem.appendChild(doc.createElement(childElementLN));
- docElem.appendChild(doc.createElement(childElementLN));
-
- NodeList list = docElem.getElementsByTagName(childElementLN);
-
- assertEquals("Incorrect number of child elements", 7,
list.getLength());
+ DOMTestUtil.execute(new DOMTestUtil.Test() {
+ public void execute(DocumentBuilderFactory dbf) throws Exception {
+ String childElementLN = "Child";
+
+ Document doc = dbf.newDocumentBuilder().newDocument();
+ Element docElem = doc.getDocumentElement();
+ assertNull("The document element shoudl be null", docElem);
+
+ docElem = doc.createElement("Test");
+ docElem.appendChild(doc.createElement(childElementLN));
+ docElem.appendChild(doc.createElement(childElementLN));
+ docElem.appendChild(doc.createElement(childElementLN));
+ docElem.appendChild(doc.createElement(childElementLN));
+ docElem.appendChild(doc.createElement(childElementLN));
+ docElem.appendChild(doc.createElement(childElementLN));
+ docElem.appendChild(doc.createElement(childElementLN));
+
+ NodeList list = docElem.getElementsByTagName(childElementLN);
+
+ assertEquals("Incorrect number of child elements", 7,
list.getLength());
+ }
+ });
}
public void testGetElementsbyTagNameNS() throws Exception {
- String childElementLN = "test:Child";
- String childElementNS = "http://ws.apache.org/ns/axis2/dom";
-
- Document doc = new
DOOMDocumentBuilderFactory().newDocumentBuilder().newDocument();
- Element docElem = doc.getDocumentElement();
- assertNull("The document element shoudl be null", docElem);
-
- docElem = doc.createElementNS("http://test.org", "test:Test");
-
- docElem.appendChild(doc.createElementNS(childElementNS,
childElementLN));
- docElem.appendChild(doc.createElementNS(childElementNS,
childElementLN));
- docElem.appendChild(doc.createElementNS(childElementNS,
childElementLN));
- docElem.appendChild(doc.createElementNS(childElementNS,
childElementLN));
- docElem.appendChild(doc.createElementNS(childElementNS,
childElementLN));
- docElem.appendChild(doc.createElementNS(childElementNS,
childElementLN));
- docElem.appendChild(doc.createElementNS(childElementNS,
childElementLN));
-
- NodeList list = docElem.getElementsByTagNameNS(childElementNS,
childElementLN);
-
- assertEquals("Incorrect number of child elements", 7,
list.getLength());
+ DOMTestUtil.execute(new DOMTestUtil.Test() {
+ public void execute(DocumentBuilderFactory dbf) throws Exception {
+ String childElementQN = "test:Child";
+ String childElementLN = "Child";
+ String childElementNS = "http://ws.apache.org/ns/axis2/dom";
+
+ Document doc = dbf.newDocumentBuilder().newDocument();
+ Element docElem = doc.getDocumentElement();
+ assertNull("The document element shoudl be null", docElem);
+
+ docElem = doc.createElementNS("http://test.org", "test:Test");
+
+ docElem.appendChild(doc.createElementNS(childElementNS,
childElementQN));
+ docElem.appendChild(doc.createElementNS(childElementNS,
childElementQN));
+ docElem.appendChild(doc.createElementNS(childElementNS,
childElementQN));
+ docElem.appendChild(doc.createElementNS(childElementNS,
childElementQN));
+ docElem.appendChild(doc.createElementNS(childElementNS,
childElementQN));
+ docElem.appendChild(doc.createElementNS(childElementNS,
childElementQN));
+ docElem.appendChild(doc.createElementNS(childElementNS,
childElementQN));
+
+ NodeList list = docElem.getElementsByTagNameNS(childElementNS,
childElementLN);
+
+ assertEquals("Incorrect number of child elements", 7,
list.getLength());
+ }
+ });
}
}
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/dom/TextImplTest.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/dom/TextImplTest.java?rev=726537&r1=726536&r2=726537&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/dom/TextImplTest.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/dom/TextImplTest.java
Sun Dec 14 13:32:13 2008
@@ -19,10 +19,14 @@
package org.apache.axiom.om.impl.dom;
+import javax.xml.parsers.DocumentBuilderFactory;
+
import junit.framework.TestCase;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMText;
import org.apache.axiom.om.impl.dom.factory.OMDOMFactory;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
import org.w3c.dom.Text;
public class TextImplTest extends TestCase {
@@ -56,27 +60,31 @@
.getText());
}
- public void testSplitText() {
- String textValue = "temp text value";
-
- OMDOMFactory fac = new OMDOMFactory();
- DocumentImpl doc = new DocumentImpl(fac);
-
- Text txt = doc.createTextNode(textValue);
- txt.splitText(3);
-
- assertNotNull("Text value missing in the original Text node", txt
- .getNodeValue());
-
- assertNotNull("Sibling missing after split", txt.getNextSibling());
- assertNotNull("Text value missing in the new split Text node", txt
- .getNextSibling().getNodeValue());
-
- assertEquals("Incorrect split point", textValue.substring(0, 3), txt
- .getNodeValue());
- assertEquals("Incorrect split point", textValue.substring(3, textValue
- .length()), txt.getNextSibling().getNodeValue());
-
+ public void testSplitText() throws Exception {
+ DOMTestUtil.execute(new DOMTestUtil.Test() {
+ public void execute(DocumentBuilderFactory dbf) throws Exception {
+ String textValue = "temp text value";
+
+ Document doc = dbf.newDocumentBuilder().newDocument();
+
+ Element element = doc.createElement("test");
+ Text txt = doc.createTextNode(textValue);
+ element.appendChild(txt);
+ txt.splitText(3);
+
+ assertNotNull("Text value missing in the original Text node",
txt
+ .getNodeValue());
+
+ assertNotNull("Sibling missing after split",
txt.getNextSibling());
+ assertNotNull("Text value missing in the new split Text node",
txt
+ .getNextSibling().getNodeValue());
+
+ assertEquals("Incorrect split point", textValue.substring(0,
3), txt
+ .getNodeValue());
+ assertEquals("Incorrect split point", textValue.substring(3,
textValue
+ .length()), txt.getNextSibling().getNodeValue());
+ }
+ });
}
}