geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r574375 - in /geronimo/server/trunk/testsuite/webservices-testsuite/jaxws-tests/jaxws-ejb/src: main/java/org/apache/geronimo/test/JAXWSBean.java test/java/org/apache/geronimo/testsuite/testset/JaxWSTest.java test/resources/request2.xml
Date Mon, 10 Sep 2007 21:10:28 GMT
Author: gawor
Date: Mon Sep 10 14:10:28 2007
New Revision: 574375

URL: http://svn.apache.org/viewvc?rev=574375&view=rev
Log:
improved tests and added a basic test case for exception handling

Added:
    geronimo/server/trunk/testsuite/webservices-testsuite/jaxws-tests/jaxws-ejb/src/test/resources/request2.xml
Modified:
    geronimo/server/trunk/testsuite/webservices-testsuite/jaxws-tests/jaxws-ejb/src/main/java/org/apache/geronimo/test/JAXWSBean.java
    geronimo/server/trunk/testsuite/webservices-testsuite/jaxws-tests/jaxws-ejb/src/test/java/org/apache/geronimo/testsuite/testset/JaxWSTest.java

Modified: geronimo/server/trunk/testsuite/webservices-testsuite/jaxws-tests/jaxws-ejb/src/main/java/org/apache/geronimo/test/JAXWSBean.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/testsuite/webservices-testsuite/jaxws-tests/jaxws-ejb/src/main/java/org/apache/geronimo/test/JAXWSBean.java?rev=574375&r1=574374&r2=574375&view=diff
==============================================================================
--- geronimo/server/trunk/testsuite/webservices-testsuite/jaxws-tests/jaxws-ejb/src/main/java/org/apache/geronimo/test/JAXWSBean.java
(original)
+++ geronimo/server/trunk/testsuite/webservices-testsuite/jaxws-tests/jaxws-ejb/src/main/java/org/apache/geronimo/test/JAXWSBean.java
Mon Sep 10 14:10:28 2007
@@ -23,6 +23,11 @@
 import javax.jws.WebService;
 import javax.jws.HandlerChain;
 import javax.jws.soap.SOAPBinding;
+import javax.xml.namespace.QName;
+import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPFactory;
+import javax.xml.soap.SOAPFault;
+import javax.xml.ws.soap.SOAPFaultException;
 
 @WebService
 @Stateless(mappedName="JAXWSBean")
@@ -40,6 +45,21 @@
             throw new RuntimeException("Wrong parameter");
         }
         return "Hello " + me;
+    }
+    
+    public void greetMeFault(String me) {
+        System.out.println("generate SOAP fault");
+        SOAPFault fault = null;
+        try {
+            fault = SOAPFactory.newInstance().createFault();
+            fault.setFaultCode(new QName("http://foo", "MyFaultCode"));
+            fault.setFaultString("my error");
+            fault.setFaultActor("my actor");
+        } catch (SOAPException ex) {
+            throw new RuntimeException(ex);
+        }
+
+        throw new SOAPFaultException(fault);
     }
     
 }

Modified: geronimo/server/trunk/testsuite/webservices-testsuite/jaxws-tests/jaxws-ejb/src/test/java/org/apache/geronimo/testsuite/testset/JaxWSTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/testsuite/webservices-testsuite/jaxws-tests/jaxws-ejb/src/test/java/org/apache/geronimo/testsuite/testset/JaxWSTest.java?rev=574375&r1=574374&r2=574375&view=diff
==============================================================================
--- geronimo/server/trunk/testsuite/webservices-testsuite/jaxws-tests/jaxws-ejb/src/test/java/org/apache/geronimo/testsuite/testset/JaxWSTest.java
(original)
+++ geronimo/server/trunk/testsuite/webservices-testsuite/jaxws-tests/jaxws-ejb/src/test/java/org/apache/geronimo/testsuite/testset/JaxWSTest.java
Mon Sep 10 14:10:28 2007
@@ -21,34 +21,32 @@
 import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.OutputStream;
 import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.StringReader;
 import java.net.HttpURLConnection;
 import java.net.URL;
