You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2006/05/19 01:16:10 UTC

svn commit: r407656 [2/2] - in /incubator/servicemix/trunk: servicemix-core/src/main/java/org/apache/servicemix/jbi/jaxp/ servicemix-core/src/main/java/org/apache/servicemix/jbi/util/ servicemix-http/src/main/java/org/apache/servicemix/http/ servicemix...

Added: incubator/servicemix/trunk/servicemix-soap/src/test/java/org/apache/servicemix/soap/marshalers/FaultTest.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-soap/src/test/java/org/apache/servicemix/soap/marshalers/FaultTest.java?rev=407656&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-soap/src/test/java/org/apache/servicemix/soap/marshalers/FaultTest.java (added)
+++ incubator/servicemix/trunk/servicemix-soap/src/test/java/org/apache/servicemix/soap/marshalers/FaultTest.java Thu May 18 16:16:09 2006
@@ -0,0 +1,161 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.servicemix.soap.marshalers;
+
+import java.io.ByteArrayOutputStream;
+
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+import org.apache.servicemix.jbi.jaxp.StringSource;
+import org.apache.servicemix.jbi.util.DOMUtil;
+import org.apache.servicemix.soap.SoapFault;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+public class FaultTest extends TestCase {
+
+    private SourceTransformer sourceTransformer = new SourceTransformer();
+    
+    protected void testSoap11(boolean useDom) throws Exception {
+        SoapMarshaler marshaler = new SoapMarshaler(true, useDom);
+        try {
+            marshaler.createReader().read(getClass().getResourceAsStream("fault-1.1-ok.xml"));
+        } catch (SoapFault fault) {
+            assertEquals(SoapMarshaler.SOAP_11_CODE_SERVER, fault.getCode());
+            assertNull(fault.getSubcode());
+            assertEquals("Server Error", fault.getReason());
+            assertNotNull(fault.getDetails());
+            Node node = sourceTransformer.toDOMNode(fault.getDetails());
+            Element e = node instanceof Document ? ((Document) node).getDocumentElement() : (Element) node;
+            assertEquals(new QName("Some-URI", "myfaultdetails"), DOMUtil.getQName(e));
+        }
+    }
+    
+    public void testReadSoap11UsingDom() throws Exception {
+        testSoap11(true);
+    }
+    
+    public void testReadSoap11UsingStax() throws Exception {
+        testSoap11(false);
+    }
+    
+    protected void testSoap12(boolean useDom) throws Exception {
+        SoapMarshaler marshaler = new SoapMarshaler(true, useDom);
+        try {
+            marshaler.createReader().read(getClass().getResourceAsStream("fault-1.2-ok.xml"));
+        } catch (SoapFault fault) {
+            assertEquals(SoapMarshaler.SOAP_12_CODE_SENDER, fault.getCode());
+            assertEquals(new QName("http://www.example.org/timeouts", "MessageTimeout"), fault.getSubcode());
+            assertEquals("Sender Timeout", fault.getReason());
+            assertNotNull(fault.getDetails());
+            Node node = sourceTransformer.toDOMNode(fault.getDetails());
+            Element e = node instanceof Document ? ((Document) node).getDocumentElement() : (Element) node;
+            assertEquals(new QName("http://www.example.org/timeouts", "MaxTime"), DOMUtil.getQName(e));
+        }
+    }
+    
+    public void testReadSoap12UsingDom() throws Exception {
+        testSoap12(true);
+    }
+    
+    public void testReadSoap12UsingStax() throws Exception {
+        testSoap12(false);
+    }
+    
+    public void testWriteSoap11UsingDom() throws Exception {
+        testWriteSoap11(true);
+    }
+
+    public void testWriteSoap11UsingStax() throws Exception {
+        testWriteSoap11(false);
+    }
+
+    protected void testWriteSoap11(boolean useDom) throws Exception {
+        SoapMarshaler marshaler = new SoapMarshaler(true, useDom);
+        marshaler.setSoapUri(SoapMarshaler.SOAP_11_URI);
+        SoapMessage msg = new SoapMessage();
+        SoapFault fault = new SoapFault(new QName("my:urn", "code"), null, "My reason", null, null, new StringSource("<ns1:hello xmlns:ns1='my:urn'>world</ns1:hello>"));
+        msg.setFault(fault);
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        marshaler.createWriter(msg).write(baos);
+        System.err.println(baos.toString());
+
+        Node node = sourceTransformer.toDOMNode(new StringSource(baos.toString()));
+        Element e = ((Document) node).getDocumentElement();
+        assertEquals(new QName(SoapMarshaler.SOAP_11_URI, SoapMarshaler.ENVELOPE), DOMUtil.getQName(e));
+        e = DOMUtil.getFirstChildElement(e);
+        assertEquals(new QName(SoapMarshaler.SOAP_11_URI, SoapMarshaler.BODY), DOMUtil.getQName(e));
+        Element elFault = DOMUtil.getFirstChildElement(e);
+        assertEquals(new QName(SoapMarshaler.SOAP_11_URI, SoapMarshaler.FAULT), DOMUtil.getQName(elFault));
+        Element elCode = DOMUtil.getFirstChildElement(elFault);
+        assertEquals(SoapMarshaler.SOAP_11_FAULTCODE, DOMUtil.getQName(elCode));
+        assertEquals(new QName("my:urn", "code"), DOMUtil.createQName(elCode, DOMUtil.getElementText(elCode)));
+        Element elReason = DOMUtil.getNextSiblingElement(elCode);
+        assertEquals(SoapMarshaler.SOAP_11_FAULTSTRING, DOMUtil.getQName(elReason));
+        Element elDetail = DOMUtil.getNextSiblingElement(elReason);
+        assertEquals(SoapMarshaler.SOAP_11_FAULTDETAIL, DOMUtil.getQName(elDetail));
+        e = DOMUtil.getFirstChildElement(elDetail);
+        assertEquals(new QName("my:urn", "hello"), DOMUtil.getQName(e));
+    }
+    
+    public void testWriteSoap12UsingDom() throws Exception {
+        testWriteSoap12(true);
+    }
+    
+    public void testWriteSoap12UsingStax() throws Exception {
+        testWriteSoap12(false);
+    }
+    
+    protected void testWriteSoap12(boolean useDom) throws Exception {
+        SoapMarshaler marshaler = new SoapMarshaler(true, useDom);
+        marshaler.setSoapUri(SoapMarshaler.SOAP_12_URI);
+        SoapMessage msg = new SoapMessage();
+        SoapFault fault = new SoapFault(new QName("my:urn", "code"), null, "My reason", null, null, 
+                                        new StringSource("<ns1:hello xmlns:ns1='my:urn'>world</ns1:hello>"));
+        msg.setFault(fault);
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        marshaler.createWriter(msg).write(baos);
+        System.err.println(baos.toString());
+
+        Node node = sourceTransformer.toDOMNode(new StringSource(baos.toString()));
+        Element e = ((Document) node).getDocumentElement();
+        assertEquals(new QName(SoapMarshaler.SOAP_12_URI, SoapMarshaler.ENVELOPE), DOMUtil.getQName(e));
+        e = DOMUtil.getFirstChildElement(e);
+        assertEquals(new QName(SoapMarshaler.SOAP_12_URI, SoapMarshaler.BODY), DOMUtil.getQName(e));
+        Element elFault = DOMUtil.getFirstChildElement(e);
+        assertEquals(new QName(SoapMarshaler.SOAP_12_URI, SoapMarshaler.FAULT), DOMUtil.getQName(elFault));
+        Element elCode = DOMUtil.getFirstChildElement(elFault);
+        assertEquals(SoapMarshaler.SOAP_12_FAULTCODE, DOMUtil.getQName(elCode));
+        e = DOMUtil.getFirstChildElement(elCode);
+        assertEquals(SoapMarshaler.SOAP_12_FAULTVALUE, DOMUtil.getQName(e));
+        e = DOMUtil.getNextSiblingElement(e);
+        assertEquals(SoapMarshaler.SOAP_12_FAULTSUBCODE, DOMUtil.getQName(e));
+        e = DOMUtil.getFirstChildElement(e);
+        assertEquals(SoapMarshaler.SOAP_12_FAULTVALUE, DOMUtil.getQName(e));
+        assertEquals(new QName("my:urn", "code"), DOMUtil.createQName(e, DOMUtil.getElementText(e)));
+        Element elReason = DOMUtil.getNextSiblingElement(elCode);
+        assertEquals(SoapMarshaler.SOAP_12_FAULTREASON, DOMUtil.getQName(elReason));
+        Element elDetail = DOMUtil.getNextSiblingElement(elReason);
+        assertEquals(SoapMarshaler.SOAP_12_FAULTDETAIL, DOMUtil.getQName(elDetail));
+        e = DOMUtil.getFirstChildElement(elDetail);
+        assertEquals(new QName("my:urn", "hello"), DOMUtil.getQName(e));
+    }
+    
+}

