You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2012/02/17 02:56:14 UTC

svn commit: r1245288 - /camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfProducerTest.java

Author: ningjiang
Date: Fri Feb 17 01:56:13 2012
New Revision: 1245288

URL: http://svn.apache.org/viewvc?rev=1245288&view=rev
Log:
Added a cxf producer connect refuse test which is based on the mailing list

Modified:
    camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfProducerTest.java

Modified: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfProducerTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfProducerTest.java?rev=1245288&r1=1245287&r2=1245288&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfProducerTest.java (original)
+++ camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfProducerTest.java Fri Feb 17 01:56:13 2012
@@ -16,17 +16,28 @@
  */
 package org.apache.camel.component.cxf;
 
+import java.io.IOException;
+import java.net.ConnectException;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.Source;
 import javax.xml.ws.Endpoint;
 
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import org.xml.sax.SAXException;
+
 import org.apache.camel.CamelContext;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.ProducerTemplate;
 import org.apache.camel.component.cxf.common.message.CxfConstants;
+import org.apache.camel.component.cxf.converter.CxfPayloadConverter;
+import org.apache.camel.converter.jaxp.XmlConverter;
 import org.apache.camel.impl.DefaultCamelContext;
 import org.apache.cxf.bus.CXFBusFactory;
 import org.apache.cxf.endpoint.Client;
@@ -121,6 +132,18 @@ public class CxfProducerTest extends Ass
     public void testInvokingAWrongServer() throws Exception {
         Exchange reply = sendSimpleMessage(getWrongEndpointUri());
         assertNotNull("We should get the exception here", reply.getException());
+        assertTrue(reply.getException().getCause() instanceof ConnectException);
+        
+        
+        //Test the data format PAYLOAD
+        reply = sendSimpleMessageWithPayloadMessage(getWrongEndpointUri() + "&dataFormat=PAYLOAD");
+        assertNotNull("We should get the exception here", reply.getException());
+        assertTrue(reply.getException().getCause() instanceof ConnectException);
+        
+        //Test the data format MESSAGE
+        reply = sendSimpleMessageWithRawMessage(getWrongEndpointUri() + "&dataFormat=MESSAGE");
+        assertNotNull("We should get the exception here", reply.getException());
+        assertTrue(reply.getException().getCause() instanceof ConnectException);
     }
 
     @Test
@@ -170,6 +193,33 @@ public class CxfProducerTest extends Ass
         return exchange;
 
     }
+    
+    private Exchange sendSimpleMessageWithRawMessage(String endpointUri) {
+        Exchange exchange = template.request(endpointUri, new Processor() {
+            public void process(final Exchange exchange) {
+                exchange.getIn().setBody("<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
+                                 + "<soap:Body><ns1:echo xmlns:ns1=\"http://cxf.component.camel.apache.org/\">"
+                                 + "<arg0 xmlns=\"http://cxf.component.camel.apache.org/\">hello world</arg0>"
+                                 + "</ns1:echo></soap:Body></soap:Envelope>");
+            }
+        });
+        return exchange;
+    }
+    
+    private Exchange sendSimpleMessageWithPayloadMessage(String endpointUri) {
+        Exchange exchange = template.request(endpointUri, new Processor() {
+            public void process(final Exchange exchange) throws Exception {
+                Document document = new XmlConverter().toDOMDocument("<ns1:echo xmlns:ns1=\"http://cxf.component.camel.apache.org/\">"
+                                 + "<arg0 xmlns=\"http://cxf.component.camel.apache.org/\">hello world</arg0>"
+                                 + "</ns1:echo>");
+                exchange.getIn().setBody(CxfPayloadConverter.documentToCxfPayload(document, exchange));
+                exchange.getIn().setHeader(CxfConstants.OPERATION_NAME, ECHO_OPERATION);
+                
+            }
+        });
+        return exchange;
+    }
+    
     protected Exchange sendJaxWsMessage() {
         Exchange exchange = template.request(getJaxwsEndpointUri(), new Processor() {
             public void process(final Exchange exchange) {
@@ -182,4 +232,6 @@ public class CxfProducerTest extends Ass
         });
         return exchange;
     }
+    
+    
 }