You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by ve...@apache.org on 2010/04/25 16:42:56 UTC

svn commit: r937807 - in /webservices/commons/trunk/modules/axiom/modules: axiom-api/src/test/java/org/apache/axiom/om/ axiom-tests/src/test/java/org/apache/axiom/om/

Author: veithen
Date: Sun Apr 25 14:42:56 2010
New Revision: 937807

URL: http://svn.apache.org/viewvc?rev=937807&view=rev
Log:
Preparing WSCOMMONS-517: Moved some declareDefaultNamespace related test cases to OMElementTestBase to extend their scope to DOOM.

Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/OMElementTestBase.java
    webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/DefaultNSHandlingTest.java
    webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/NamespaceTest.java

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/OMElementTestBase.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/OMElementTestBase.java?rev=937807&r1=937806&r2=937807&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/OMElementTestBase.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/OMElementTestBase.java Sun Apr 25 14:42:56 2010
@@ -19,12 +19,17 @@
 
 package org.apache.axiom.om;
 
+import java.io.ByteArrayInputStream;
 import java.util.Iterator;
 
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
 
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
 import org.apache.axiom.om.util.AXIOMUtil;
+import org.apache.axiom.om.util.StAXUtils;
 import org.apache.axiom.soap.SOAP11Constants;
 
 public abstract class OMElementTestBase extends AbstractTestCase {
@@ -372,4 +377,140 @@ public abstract class OMElementTestBase 
         assertEquals(ns1, it.next());
         assertFalse(it.hasNext());
     }