-import java.util.Properties;
 import java.util.Iterator;
 import java.util.Map;
+import java.util.Properties;
 
 import javax.naming.InitialContext;
-import javax.wsdl.factory.WSDLFactory;
 import javax.wsdl.Definition;
-import javax.wsdl.Operation;
 import javax.wsdl.PortType;
+import javax.wsdl.factory.WSDLFactory;
 import javax.wsdl.xml.WSDLReader;
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.namespace.QName;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.NodeList;
-import org.w3c.dom.Element;
-
-import org.xml.sax.InputSource;
 
 import org.apache.geronimo.test.JAXWSGreeter;
-
 import org.apache.geronimo.testsupport.TestSupport;
 import org.testng.annotations.Test;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Text;
+import org.xml.sax.InputSource;
 
 public class JaxWSTest extends TestSupport {
 
@@ -62,77 +60,138 @@
         URL url = new URL(baseURL + "JAXWSBeanService/JAXWSBean");
         HttpURLConnection conn = (HttpURLConnection) url.openConnection();
         try {
-            conn.setDoOutput(true);
-            conn.setDoInput(true);
-            conn.setUseCaches(false);
-            conn.setRequestMethod("POST");
-            conn.setRequestProperty("Content-Type", "text/xml");
-
-            OutputStream out = conn.getOutputStream();
-
-            byte[] data = new byte[1024];
-            int read = 0;
-            while ((read = requestInput.read(data, 0, data.length)) != -1) {
-                out.write(data, 0, read);
-            }
+            String reply = call(requestInput, conn);
+            
+            assertEquals("responseCode", 200, conn.getResponseCode());
+            String contentType = conn.getHeaderField("Content-Type");
+            assertTrue("contentType", contentType.indexOf("text/xml") != -1);
+                        
+            InputSource is = new InputSource(new StringReader(reply));
+            Document doc = parseMessage(is);
+            
+            Text replyMsg = findText(doc.getDocumentElement(), "Hello foo bar");
+            assertTrue("reploy message", replyMsg != null);
+         
+        } finally {
+            conn.disconnect();
+        }
+    }
+
+    @Test
+    public void testInvocationFault() throws Exception {
+        InputStream requestInput = JaxWSTest.class.getResourceAsStream("/request2.xml");
+        assertNotNull("SOAP request not specified", requestInput);
+                
+        URL url = new URL(baseURL + "JAXWSBeanService/JAXWSBean");
+        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
+        try {
+            String reply = call(requestInput, conn);
 
-            requestInput.close();
+            assertEquals("responseCode", 500, conn.getResponseCode());
+            String contentType = conn.getHeaderField("Content-Type");
+            assertTrue("contentType", contentType.indexOf("text/xml") != -1);
+                        
+            InputSource is = new InputSource(new StringReader(reply));
+            Document doc = parseMessage(is);
+            
+            Element faultString = findElement(doc.getDocumentElement(), "faultstring");
+            assertTrue("faultString", faultString != null);
+            assertEquals("faultString value", "my error", faultString.getFirstChild().getNodeValue());
+            
+        } finally {
+            conn.disconnect();
+        }
+    }
 
-            out.flush();
-            out.close();
+    private Document parseMessage(InputSource is) throws Exception {
+        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+        dbf.setNamespaceAware(true);
+        DocumentBuilder db = dbf.newDocumentBuilder();
 
-            boolean found = false;
-            boolean found2 = false;
+        Document doc = db.parse(is);
+        return doc;
+    }
 
