Author: ningjiang
Date: Thu Dec 11 05:21:40 2008
New Revision: 725680

URL: http://svn.apache.org/viewvc?rev=725680&view=rev
Log:
Merged revisions 725652,725660 via svnmerge from 
https://svn.apache.org/repos/asf/activemq/camel/trunk

........
  r725652 | jstrachan | 2008-12-11 18:48:32 +0800 (Thu, 11 Dec 2008) | 1 line
  
  added a few more tests and examples to CAMEL-1171
........
  r725660 | jstrachan | 2008-12-11 19:07:48 +0800 (Thu, 11 Dec 2008) | 1 line
  
  added a few more tests and examples to CAMEL-1171 and reformatted the test a 
little to act as slightly more clear snippets on the different permutations 
available
........

Modified:
    activemq/camel/branches/camel-1.x/   (props changed)
    
activemq/camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/model/InOutType.java
   (props changed)
    
activemq/camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/processor/SetExchangePatternTest.java
    
activemq/camel/branches/camel-1.x/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/setExchangePattern.xml

Propchange: activemq/camel/branches/camel-1.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Dec 11 05:21:40 2008
@@ -1 +1 @@
-/activemq/camel/trunk:709850,711200,711206,711219-711220,711523,711531,711756,711784,711859,711874,711962,711971,712064,712119,712148,712662,712692,712925,713013,713107,713136,713273,713290,713292,713295,713314,713475,713625,713932,713944,714032,717965,717989,718242,718273,718312-718515,719163-719184,719334,719339,719524,719662,719848,719851,719855,719864,719978-719979,720207,720435-720437,720806,721272,721331,721333-721334,721360,721669,721764,721813,721985,722005,722070,722110,722415,722438,722726,722845,722878,723264,723314,723325-723327,723409,723835,723966,724122,724619,724681,725040,725309-725320,725340,725351,725569-725572,725612
+/activemq/camel/trunk:709850,711200,711206,711219-711220,711523,711531,711756,711784,711859,711874,711962,711971,712064,712119,712148,712662,712692,712925,713013,713107,713136,713273,713290,713292,713295,713314,713475,713625,713932,713944,714032,717965,717989,718242,718273,718312-718515,719163-719184,719334,719339,719524,719662,719848,719851,719855,719864,719978-719979,720207,720435-720437,720806,721272,721331,721333-721334,721360,721669,721764,721813,721985,722005,722070,722110,722415,722438,722726,722845,722878,723264,723314,723325-723327,723409,723835,723966,724122,724619,724681,725040,725309-725320,725340,725351,725569-725572,725612,725652-725660

Propchange: activemq/camel/branches/camel-1.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Propchange: 
activemq/camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/model/InOutType.java
            ('svn:mergeinfo' removed)

Modified: 
activemq/camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/processor/SetExchangePatternTest.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/processor/SetExchangePatternTest.java?rev=725680&r1=725679&r2=725680&view=diff
==============================================================================
--- 
activemq/camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/processor/SetExchangePatternTest.java
 (original)
+++ 
activemq/camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/processor/SetExchangePatternTest.java
 Thu Dec 11 05:21:40 2008
@@ -17,69 +17,91 @@
 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 testInOut() throws Exception {
+        assertMessageReceivedWithPattern("direct:testInOut", 
ExchangePattern.InOut);
     }