+    
+    private int getNumberOfOccurrences(String xml, String pattern) {
+        int index = -1;
+        int count = 0;
+        while ((index = xml.indexOf(pattern, index + 1)) != -1) {
+            count++;
+        }
+
+        return count;
+    }
+
+    public void testDeclareDefaultNamespace1() throws XMLStreamException {
+
+        /**
+         * <RootElement xmlns="http://one.org">
+         *   <ns2:ChildElementOne xmlns:ns2="http://ws.apache.org/axis2" xmlns="http://two.org">
+         *      <ChildElementTwo xmlns="http://one.org" />
+         *   </ns2:ChildElementOne>
+         * </RootElement>
+         */
+
+        OMFactory omFac = omMetaFactory.getOMFactory();
+
+        OMElement documentElement = omFac.createOMElement("RootElement", null);
+        documentElement.declareDefaultNamespace("http://one.org");
+
+        OMNamespace ns = omFac.createOMNamespace("http://ws.apache.org/axis2", "ns2");
+        OMElement childOne = omFac.createOMElement("ChildElementOne", ns, documentElement);
+        childOne.declareDefaultNamespace("http://two.org");
+
+        OMElement childTwo = omFac.createOMElement("ChildElementTwo", null, childOne);
+        childTwo.declareDefaultNamespace("http://one.org");
+
+
+        assertEquals(2, getNumberOfOccurrences(documentElement.toStringWithConsume(),
+                "xmlns=\"http://one.org\""));
+    }
+
+    public void testDeclareDefaultNamespace2() throws XMLStreamException {
+
+        /**
+         * <RootElement xmlns:ns1="http://one.org" xmlns:ns2="http://one.org">
+         *   <ns2:ChildElementOne xmlns="http://one.org">
+         *      <ns2:ChildElementTwo />
+         *   </ns2:ChildElementOne>
+         * </RootElement>
+         */
+
+        OMFactory omFac = omMetaFactory.getOMFactory();
+
+        OMElement documentElement = omFac.createOMElement("RootElement", null);
+        OMNamespace ns1 = documentElement.declareNamespace("http://one.org", "ns1");
+        OMNamespace ns2 = documentElement.declareNamespace("http://one.org", "ns2");
+
+        OMElement childOne = omFac.createOMElement("ChildElementOne", ns2, documentElement);
+        childOne.declareDefaultNamespace("http://one.org");
+
+        OMElement childTwo = omFac.createOMElement("ChildElementTwo", ns1, childOne);
+
+        assertEquals(1, getNumberOfOccurrences(documentElement.toStringWithConsume(),
+                "xmlns:ns2=\"http://one.org\""));
+    }
+
+    public void testMultipleDefaultNS() {
+        OMFactory omFactory = omMetaFactory.getOMFactory();
+        OMNamespace defaultNS1 = omFactory.createOMNamespace("http://defaultNS1.org", null);
+        OMNamespace defaultNS2 = omFactory.createOMNamespace("http://defaultNS2.org", null);
+
+        OMElement omElementOne = omFactory.createOMElement("DocumentElement", null);
+        omElementOne.declareDefaultNamespace("http://defaultNS1.org");
+        OMElement omElementOneChild = omFactory.createOMElement("ChildOne", null, omElementOne);
+
+
+        OMElement omElementTwo = omFactory.createOMElement("Foo", defaultNS2, omElementOne);
+        omElementTwo.declareDefaultNamespace("http://defaultNS2.org");
+        OMElement omElementTwoChild = omFactory.createOMElement("ChildOne", null, omElementTwo);
+
+        OMElement omElementThree = omFactory.createOMElement("Bar", defaultNS1, omElementTwo);
+        omElementThree.declareDefaultNamespace("http://defaultNS1.org");
+
+        OMNamespace omElementOneChildNS = omElementOneChild.getNamespace();
+        OMNamespace omElementTwoChildNS = omElementTwoChild.getNamespace();
+        // TODO: LLOM's and DOOM's behaviors are slightly different here; need to check if both are allowed
+        assertTrue(omElementOneChildNS == null || "".equals(omElementOneChildNS.getNamespaceURI()));
+        assertTrue(omElementTwoChildNS == null || "".equals(omElementTwoChildNS.getNamespaceURI()));
+    }
+
+    public void testChildReDeclaringParentsDefaultNSWithPrefix() throws Exception {
+        OMFactory fac = omMetaFactory.getOMFactory();
+        OMElement elem = fac.createOMElement("RequestSecurityToken", null);
+        elem.declareDefaultNamespace("http://schemas.xmlsoap.org/ws/2005/02/trust");
+        fac.createOMElement(new QName("TokenType"), elem).setText("test");
+        fac.createOMElement(new QName("RequestType"), elem).setText("test1");
+
+        fac.createOMElement(
+                new QName("http://schemas.xmlsoap.org/ws/2005/02/trust", "Entropy", "wst"),
+                elem);
+        String xml = elem.toString();
+
+        XMLStreamReader reader = StAXUtils.createXMLStreamReader(
+                new ByteArrayInputStream(xml.getBytes()));
+
+        StAXOMBuilder builder = new StAXOMBuilder(omMetaFactory.getOMFactory(), reader);
+        builder.getDocumentElement().build();
+
+        // The StAX implementation may or may not have a trailing blank in the tag
+        String assertText1 =
+                "<wst:Entropy xmlns:wst=\"http://schemas.xmlsoap.org/ws/2005/02/trust\" />";
+        String assertText2 =
+                "<wst:Entropy xmlns:wst=\"http://schemas.xmlsoap.org/ws/2005/02/trust\"/>";
+        String assertText3 =
+                "<wst:Entropy xmlns:wst=\"http://schemas.xmlsoap.org/ws/2005/02/trust\"></wst:Entropy>";
+
+        assertTrue((xml.indexOf(assertText1) != -1) ||
+                (xml.indexOf(assertText2) != -1) ||
+                (xml.indexOf(assertText3) != -1));
+    }
+
+    public void testChildReDeclaringGrandParentsDefaultNSWithPrefix() {
+        OMFactory fac = omMetaFactory.getOMFactory();
+        OMElement elem = fac.createOMElement("RequestSecurityToken", null);
+        elem.declareDefaultNamespace("http://schemas.xmlsoap.org/ws/2005/02/trust");
+        fac.createOMElement(new QName("TokenType"), elem).setText("test");
+        fac.createOMElement(new QName("RequestType"), elem).setText("test1");
+
+        OMElement entElem = fac.createOMElement(
+                new QName("http://schemas.xmlsoap.org/ws/2005/02/trust", "Entropy", "wst"),
+                elem);
+        OMElement binSecElem = fac.createOMElement(
+                new QName("http://schemas.xmlsoap.org/ws/2005/02/trust", "Binarysecret", "wst"),
+                entElem);
+        binSecElem.setText("secret value");
+        String xml = elem.toString();
+        assertTrue("Binarysecret element should have \'wst\' ns prefix",
+                   xml.indexOf("<wst:Binarysecret") != -1);
+    }
 }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/DefaultNSHandlingTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/DefaultNSHandlingTest.java?rev=937807&r1=937806&r2=937807&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/DefaultNSHandlingTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/DefaultNSHandlingTest.java Sun Apr 25 14:42:56 2010
