Author: davsclaus
Date: Mon Apr 27 13:22:41 2009
New Revision: 768969
URL: http://svn.apache.org/viewvc?rev=768969&view=rev
Log:
CAMEL-1558: Added interceptEndpoint to intercept when an exchange is being sent
to the given endpoint.
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptorSimplePredicateTest.java
- copied, changed from r768963,
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptorSimpleLogTest.java
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptorSimplePredicateWithStopTest.java
(with props)
Copied:
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptorSimplePredicateTest.java
(from r768963,
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptorSimpleLogTest.java)
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptorSimplePredicateTest.java?p2=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptorSimplePredicateTest.java&p1=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptorSimpleLogTest.java&r1=768963&r2=768969&rev=768969&view=diff
==============================================================================
---
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptorSimpleLogTest.java
(original)
+++
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptorSimplePredicateTest.java
Mon Apr 27 13:22:41 2009
@@ -17,36 +17,53 @@
package org.apache.camel.processor;
import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Processor;
+import org.apache.camel.Exchange;
import org.apache.camel.builder.RouteBuilder;
/**
* Testing http://camel.apache.org/dsl.html
*/
-public class InterceptorSimpleLogTest extends ContextTestSupport {
+public class InterceptorSimplePredicateTest extends ContextTestSupport {
- public void testInterceptLog() throws Exception {
- getMockEndpoint("mock:result").expectedMessageCount(1);
- getMockEndpoint("mock:first").expectedMessageCount(1);
+ public void testNoIntercept() throws Exception {
+ getMockEndpoint("mock:intercepted").expectedMessageCount(0);
+ getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
}
+ public void testIntercepted() throws Exception {
+ getMockEndpoint("mock:intercepted").expectedMessageCount(1);
+ getMockEndpoint("mock:result").expectedBodiesReceived("This is a test
body");
+
+ template.sendBodyAndHeader("direct:start", "Hello World", "usertype",
"test");
+
+ assertMockEndpointsSatisfied();
+ }
+
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() throws Exception {
// START SNIPPET: e1
- // intercept all incomming routes and log it
- intercept().to("log:received");
+ intercept()
+ .when(header("usertype").isEqualTo("test"))
+ .process(new MyTestServiceProcessor())
+ .to("mock:intercepted");
- // and here we have a couple of routes
- from("direct:start").to("mock:first").to("seda:bar");
-
- from("seda:bar").to("mock:result");
+ // and here is our route
+ from("direct:start").to("seda:bar").to("mock:result");
// END SNIPPET: e1
}
};
}
+ private class MyTestServiceProcessor implements Processor {
+
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setBody("This is a test body");
+ }
+ }
}
\ No newline at end of file
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptorSimplePredicateWithStopTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptorSimplePredicateWithStopTest.java?rev=768969&view=auto
==============================================================================
---
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptorSimplePredicateWithStopTest.java
(added)
+++
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptorSimplePredicateWithStopTest.java
Mon Apr 27 13:22:41 2009
@@ -0,0 +1,61 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.processor;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * Testing http://camel.apache.org/dsl.html
+ */
+public class InterceptorSimplePredicateWithStopTest extends ContextTestSupport
{
+
+ public void testIntercept() throws Exception {
+ getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
+
+ template.sendBodyAndHeader("direct:start", "Hello World", "usertype",
"test");
+ template.sendBody("direct:start", "Hello World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() throws Exception {
+ // START SNIPPET: e1
+ intercept()
+ .when(header("usertype").isEqualTo("test"))
+ // here we use stop() to tell Camel to NOT continue
routing the message.
+ // this let us act as a filter, to drop certain messages.
+ .stop();
+
+ // and here is our route
+ from("direct:start").to("seda:bar").to("mock:result");
+ // END SNIPPET: e1
+ }
+ };
+ }
+
+ private class MyTestServiceProcessor implements Processor {
+
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setBody("This is a test body");
+ }
+ }
+}
\ No newline at end of file
Propchange:
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptorSimplePredicateWithStopTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptorSimplePredicateWithStopTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date