-   
-    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);
+
+    public void testInOnly() throws Exception {
+        assertMessageReceivedWithPattern("direct:testInOnly", 
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);
+
+    public void testSetToInOnlyThenTo() throws Exception {
+        assertMessageReceivedWithPattern("direct:testSetToInOnlyThenTo", 
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);
+
+    public void testSetToInOutThenTo() throws Exception {
+        assertMessageReceivedWithPattern("direct:testSetToInOutThenTo", 
ExchangePattern.InOut);
+    }
+
+    public void testToWithInOnlyParam() throws Exception {
+        assertMessageReceivedWithPattern("direct:testToWithInOnlyParam", 
ExchangePattern.InOnly);
     }
-    
-    public void testSetInOnly2() throws Exception {
-        MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:result", 
MockEndpoint.class);
-        resultEndpoint.expectedBodiesReceived("InOutMessage");        
-        sendMessage("direct:inOut2", ExchangePattern.InOut, "InOutMessage");
+
+    public void testToWithInOutParam() throws Exception {
+        assertMessageReceivedWithPattern("direct:testToWithInOutParam", 
ExchangePattern.InOut);
+    }
+
+    public void testToWithRobustInOnlyParam() throws Exception {
+        assertMessageReceivedWithPattern("direct:testToWithRobustInOnlyParam", 
ExchangePattern.RobustInOnly);
+    }
+
+    public void testSetExchangePatternInOnly() throws Exception {
+        
assertMessageReceivedWithPattern("direct:testSetExchangePatternInOnly", 
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
-                from("direct:inOnly").inOut().to("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
-                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
-                from("direct:inOut2").inOnly("mock:result");
-             // END SNIPPET: example   
+                // Send to an endpoint using InOut
+                from("direct:testInOut").inOut("mock:result");
+
+                // Send to an endpoint using InOut
+                from("direct:testInOnly").inOnly("mock:result");
+
+                // Set the exchange pattern to InOut, then send it from 
direct:inOnly to mock:result endpoint
+                
from("direct:testSetToInOnlyThenTo").inOnly().to("mock:result");
+                from("direct:testSetToInOutThenTo").inOut().to("mock:result");
+
+                // Or we can pass the pattern as a parameter to the to() method
+                
from("direct:testToWithInOnlyParam").to(ExchangePattern.InOnly, "mock:result");
+                from("direct:testToWithInOutParam").to(ExchangePattern.InOut, 
"mock:result");
+                
from("direct:testToWithRobustInOnlyParam").to(ExchangePattern.RobustInOnly, 
"mock:result");
+
+                // Set the exchange pattern to InOut, then send it on
+                
from("direct:testSetExchangePatternInOnly").setExchangePattern(ExchangePattern.InOnly).to("mock:result");
+             // END SNIPPET: example
             }
         };
     }

Modified: 
activemq/camel/branches/camel-1.x/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/setExchangePattern.xml
URL: 
http://svn.apache.org/viewvc/activemq/camel/branches/camel-1.x/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/setExchangePattern.xml?rev=725680&r1=725679&r2=725680&view=diff
==============================================================================
--- 
activemq/camel/branches/camel-1.x/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/setExchangePattern.xml
 (original)
+++ 
activemq/camel/branches/camel-1.x/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/setExchangePattern.xml
 Thu Dec 11 05:21:40 2008
@@ -23,31 +23,50 @@
     ">
 
   <!-- START SNIPPET: example -->
-  <camelContext id="camel" 
xmlns="http://activemq.apache.org/camel/schema/spring";>
-    <!-- Set the exchange pattern to InOut, then send it from direct:inOnly to 
mock:result endpoint -->
+  <camelContext xmlns="http://activemq.apache.org/camel/schema/spring";>
+    <!-- Send the exchange as InOnly -->
     <route>
-      <from uri="direct:inOnly"/>
-      <setExchangePattern pattern="InOut"/>            
-      <to uri="mock:result"/>      
+      <from uri="direct:testInOut"/>
+      <inOut uri="mock:result"/>
+    </route>
+
+    <!-- Send the exchange as InOnly -->
+    <route>
+      <from uri="direct:testInOnly"/>
+      <inOnly uri="mock:result"/>
     </route>
 
-    <!-- Set the exchange pattern to InOnly, then send it from direct:inOut to 
mock:result endpoint -->
+
+    <!-- lets set the exchange pattern then send it on -->
     <route>
-      <from uri="direct:inOut"/>
+      <from uri="direct:testSetToInOnlyThenTo"/>
       <setExchangePattern pattern="InOnly"/>
-      <to uri="mock:result"/> 
+      <to uri="mock:result"/>      
     </route>
-    
-    <!-- Send the exchange from direct:inOut1 to mock:result with setting the 
exchange pattern to be RobustInOnly-->
     <route>
-      <from uri="direct:inOut1"/>
-      <to uri="mock:result" pattern="RobustInOnly"/>
+      <from uri="direct:testSetToInOutThenTo"/>
+      <setExchangePattern pattern="InOut"/>
+      <to uri="mock:result"/>
     </route>
-    
-    <!-- Send the exchange from direct:inOut2 to mock:result with setting the 
exchange pattern to be InOnly -->
     <route>
-      <from uri="direct:inOut2"/>
-      <inOnly uri="mock:result"/>
+      <from uri="direct:testSetExchangePatternInOnly"/>
+      <setExchangePattern pattern="InOnly"/>
+      <to uri="mock:result"/>
+    </route>
+
+
+    <!-- Lets pass the pattern as an argument in the to element -->
+    <route>
+      <from uri="direct:testToWithInOnlyParam"/>
+      <to uri="mock:result" pattern="InOnly"/>
+    </route>
+    <route>
+      <from uri="direct:testToWithInOutParam"/>
+      <to uri="mock:result" pattern="InOut"/>
+    </route>
+    <route>
+      <from uri="direct:testToWithRobustInOnlyParam"/>
+      <to uri="mock:result" pattern="RobustInOnly"/>
     </route>
    </camelContext>
    <!-- END SNIPPET: example -->


Reply via email to