@@ -27,9 +27,7 @@ import org.jaxen.JaxenException;
 import org.jaxen.SimpleNamespaceContext;
 import org.jaxen.XPath;
 
-import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
 import java.io.ByteArrayInputStream;
 import java.util.Iterator;
@@ -69,77 +67,6 @@ public class DefaultNSHandlingTest exten
                 "http://www.w3.org/TR/REC-html40".equals(element.getNamespace().getNamespaceURI()));
     }
 
-    public void testMultipleDefaultNS() {
-        OMFactory omFactory = OMAbstractFactory.getOMFactory();
-        OMNamespace defaultNS1 = omFactory.createOMNamespace("http://defaultNS1.org", null);
-        OMNamespace defaultNS2 = omFactory.createOMNamespace("http://defaultNS2.org", null);
-
-        OMElement omElementOne = omFactory.createOMElement("DocumentElement", null);
-        omElementOne.declareDefaultNamespace("http://defaultNS1.org");
-        OMElement omElementOneChild = omFactory.createOMElement("ChildOne", null, omElementOne);
-
-
-        OMElement omElementTwo = omFactory.createOMElement("Foo", defaultNS2, omElementOne);
-        omElementTwo.declareDefaultNamespace("http://defaultNS2.org");
-        OMElement omElementTwoChild = omFactory.createOMElement("ChildOne", null, omElementTwo);
-
-        OMElement omElementThree = omFactory.createOMElement("Bar", defaultNS1, omElementTwo);
-        omElementThree.declareDefaultNamespace("http://defaultNS1.org");
-
-        assertTrue("".equals(omElementOneChild.getNamespace().getNamespaceURI()));
-        assertTrue("".equals(omElementTwoChild.getNamespace().getNamespaceURI()));
-    }
-
-    public void testChildReDeclaringParentsDefaultNSWithPrefix() throws Exception {
-        OMFactory fac = OMAbstractFactory.getOMFactory();
-        OMElement elem = fac.createOMElement("RequestSecurityToken", null);
-        elem.declareDefaultNamespace("http://schemas.xmlsoap.org/ws/2005/02/trust");
-        fac.createOMElement(new QName("TokenType"), elem).setText("test");
-        fac.createOMElement(new QName("RequestType"), elem).setText("test1");
-
-        fac.createOMElement(
-                new QName("http://schemas.xmlsoap.org/ws/2005/02/trust", "Entropy", "wst"),
-                elem);
-        String xml = elem.toString();
-
-        XMLStreamReader reader = StAXUtils.createXMLStreamReader(
-                new ByteArrayInputStream(xml.getBytes()));
-
-        StAXOMBuilder builder = new StAXOMBuilder(reader);
-        builder.getDocumentElement().build();
-
-        // The StAX implementation may or may not have a trailing blank in the tag
-        String assertText1 =
-                "<wst:Entropy xmlns:wst=\"http://schemas.xmlsoap.org/ws/2005/02/trust\" />";
-        String assertText2 =
-                "<wst:Entropy xmlns:wst=\"http://schemas.xmlsoap.org/ws/2005/02/trust\"/>";
-        String assertText3 =
-                "<wst:Entropy xmlns:wst=\"http://schemas.xmlsoap.org/ws/2005/02/trust\"></wst:Entropy>";
-
-        assertTrue((xml.indexOf(assertText1) != -1) ||
-                (xml.indexOf(assertText2) != -1) ||
-                (xml.indexOf(assertText3) != -1));
-    }
-
-    public void testChildReDeclaringGrandParentsDefaultNSWithPrefix() {
-        OMFactory fac = OMAbstractFactory.getOMFactory();
-        OMElement elem = fac.createOMElement("RequestSecurityToken", null);
-        elem.declareDefaultNamespace("http://schemas.xmlsoap.org/ws/2005/02/trust");
-        fac.createOMElement(new QName("TokenType"), elem).setText("test");
-        fac.createOMElement(new QName("RequestType"), elem).setText("test1");
-
-        OMElement entElem = fac.createOMElement(
-                new QName("http://schemas.xmlsoap.org/ws/2005/02/trust", "Entropy", "wst"),
-                elem);
-        OMElement binSecElem = fac.createOMElement(
-                new QName("http://schemas.xmlsoap.org/ws/2005/02/trust", "Binarysecret", "wst"),
-                entElem);
-        binSecElem.setText("secret value");
-        String xml = elem.toString();
-        assertTrue("Binarysecret element should have \'wst\' ns prefix",
-                   xml.indexOf("<wst:Binarysecret") != -1);
-    }
-
 //    public void testForIssueWSCOMMONS119() {
 //
 //        try {

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/NamespaceTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/NamespaceTest.java?rev=937807&r1=937806&r2=937807&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/NamespaceTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/NamespaceTest.java Sun Apr 25 14:42:56 2010
@@ -119,59 +119,6 @@ public class NamespaceTest extends XMLTe
         assertTrue(documentElement.toStringWithConsume().indexOf("ns2:ChildElement") > -1);
     }
 
