ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1380836 - 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/document/ axiom-dom-testsuite/src/main/java/org/apache/axio...
Date Tue, 04 Sep 2012 20:00:27 GMT
Author: veithen
Date: Tue Sep  4 20:00:26 2012
New Revision: 1380836

URL: http://svn.apache.org/viewvc?rev=1380836&view=rev
Log:
Added a couple of DOM test cases that reveal several problems in DOOM. A fix will follow later.

Added:
    webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/DOMUtils.java
  (with props)
    webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestCreateAttributeNSInvalid.java
  (with props)
    webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestSetAttributeNSInvalid.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/document/TestCreateAttributeNS.java
    webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestSetAttributeNS.java
    webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/DOMImplementationTest.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=1380836&r1=1380835&r2=1380836&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 Sep  4 20:00:26 2012
@@ -19,12 +19,27 @@
 package org.apache.axiom.ts.dom;
 
 import javax.xml.XMLConstants;
+import javax.xml.namespace.QName;
 import javax.xml.parsers.DocumentBuilderFactory;
 
 import org.apache.axiom.testutils.conformance.ConformanceTestFile;
 import org.apache.axiom.testutils.suite.TestSuiteBuilder;
 
 public class DOMTestSuiteBuilder extends TestSuiteBuilder {
+    private static final QName[] validAttrQNames = new QName[] {
+        new QName("urn:ns2", "attr", "q"),
+        new QName("", "attr", ""),
+        new QName(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "ns", XMLConstants.XMLNS_ATTRIBUTE),
+        new QName(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, XMLConstants.XMLNS_ATTRIBUTE, ""),
+    };
+    
+    private static final QName[] invalidAttrQNames = new QName[] {
+        new QName(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "attr", ""),
+        new QName(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "attr", "p"),
+        new QName("urn:test", "p", XMLConstants.XMLNS_ATTRIBUTE),
+        new QName("", XMLConstants.XMLNS_ATTRIBUTE, ""),
+    };
+    
     private final DocumentBuilderFactory dbf;
     
     public DOMTestSuiteBuilder(DocumentBuilderFactory dbf) {
@@ -53,7 +68,12 @@ public class DOMTestSuiteBuilder extends
             addTest(new org.apache.axiom.ts.dom.document.TestCloneNode(dbf, conformanceFiles[i]));
         }
         addTest(new org.apache.axiom.ts.dom.document.TestCreateAttribute(dbf));
-        addTest(new org.apache.axiom.ts.dom.document.TestCreateAttributeNS(dbf));
+        for (int i=0; i<validAttrQNames.length; i++) {
+            addTest(new org.apache.axiom.ts.dom.document.TestCreateAttributeNS(dbf, validAttrQNames[i]));
+        }
+        for (int i=0; i<invalidAttrQNames.length; i++) {
+            addTest(new org.apache.axiom.ts.dom.document.TestCreateAttributeNSInvalid(dbf,
invalidAttrQNames[i]));
+        }
         addTest(new org.apache.axiom.ts.dom.document.TestCreateAttributeNSWithoutNamespace(dbf));
         addTest(new org.apache.axiom.ts.dom.document.TestCreateCDATASection(dbf));
         addTest(new org.apache.axiom.ts.dom.document.TestCreateElement(dbf));
@@ -119,10 +139,12 @@ public class DOMTestSuiteBuilder extends
         addTest(new org.apache.axiom.ts.dom.element.TestSetAttributeNodeNSReplace(dbf));
         addTest(new org.apache.axiom.ts.dom.element.TestSetAttributeNodeNSWrongDocument(dbf));
         addTest(new org.apache.axiom.ts.dom.element.TestSetAttributeNodeWrongDocument(dbf));
-        addTest(new org.apache.axiom.ts.dom.element.TestSetAttributeNS(dbf, "urn:ns2", "q",
"attr", "value"));
-        addTest(new org.apache.axiom.ts.dom.element.TestSetAttributeNS(dbf, null, null, "attr",
"value"));
-        addTest(new org.apache.axiom.ts.dom.element.TestSetAttributeNS(dbf, XMLConstants.XMLNS_ATTRIBUTE_NS_URI,
"xmlns", "ns", "urn:ns"));
-        addTest(new org.apache.axiom.ts.dom.element.TestSetAttributeNS(dbf, XMLConstants.XMLNS_ATTRIBUTE_NS_URI,
null, "xmlns", "urn:ns"));
+        for (int i=0; i<validAttrQNames.length; i++) {
+            addTest(new org.apache.axiom.ts.dom.element.TestSetAttributeNS(dbf, validAttrQNames[i],
"value"));
+        }
+        for (int i=0; i<invalidAttrQNames.length; i++) {
+            addTest(new org.apache.axiom.ts.dom.element.TestSetAttributeNSInvalid(dbf, invalidAttrQNames[i]));
+        }
         addTest(new org.apache.axiom.ts.dom.element.TestSetPrefixNotNullWithNamespace(dbf));
         addTest(new org.apache.axiom.ts.dom.element.TestSetPrefixNotNullWithoutNamespace(dbf));
         addTest(new org.apache.axiom.ts.dom.element.TestSetPrefixNull(dbf));

Added: webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/DOMUtils.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/DOMUtils.java?rev=1380836&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/DOMUtils.java
(added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/DOMUtils.java
Tue Sep  4 20:00:26 2012
@@ -0,0 +1,40 @@
+/*
+ * 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;
+
+import javax.xml.namespace.QName;
+
+public final class DOMUtils {
+    private DOMUtils() {}
+    
+    public static String getNamespaceURI(QName qname) {
+        String uri = qname.getNamespaceURI();
+        return uri.length() == 0 ? null : uri;
+    }
+    
+    public static String getPrefix(QName qname) {
+        String prefix = qname.getPrefix();
+        return prefix.length() == 0 ? null : prefix;
+    }
+    
+    public static String getQualifiedName(QName qname) {
+        String prefix = qname.getPrefix();
+        return prefix.length() == 0 ? qname.getLocalPart() : prefix + ":" + qname.getLocalPart();
+    }
+}

Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/DOMUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestCreateAttributeNS.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestCreateAttributeNS.java?rev=1380836&r1=1380835&r2=1380836&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestCreateAttributeNS.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestCreateAttributeNS.java
Tue Sep  4 20:00:26 2012
@@ -18,22 +18,29 @@
  */
 package org.apache.axiom.ts.dom.document;
 
+import javax.xml.namespace.QName;
 import javax.xml.parsers.DocumentBuilderFactory;
 
 import org.apache.axiom.ts.dom.DOMTestCase;
+import org.apache.axiom.ts.dom.DOMUtils;
 import org.w3c.dom.Attr;
 import org.w3c.dom.Document;
 
 public class TestCreateAttributeNS extends DOMTestCase {
-    public TestCreateAttributeNS(DocumentBuilderFactory dbf) {
+    private final QName qname;
+    
+    public TestCreateAttributeNS(DocumentBuilderFactory dbf, QName qname) {
         super(dbf);
+        this.qname = qname;
+        addTestProperty("ns", qname.getNamespaceURI());
+        addTestProperty("name", DOMUtils.getQualifiedName(qname));
     }
 
     protected void runTest() throws Throwable {
-        String localName = "attrIdentifier";
-        String uri = "http://ws.apache.org/axis2/ns";
-        String prefix = "axis2";
-        String name = prefix + ":" + localName;
+        String localName = qname.getLocalPart();
+        String uri = DOMUtils.getNamespaceURI(qname);
+        String prefix = DOMUtils.getPrefix(qname);
+        String name = DOMUtils.getQualifiedName(qname);
 
         Document doc = dbf.newDocumentBuilder().newDocument();
 
@@ -46,6 +53,8 @@ public class TestCreateAttributeNS exten
         assertEquals(name, attr.getName());
 
         // Check defaults
+        assertSame(doc, attr.getOwnerDocument());
+        assertNull(attr.getOwnerElement());
         assertNull(attr.getFirstChild());
         assertEquals("", attr.getValue());
     }

Added: webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestCreateAttributeNSInvalid.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestCreateAttributeNSInvalid.java?rev=1380836&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestCreateAttributeNSInvalid.java
(added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestCreateAttributeNSInvalid.java
Tue Sep  4 20:00:26 2012
@@ -0,0 +1,48 @@
+/*
+ * 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.document;
+
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.apache.axiom.ts.dom.DOMTestCase;
+import org.apache.axiom.ts.dom.DOMUtils;
+import org.w3c.dom.DOMException;
+import org.w3c.dom.Document;
+
+public class TestCreateAttributeNSInvalid extends DOMTestCase {
+    private final QName qname;
+    
+    public TestCreateAttributeNSInvalid(DocumentBuilderFactory dbf, QName qname) {
+        super(dbf);
+        this.qname = qname;
+        addTestProperty("ns", qname.getNamespaceURI());
+        addTestProperty("name", DOMUtils.getQualifiedName(qname));
+    }
+
+    protected void runTest() throws Throwable {
+        Document document = dbf.newDocumentBuilder().newDocument();
+        try {
+            document.createAttributeNS(DOMUtils.getNamespaceURI(qname), DOMUtils.getQualifiedName(qname));
+            fail("Expected DOMException");
+        } catch (DOMException ex) {
+            assertEquals(DOMException.NAMESPACE_ERR, ex.code);
+        }
+    }
+}

Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestCreateAttributeNSInvalid.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestSetAttributeNS.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/TestSetAttributeNS.java?rev=1380836&r1=1380835&r2=1380836&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestSetAttributeNS.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestSetAttributeNS.java
Tue Sep  4 20:00:26 2012
@@ -18,47 +18,43 @@
  */
 package org.apache.axiom.ts.dom.element;
 
+import javax.xml.namespace.QName;
 import javax.xml.parsers.DocumentBuilderFactory;
 
 import org.apache.axiom.ts.dom.DOMTestCase;
+import org.apache.axiom.ts.dom.DOMUtils;
 import org.w3c.dom.Attr;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.NamedNodeMap;
 
 public class TestSetAttributeNS extends DOMTestCase {
-    private final String namespaceURI;
-    private final String prefix;
-    private final String localName;
-    private final String name;
+    private final QName qname;
     private final String value;
     
-    public TestSetAttributeNS(DocumentBuilderFactory dbf, String namespaceURI, String prefix,
String localName, String value) {
+    public TestSetAttributeNS(DocumentBuilderFactory dbf, QName qname, String value) {
         super(dbf);
-        this.namespaceURI = namespaceURI;
-        this.prefix = prefix;
-        this.localName = localName;
-        name = prefix == null ? localName : prefix + ":" + localName;
+        this.qname = qname;
         this.value = value;
-        addTestProperty("uri", namespaceURI == null ? "" : namespaceURI);
-        addTestProperty("name", name);
+        addTestProperty("ns", qname.getNamespaceURI());
+        addTestProperty("name", DOMUtils.getQualifiedName(qname));
     }
 
     protected void runTest() throws Throwable {
         Document document = dbf.newDocumentBuilder().newDocument();
         Element element = document.createElementNS("urn:ns1", "p:element");
-        element.setAttributeNS(namespaceURI, name, value);
+        element.setAttributeNS(DOMUtils.getNamespaceURI(qname), DOMUtils.getQualifiedName(qname),
value);
         assertTrue(element.hasAttributes());
         NamedNodeMap attributes = element.getAttributes();
         assertEquals(1, attributes.getLength());
         Attr attr = (Attr)attributes.item(0);
         assertSame(document, attr.getOwnerDocument());
         assertSame(element, attr.getOwnerElement());
-        assertEquals(namespaceURI, attr.getNamespaceURI());
-        assertEquals(prefix, attr.getPrefix());
-        assertEquals(localName, attr.getLocalName());
-        assertEquals(name, attr.getName());
+        assertEquals(DOMUtils.getNamespaceURI(qname), attr.getNamespaceURI());
+        assertEquals(DOMUtils.getPrefix(qname), attr.getPrefix());
+        assertEquals(qname.getLocalPart(), attr.getLocalName());
+        assertEquals(DOMUtils.getQualifiedName(qname), attr.getName());
         assertEquals(value, attr.getValue());
-        assertSame(attr, element.getAttributeNodeNS(namespaceURI, localName));
+        assertSame(attr, element.getAttributeNodeNS(DOMUtils.getNamespaceURI(qname), qname.getLocalPart()));
     }
 }

Added: webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestSetAttributeNSInvalid.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/TestSetAttributeNSInvalid.java?rev=1380836&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestSetAttributeNSInvalid.java
(added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestSetAttributeNSInvalid.java
Tue Sep  4 20:00:26 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.namespace.QName;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.apache.axiom.ts.dom.DOMTestCase;
+import org.apache.axiom.ts.dom.DOMUtils;
+import org.w3c.dom.DOMException;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+public class TestSetAttributeNSInvalid extends DOMTestCase {
+    private final QName qname;
+
+    public TestSetAttributeNSInvalid(DocumentBuilderFactory dbf, QName qname) {
+        super(dbf);
+        this.qname = qname;
+        addTestProperty("ns", qname.getNamespaceURI());
+        addTestProperty("name", DOMUtils.getQualifiedName(qname));
+    }
+
+    protected void runTest() throws Throwable {
+        Document document = dbf.newDocumentBuilder().newDocument();
+        Element element = document.createElementNS(null, "test");
+        try {
+            element.setAttributeNS(DOMUtils.getNamespaceURI(qname), DOMUtils.getQualifiedName(qname),
"value");
+            fail("Expected DOMException");
+        } catch (DOMException ex) {
+            assertEquals(DOMException.NAMESPACE_ERR, ex.code);
+        }
+    }
+}

Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestSetAttributeNSInvalid.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/DOMImplementationTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/DOMImplementationTest.java?rev=1380836&r1=1380835&r2=1380836&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/DOMImplementationTest.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/DOMImplementationTest.java
Tue Sep  4 20:00:26 2012
@@ -23,10 +23,19 @@ import junit.framework.TestSuite;
 
 import org.apache.axiom.om.impl.dom.factory.OMDOMMetaFactory;
 import org.apache.axiom.ts.dom.DOMTestSuiteBuilder;
+import org.apache.axiom.ts.dom.document.TestCreateAttributeNS;
+import org.apache.axiom.ts.dom.document.TestCreateAttributeNSInvalid;
+import org.apache.axiom.ts.dom.element.TestSetAttributeNSInvalid;
 
 public class DOMImplementationTest extends TestCase {
     public static TestSuite suite() {
         DOMTestSuiteBuilder builder = new DOMTestSuiteBuilder(new OMDOMMetaFactory().newDocumentBuilderFactory());
+        
+        // TODO
+        builder.exclude(TestCreateAttributeNS.class, "(name=xmlns)");
+        builder.exclude(TestCreateAttributeNSInvalid.class);
+        builder.exclude(TestSetAttributeNSInvalid.class);
+        
         return builder.build();
     }
 }



Mime
View raw message