cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r777336 - /cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/dispatch/DispatchClientServerTest.java
Date Fri, 22 May 2009 00:38:14 GMT
Author: dkulp
Date: Fri May 22 00:38:13 2009
New Revision: 777336

URL: http://svn.apache.org/viewvc?rev=777336&view=rev
Log:
Port some more tests from trunk

Modified:
    cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/dispatch/DispatchClientServerTest.java

Modified: cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/dispatch/DispatchClientServerTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/dispatch/DispatchClientServerTest.java?rev=777336&r1=777335&r2=777336&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/dispatch/DispatchClientServerTest.java
(original)
+++ cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/dispatch/DispatchClientServerTest.java
Fri May 22 00:38:13 2009
@@ -20,7 +20,6 @@
 package org.apache.cxf.systest.dispatch;
 
 import java.io.InputStream;
-import java.net.SocketTimeoutException;
 import java.net.URL;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
@@ -40,6 +39,7 @@
 import javax.xml.ws.Response;
 import javax.xml.ws.Service;
 
+import org.w3c.dom.Document;
 import org.w3c.dom.Node;
 
 import org.xml.sax.InputSource;
@@ -49,9 +49,12 @@
 import org.apache.cxf.bus.spring.SpringBusFactory;
 import org.apache.cxf.helpers.DOMUtils;
 import org.apache.cxf.helpers.XMLUtils;
+import org.apache.cxf.interceptor.LoggingInInterceptor;
+import org.apache.cxf.interceptor.LoggingOutInterceptor;
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
 import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
 import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
+import org.apache.hello_world_soap_http.BadRecordLitFault;
 import org.apache.hello_world_soap_http.GreeterImpl;
 import org.apache.hello_world_soap_http.SOAPService;
 import org.apache.hello_world_soap_http.types.GreetMe;
@@ -92,6 +95,23 @@
     public static void startServers() throws Exception {
         assertTrue("server did not launch correctly", launchServer(Server.class));
     }
