camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r833381 - in /camel/trunk/components/camel-cxf/src: main/java/org/apache/camel/component/cxf/transport/CamelDestination.java test/java/org/apache/camel/component/cxf/transport/CamelDestinationTest.java
Date Fri, 06 Nov 2009 13:02:21 GMT
Author: ningjiang
Date: Fri Nov  6 13:02:21 2009
New Revision: 833381

URL: http://svn.apache.org/viewvc?rev=833381&view=rev
Log:
CAMEL-2142 added unit test for checkException

Modified:
    camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/transport/CamelDestination.java
    camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/transport/CamelDestinationTest.java

Modified: camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/transport/CamelDestination.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/transport/CamelDestination.java?rev=833381&r1=833380&r2=833381&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/transport/CamelDestination.java
(original)
+++ camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/transport/CamelDestination.java
Fri Nov  6 13:02:21 2009
@@ -86,6 +86,13 @@
         return LOG;
     }
 
+    public void setCheckException(boolean exception) {
+        checkException = exception;
+    }
+    
+    public boolean isCheckException() {
+        return checkException;
+    }
     /**
      * @param inMessage the incoming message
      * @return the inbuilt backchannel

Modified: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/transport/CamelDestinationTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/transport/CamelDestinationTest.java?rev=833381&r1=833380&r2=833381&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/transport/CamelDestinationTest.java
(original)
+++ camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/transport/CamelDestinationTest.java
Fri Nov  6 13:02:21 2009
@@ -23,7 +23,9 @@
 import javax.xml.namespace.QName;
 
 import org.apache.camel.CamelContext;
+import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.impl.DefaultCamelContext;
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusFactory;
@@ -46,6 +48,7 @@
     protected RouteBuilder createRouteBuilder() {
         return new RouteBuilder() {
             public void configure() {
+                onException(RuntimeCamelException.class).handled(true).to("mock:error");
                 from("direct:Producer").to("direct:EndpointA");
             }
         };
@@ -136,7 +139,7 @@
         String reponse = new String(bytes);
         assertEquals("The reponse date should be equals", content, reponse);
     }
-
+    
     @Test
     public void testRoundTripDestination() throws Exception {
 
@@ -170,6 +173,8 @@
                 }
             }
         };
+        MockEndpoint error = (MockEndpoint)context.getEndpoint("mock:error");
+        error.expectedMessageCount(0);
         //this call will active the camelDestination
         destination.setMessageObserver(observer);
         // set is oneway false for get response from destination
@@ -179,7 +184,60 @@
         // create the thread to handler the Destination incomming message
 
         verifyReceivedMessage(inMessage, "HelloWorld Response");
+        error.assertIsSatisfied();
+        destination.shutdown();
+    }
+    
+    @Test
+    public void testRoundTripDestinationWithFault() throws Exception {
+
+        inMessage = null;
+        EndpointInfo conduitEpInfo = new EndpointInfo();
+        conduitEpInfo.setAddress("camel://direct:Producer");
+        // set up the conduit send to be true
+        CamelConduit conduit = setupCamelConduit(conduitEpInfo, true, false);
+        final Message outMessage = new MessageImpl();
+
+        endpointInfo.setAddress("camel://direct:EndpointA");
+        final CamelDestination destination = setupCamelDestination(endpointInfo, true);
+        destination.setCheckException(true);
+
+        // set up MessageObserver for handlering the conduit message
+        MessageObserver observer = new MessageObserver() {
+            public void onMessage(Message m) {
+                try {
+                    Exchange exchange = new ExchangeImpl();
+                    exchange.setInMessage(m);
+                    m.setExchange(exchange);
+                    verifyReceivedMessage(m, "HelloWorld");
+                    //verifyHeaders(m, outMessage);
+                    // setup the message for
+                    Conduit backConduit;
+                    backConduit = destination.getBackChannel(m, null, null);
+                    // wait for the message to be got from the conduit
+                    Message replyMessage = new MessageImpl();
+                    replyMessage.setContent(Exception.class, new RuntimeCamelException());
+                    sendoutMessage(backConduit, replyMessage, true, "HelloWorld Fault");
+                } catch (Exception e) {
+                    throw new RuntimeException(e);
+                }
+            }
+        };
+        
+        MockEndpoint error = (MockEndpoint)context.getEndpoint("mock:error");
+        error.expectedMessageCount(1);
+        
+        //this call will active the camelDestination
+        destination.setMessageObserver(observer);
+        // set is oneway false for get response from destination
+        // need to use another thread to send the request message
+        sendoutMessage(conduit, outMessage, false, "HelloWorld");
+        // wait for the message to be got from the destination,
+        // create the thread to handler the Destination incomming message
 
+        verifyReceivedMessage(inMessage, "HelloWorld Fault");
+        error.assertIsSatisfied();
+        
         destination.shutdown();
     }
 



Mime
View raw message