cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1071449 - in /cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider: HWSoapMessageDocProvider.java ProviderClientServerTest.java
Date Wed, 16 Feb 2011 23:55:20 GMT
Author: dkulp
Date: Wed Feb 16 23:55:20 2011
New Revision: 1071449

URL: http://svn.apache.org/viewvc?rev=1071449&view=rev
Log:
Add test case for the faults from Provider Message mode

Modified:
    cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/HWSoapMessageDocProvider.java
    cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/ProviderClientServerTest.java

Modified: cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/HWSoapMessageDocProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/HWSoapMessageDocProvider.java?rev=1071449&r1=1071448&r2=1071449&view=diff
==============================================================================
--- cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/HWSoapMessageDocProvider.java
(original)
+++ cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/HWSoapMessageDocProvider.java
Wed Feb 16 23:55:20 2011
@@ -23,8 +23,14 @@ import java.io.InputStream;
 
 import javax.annotation.Resource;
 import javax.xml.namespace.QName;
+import javax.xml.soap.Detail;
+import javax.xml.soap.DetailEntry;
 import javax.xml.soap.MessageFactory;
 import javax.xml.soap.SOAPBody;
+import javax.xml.soap.SOAPElement;
+import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPFactory;
+import javax.xml.soap.SOAPFault;
 import javax.xml.soap.SOAPMessage;
 import javax.xml.ws.Provider;
 import javax.xml.ws.Service;
@@ -32,6 +38,7 @@ import javax.xml.ws.ServiceMode;
 import javax.xml.ws.WebServiceContext;
 import javax.xml.ws.WebServiceProvider;
 import javax.xml.ws.handler.MessageContext;
+import javax.xml.ws.soap.SOAPFaultException;
 
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
@@ -77,26 +84,50 @@ public class HWSoapMessageDocProvider im
         }
         
         SOAPMessage response = null;        
+        SOAPBody body = null;
         try {
-            SOAPBody body = request.getSOAPBody();
-            Node n = body.getFirstChild();
+            body = request.getSOAPBody();
+        } catch (SOAPException e) {
+            e.printStackTrace();
+            return null;
+        }
+        Node n = body.getFirstChild();
 
-            while (n.getNodeType() != Node.ELEMENT_NODE) {
-                n = n.getNextSibling();
-            }
-            if (n.getLocalName().equals(sayHi.getLocalPart())) {
+        while (n.getNodeType() != Node.ELEMENT_NODE) {
+            n = n.getNextSibling();
+        }
+        if (n.getLocalName().equals(sayHi.getLocalPart())) {
+            response = sayHiResponse;
+        } else if (n.getLocalName().equals(greetMe.getLocalPart())) {
+            Element el = DOMUtils.getFirstElement(n);
+            String v = DOMUtils.getContent(el);
+            System.out.println(v);
+            if (v.contains("Return sayHi")) {
                 response = sayHiResponse;
-            } else if (n.getLocalName().equals(greetMe.getLocalPart())) {
-                Element el = DOMUtils.getFirstElement(n);
-                String v = DOMUtils.getContent(el);
-                if (v.contains("Return sayHi")) {
-                    response = sayHiResponse;
-                } else {
-                    response = greetMeResponse;
+            } else if (v.contains("throwFault")) {
+                try {
+                    SOAPFactory f = SOAPFactory.newInstance(); 
+                    SOAPFault soapFault = f.createFault(); 
+                    
+                    soapFault.setFaultString("Test Fault String ****"); 
+       
+                    Detail detail = soapFault.addDetail(); 
+                    detail = soapFault.getDetail(); 
+       
+                    QName qName = new QName("http://www.Hello.org/greeter", "TestFault",
"ns"); 
+                    DetailEntry de = detail.addDetailEntry(qName); 
+       
+                    qName = new QName("http://www.Hello.org/greeter", "ErrorCode", "ns");

+                    SOAPElement errorElement = de.addChildElement(qName); 
+                    errorElement.setTextContent("errorcode");
+                    throw new SOAPFaultException(soapFault);
+                } catch (SOAPException ex) {
+                    //ignore
                 }
+                           
+            } else {
+                response = greetMeResponse;
             }
-        } catch (Exception ex) {
-            ex.printStackTrace();
         }
         return response;
     }

Modified: cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/ProviderClientServerTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/ProviderClientServerTest.java?rev=1071449&r1=1071448&r2=1071449&view=diff
==============================================================================
--- cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/ProviderClientServerTest.java
(original)
+++ cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/provider/ProviderClientServerTest.java
Wed Feb 16 23:55:20 2011
@@ -24,6 +24,7 @@ import java.net.URL;
 
 import javax.xml.namespace.QName;
 import javax.xml.ws.Endpoint;
+import javax.xml.ws.soap.SOAPFaultException;
 
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
 import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
@@ -60,7 +61,7 @@ public class ProviderClientServerTest ex
 
     @BeforeClass
     public static void startServers() throws Exception {
-        assertTrue("server did not launch correctly", launchServer(Server.class));
+        assertTrue("server did not launch correctly", launchServer(Server.class, true));
     }
     
     @Test
@@ -98,6 +99,13 @@ public class ProviderClientServerTest ex
                 assertNotNull("no response received from service", reply);
                 assertEquals(response2, reply);
             }
+
+            try {
+                greeter.greetMe("throwFault");
+                fail("Expected a fault");
+            } catch (SOAPFaultException ex) {
+                assertTrue(ex.getMessage().contains("Test Fault String"));
+            }
         } catch (UndeclaredThrowableException ex) {
             throw (Exception)ex.getCause();
         }



Mime
View raw message