+    
+    @org.junit.Before
+    public void setUp() {
+        BusFactory.getDefaultBus().getOutInterceptors().add(new LoggingOutInterceptor());
+        BusFactory.getDefaultBus().getInInterceptors().add(new LoggingInInterceptor());
+    }
+    
+    private void waitForFuture(Future fd) throws Exception {
+        int count = 0;
+        while (!fd.isDone()) {
+            ++count;
+            if (count > 500) {
+                fail("Did not finish in 10 seconds");
+            }
+            Thread.sleep(20);
+        }
+    }
 
     @Test
     public void testSOAPMessage() throws Exception {
@@ -141,9 +161,8 @@
         TestSOAPMessageHandler tsmh = new TestSOAPMessageHandler();
         Future f = disp.invokeAsync(soapReqMsg3, tsmh);
         assertNotNull(f);
-        while (!f.isDone()) {
-            // wait
-        }
+        waitForFuture(f);
+        
         String expected3 = "Hello TestSOAPInputMessage3";
         assertEquals("Response should be : Hello TestSOAPInputMessage3", 
                      expected3, tsmh.getReplyBuffer().trim());
@@ -206,9 +225,7 @@
         TestDOMSourceHandler tdsh = new TestDOMSourceHandler();
         Future fd = disp.invokeAsync(domReqMsg3, tdsh);
         assertNotNull(fd);
-        while (!fd.isDone()) {
-            // wait
-        }
+        waitForFuture(fd);
         String expected3 = "Hello TestSOAPInputMessage3";
         assertEquals("Response should be : Hello TestSOAPInputMessage3", expected3, 
                      tdsh.getReplyBuffer().trim());
@@ -216,6 +233,7 @@
     
     @Test
     public void testDOMSourcePAYLOAD() throws Exception {
+        
         /*URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
         assertNotNull(wsdl);
 
@@ -238,8 +256,15 @@
         
         assertNotNull(domResMsg);
         String expected = "Hello TestSOAPInputMessage";
-        assertEquals("Response should be : Hello TestSOAPInputMessage", expected, domResMsg.getNode()
-            .getTextContent().trim());
+        
+        Node node = domResMsg.getNode();
+        assertNotNull(node);
+        if (node instanceof Document) {
+            node = ((Document)node).getDocumentElement();
+        }
+        String content = node.getTextContent();
+        assertNotNull(content);
+        assertEquals("Response should be : Hello TestSOAPInputMessage", expected, content.trim());
 
         InputStream is1 = getClass().getResourceAsStream("resources/GreetMeDocLiteralReq1.xml");
         SOAPMessage soapReqMsg1 = MessageFactory.newInstance().createMessage(null, is1);
@@ -257,8 +282,16 @@
         DOMSource domRespMsg2 = (DOMSource)response.get();
         assertNotNull(domRespMsg2);
         String expected2 = "Hello TestSOAPInputMessage2";
-        assertEquals("Response should be : Hello TestSOAPInputMessage2", expected2, domRespMsg2.getNode()
-            .getTextContent().trim());
+        
+        node = domRespMsg2.getNode();
+        assertNotNull(node);
+        if (node instanceof Document) {
+            node = ((Document)node).getDocumentElement();
+        }
+        content = node.getTextContent();
+        assertNotNull(content);
+
+        assertEquals("Response should be : Hello TestSOAPInputMessage2", expected2, content.trim());
 
         InputStream is3 = getClass().getResourceAsStream("resources/GreetMeDocLiteralReq3.xml");
         SOAPMessage soapReqMsg3 = MessageFactory.newInstance().createMessage(null, is3);
@@ -268,9 +301,7 @@
         TestDOMSourceHandler tdsh = new TestDOMSourceHandler();
         Future fd = disp.invokeAsync(domReqMsg3, tdsh);
         assertNotNull(fd);
-        while (!fd.isDone()) {
-            // wait
-        }
+        waitForFuture(fd);
         String expected3 = "Hello TestSOAPInputMessage3";
         assertEquals("Response should be : Hello TestSOAPInputMessage3", 
                      expected3, tdsh.getReplyBuffer().trim());
@@ -310,12 +341,25 @@
         TestJAXBHandler tjbh = new TestJAXBHandler();
         Future fd = disp.invokeAsync(greetMe, tjbh);
         assertNotNull(fd);
-        while (!fd.isDone()) {
-            // wait
-        }
+        waitForFuture(fd);
+
         String responseValue3 = ((GreetMeResponse)tjbh.getResponse()).getResponseType();
         assertTrue("Expected string, " + expected, expected.equals(responseValue3));
         
+        org.apache.hello_world_soap_http.types.TestDocLitFault fr = 
+            new  org.apache.hello_world_soap_http.types.TestDocLitFault();
+        fr.setFaultType(BadRecordLitFault.class.getSimpleName());
+            
+        tjbh = new TestJAXBHandler();
+        fd = disp.invokeAsync(fr, tjbh);
+        waitForFuture(fd);
+        try {
+            fd.get();
+            fail("did not get expected exception");
+        } catch (ExecutionException ex) {
+            //expected
+        }
+        
         GreetMeLater later = new GreetMeLater();
         later.setRequestType(1000);
         
@@ -327,7 +371,7 @@
             o.get(10, TimeUnit.SECONDS);
             fail("Should have gotten a SocketTimeoutException");
         } catch (ExecutionException ex) {
-            assertTrue(ex.getCause() instanceof SocketTimeoutException);
+            //ignore - expected
         }
 
         later.setRequestType(20000);
@@ -433,9 +477,8 @@
         TestSAXSourceHandler tssh = new TestSAXSourceHandler();
         Future fd = disp.invokeAsync(saxSourceReq3, tssh);
         assertNotNull(fd);
-        while (!fd.isDone()) {
-            //wait
-        }
+        waitForFuture(fd);
+
         String expected3 = "Hello TestSOAPInputMessage3";
         SAXSource saxSourceResp3 = tssh.getSAXSource();
         assertNotNull(saxSourceResp3);
@@ -502,9 +545,8 @@
         TestSAXSourceHandler tssh = new TestSAXSourceHandler();
         Future fd = disp.invokeAsync(saxSourceReq3, tssh);
         assertNotNull(fd);
-        while (!fd.isDone()) {
-            //wait
-        }
+        waitForFuture(fd);
+
         String expected3 = "Hello TestSOAPInputMessage3";
         SAXSource saxSourceResp3 = tssh.getSAXSource();
         assertNotNull(saxSourceResp3);
@@ -549,9 +591,8 @@
         TestStreamSourceHandler tssh = new TestStreamSourceHandler();
         Future fd = disp.invokeAsync(streamSourceReq3, tssh);
         assertNotNull(fd);
-        while (!fd.isDone()) {
-            //wait
-        }
+        waitForFuture(fd);
+
         String expected3 = "Hello TestSOAPInputMessage3";
         StreamSource streamSourceResp3 = tssh.getStreamSource();
         assertNotNull(streamSourceResp3);
@@ -600,9 +641,8 @@
         TestStreamSourceHandler tssh = new TestStreamSourceHandler();
         Future fd = disp.invokeAsync(streamSourceReq3, tssh);
         assertNotNull(fd);
-        while (!fd.isDone()) {
-            //wait
-        }
+        waitForFuture(fd);
+        
         String expected3 = "Hello TestSOAPInputMessage3";
         StreamSource streamSourceResp3 = tssh.getStreamSource();
         assertNotNull(streamSourceResp3);



Mime
View raw message