Modified: incubator/servicemix/trunk/servicemix-soap/src/test/java/org/apache/servicemix/soap/marshalers/SoapMessageMarshalerTest.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-soap/src/test/java/org/apache/servicemix/soap/marshalers/SoapMessageMarshalerTest.java?rev=407656&r1=407655&r2=407656&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-soap/src/test/java/org/apache/servicemix/soap/marshalers/SoapMessageMarshalerTest.java (original)
+++ incubator/servicemix/trunk/servicemix-soap/src/test/java/org/apache/servicemix/soap/marshalers/SoapMessageMarshalerTest.java Thu May 18 16:16:09 2006
@@ -249,6 +249,5 @@
         QName qname = DOMUtil.createQName(root, DOMUtil.getElementText(root)); 
         assertEquals(new QName("uri:test", "MyConsumerService"), qname); 
 	}
-	
-	
+    
 }

Added: incubator/servicemix/trunk/servicemix-soap/src/test/resources/org/apache/servicemix/soap/marshalers/fault-1.1-ok.xml
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-soap/src/test/resources/org/apache/servicemix/soap/marshalers/fault-1.1-ok.xml?rev=407656&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-soap/src/test/resources/org/apache/servicemix/soap/marshalers/fault-1.1-ok.xml (added)
+++ incubator/servicemix/trunk/servicemix-soap/src/test/resources/org/apache/servicemix/soap/marshalers/fault-1.1-ok.xml Thu May 18 16:16:09 2006
@@ -0,0 +1,21 @@
+<SOAP-ENV:Envelope
+  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://schemas.xmlsoap.org/soap/envelope/ http://schemas.xmlsoap.org/soap/envelope/">
+   <SOAP-ENV:Body>
+       <SOAP-ENV:Fault>
+           <faultcode>SOAP-ENV:Server</faultcode>
+           <faultstring>Server Error</faultstring>
+           <detail>
+               <e:myfaultdetails xmlns:e="Some-URI">
+                 <message>
+                   My application didn't work
+                 </message>
+                 <errorcode>
+                   1001
+                 </errorcode>
+               </e:myfaultdetails>
+           </detail>
+       </SOAP-ENV:Fault>
+   </SOAP-ENV:Body>
+</SOAP-ENV:Envelope>

