geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r682742 - in /geronimo/server/trunk/testsuite/webservices-testsuite/jaxrpc-jaxws-tests/jaxrpc-jaxws-war/src/test: java/org/apache/geronimo/testsuite/testset/WSTest.java resources/request3.xml
Date Tue, 05 Aug 2008 15:16:44 GMT
Author: gawor
Date: Tue Aug  5 08:16:43 2008
New Revision: 682742

URL: http://svn.apache.org/viewvc?rev=682742&view=rev
Log:
update the test (related to GERONIMO-3793)

Added:
    geronimo/server/trunk/testsuite/webservices-testsuite/jaxrpc-jaxws-tests/jaxrpc-jaxws-war/src/test/resources/request3.xml
  (with props)
Modified:
    geronimo/server/trunk/testsuite/webservices-testsuite/jaxrpc-jaxws-tests/jaxrpc-jaxws-war/src/test/java/org/apache/geronimo/testsuite/testset/WSTest.java

Modified: geronimo/server/trunk/testsuite/webservices-testsuite/jaxrpc-jaxws-tests/jaxrpc-jaxws-war/src/test/java/org/apache/geronimo/testsuite/testset/WSTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/testsuite/webservices-testsuite/jaxrpc-jaxws-tests/jaxrpc-jaxws-war/src/test/java/org/apache/geronimo/testsuite/testset/WSTest.java?rev=682742&r1=682741&r2=682742&view=diff
==============================================================================
--- geronimo/server/trunk/testsuite/webservices-testsuite/jaxrpc-jaxws-tests/jaxrpc-jaxws-war/src/test/java/org/apache/geronimo/testsuite/testset/WSTest.java
(original)
+++ geronimo/server/trunk/testsuite/webservices-testsuite/jaxrpc-jaxws-tests/jaxrpc-jaxws-war/src/test/java/org/apache/geronimo/testsuite/testset/WSTest.java
Tue Aug  5 08:16:43 2008
@@ -19,9 +19,11 @@
 package org.apache.geronimo.testsuite.testset;
 
 import java.io.BufferedReader;
+import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.OutputStream;
+import java.io.StringReader;
 import java.net.HttpURLConnection;
 import java.net.URL;
 import java.util.Iterator;
@@ -31,9 +33,16 @@
 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 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 WSTest extends TestSupport {
@@ -42,67 +51,121 @@
     
     @Test
     public void testJAXRPCInvocation() throws Exception {
-        testInvocation("servlet1", "/request1.xml");
+        Document doc = getResponse("/servlet1", "/request1.xml");
+        Text replyText = findText(doc.getDocumentElement(), "Hello foo bar");
+        assertTrue("reply message", replyText != null);
     }
 
     @Test
     public void testJAXWSInvocation() throws Exception {
-        testInvocation("servlet2", "/request2.xml");
+        Document doc = getResponse("/servlet1", "/request2.xml");
+        Text replyText = findText(doc.getDocumentElement(), "Hello foo bar");
+        if (replyText == null) {
+            // XXX: work-around for CXF, wants <requestType> to be unqualified
+            doc = getResponse("/servlet1", "/request3.xml");
+            replyText = findText(doc.getDocumentElement(), "Hello foo bar");            
+        }
+        assertTrue("reply message", replyText != null);
     }
 
-    private void testInvocation(String servlet, String request) throws Exception {
+    private Document getResponse(String servlet, String requestFile) throws Exception {
         String warName = System.getProperty("webAppName");
         assertNotNull("Web application name not specified", warName);
         
-        InputStream requestInput = WSTest.class.getResourceAsStream(request);
+        InputStream requestInput = WSTest.class.getResourceAsStream(requestFile);
         assertNotNull("SOAP request not specified", requestInput);
                 
-        URL url = new URL(baseURL + warName + "/" + servlet);
+        URL url = new URL(baseURL + warName + servlet);
         HttpURLConnection conn = (HttpURLConnection) url.openConnection();
-        conn.setConnectTimeout(30 * 1000);
-        conn.setReadTimeout(30 * 1000);
         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);
-            }
-
-            requestInput.close();
-
-            out.flush();
-            out.close();
-
-            boolean found = false;
+            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);
+            
+            return doc;
+            
+        } finally {
+            conn.disconnect();
+        }
+    }
+    
+    private Document parseMessage(InputSource is) throws Exception {
+        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+        dbf.setNamespaceAware(true);
+        DocumentBuilder db = dbf.newDocumentBuilder();
 
-            BufferedReader in = 
-                new BufferedReader(new InputStreamReader(conn.getInputStream()));
-            String inputLine;
-            while ((inputLine = in.readLine()) != null) {
-                System.out.println(inputLine);
-
-                if (found == false &&
-                    inputLine.indexOf("Hello foo bar") != -1) {
-                    found = true;
+        Document doc = db.parse(is);
+        return doc;
+    }
+    
+    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;
                 }
             }
-            in.close();
+        }   
+        return null;
+    }
+    
+    private String call(InputStream requestInput, HttpURLConnection conn) throws IOException
{        
+        conn.setConnectTimeout(30 * 1000);
+        conn.setReadTimeout(30 * 1000);
+        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);
+        }
 
-            assertTrue("Reply", found);
+        requestInput.close();
 
-        } finally {
-            conn.disconnect();
+        out.flush();
+        out.close();
+
+        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();
+        System.out.println("--");
+        
+        return buf.toString();
     }
-
+    
     @Test
     public void testJAXRPCWSDL() throws Exception {
         testWSDL("servlet1", new String [] {"greetMe"});

Added: geronimo/server/trunk/testsuite/webservices-testsuite/jaxrpc-jaxws-tests/jaxrpc-jaxws-war/src/test/resources/request3.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/testsuite/webservices-testsuite/jaxrpc-jaxws-tests/jaxrpc-jaxws-war/src/test/resources/request3.xml?rev=682742&view=auto
==============================================================================
--- geronimo/server/trunk/testsuite/webservices-testsuite/jaxrpc-jaxws-tests/jaxrpc-jaxws-war/src/test/resources/request3.xml
(added)
+++ geronimo/server/trunk/testsuite/webservices-testsuite/jaxrpc-jaxws-tests/jaxrpc-jaxws-war/src/test/resources/request3.xml
Tue Aug  5 08:16:43 2008
@@ -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>
+     <greetMe xmlns="http://apache.org/greeter_control/types">
+       <requestType>foo bar</requestType>
+     </greetMe>
+   </soap:Body>
+</soap:Envelope>

Propchange: geronimo/server/trunk/testsuite/webservices-testsuite/jaxrpc-jaxws-tests/jaxrpc-jaxws-war/src/test/resources/request3.xml
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message