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/05 21:28:42 UTC

svn commit: r1381313 - in /webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src: main/java/org/apache/axiom/ts/dom/ main/java/org/apache/axiom/ts/dom/element/ test/java/org/apache/axiom/ts/dom/

Author: veithen
Date: Wed Sep  5 19:28:41 2012
New Revision: 1381313

URL: http://svn.apache.org/viewvc?rev=1381313&view=rev
Log:
AXIOM-423: Increased test coverage of Node#lookupNamespaceURI.

Added:
    webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestLookupNamespaceURIExplicit.java   (with props)
    webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestLookupNamespaceURIImplicit.java
      - copied, changed from r1380751, webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestLookupNamespaceURI.java
Removed:
    webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestLookupNamespaceURI.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/test/java/org/apache/axiom/ts/dom/XercesTest.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=1381313&r1=1381312&r2=1381313&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 Wed Sep  5 19:28:41 2012
@@ -119,7 +119,8 @@ public class DOMTestSuiteBuilder extends
         addTest(new org.apache.axiom.ts.dom.element.TestGetTextContent(dbf));
         addTest(new org.apache.axiom.ts.dom.element.TestInsertBefore(dbf));
         addTest(new org.apache.axiom.ts.dom.element.TestInsertBeforeWithDocumentFragment(dbf));
-        addTest(new org.apache.axiom.ts.dom.element.TestLookupNamespaceURI(dbf));
+        addTest(new org.apache.axiom.ts.dom.element.TestLookupNamespaceURIExplicit(dbf));
+        addTest(new org.apache.axiom.ts.dom.element.TestLookupNamespaceURIImplicit(dbf));
         addTest(new org.apache.axiom.ts.dom.element.TestRemoveAttributeNotOwner(dbf));
         addTest(new org.apache.axiom.ts.dom.element.TestRemoveFirstChild(dbf));
         addTest(new org.apache.axiom.ts.dom.element.TestRemoveLastChild(dbf));

Added: webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestLookupNamespaceURIExplicit.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/TestLookupNamespaceURIExplicit.java?rev=1381313&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestLookupNamespaceURIExplicit.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestLookupNamespaceURIExplicit.java Wed Sep  5 19:28:41 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.dom.element;
+
+import javax.xml.XMLConstants;
+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#lookupNamespaceURI(String)} on an {@link Element} for
+ * namespaces defined explicitly by attributes representing namespace declarations.
+ */
+public class TestLookupNamespaceURIExplicit extends DOMTestCase {
+    public TestLookupNamespaceURIExplicit(DocumentBuilderFactory dbf) {
+        super(dbf);
+    }
+
+    protected void runTest() throws Throwable {
+        Document document = dbf.newDocumentBuilder().newDocument();
+        
+        Element e1 = document.createElementNS("urn:ns0", "ns0:e1");
+        e1.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns", "urn:ns1");
+        e1.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:p", "urn:ns2");
+        e1.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:q", "urn:ns4");
+        
+        Element e2 = document.createElementNS("urn:ns0", "ns0:e2");
+        e2.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:p", "urn:ns3");
+        // This attribute undeclares the "q" prefix. Note that this is allowed only in XML 1.1.
+        e2.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:q", "");
+        e1.appendChild(e2);
+        
+        Element e3 = document.createElementNS("urn:ns0", "ns0:e3");
+        e3.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns", "");
+        // Add some attributes to check that lookupNamespaceURI doesn't confuse normal attributes
+        // and namespace declarations
+        e3.setAttributeNS("urn:test", "ns:p", "value");
+        e3.setAttributeNS(null, "q", "value");
+        e2.appendChild(e3);
+        
+        assertEquals("urn:ns1", e1.lookupNamespaceURI(null));
+        assertEquals("urn:ns1", e2.lookupNamespaceURI(null));
+        assertNull(e3.lookupNamespaceURI(null));
+        
+        assertEquals("urn:ns2", e1.lookupNamespaceURI("p"));
+        assertEquals("urn:ns3", e2.lookupNamespaceURI("p"));
+        assertEquals("urn:ns3", e3.lookupNamespaceURI("p"));
+        
+        assertEquals("urn:ns4", e1.lookupNamespaceURI("q"));
+        assertEquals(null, e2.lookupNamespaceURI("q"));
+        assertEquals(null, e3.lookupNamespaceURI("q"));
+    }
+}

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