Added: incubator/servicemix/trunk/servicemix-soap/src/test/resources/org/apache/servicemix/soap/marshalers/fault-1.2-ok.xml
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-soap/src/test/resources/org/apache/servicemix/soap/marshalers/fault-1.2-ok.xml?rev=407656&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-soap/src/test/resources/org/apache/servicemix/soap/marshalers/fault-1.2-ok.xml (added)
+++ incubator/servicemix/trunk/servicemix-soap/src/test/resources/org/apache/servicemix/soap/marshalers/fault-1.2-ok.xml Thu May 18 16:16:09 2006
@@ -0,0 +1,20 @@
+<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope"
+              xmlns:m="http://www.example.org/timeouts"
+              xmlns:xml="http://www.w3.org/XML/1998/namespace">
+ <env:Body>
+  <env:Fault>
+   <env:Code>
+     <env:Value>env:Sender</env:Value>
+     <env:Subcode>
+      <env:Value>m:MessageTimeout</env:Value>
+     </env:Subcode>
+   </env:Code>
+   <env:Reason>
+     <env:Text xml:lang="en">Sender Timeout</env:Text>
+   </env:Reason>
+   <env:Detail>
+     <m:MaxTime>P5M</m:MaxTime>
+   </env:Detail>    
+  </env:Fault>
+ </env:Body>
+</env:Envelope>
\ No newline at end of file