axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r734227 - /webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPElementTest.java
Date Tue, 13 Jan 2009 20:11:24 GMT
Author: veithen
Date: Tue Jan 13 12:11:21 2009
New Revision: 734227

URL: http://svn.apache.org/viewvc?rev=734227&view=rev
Log:
Avoid using TestCase#fail in case of an exception. Instead just let JUnit intercept the exception.

Modified:
    webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPElementTest.java

Modified: webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPElementTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPElementTest.java?rev=734227&r1=734226&r2=734227&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPElementTest.java
(original)
+++ webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPElementTest.java
Tue Jan 13 12:11:21 2009
@@ -56,36 +56,28 @@
     }
 
     @Validated @Test
-    public void testAddTextNode() {
+    public void testAddTextNode() throws Exception {
         assertNotNull(soapEle);
         String value = "foo";
-        try {
-            soapEle.addTextNode(value);
-        } catch (SOAPException e) {
-            fail("Unexpected Exception " + e);
-        }
+        soapEle.addTextNode(value);
         assertEquals(value, soapEle.getValue());
         Text text = assertContainsText(soapEle);
         assertEquals(value, text.getValue());
     }
 
     @Validated @Test
-    public void testChildren() {
-        try {
-            soapEle.addTextNode("foo");
-            SOAPElement childEle1 =
-                    SOAPFactoryImpl.newInstance().createElement("Child1",
-                                                                "ch",
-                                                                "http://test.apache.org/");
-            SOAPElement childEle2 =
-                    SOAPFactoryImpl.newInstance().createElement("Child2",
-                                                                "ch",
-                                                                "http://test.apache.org/");
-            soapEle.addChildElement(childEle1);
-            soapEle.addChildElement(childEle2);
-        } catch (SOAPException e) {
-            fail("Unexpected Exception " + e);
-        }
+    public void testChildren() throws Exception {
+        soapEle.addTextNode("foo");
+        SOAPElement childEle1 =
+                SOAPFactoryImpl.newInstance().createElement("Child1",
+                                                            "ch",
+                                                            "http://test.apache.org/");
+        SOAPElement childEle2 =
+                SOAPFactoryImpl.newInstance().createElement("Child2",
+                                                            "ch",
+                                                            "http://test.apache.org/");
+        soapEle.addChildElement(childEle1);
+        soapEle.addChildElement(childEle2);
 
         Object o = soapEle.getChildElements().next();
         Object o2 = soapEle.getChildElements().next();
@@ -119,14 +111,10 @@
     }
 
     @Validated @Test
-    public void testChildrenAndSiblings() {
-        try {
-            soapEle.addTextNode("foo");
-            soapEle.addChildElement("Child1", "ch", "http://test.apache.org/");
-            soapEle.addChildElement("Child2", "ch", "http://test.apache.org/");
-        } catch (SOAPException e) {
-            fail("Unexpected Exception " + e);
-        }
+    public void testChildrenAndSiblings() throws Exception {
+        soapEle.addTextNode("foo");
+        soapEle.addChildElement("Child1", "ch", "http://test.apache.org/");
+        soapEle.addChildElement("Child2", "ch", "http://test.apache.org/");
 
         Object o = soapEle.getChildElements().next();
         Object o2 = soapEle.getChildElements().next();
@@ -179,31 +167,23 @@
     }
 
     @Validated @Test
-    public void testCommentSibling() {
-        try {
-            soapEle.addTextNode("foo");
-            soapEle.addChildElement("Child1", "ch", "http://test.apache.org/");
-            soapEle.addTextNode("<!-- This is a Comment-->");
-            soapEle.addChildElement("Child2", "ch", "http://test.apache.org/");
-        } catch (SOAPException e) {
-            fail("Unexpected Exception " + e);
-        }
+    public void testCommentSibling() throws Exception {
+        soapEle.addTextNode("foo");
+        soapEle.addChildElement("Child1", "ch", "http://test.apache.org/");
+        soapEle.addTextNode("<!-- This is a Comment-->");
+        soapEle.addChildElement("Child2", "ch", "http://test.apache.org/");
 
         assertTrue(((Text)soapEle.getFirstChild().getNextSibling().getNextSibling()).isComment());
         assertTrue(((Text)soapEle.getLastChild().getPreviousSibling()).isComment());
     }
 
     @Validated @Test
-    public void testCommentSibling2() {
-        try {
-            soapEle.addTextNode("foo");
-            soapEle.addTextNode("<!-- This is a Comment-->");
-            soapEle.addTextNode("bar");
-            soapEle.addChildElement("Child1", "ch", "http://test.apache.org/");
-            soapEle.addChildElement("Child2", "ch", "http://test.apache.org/");
-        } catch (SOAPException e) {
-            fail("Unexpected Exception " + e);
-        }
+    public void testCommentSibling2() throws Exception {
+        soapEle.addTextNode("foo");
+        soapEle.addTextNode("<!-- This is a Comment-->");
+        soapEle.addTextNode("bar");
+        soapEle.addChildElement("Child1", "ch", "http://test.apache.org/");
+        soapEle.addChildElement("Child2", "ch", "http://test.apache.org/");
 
         assertTrue(((Text)soapEle.getFirstChild().getNextSibling()).isComment());
         assertFalse(((Text)soapEle.getLastChild().getPreviousSibling()
@@ -213,256 +193,217 @@
     }
 
     @Validated @Test
-    public void testAddChildElement() {
-        try {
-            String s = "MyName1";
-            String p = "MyPrefix1";
-            String u = "myURI";
-            SOAPBody body = MessageFactory.newInstance().createMessage().getSOAPBody();
-            SOAPElement myse = body.addNamespaceDeclaration(p, u);
-            SOAPElement se = body.addChildElement(s, p);
-            if (se == null) {
-                fail("SOAPElement was null");
+    public void testAddChildElement() throws Exception {
+        String s = "MyName1";
+        String p = "MyPrefix1";
+        String u = "myURI";
+        SOAPBody body = MessageFactory.newInstance().createMessage().getSOAPBody();
+        SOAPElement myse = body.addNamespaceDeclaration(p, u);
+        SOAPElement se = body.addChildElement(s, p);
+        if (se == null) {
+            fail("SOAPElement was null");
+        } else {
+            Iterator i = body.getChildElements();
+            int count = getIteratorCount(i);
+            i = body.getChildElements();
+            if (count != 1) {
+                fail("Wrong iterator count returned of " + count + ", expected 1");
             } else {
-                Iterator i = body.getChildElements();
-                int count = getIteratorCount(i);
-                i = body.getChildElements();
-                if (count != 1) {
-                    fail("Wrong iterator count returned of " + count + ", expected 1");
-                } else {
-                    SOAPElement se2 = (SOAPElement)i.next();
-                    if (!se.equals(se2)) {
-                        fail("Elements not equal");
-                    }
-                }
-                String name = se.getElementName().getLocalName();
-                Name n = se.getElementName();
-                String prefix = se.getElementName().getPrefix();
-                if (!name.equals(s) || !prefix.equals(p)) {
-                    fail("addChildElement() did not return correct local name and prefix");
+                SOAPElement se2 = (SOAPElement)i.next();
+                if (!se.equals(se2)) {
+                    fail("Elements not equal");
                 }
             }
-        } catch (Exception e) {
-            e.printStackTrace();
-            fail("Exception: " + e);
+            String name = se.getElementName().getLocalName();
+            Name n = se.getElementName();
+            String prefix = se.getElementName().getPrefix();
+            if (!name.equals(s) || !prefix.equals(p)) {
+                fail("addChildElement() did not return correct local name and prefix");
+            }
         }
     }
 
     @Validated @Test
-    public void testAddChildElement2() {
+    public void testAddChildElement2() throws Exception {
         boolean pass = true;
-        try {
-            SOAPMessage msg =
-                    MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL).createMessage();
-            SOAPEnvelope soapEnvelope = msg.getSOAPPart().getEnvelope();
-            SOAPBody body = msg.getSOAPBody();
-
-            Name name = soapEnvelope.createName("MyChild1");
-            //Add child element Name object with localName=MyChild1
-            SOAPElement se = body.addChildElement(name);
-            if (se == null) {
-                fail("addChildElement() did not return SOAPElement");
-                //pass = false;
-            } else {
-                //Find the child element just added
-                Iterator childs = body.getChildElements(name);
-                int count = 0;
-                while (childs.hasNext()) {
-                    Object obj = (Object)childs.next();
-                    count++;
-                }
-
-                childs = body.getChildElements(name);
-                assertTrue(count == 1);
+        SOAPMessage msg =
+                MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL).createMessage();
+        SOAPEnvelope soapEnvelope = msg.getSOAPPart().getEnvelope();
+        SOAPBody body = msg.getSOAPBody();
+
+        Name name = soapEnvelope.createName("MyChild1");
+        //Add child element Name object with localName=MyChild1
+        SOAPElement se = body.addChildElement(name);
+        if (se == null) {
+            fail("addChildElement() did not return SOAPElement");
+            //pass = false;
+        } else {
+            //Find the child element just added
+            Iterator childs = body.getChildElements(name);
+            int count = 0;
+            while (childs.hasNext()) {
+                Object obj = (Object)childs.next();
+                count++;
+            }
 
-                SOAPElement se2 = (SOAPElement)childs.next();
-                assertEquals(se, se2);
-                //se = se2 (expected)
-
-                //Retrieve the SOAPElement Name
-                Name n = se.getElementName();
-                //System.out.println("localName="+n.getLocalName()+" prefix="
-                //			+n.getPrefix()+" URI="+n.getURI()+" qualifiedName="
-                //			+n.getQualifiedName());
-                assertEquals(n, name);
-                //if (!n.equals(name)) {
-                //System.out.println("Name objects are not equal (unexpected)");
-                //System.out.println("addChildElement() did not return " +
-                //"correct Name object expected localName=" +
-                //name.getLocalName() + ", got localName="
-                //+ n.getLocalName());
-                //}
+            childs = body.getChildElements(name);
+            assertTrue(count == 1);
 
-                //Name objects are equal (expected)
-            }
+            SOAPElement se2 = (SOAPElement)childs.next();
+            assertEquals(se, se2);
+            //se = se2 (expected)
 
-        } catch (Exception e) {
-            fail("Exception: " + e);
+            //Retrieve the SOAPElement Name
+            Name n = se.getElementName();
+            //System.out.println("localName="+n.getLocalName()+" prefix="
+            //			+n.getPrefix()+" URI="+n.getURI()+" qualifiedName="
+            //			+n.getQualifiedName());
+            assertEquals(n, name);
+            //if (!n.equals(name)) {
+            //System.out.println("Name objects are not equal (unexpected)");
+            //System.out.println("addChildElement() did not return " +
+            //"correct Name object expected localName=" +
+            //name.getLocalName() + ", got localName="
+            //+ n.getLocalName());
+            //}
+
+            //Name objects are equal (expected)
         }
     }
 
     @Validated @Test
-    public void testAddTextNode2() {
-        try {
-            SOAPMessage msg = MessageFactory.newInstance().createMessage();
-            SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
-            SOAPBody body = envelope.getBody();
-            Iterator iStart = envelope.getChildElements();
-            int countStart = getIteratorCount(iStart);
-            SOAPElement se = envelope.addTextNode("<txt>This is text</txt>");
-            if (se == null) {
-                fail("addTextNode() did not return SOAPElement");
-            } else if (!envelope.getValue().equals("<txt>This is text</txt>"))
{
-                String s = body.getValue();
-                fail("addTextNode() did not return expected text, Returned " + s +
-                        ", Expected <txt>This is text</txt>");
-            }
-            Iterator i = envelope.getChildElements();
-            int count = getIteratorCount(i);
-            i = envelope.getChildElements();
-            if (count != ++countStart) {
-                fail("Wrong iterator count returned of " +
-                        count + ", expected " + countStart);
-            } else {
-                Object obj = null;
-                while (i.hasNext()) {
-                    obj = i.next();
-                    if (obj instanceof Text) {
-                        break;
-                    }
-                }
-                if (!(obj instanceof Text)) {
-                    fail("obj is not instanceof Text");
+    public void testAddTextNode2() throws Exception {
+        SOAPMessage msg = MessageFactory.newInstance().createMessage();
+        SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
+        SOAPBody body = envelope.getBody();
+        Iterator iStart = envelope.getChildElements();
+        int countStart = getIteratorCount(iStart);
+        SOAPElement se = envelope.addTextNode("<txt>This is text</txt>");
+        if (se == null) {
+            fail("addTextNode() did not return SOAPElement");
+        } else if (!envelope.getValue().equals("<txt>This is text</txt>")) {
+            String s = body.getValue();
+            fail("addTextNode() did not return expected text, Returned " + s +
+                    ", Expected <txt>This is text</txt>");
+        }
+        Iterator i = envelope.getChildElements();
+        int count = getIteratorCount(i);
+        i = envelope.getChildElements();
+        if (count != ++countStart) {
+            fail("Wrong iterator count returned of " +
+                    count + ", expected " + countStart);
+        } else {
+            Object obj = null;
+            while (i.hasNext()) {
+                obj = i.next();
+                if (obj instanceof Text) {
+                    break;
                 }
             }
-        } catch (Exception e) {
-            fail("Exception: " + e);
+            if (!(obj instanceof Text)) {
+                fail("obj is not instanceof Text");
+            }
         }
     }
 
     @Validated @Test
-    public void testRemoveAttribute() {
-        try {
-            SOAPMessage msg = MessageFactory.newInstance().createMessage();
-            SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
-            SOAPBody body = envelope.getBody();
-            Name name = envelope.createName("MyAttr1");
-            String value = "MyValue1";
-            body.addAttribute(name, value);
-            boolean b = body.removeAttribute(name);
-            assertTrue("removeAttribute() did not return true", b);
-            b = body.removeAttribute(name);
-            assertFalse("removeAttribute() did not return false", b);
-            assertNull(body.getAttributeValue(name));
-        } catch (Exception e) {
-            fail("Exception: " + e);
-        }
+    public void testRemoveAttribute() throws Exception {
+        SOAPMessage msg = MessageFactory.newInstance().createMessage();
+        SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
+        SOAPBody body = envelope.getBody();
+        Name name = envelope.createName("MyAttr1");
+        String value = "MyValue1";
+        body.addAttribute(name, value);
+        boolean b = body.removeAttribute(name);
+        assertTrue("removeAttribute() did not return true", b);
+        b = body.removeAttribute(name);
+        assertFalse("removeAttribute() did not return false", b);
+        assertNull(body.getAttributeValue(name));
     }
 
     @Validated @Test
-    public void testRemoveAttribute2() {
-        try {
-            SOAPMessage msg = MessageFactory.newInstance().createMessage();
-            SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
-            SOAPBody body = envelope.getBody();
-
-            QName name = new QName("MyAttr1");
-            String value = "MyValue1";
-            body.addAttribute(name, value);
-            boolean b = body.removeAttribute(name);
-            assertTrue(b);
-
-            b = body.removeAttribute(name);
-            if (b) {
-                //removeAttribute() did not return false
-                fail();
-            }
-            //getAttributeValue should return null
-            assertNull(body.getAttributeValue(name));
-        } catch (Exception e) {
-            fail("Error : " + e);
+    public void testRemoveAttribute2() throws Exception {
+        SOAPMessage msg = MessageFactory.newInstance().createMessage();
+        SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
+        SOAPBody body = envelope.getBody();
+
+        QName name = new QName("MyAttr1");
+        String value = "MyValue1";
+        body.addAttribute(name, value);
+        boolean b = body.removeAttribute(name);
+        assertTrue(b);
+
+        b = body.removeAttribute(name);
+        if (b) {
+            //removeAttribute() did not return false
+            fail();
         }
+        //getAttributeValue should return null
+        assertNull(body.getAttributeValue(name));
     }
 
     @Validated @Test
-    public void testRemoveAttributeName() {
-        try {
-            SOAPMessage msg = MessageFactory.newInstance().createMessage();
-            SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
-            SOAPBody body = envelope.getBody();
+    public void testRemoveAttributeName() throws Exception {
+        SOAPMessage msg = MessageFactory.newInstance().createMessage();
+        SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
+        SOAPBody body = envelope.getBody();
 
-            Name name = envelope.createName("MyAttr1");
-            String value = "MyValue1";
-            body.addAttribute(name, value);
-            boolean b = body.removeAttribute(name);
-            assertTrue(b);
+        Name name = envelope.createName("MyAttr1");
+        String value = "MyValue1";
+        body.addAttribute(name, value);
+        boolean b = body.removeAttribute(name);
+        assertTrue(b);
 
-            b = body.removeAttribute(name);
-            assertTrue(!b);
+        b = body.removeAttribute(name);
+        assertTrue(!b);
 
-            String s = body.getAttributeValue(name);
-            assertNull(s);
-        } catch (Exception e) {
-            fail("Failed : " + e);
-        }
+        String s = body.getAttributeValue(name);
+        assertNull(s);
     }
 
 
-    public void _testRemoveAttributeQName() {
-        try {
-            SOAPMessage msg =
-                    MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL).createMessage();
-            SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
-            SOAPBody body = envelope.getBody();
-
-            QName name = new QName("MyAttr1");
-            String value = "MyValue1";
-            body.addAttribute(name, value);
-            boolean b = body.removeAttribute(name);
-            assertTrue(b);
-            b = body.removeAttribute(name);
-            assertTrue(!b);
+    public void _testRemoveAttributeQName() throws Exception {
+        SOAPMessage msg =
+                MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL).createMessage();
+        SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
+        SOAPBody body = envelope.getBody();
 
-            assertNull(body.getAttributeValue(name));
-        } catch (Exception e) {
-            fail();
-        }
+        QName name = new QName("MyAttr1");
+        String value = "MyValue1";
+        body.addAttribute(name, value);
+        boolean b = body.removeAttribute(name);
+        assertTrue(b);
+        b = body.removeAttribute(name);
+        assertTrue(!b);
 
+        assertNull(body.getAttributeValue(name));
     }
 
     @Validated @Test
-    public void testRemoveNamespaceDeclaration() {
-        try {
-            String prefix = "myPrefix";
-            String uri = "myURI";
-            SOAPMessage msg = MessageFactory.newInstance().createMessage();
-            SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
-            SOAPBody body = envelope.getBody();
-            body.addNamespaceDeclaration(prefix, uri);
-            boolean b = body.removeNamespaceDeclaration(prefix);
-            assertTrue("removeNamespaceDeclaration() did not return true", b);
-            b = body.removeNamespaceDeclaration(prefix);
-            assertFalse("removeNamespaceDeclaration() did not return false", b);
-            assertNull(body.getNamespaceURI(prefix));
-        } catch (Exception e) {
-            fail("Exception: " + e);
-        }
+    public void testRemoveNamespaceDeclaration() throws Exception {
+        String prefix = "myPrefix";
+        String uri = "myURI";
+        SOAPMessage msg = MessageFactory.newInstance().createMessage();
+        SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
+        SOAPBody body = envelope.getBody();
+        body.addNamespaceDeclaration(prefix, uri);
+        boolean b = body.removeNamespaceDeclaration(prefix);
+        assertTrue("removeNamespaceDeclaration() did not return true", b);
+        b = body.removeNamespaceDeclaration(prefix);
+        assertFalse("removeNamespaceDeclaration() did not return false", b);
+        assertNull(body.getNamespaceURI(prefix));
     }
 
-    public void _testSetEncodingStyle() {
+    public void _testSetEncodingStyle() throws Exception {
+        SOAPMessage msg = MessageFactory.newInstance().createMessage();
+        SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
+        SOAPBody body = envelope.getBody();
+        body.setEncodingStyle(SOAPConstants.URI_NS_SOAP_ENCODING);
         try {
-            SOAPMessage msg = MessageFactory.newInstance().createMessage();
-            SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
-            SOAPBody body = envelope.getBody();
-            body.setEncodingStyle(SOAPConstants.URI_NS_SOAP_ENCODING);
-            try {
-                body.setEncodingStyle("BOGUS");
-                fail("Expected Exception did not occur");
-            } catch (IllegalArgumentException e) {
-                assertTrue("Expected Exception occurred", true);
-            }
-        } catch (Exception e) {
-            fail("Exception: " + e);
+            body.setEncodingStyle("BOGUS");
+            fail("Expected Exception did not occur");
+        } catch (IllegalArgumentException e) {
+            assertTrue("Expected Exception occurred", true);
         }
     }
 
@@ -497,297 +438,249 @@
     * test for addChildElement(QName qname)
     */
     @Validated @Test
-    public void testAddChildElement3() {
-        try {
-            QName qname = new QName("http://sample.apache.org/trader", "GetStockQuote", "w");
-            soapEle.addChildElement(qname);
-            assertNotNull(soapEle);
-
-        } catch (Exception e) {
-            fail("Exception: " + e);
-        }
+    public void testAddChildElement3() throws Exception {
+        QName qname = new QName("http://sample.apache.org/trader", "GetStockQuote", "w");
+        soapEle.addChildElement(qname);
+        assertNotNull(soapEle);
     }
 
 
     @Validated @Test
-    public void testGetAttributeValue() {
+    public void testGetAttributeValue() throws Exception {
         assertNotNull(soapEle);
         String value = "234.50";
-        try {
-            QName qname = new QName("http://sample.apache.org/trader", "GetStockQuote", "w");
-            soapEle.addAttribute(qname, value);
-            String valueReturned = soapEle.getAttributeValue(qname);
-            assertEquals(value, valueReturned);
-
-        } catch (SOAPException e) {
-            fail("Unexpected Exception " + e);
-        }
+        QName qname = new QName("http://sample.apache.org/trader", "GetStockQuote", "w");
+        soapEle.addAttribute(qname, value);
+        String valueReturned = soapEle.getAttributeValue(qname);
+        assertEquals(value, valueReturned);
     }
 
 
-    public void _testGetChildElements() {
-        try {
-            SOAPElement childEle1 =
-                    SOAPFactoryImpl.newInstance().createElement("Child1",
-                                                                "ch",
-                                                                "http://test.apache.org/");
-            SOAPElement childEle2 =
-                    SOAPFactoryImpl.newInstance().createElement("Child2",
-                                                                "ch",
-                                                                "http://test.apache.org/");
-            childEle1.addChildElement(childEle2);
-            soapEle.addChildElement(childEle1);
-
-            QName qname = new QName("http://test.apache.org/", "Child1", "ch");
-            Iterator childElements = soapEle.getChildElements(qname);
-
-
-            int childCount = 0;
-            while (childElements.hasNext()) {
-                Node node = (Node)childElements.next();
-                childCount++;
-            }
-            assertEquals(childCount, 2);
-        } catch (SOAPException e) {
-            fail("Unexpected Exception " + e);
+    public void _testGetChildElements() throws Exception {
+        SOAPElement childEle1 =
+                SOAPFactoryImpl.newInstance().createElement("Child1",
+                                                            "ch",
+                                                            "http://test.apache.org/");
+        SOAPElement childEle2 =
+                SOAPFactoryImpl.newInstance().createElement("Child2",
+                                                            "ch",
+                                                            "http://test.apache.org/");
+        childEle1.addChildElement(childEle2);
+        soapEle.addChildElement(childEle1);
+
+        QName qname = new QName("http://test.apache.org/", "Child1", "ch");
+        Iterator childElements = soapEle.getChildElements(qname);
+
+
+        int childCount = 0;
+        while (childElements.hasNext()) {
+            Node node = (Node)childElements.next();
+            childCount++;
         }
+        assertEquals(childCount, 2);
     }
 
     //TODO : check why this is failing
-    public void _testGetChildElements2() {
-        try {
-            MessageFactory fact = MessageFactory.newInstance();
-            SOAPMessage message = fact.createMessage();
-            SOAPPart soapPart = message.getSOAPPart();
-            SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
-            SOAPBody soapBody = soapEnvelope.getBody();
-
-            Name name = soapEnvelope.createName("MyChild1");
-            SOAPElement se = soapBody.addChildElement(name);
-            Iterator childElementsCount = soapBody.getChildElements();
-            Iterator childElements = soapBody.getChildElements();
-
-            int childCount = 0;
-            while (childElementsCount.hasNext()) {
-                Node node = (Node)childElementsCount.next();
-                childCount++;
-            }
-            assertEquals(childCount, 1);
-            SOAPElement se2 = (SOAPElement)childElements.next();
-            if (!se.equals(se2)) {
-                fail();
-            } else {
-                System.out.println("SOAPElement se = se2 (expected)");
-            }
-
-            Name n = se.getElementName();
-            assertEquals(n, name);
-        } catch (SOAPException e) {
-            fail("Unexpected Exception " + e);
-        }
-    }
-
-    @Validated @Test
-    public void testGetChildElements3() {
-        try {
-            MessageFactory fact = MessageFactory.newInstance();
-            SOAPMessage message = fact.createMessage();
-            SOAPPart soapPart = message.getSOAPPart();
-            SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
-            SOAPBody soapBody = soapEnvelope.getBody();
-
-            //Name name = soapEnvelope.createName("MyChild1");
-            QName name = new QName("MyChild1");
-            SOAPElement se = soapBody.addChildElement(name);
-            Iterator childElementsCount = soapBody.getChildElements();
-            Iterator childElements = soapBody.getChildElements();
-
-            int childCount = 0;
-            while (childElementsCount.hasNext()) {
-                Node node = (Node)childElementsCount.next();
-                childCount++;
-            }
-            assertEquals(childCount, 1);
-            SOAPElement se2 = (SOAPElement)childElements.next();
-            assertEquals(se, se2);
-
-            QName n = se.getElementQName();
-            assertEquals(n, name);
-        } catch (SOAPException e) {
-            fail("Unexpected Exception " + e);
+    public void _testGetChildElements2() throws Exception {
+        MessageFactory fact = MessageFactory.newInstance();
+        SOAPMessage message = fact.createMessage();
+        SOAPPart soapPart = message.getSOAPPart();
+        SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
+        SOAPBody soapBody = soapEnvelope.getBody();
+
+        Name name = soapEnvelope.createName("MyChild1");
+        SOAPElement se = soapBody.addChildElement(name);
+        Iterator childElementsCount = soapBody.getChildElements();
+        Iterator childElements = soapBody.getChildElements();
+
+        int childCount = 0;
+        while (childElementsCount.hasNext()) {
+            Node node = (Node)childElementsCount.next();
+            childCount++;
+        }
+        assertEquals(childCount, 1);
+        SOAPElement se2 = (SOAPElement)childElements.next();
+        if (!se.equals(se2)) {
+            fail();
+        } else {
+            System.out.println("SOAPElement se = se2 (expected)");
         }
-    }
 
-    public void _testRemoveAttribute2() {
-        try {
-            QName qname = new QName("http://child1.apache.org/", "Child1", "ch");
-            String value = "MyValue1";
-            soapEle.addAttribute(qname, value);
-            boolean b = soapEle.removeAttribute(qname);
-            assertTrue("removeAttribute() did not return true", b);
-            b = soapEle.removeAttribute(qname);
-            assertFalse("removeAttribute() did not return false", b);
-            assertNull(soapEle.getAttributeValue(qname));
-        } catch (Exception e) {
-            e.printStackTrace();
-            fail("Exception: " + e);
-        }
+        Name n = se.getElementName();
+        assertEquals(n, name);
     }
 
-    public void _testSetElementQName() {
-        try {
-            QName qname = new QName("http://child1.apache.org/", "newName", "ch");
-            soapEle.setElementQName(qname);
-            assertNull(soapEle.getElementName().getLocalName(), "newName");
-        } catch (Exception e) {
-            e.printStackTrace();
-            fail("Exception: " + e);
-        }
+    @Validated @Test
+    public void testGetChildElements3() throws Exception {
+        MessageFactory fact = MessageFactory.newInstance();
+        SOAPMessage message = fact.createMessage();
+        SOAPPart soapPart = message.getSOAPPart();
+        SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
+        SOAPBody soapBody = soapEnvelope.getBody();
+
+        //Name name = soapEnvelope.createName("MyChild1");
+        QName name = new QName("MyChild1");
+        SOAPElement se = soapBody.addChildElement(name);
+        Iterator childElementsCount = soapBody.getChildElements();
+        Iterator childElements = soapBody.getChildElements();
+
+        int childCount = 0;
+        while (childElementsCount.hasNext()) {
+            Node node = (Node)childElementsCount.next();
+            childCount++;
+        }
+        assertEquals(childCount, 1);
+        SOAPElement se2 = (SOAPElement)childElements.next();
+        assertEquals(se, se2);
+
+        QName n = se.getElementQName();
+        assertEquals(n, name);
+    }
+
+    public void _testRemoveAttribute2() throws Exception {
+        QName qname = new QName("http://child1.apache.org/", "Child1", "ch");
+        String value = "MyValue1";
+        soapEle.addAttribute(qname, value);
+        boolean b = soapEle.removeAttribute(qname);
+        assertTrue("removeAttribute() did not return true", b);
+        b = soapEle.removeAttribute(qname);
+        assertFalse("removeAttribute() did not return false", b);
+        assertNull(soapEle.getAttributeValue(qname));
+    }
+
+    public void _testSetElementQName() throws Exception {
+        QName qname = new QName("http://child1.apache.org/", "newName", "ch");
+        soapEle.setElementQName(qname);
+        assertNull(soapEle.getElementName().getLocalName(), "newName");
     }
 
-    public void _testCreateQName() {
+    public void _testCreateQName() throws Exception {
         String prefix = "";
-        try {
-            //SOAPMessage message = MessageFactory.newInstance().createMessage();
-            SOAPMessage message =
-                    MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL).createMessage();
-            SOAPPart soapPart = message.getSOAPPart();
-            SOAPEnvelope envelope = soapPart.getEnvelope();
-            SOAPBody body = envelope.getBody();
-
-            QName qname = envelope.createQName("qname", prefix);
-            String tprefix = qname.getPrefix();
-            String turi = qname.getNamespaceURI();
-            String tname = qname.getLocalPart();
-            if (!tprefix.equals(prefix) || !turi.equals(envelope.getElementName().getURI()))
{
-                fail("createQName() did not create correct qname\n" +
-                        "expected: <uri=" + envelope.getElementName().getURI() +
-                        ", prefix=" + prefix + ", localpart=qname>\n" +
-                        "got:      <uri=" + turi +
-                        ", prefix=" + tprefix + ", localpart=" + tname + ">");
-            }
-            qname = body.createQName("qname", body.getElementName().getPrefix());
-            tprefix = qname.getPrefix();
-            turi = qname.getNamespaceURI();
-            tname = qname.getLocalPart();
-            if (!tprefix.equals(body.getElementName().getPrefix()) ||
-                    !turi.equals(body.getElementName().getURI())) {
-                fail("createQName() did not create correct qname\n" +
-                        "expected: <uri=" + body.getElementName().getURI() +
-                        ", prefix=" + body.getElementName().getPrefix() + ", localpart=qname>\n"
+
-                        "got:      <uri=" + turi +
-                        ", prefix=" + tprefix + ", localpart=" + tname + ">");
-            }
-        } catch (Exception e) {
-            fail("Failed " + e);
+        //SOAPMessage message = MessageFactory.newInstance().createMessage();
+        SOAPMessage message =
+                MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL).createMessage();
+        SOAPPart soapPart = message.getSOAPPart();
+        SOAPEnvelope envelope = soapPart.getEnvelope();
+        SOAPBody body = envelope.getBody();
+
+        QName qname = envelope.createQName("qname", prefix);
+        String tprefix = qname.getPrefix();
+        String turi = qname.getNamespaceURI();
+        String tname = qname.getLocalPart();
+        if (!tprefix.equals(prefix) || !turi.equals(envelope.getElementName().getURI()))
{
+            fail("createQName() did not create correct qname\n" +
+                    "expected: <uri=" + envelope.getElementName().getURI() +
+                    ", prefix=" + prefix + ", localpart=qname>\n" +
+                    "got:      <uri=" + turi +
+                    ", prefix=" + tprefix + ", localpart=" + tname + ">");
+        }
+        qname = body.createQName("qname", body.getElementName().getPrefix());
+        tprefix = qname.getPrefix();
+        turi = qname.getNamespaceURI();
+        tname = qname.getLocalPart();
+        if (!tprefix.equals(body.getElementName().getPrefix()) ||
+                !turi.equals(body.getElementName().getURI())) {
+            fail("createQName() did not create correct qname\n" +
+                    "expected: <uri=" + body.getElementName().getURI() +
+                    ", prefix=" + body.getElementName().getPrefix() + ", localpart=qname>\n"
+
+                    "got:      <uri=" + turi +
+                    ", prefix=" + tprefix + ", localpart=" + tname + ">");
         }
     }
 
     @Validated @Test
-    public void testRemoveContent() {
+    public void testRemoveContent() throws Exception {
         boolean pass = true;
-        try {
-            MessageFactory factory = MessageFactory.newInstance();
-            SOAPMessage message = factory.createMessage();
-            SOAPPart soapPart = message.getSOAPPart();
-            SOAPEnvelope envelope = soapPart.getEnvelope();
-            SOAPBody body = envelope.getBody();
-
-            Name name = envelope.createName("MyChild");
-            SOAPElement se = body.addChildElement(name);
-            assertNotNull(se);
-            Iterator childs = body.getChildElements(name);
-            int childElementCount = 0;
-            for (int a = 0; childs.hasNext(); a++) {
-                childs.next();
-                childElementCount++;
-            }
-            childs = body.getChildElements(name);
-            assertEquals(childElementCount, 1);
+        MessageFactory factory = MessageFactory.newInstance();
+        SOAPMessage message = factory.createMessage();
+        SOAPPart soapPart = message.getSOAPPart();
+        SOAPEnvelope envelope = soapPart.getEnvelope();
+        SOAPBody body = envelope.getBody();
+
+        Name name = envelope.createName("MyChild");
+        SOAPElement se = body.addChildElement(name);
+        assertNotNull(se);
+        Iterator childs = body.getChildElements(name);
+        int childElementCount = 0;
+        for (int a = 0; childs.hasNext(); a++) {
+            childs.next();
+            childElementCount++;
+        }
+        childs = body.getChildElements(name);
+        assertEquals(childElementCount, 1);
+
+        Name n = se.getElementName();
+        assertEquals(n, name);
+        //Child addition verified, now call removeContents to delete it
+        se.removeContents();
+        childs = se.getChildElements();
+        childElementCount = 0;
+        for (int a = 0; childs.hasNext(); a++) {
+            childs.next();
+            childElementCount++;
+        }
+        assertEquals(childElementCount, 0);
+    }
+
+    @Validated @Test
+    public void testSetElementQName() throws Exception {
+        MessageFactory factory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
+        SOAPMessage message = factory.createMessage();
+        SOAPPart soapPart = message.getSOAPPart();
+        SOAPEnvelope envelope = soapPart.getEnvelope();
+        SOAPBody body = envelope.getBody();
+
+        QName qname1 = new QName("http://fooURI.com", "fooElement", "foo");
+        QName qname2 = new QName("http://foo2URI.com", "fooElement2", "foo2");
+        SOAPElement se = body.addChildElement(qname1);
+        QName qname = se.getElementQName();
+        se = se.setElementQName(qname2);
+        qname = se.getElementQName();
+
+        if (!qname.getNamespaceURI().equals(qname2.getNamespaceURI()) ||
+                !qname.getLocalPart().equals(qname2.getLocalPart()) ||
+                !qname.getPrefix().equals(qname2.getPrefix())) {
+            System.out.println("setElementQName() did not reset " +
+                    "element qname\nexpected: <URI=" + qname2.getNamespaceURI() +
+                    ", prefix=" + qname2.getPrefix() + ", localpart=" + qname2.getLocalPart()
+
+                    ">\ngot:      <URI=" + qname.getNamespaceURI() + ", prefix=" +
+                    qname.getPrefix() +
+                    ", localpart=" + qname.getLocalPart() + ">");
+        }
+    }
+
+    @Validated @Test
+    public void testSetElementQName2() throws Exception {
+        MessageFactory factory = MessageFactory.newInstance();
+        SOAPMessage message = factory.createMessage();
+        SOAPPart soapPart = message.getSOAPPart();
+        SOAPEnvelope envelope = soapPart.getEnvelope();
+        SOAPBody body = envelope.getBody();
+        SOAPHeader header = envelope.getHeader();
 
-            Name n = se.getElementName();
-            assertEquals(n, name);
-            //Child addition verified, now call removeContents to delete it
-            se.removeContents();
-            childs = se.getChildElements();
-            childElementCount = 0;
-            for (int a = 0; childs.hasNext(); a++) {
-                childs.next();
-                childElementCount++;
-            }
-            assertEquals(childElementCount, 0);
-        } catch (Exception e) {
-            fail();
+        QName qname = new QName("qname");
+        //Try and change element name of SOAPEnvelope (expect SOAPException)
+        try {
+            envelope.setElementQName(qname);
+            fail("Did not throw expected SOAPException");
+        } catch (SOAPException e) {
+            //Caught expected SOAPException
         }
-    }
 
-    @Validated @Test
-    public void testSetElementQName() {
+        //Try and change element name of SOAPHeader (expect SOAPException)
         try {
-            MessageFactory factory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
-            SOAPMessage message = factory.createMessage();
-            SOAPPart soapPart = message.getSOAPPart();
-            SOAPEnvelope envelope = soapPart.getEnvelope();
-            SOAPBody body = envelope.getBody();
-
-            QName qname1 = new QName("http://fooURI.com", "fooElement", "foo");
-            QName qname2 = new QName("http://foo2URI.com", "fooElement2", "foo2");
-            SOAPElement se = body.addChildElement(qname1);
-            QName qname = se.getElementQName();
-            se = se.setElementQName(qname2);
-            qname = se.getElementQName();
-
-            if (!qname.getNamespaceURI().equals(qname2.getNamespaceURI()) ||
-                    !qname.getLocalPart().equals(qname2.getLocalPart()) ||
-                    !qname.getPrefix().equals(qname2.getPrefix())) {
-                System.out.println("setElementQName() did not reset " +
-                        "element qname\nexpected: <URI=" + qname2.getNamespaceURI() +
-                        ", prefix=" + qname2.getPrefix() + ", localpart=" + qname2.getLocalPart()
+
-                        ">\ngot:      <URI=" + qname.getNamespaceURI() + ", prefix="
+
-                        qname.getPrefix() +
-                        ", localpart=" + qname.getLocalPart() + ">");
-            }
-        } catch (Exception e) {
-            fail("Error :" + e);
+            header.setElementQName(qname);
+            fail("Did not throw expected SOAPException");
+        } catch (SOAPException e) {
+            //Caught expected SOAPException
         }
-    }
 
-    @Validated @Test
-    public void testSetElementQName2() {
+        //Try and change element name of SOAPBody (expect SOAPException)
         try {
-            MessageFactory factory = MessageFactory.newInstance();
-            SOAPMessage message = factory.createMessage();
-            SOAPPart soapPart = message.getSOAPPart();
-            SOAPEnvelope envelope = soapPart.getEnvelope();
-            SOAPBody body = envelope.getBody();
-            SOAPHeader header = envelope.getHeader();
-
-            QName qname = new QName("qname");
-            //Try and change element name of SOAPEnvelope (expect SOAPException)
-            try {
-                envelope.setElementQName(qname);
-                fail("Did not throw expected SOAPException");
-            } catch (SOAPException e) {
-                //Caught expected SOAPException
-            }
-
-            //Try and change element name of SOAPHeader (expect SOAPException)
-            try {
-                header.setElementQName(qname);
-                fail("Did not throw expected SOAPException");
-            } catch (SOAPException e) {
-                //Caught expected SOAPException
-            }
-
-            //Try and change element name of SOAPBody (expect SOAPException)
-            try {
-                body.setElementQName(qname);
-                fail("Did not throw expected SOAPException");
-            } catch (SOAPException e) {
-                //Caught expected SOAPException
-            }
-        } catch (Exception e) {
-            fail("Error : " + e);
+            body.setElementQName(qname);
+            fail("Did not throw expected SOAPException");
+        } catch (SOAPException e) {
+            //Caught expected SOAPException
         }
     }
     



Mime
View raw message