-            // FIXME: Simple test is required for now, as CXF has problems
-            BufferedReader in = 
-                new BufferedReader(new InputStreamReader(conn.getInputStream()));
-            String inputLine;
-            while ((inputLine = in.readLine()) != null) {
-                System.out.println(inputLine);
-
-                if (found == false &&
-                    inputLine.indexOf("foo bar") != -1) {
-                    found = true;
-                }
-                if (found2 == false &&
-                    inputLine.indexOf("Hello") != -1) {
-                    found2 = true;
+    private Element findElement(Element element, String name) {
+        NodeList list = element.getChildNodes();
+        for (int i = 0; i < list.getLength(); i++) {
+            Node child = (Node)list.item(i);
+            if (child instanceof Element) {
+                Element childEl = (Element)child;
+                if (name.equals(childEl.getLocalName())) {
+                    return childEl;
+                } else {
+                    childEl = findElement(childEl, name);
+                    if (childEl != null) {
+                        return childEl;
+                    }
                 }
             }
-            in.close();
-
-            assertTrue("Reply", found);
-
-            if(!found2) {
-                System.out.println("Did not find \"Hello\" in the Response");
+        }
+        return null;
+    }
+    
+    private Text findText(Element element, String value) {
+        NodeList list = element.getChildNodes();
+        for (int i = 0; i < list.getLength(); i++) {
+            Node child = (Node)list.item(i);
+            if (child instanceof Text) {
+                Text text = (Text)child;
+                if (text.getData().indexOf(value) != -1) {
+                    return text;
+                }
+            } else if (child instanceof Element) {
+                Element childEl = (Element)child;
+                Text text = findText(childEl, value);
+                if (text != null) {
+                    return text;
+                }
             }
+        }   
+        return null;
+    }
+    
+    private String call(InputStream requestInput, HttpURLConnection conn) throws IOException
{        
+        conn.setDoOutput(true);
+        conn.setDoInput(true);
+        conn.setUseCaches(false);
+        conn.setRequestMethod("POST");
+        conn.setRequestProperty("Content-Type", "text/xml");
+
+        OutputStream out = conn.getOutputStream();
+
+        byte[] data = new byte[1024];
+        int read = 0;
+        while ((read = requestInput.read(data, 0, data.length)) != -1) {
+            out.write(data, 0, read);
+        }
 
-            /* Better test, disabled for now
-            InputSource is = new InputSource(conn.getInputStream());
-
-            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
-            dbf.setNamespaceAware(true);
-            DocumentBuilder db = dbf.newDocumentBuilder();
-
-            Document doc = db.parse(is);
-            
-            NodeList nodes = doc.getElementsByTagNameNS("http://apache.org/hello_world_soap_http/types",
-                                                        "responseType");
-            assertEquals(1, nodes.getLength());
-
-            Element element = (Element)nodes.item(0);
-
-            assertTrue(element.getFirstChild() != null);
+        requestInput.close();
 
-            assertEquals("Hello foo bar", element.getFirstChild().getNodeValue());
-            */
+        out.flush();
+        out.close();
 
-        } finally {
-            conn.disconnect();
+        InputStream is = null;
+        
+        try {
+            is = conn.getInputStream();
+        } catch (IOException e) {
+            is = conn.getErrorStream();
+        }
+        
+        StringBuffer buf = new StringBuffer();
+        BufferedReader in = new BufferedReader(new InputStreamReader(is));
+        String inputLine;
+        while ((inputLine = in.readLine()) != null) {
+            System.out.println(inputLine);
+            buf.append(inputLine);
         }
+        in.close();
+        
+        return buf.toString();
     }
 
+    
     @Test
     public void testWSDL() throws Exception {
         URL url = new URL(baseURL + "JAXWSBeanService/JAXWSBean?wsdl");

Added: geronimo/server/trunk/testsuite/webservices-testsuite/jaxws-tests/jaxws-ejb/src/test/resources/request2.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/testsuite/webservices-testsuite/jaxws-tests/jaxws-ejb/src/test/resources/request2.xml?rev=574375&view=auto
==============================================================================
--- geronimo/server/trunk/testsuite/webservices-testsuite/jaxws-tests/jaxws-ejb/src/test/resources/request2.xml
(added)
+++ geronimo/server/trunk/testsuite/webservices-testsuite/jaxws-tests/jaxws-ejb/src/test/resources/request2.xml
Mon Sep 10 14:10:28 2007
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
+   <soap:Body>
+      <greetMeFault xmlns="http://test.geronimo.apache.org/">
+         <arg0>ignore</arg0>
+      </greetMeFault>
+   </soap:Body>
+</soap:Envelope>



Mime
View raw message