camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r725652 - /activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SetExchangePatternTest.java
Date Thu, 11 Dec 2008 10:48:33 GMT
Author: jstrachan
Date: Thu Dec 11 02:48:32 2008
New Revision: 725652

URL: http://svn.apache.org/viewvc?rev=725652&view=rev
Log:
added a few more tests and examples to CAMEL-1171

Modified:
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SetExchangePatternTest.java

Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SetExchangePatternTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SetExchangePatternTest.java?rev=725652&r1=725651&r2=725652&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SetExchangePatternTest.java
(original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SetExchangePatternTest.java
Thu Dec 11 02:48:32 2008
@@ -17,67 +17,82 @@
 package org.apache.camel.processor;
 
 import org.apache.camel.ContextTestSupport;
-import org.apache.camel.Exchange;
 import org.apache.camel.ExchangePattern;
-import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 
 public class SetExchangePatternTest extends ContextTestSupport {
-    
-    private void sendMessage(String uri, final ExchangePattern ep, final String message)
{
-        template.send(uri, new Processor() {
-            public void process(Exchange exchange) throws Exception {
-                exchange.setPattern(ep); 
-                exchange.getIn().setBody(message);
-            }
-            
-        });
+
+    public void testInvokeWithInOut() throws Exception {
+        assertMessageReceivedWithPattern("direct:invokeWithInOut", ExchangePattern.InOut);
+    }
+
+    public void testInvokeWithInOnly() throws Exception {
+        assertMessageReceivedWithPattern("direct:invokeWithInOnly", ExchangePattern.InOnly);
     }
-   
+
     public void testSetInOut() throws Exception {
-        MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:result", MockEndpoint.class);
-        resultEndpoint.expectedBodiesReceived("InOnlyMessage");        
-        sendMessage("direct:inOnly", ExchangePattern.InOnly, "InOnlyMessage");
-        resultEndpoint.assertIsSatisfied();
-        assertEquals("The exchange pattern should be InOut", resultEndpoint.getExchanges().get(0).getPattern(),
ExchangePattern.InOut);
+        assertMessageReceivedWithPattern("direct:inOnly", ExchangePattern.InOut);
     }
-    
+
+    public void testSetInOutAsToParam() throws Exception {
+        assertMessageReceivedWithPattern("direct:inOnlyAsToParam", ExchangePattern.InOnly);
+    }
+
     public void testSetInOnly() throws Exception {
-        MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:result", MockEndpoint.class);
-        resultEndpoint.expectedBodiesReceived("InOutMessage");        
-        sendMessage("direct:inOut", ExchangePattern.InOut, "InOutMessage");
-        resultEndpoint.assertIsSatisfied();
-        assertEquals("The exchange pattern should be InOnly", resultEndpoint.getExchanges().get(0).getPattern(),
ExchangePattern.InOnly);
+        assertMessageReceivedWithPattern("direct:inOut", ExchangePattern.InOnly);
     }
     
     public void testSetRobustInOnly() throws Exception {
-        MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:result", MockEndpoint.class);
-        resultEndpoint.expectedBodiesReceived("InOutMessage");        
-        sendMessage("direct:inOut1", ExchangePattern.InOut, "InOutMessage");
-        resultEndpoint.assertIsSatisfied();
-        assertEquals("The exchange pattern should be InOnly", resultEndpoint.getExchanges().get(0).getPattern(),
ExchangePattern.RobustInOnly);
+        assertMessageReceivedWithPattern("direct:inOut1", ExchangePattern.RobustInOnly);
     }
     
     public void testSetInOnly2() throws Exception {
-        MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:result", MockEndpoint.class);
-        resultEndpoint.expectedBodiesReceived("InOutMessage");        
-        sendMessage("direct:inOut2", ExchangePattern.InOut, "InOutMessage");
+        assertMessageReceivedWithPattern("direct:inOut2", ExchangePattern.InOnly);
+    }
+
+
+    protected void assertMessageReceivedWithPattern(String sendUri, ExchangePattern expectedPattern)
throws InterruptedException {
+        ExchangePattern sendPattern;
+        switch (expectedPattern) {
+            case InOut:
+                sendPattern = ExchangePattern.InOnly;
+                break;
+            case InOnly:
+            case RobustInOnly:
+                sendPattern = ExchangePattern.InOut;
+                break;
+            default:
+                sendPattern = ExchangePattern.InOnly;
+        }
+
+        MockEndpoint resultEndpoint = getMockEndpoint("mock:result");
+        String expectedBody = "InOnlyMessage";
+        resultEndpoint.expectedBodiesReceived(expectedBody);
+        template.sendBody(sendUri, sendPattern, expectedBody);
         resultEndpoint.assertIsSatisfied();
-        assertEquals("The exchange pattern should be InOnly", resultEndpoint.getExchanges().get(0).getPattern(),
ExchangePattern.InOnly);
+        ExchangePattern actualPattern = resultEndpoint.getExchanges().get(0).getPattern();
+        assertEquals("received exchange pattern", actualPattern, expectedPattern);
     }
-    
+
+
     protected RouteBuilder createRouteBuilder() {
         return new RouteBuilder() {
             public void configure() {
              // START SNIPPET: example
-                //Set the exchange pattern to InOut, then send it from direct:inOnly to mock:result
endpoint
+                // Send to an endpoint using InOut
+                from("direct:invokeWithInOut").inOut("mock:result");
+                // Send to an endpoint using InOut
+                from("direct:invokeWithInOnly").inOnly("mock:result");
+                // Set the exchange pattern to InOut, then send it from direct:inOnly to
mock:result endpoint
                 from("direct:inOnly").inOut().to("mock:result");
-                //Set the exchange pattern to InOut, then send it from direct:inOut to mock:result
endpoint               
+                // Or we can pass the pattern as a parameter
+                from("direct:inOnlyAsToParam").to(ExchangePattern.InOnly, "mock:result");
+                // Set the exchange pattern to InOut, then send it from direct:inOut to mock:result
endpoint
                 from("direct:inOut").setExchangePattern(ExchangePattern.InOnly).to("mock:result");
-                //Send the exchange from direct:inOut1 to mock:result with setting the exchange
pattern to be RobustInOnly
+                // Send the exchange from direct:inOut1 to mock:result with setting the exchange
pattern to be RobustInOnly
                 from("direct:inOut1").to(ExchangePattern.RobustInOnly, "mock:result");
-                //Send the exchange from direct:inOut2 to mock:result with setting the exchange
pattern to be InOnly
+                // Send the exchange from direct:inOut2 to mock:result with setting the exchange
pattern to be InOnly
                 from("direct:inOut2").inOnly("mock:result");
              // END SNIPPET: example   
             }



Mime
View raw message