Copied: webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestLookupNamespaceURIImplicit.java (from r1380751, webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestLookupNamespaceURI.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/TestLookupNamespaceURIImplicit.java?p2=webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestLookupNamespaceURIImplicit.java&p1=webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestLookupNamespaceURI.java&r1=1380751&r2=1381313&rev=1381313&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestLookupNamespaceURI.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestLookupNamespaceURIImplicit.java Wed Sep  5 19:28:41 2012
@@ -23,10 +23,16 @@ 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;
 
-public class TestLookupNamespaceURI extends DOMTestCase {
+/**
+ * Tests the behavior of {@link Node#lookupNamespaceURI(String)} on an {@link Element} for
+ * namespaces defined implicitly by the namespace prefix/URI of the element and its ancestors, i.e.
+ * for namespaces not defined explicitly by attributes representing namespace declarations.
+ */
+public class TestLookupNamespaceURIImplicit extends DOMTestCase {
 
-    public TestLookupNamespaceURI(DocumentBuilderFactory dbf) {
+    public TestLookupNamespaceURIImplicit(DocumentBuilderFactory dbf) {
         super(dbf);
     }
 
@@ -52,14 +58,22 @@ public class TestLookupNamespaceURI exte
         parent.appendChild(element2);
         // parent has the prefix
         Element element3 = doc.createElement(element3Name);
+        element3.setAttributeNS("urn:test", "ns3:attr", "value");
         parent.appendChild(element3);
 
         assertEquals("Incorrect default namespace returned for the element", ns1,
                 element1.lookupNamespaceURI(null));
+        assertNull(element1.lookupNamespaceURI("ns0"));
+        
         assertEquals("Incorrect namespace returned for the element", ns2,
                 element2.lookupNamespaceURI(pref2));
+        assertNull(element2.lookupNamespaceURI("ns0"));
+        assertNull(element2.lookupNamespaceURI(null));
+        
         assertEquals("Incorrect namespace returned for the given prefix", nsParent,
                 element3.lookupNamespaceURI(prefParent));
+        // This asserts that namespaces can only be defined implicitly by elements, but not attributes
+        assertNull(element3.lookupNamespaceURI("ns3"));
     }
 
 }
\ No newline at end of file

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/test/java/org/apache/axiom/ts/dom/XercesTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/test/java/org/apache/axiom/ts/dom/XercesTest.java?rev=1381313&r1=1381312&r2=1381313&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/test/java/org/apache/axiom/ts/dom/XercesTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/test/java/org/apache/axiom/ts/dom/XercesTest.java Wed Sep  5 19:28:41 2012
@@ -24,6 +24,7 @@ import junit.framework.TestCase;
 import junit.framework.TestSuite;
 
 import org.apache.axiom.ts.dom.document.TestLookupNamespaceURIWithEmptyDocument;
+import org.apache.axiom.ts.dom.element.TestLookupNamespaceURIExplicit;
 import org.apache.xerces.jaxp.DocumentBuilderFactoryImpl;
 
 public class XercesTest extends TestCase {
@@ -35,6 +36,9 @@ public class XercesTest extends TestCase
         // XERCESJ-1582
         builder.exclude(TestLookupNamespaceURIWithEmptyDocument.class);
         
+        // XERCESJ-1394
+        builder.exclude(TestLookupNamespaceURIExplicit.class);
+        
         return builder.build();
     }
 }