-    public void testNamespaceProblem2() throws XMLStreamException {
-
-        /**
-         * <RootElement xmlns="http://one.org">
-         *   <ns2:ChildElementOne xmlns:ns2="http://ws.apache.org/axis2" xmlns="http://two.org">
-         *      <ChildElementTwo xmlns="http://one.org" />
-         *   </ns2:ChildElementOne>
-         * </RootElement>
-         */
-
-        OMFactory omFac = OMAbstractFactory.getOMFactory();
-
-        OMElement documentElement = omFac.createOMElement("RootElement", null);
-        documentElement.declareDefaultNamespace("http://one.org");
-
-        OMNamespace ns = omFac.createOMNamespace("http://ws.apache.org/axis2", "ns2");
-        OMElement childOne = omFac.createOMElement("ChildElementOne", ns, documentElement);
-        childOne.declareDefaultNamespace("http://two.org");
-
-        OMElement childTwo = omFac.createOMElement("ChildElementTwo", null, childOne);
-        childTwo.declareDefaultNamespace("http://one.org");
-
-
-        assertEquals(2, getNumberOfOccurrences(documentElement.toStringWithConsume(),
-                "xmlns=\"http://one.org\""));
-    }
-
-    public void testNamespaceProblem3() throws XMLStreamException {
-
-        /**
-         * <RootElement xmlns:ns1="http://one.org" xmlns:ns2="http://one.org">
-         *   <ns2:ChildElementOne xmlns="http://one.org">
-         *      <ns2:ChildElementTwo />
-         *   </ns2:ChildElementOne>
-         * </RootElement>
-         */
-
-        OMFactory omFac = OMAbstractFactory.getOMFactory();
-
-        OMElement documentElement = omFac.createOMElement("RootElement", null);
-        OMNamespace ns1 = documentElement.declareNamespace("http://one.org", "ns1");
-        OMNamespace ns2 = documentElement.declareNamespace("http://one.org", "ns2");
-
-        OMElement childOne = omFac.createOMElement("ChildElementOne", ns2, documentElement);
-        childOne.declareDefaultNamespace("http://one.org");
-
-        OMElement childTwo = omFac.createOMElement("ChildElementTwo", ns1, childOne);
-
-        assertEquals(1, getNumberOfOccurrences(documentElement.toStringWithConsume(),
-                "xmlns:ns2=\"http://one.org\""));
-    }
-
-
     public void testNamespaceProblem4() throws Exception {
         String xml =
                 "<getCreditScoreResponse xmlns=\"http://www.example.org/creditscore/doclitwrapped/\"><score xmlns=\"\">750</score></getCreditScoreResponse>";
@@ -200,16 +147,6 @@ public class NamespaceTest extends XMLTe
         }
     }
 
-    private int getNumberOfOccurrences(String xml, String pattern) {
-        int index = -1;
-        int count = 0;
-        while ((index = xml.indexOf(pattern, index + 1)) != -1) {
-            count++;
-        }
-
-        return count;
-    }
-
     public void testNamespaceProblem6() {
         OMFactory fac = OMAbstractFactory.getOMFactory();
         //TODO: Find the constants for "Parameter" and "name"