camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r950535 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/component/mock/MockEndpoint.java test/java/org/apache/camel/component/mock/MockAsBeanTest.java
Date Wed, 02 Jun 2010 12:32:34 GMT
Author: ningjiang
Date: Wed Jun  2 12:32:33 2010
New Revision: 950535

URL: http://svn.apache.org/viewvc?rev=950535&view=rev
Log:
CAMEL-1915 Added returnReplyBody and returnReplyHeader into MockEndpoint

Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/mock/MockEndpoint.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/component/mock/MockAsBeanTest.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/mock/MockEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/mock/MockEndpoint.java?rev=950535&r1=950534&r2=950535&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/mock/MockEndpoint.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/mock/MockEndpoint.java
Wed Jun  2 12:32:33 2010
@@ -41,6 +41,7 @@ import org.apache.camel.Predicate;
 import org.apache.camel.Processor;
 import org.apache.camel.Producer;
 import org.apache.camel.builder.ExpressionClause;
+import org.apache.camel.builder.ProcessorBuilder;
 import org.apache.camel.impl.DefaultEndpoint;
 import org.apache.camel.impl.DefaultProducer;
 import org.apache.camel.spi.BrowsableEndpoint;
@@ -254,6 +255,24 @@ public class MockEndpoint extends Defaul
     public void whenAnyExchangeReceived(Processor processor) {
         this.defaultProcessor = processor;
     }
+    
+    /**
+     * Set the expression which value will be set to the message body
+     * @param expression which is use to set the message body 
+     */
+    public void returnReplyBody(Expression expression) {
+        this.defaultProcessor = ProcessorBuilder.setBody(expression);
+    }
+    
+    /**
+     * Set the expression which value will be set to the message header
+     * @param headerName that will be set value
+     * @param expression which is use to set the message header 
+     */
+    public void returnReplyHeader(String headerName, Expression expression) {
+        this.defaultProcessor = ProcessorBuilder.setHeader(headerName, expression);
+    }
+    
 
     /**
      * Validates that all the available expectations on this endpoint are

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/mock/MockAsBeanTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/mock/MockAsBeanTest.java?rev=950535&r1=950534&r2=950535&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/mock/MockAsBeanTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/mock/MockAsBeanTest.java
Wed Jun  2 12:32:33 2010
@@ -19,6 +19,7 @@ package org.apache.camel.component.mock;
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
+import org.apache.camel.builder.ExpressionBuilder;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.impl.JndiRegistry;
 
@@ -38,7 +39,7 @@ public class MockAsBeanTest extends Cont
     }
 
     // START SNIPPET: e1
-    public void testMockAsBean() throws Exception {
+    public void testMockAsBeanWithWhenAnyExchangeReceived() throws Exception {
         // we should expect to receive the transformed message
         getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
 
@@ -55,8 +56,8 @@ public class MockAsBeanTest extends Cont
 
         assertMockEndpointsSatisfied();
     }
-    // END SNIPPET: e1
-
+    // END SNIPPET: e1    
+    
     @Override
     // START SNIPPET: e2
     protected RouteBuilder createRouteBuilder() throws Exception {
@@ -72,5 +73,31 @@ public class MockAsBeanTest extends Cont
         };
     }
     // END SNIPPET: e2
+    
+   // START SNIPPET: e3
+    public void testMockAsBeanWithReplyBody() throws Exception {
+        // we should expect to receive the transformed message
+        getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
+        
+        foo.returnReplyBody(ExpressionBuilder.simpleExpression("Bye ${body}"));
+
+        template.sendBody("direct:start", "World");
+
+        assertMockEndpointsSatisfied();
+    }
+    // END SNIPPET: e3
+    
+   // START SNIPPET: e4
+    public void testMockAsBeanWithReplyHeader() throws Exception {
+        // we should expect to receive the transformed message
+        getMockEndpoint("mock:result").expectedHeaderReceived("myHeader", "Bye World");
+        
+        foo.returnReplyHeader("myHeader", ExpressionBuilder.simpleExpression("Bye ${body}"));
+
+        template.sendBody("direct:start", "World");
+
+        assertMockEndpointsSatisfied();
+    }
+    // END SNIPPET: e4
 
 }



Mime
View raw message