You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2020/03/27 11:26:37 UTC
[camel] 06/06: Added examples in examples dir
This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 02908eb73902317951dcbd6222d17c9a0eb0d388
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Fri Mar 27 12:25:56 2020 +0100
Added examples in examples dir
---
.../quickfixj/QuickfixjSpringTest-context.xml | 129 +++++++++++++++++++++
.../InterceptSendToMockEndpointStrategyTest.xml | 35 ++++++
.../org/apache/camel/spring/mock/camel-route.xml | 50 ++++++++
.../patterns/IsMockEndpointsAndSkipJUnit4Test.java | 63 ++++++++++
.../test/patterns/IsMockEndpointsJUnit4Test.java | 70 +++++++++++
.../interceptor/AdviceWithMockEndpointsTest.java | 123 ++++++++++++++++++++
...dviceWithMockMultipleEndpointsWithSkipTest.java | 74 ++++++++++++
.../spring/javaconfig/patterns/FilterTest.java | 87 ++++++++++++++
...CamelSpringDelegatingTestContextLoaderTest.java | 87 ++++++++++++++
.../apache/camel/spring/patterns/FilterTest.java | 65 +++++++++++
.../camel/spring/patterns/FilterTest-context.xml | 42 +++++++
.../java/org/apache/camel/test/cdi/FilterTest.java | 73 ++++++++++++
.../test/spring/CamelSpringRunnerPlainTest.java | 113 ++++++++++++++++++
.../org/apache/camel/processor/FilterTest.java | 61 ++++++++++
.../management/ManagedCustomProcessorTest.java | 109 +++++++++++++++++
15 files changed, 1181 insertions(+)
diff --git a/docs/components/modules/ROOT/examples/components/camel-quickfix/src/test/resources/org/apache/camel/component/quickfixj/QuickfixjSpringTest-context.xml b/docs/components/modules/ROOT/examples/components/camel-quickfix/src/test/resources/org/apache/camel/component/quickfixj/QuickfixjSpringTest-context.xml
new file mode 100644
index 0000000..577c4a3
--- /dev/null
+++ b/docs/components/modules/ROOT/examples/components/camel-quickfix/src/test/resources/org/apache/camel/component/quickfixj/QuickfixjSpringTest-context.xml
@@ -0,0 +1,129 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:util="http://www.springframework.org/schema/util"
+ xmlns:camel="http://camel.apache.org/schema/spring"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
+ http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
+
+ <!-- START SNIPPET: e1 -->
+ <!-- tag::e1[] -->
+ <!-- camel route -->
+ <camelContext id="quickfixjContext" xmlns="http://camel.apache.org/schema/spring">
+ <route>
+ <from uri="quickfix:example"/>
+ <filter>
+ <simple>${in.header.EventCategory} == 'AppMessageReceived'</simple>
+ <to uri="log:test"/>
+ </filter>
+ </route>
+ <route>
+ <from uri="vm:test"/>
+ <to uri="lazyQuickfix:example"/>
+ </route>
+ </camelContext>
+
+ <!-- quickfix component -->
+ <bean id="quickfix" class="org.apache.camel.component.quickfixj.QuickfixjComponent">
+ <property name="configurations">
+ <util:map>
+ <entry key="example" value-ref="quickfixjConfiguration"/>
+ </util:map>
+ </property>
+ <property name="messageFactory">
+ <bean class="org.apache.camel.component.quickfixj.QuickfixjSpringTest.CustomMessageFactory"/>
+ </property>
+ </bean>
+
+ <!-- lazy quickfix component -->
+ <bean id="lazyQuickfix" class="org.apache.camel.component.quickfixj.QuickfixjComponent">
+ <property name="lazyCreateEngines" value="true" />
+ <property name="configurations">
+ <util:map>
+ <entry key="example" value-ref="lazyQuickfixjConfiguration"/>
+ </util:map>
+ </property>
+ <property name="messageFactory">
+ <bean class="org.apache.camel.component.quickfixj.QuickfixjSpringTest.CustomMessageFactory"/>
+ </property>
+ </bean>
+
+ <!-- quickfix settings -->
+ <bean id="quickfixjConfiguration" class="org.apache.camel.component.quickfixj.QuickfixjConfiguration">
+ <property name="defaultSettings">
+ <util:map>
+ <entry key="SocketConnectProtocol" value="VM_PIPE"/>
+ <entry key="SocketAcceptProtocol" value="VM_PIPE"/>
+ <entry key="UseDataDictionary" value="N"/>
+ </util:map>
+ </property>
+ <property name="sessionSettings">
+ <util:map>
+ <entry key="FIX.4.2:INITIATOR->ACCEPTOR">
+ <util:map>
+ <entry key="ConnectionType" value="initiator"/>
+ <entry key="SocketConnectHost" value="localhost"/>
+ <entry key="SocketConnectPort" value="5000"/>
+ </util:map>
+ </entry>
+ <entry key="FIX.4.2:ACCEPTOR->INITIATOR">
+ <util:map>
+ <entry key="ConnectionType" value="acceptor"/>
+ <entry key="SocketAcceptPort" value="5000"/>
+ </util:map>
+ </entry>
+ </util:map>
+ </property>
+ </bean>
+ <!-- end::e1[] -->
+ <!-- END SNIPPET: e1 -->
+
+ <!-- lazy quickfix settings -->
+ <bean id="lazyQuickfixjConfiguration" class="org.apache.camel.component.quickfixj.QuickfixjConfiguration">
+ <property name="defaultSettings">
+ <util:map>
+ <entry key="SocketConnectProtocol" value="VM_PIPE"/>
+ <entry key="SocketAcceptProtocol" value="VM_PIPE"/>
+ <entry key="UseDataDictionary" value="N"/>
+ </util:map>
+ </property>
+ <property name="sessionSettings">
+ <util:map>
+ <entry key="FIX.4.2:INITIATOR->ACCEPTOR">
+ <util:map>
+ <entry key="ConnectionType" value="initiator"/>
+ <entry key="SocketConnectHost" value="localhost"/>
+ <entry key="SocketConnectPort" value="5001"/>
+ </util:map>
+ </entry>
+ <entry key="FIX.4.2:ACCEPTOR->INITIATOR">
+ <util:map>
+ <entry key="ConnectionType" value="acceptor"/>
+ <entry key="SocketAcceptPort" value="5001"/>
+ </util:map>
+ </entry>
+ </util:map>
+ </property>
+ </bean>
+
+</beans>
\ No newline at end of file
diff --git a/docs/components/modules/ROOT/examples/components/camel-spring/src/test/resources/org/apache/camel/spring/mock/InterceptSendToMockEndpointStrategyTest.xml b/docs/components/modules/ROOT/examples/components/camel-spring/src/test/resources/org/apache/camel/spring/mock/InterceptSendToMockEndpointStrategyTest.xml
new file mode 100644
index 0000000..881797a
--- /dev/null
+++ b/docs/components/modules/ROOT/examples/components/camel-spring/src/test/resources/org/apache/camel/spring/mock/InterceptSendToMockEndpointStrategyTest.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
+
+ <!-- START SNIPPET: e1 -->
+ <!-- tag::e1[] -->
+ <!-- the Camel route is defined in another XML file -->
+ <import resource="camel-route.xml"/>
+
+ <!-- bean which enables mocking all endpoints -->
+ <bean id="mockAllEndpoints" class="org.apache.camel.impl.engine.InterceptSendToMockEndpointStrategy"/>
+ <!-- end::e1[] -->
+ <!-- END SNIPPET: e1 -->
+
+</beans>
diff --git a/docs/components/modules/ROOT/examples/components/camel-spring/src/test/resources/org/apache/camel/spring/mock/camel-route.xml b/docs/components/modules/ROOT/examples/components/camel-spring/src/test/resources/org/apache/camel/spring/mock/camel-route.xml
new file mode 100644
index 0000000..d69fedf
--- /dev/null
+++ b/docs/components/modules/ROOT/examples/components/camel-spring/src/test/resources/org/apache/camel/spring/mock/camel-route.xml
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+ ">
+
+ <!-- START SNIPPET: e1 -->
+ <!-- tag::e1[] -->
+ <!-- this camel route is in the camel-route.xml file -->
+ <camelContext xmlns="http://camel.apache.org/schema/spring">
+
+ <route>
+ <from uri="direct:start"/>
+ <to uri="direct:foo"/>
+ <to uri="log:foo"/>
+ <to uri="mock:result"/>
+ </route>
+
+ <route>
+ <from uri="direct:foo"/>
+ <transform>
+ <constant>Bye World</constant>
+ </transform>
+ </route>
+
+ </camelContext>
+ <!-- end::e1[] -->
+ <!-- END SNIPPET: e1 -->
+
+</beans>
diff --git a/docs/components/modules/ROOT/examples/components/camel-test/src/test/java/org/apache/camel/test/patterns/IsMockEndpointsAndSkipJUnit4Test.java b/docs/components/modules/ROOT/examples/components/camel-test/src/test/java/org/apache/camel/test/patterns/IsMockEndpointsAndSkipJUnit4Test.java
new file mode 100644
index 0000000..da82ca0
--- /dev/null
+++ b/docs/components/modules/ROOT/examples/components/camel-test/src/test/java/org/apache/camel/test/patterns/IsMockEndpointsAndSkipJUnit4Test.java
@@ -0,0 +1,63 @@
+/*
+ * 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.test.patterns;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.seda.SedaEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+// START SNIPPET: e1
+// tag::e1[]
+public class IsMockEndpointsAndSkipJUnit4Test extends CamelTestSupport {
+
+ @Override
+ public String isMockEndpointsAndSkip() {
+ // override this method and return the pattern for which endpoints to mock,
+ // and skip sending to the original endpoint.
+ return "direct:foo";
+ }
+
+ @Test
+ public void testMockEndpointAndSkip() throws Exception {
+ // notice we have automatic mocked the direct:foo endpoints and the name of the endpoints is "mock:uri"
+ getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
+ getMockEndpoint("mock:direct:foo").expectedMessageCount(1);
+
+ template.sendBody("direct:start", "Hello World");
+
+ assertMockEndpointsSatisfied();
+
+ // the message was not send to the direct:foo route and thus not sent to the seda endpoint
+ SedaEndpoint seda = context.getEndpoint("seda:foo", SedaEndpoint.class);
+ assertEquals(0, seda.getCurrentQueueSize());
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start").to("direct:foo").to("mock:result");
+
+ from("direct:foo").transform(constant("Bye World")).to("seda:foo");
+ }
+ };
+ }
+}
+// end::e1[]
+// END SNIPPET: e1
diff --git a/docs/components/modules/ROOT/examples/components/camel-test/src/test/java/org/apache/camel/test/patterns/IsMockEndpointsJUnit4Test.java b/docs/components/modules/ROOT/examples/components/camel-test/src/test/java/org/apache/camel/test/patterns/IsMockEndpointsJUnit4Test.java
new file mode 100644
index 0000000..d8cf4c0
--- /dev/null
+++ b/docs/components/modules/ROOT/examples/components/camel-test/src/test/java/org/apache/camel/test/patterns/IsMockEndpointsJUnit4Test.java
@@ -0,0 +1,70 @@
+/*
+ * 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.test.patterns;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+// START SNIPPET: e1
+// tag::e1[]
+public class IsMockEndpointsJUnit4Test extends CamelTestSupport {
+
+ @Override
+ public String isMockEndpoints() {
+ // override this method and return the pattern for which endpoints to mock.
+ // use * to indicate all
+ return "*";
+ }
+
+ @Test
+ public void testMockAllEndpoints() throws Exception {
+ // notice we have automatic mocked all endpoints and the name of the endpoints is "mock:uri"
+ getMockEndpoint("mock:direct:start").expectedBodiesReceived("Hello World");
+ getMockEndpoint("mock:direct:foo").expectedBodiesReceived("Hello World");
+ getMockEndpoint("mock:log:foo").expectedBodiesReceived("Bye World");
+ getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
+
+ template.sendBody("direct:start", "Hello World");
+
+ assertMockEndpointsSatisfied();
+
+ // additional test to ensure correct endpoints in registry
+ assertNotNull(context.hasEndpoint("direct:start"));
+ assertNotNull(context.hasEndpoint("direct:foo"));
+ assertNotNull(context.hasEndpoint("log:foo"));
+ assertNotNull(context.hasEndpoint("mock:result"));
+ // all the endpoints was mocked
+ assertNotNull(context.hasEndpoint("mock:direct:start"));
+ assertNotNull(context.hasEndpoint("mock:direct:foo"));
+ assertNotNull(context.hasEndpoint("mock:log:foo"));
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start").to("direct:foo").to("log:foo").to("mock:result");
+
+ from("direct:foo").transform(constant("Bye World"));
+ }
+ };
+ }
+}
+// end::e1[]
+// END SNIPPET: e1
diff --git a/docs/components/modules/ROOT/examples/core/camel-core/src/test/java/org/apache/camel/processor/interceptor/AdviceWithMockEndpointsTest.java b/docs/components/modules/ROOT/examples/core/camel-core/src/test/java/org/apache/camel/processor/interceptor/AdviceWithMockEndpointsTest.java
new file mode 100644
index 0000000..ca8adbe
--- /dev/null
+++ b/docs/components/modules/ROOT/examples/core/camel-core/src/test/java/org/apache/camel/processor/interceptor/AdviceWithMockEndpointsTest.java
@@ -0,0 +1,123 @@
+/*
+ * 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.interceptor;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.AdviceWithRouteBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.reifier.RouteReifier;
+import org.junit.Test;
+
+public class AdviceWithMockEndpointsTest extends ContextTestSupport {
+
+ @Test
+ public void testNoAdvised() throws Exception {
+ getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
+
+ template.sendBody("direct:start", "Hello World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ // START SNIPPET: e1
+ // tag::e1[]
+ @Test
+ public void testAdvisedMockEndpoints() throws Exception {
+ // advice the first route using the inlined AdviceWith route builder
+ // which has extended capabilities than the regular route builder
+ RouteReifier.adviceWith(context.getRouteDefinitions().get(0), context, new AdviceWithRouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ // mock all endpoints
+ mockEndpoints();
+ }
+ });
+
+ getMockEndpoint("mock:direct:start").expectedBodiesReceived("Hello World");
+ getMockEndpoint("mock:direct:foo").expectedBodiesReceived("Hello World");
+ getMockEndpoint("mock:log:foo").expectedBodiesReceived("Bye World");
+ getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
+
+ template.sendBody("direct:start", "Hello World");
+
+ assertMockEndpointsSatisfied();
+
+ // additional test to ensure correct endpoints in registry
+ assertNotNull(context.hasEndpoint("direct:start"));
+ assertNotNull(context.hasEndpoint("direct:foo"));
+ assertNotNull(context.hasEndpoint("log:foo"));
+ assertNotNull(context.hasEndpoint("mock:result"));
+ // all the endpoints was mocked
+ assertNotNull(context.hasEndpoint("mock:direct:start"));
+ assertNotNull(context.hasEndpoint("mock:direct:foo"));
+ assertNotNull(context.hasEndpoint("mock:log:foo"));
+ }
+ // end::e1[]
+ // END SNIPPET: e1
+
+ // START SNIPPET: e2
+ // tag::e2[]
+ @Test
+ public void testAdvisedMockEndpointsWithPattern() throws Exception {
+ // advice the first route using the inlined AdviceWith route builder
+ // which has extended capabilities than the regular route builder
+ RouteReifier.adviceWith(context.getRouteDefinitions().get(0), context, new AdviceWithRouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ // mock only log endpoints
+ mockEndpoints("log*");
+ }
+ });
+
+ // now we can refer to log:foo as a mock and set our expectations
+ getMockEndpoint("mock:log:foo").expectedBodiesReceived("Bye World");
+
+ getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
+
+ template.sendBody("direct:start", "Hello World");
+
+ assertMockEndpointsSatisfied();
+
+ // additional test to ensure correct endpoints in registry
+ assertNotNull(context.hasEndpoint("direct:start"));
+ assertNotNull(context.hasEndpoint("direct:foo"));
+ assertNotNull(context.hasEndpoint("log:foo"));
+ assertNotNull(context.hasEndpoint("mock:result"));
+ // only the log:foo endpoint was mocked
+ assertNotNull(context.hasEndpoint("mock:log:foo"));
+ assertNull(context.hasEndpoint("mock:direct:start"));
+ assertNull(context.hasEndpoint("mock:direct:foo"));
+ }
+ // end::e2[]
+ // END SNIPPET: e2
+
+ // START SNIPPET: route
+ // tag::route[]
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start").to("direct:foo").to("log:foo").to("mock:result");
+
+ from("direct:foo").transform(constant("Bye World"));
+ }
+ };
+ }
+ // end::route[]
+ // END SNIPPET: route
+}
diff --git a/docs/components/modules/ROOT/examples/core/camel-core/src/test/java/org/apache/camel/processor/interceptor/AdviceWithMockMultipleEndpointsWithSkipTest.java b/docs/components/modules/ROOT/examples/core/camel-core/src/test/java/org/apache/camel/processor/interceptor/AdviceWithMockMultipleEndpointsWithSkipTest.java
new file mode 100644
index 0000000..49d0934
--- /dev/null
+++ b/docs/components/modules/ROOT/examples/core/camel-core/src/test/java/org/apache/camel/processor/interceptor/AdviceWithMockMultipleEndpointsWithSkipTest.java
@@ -0,0 +1,74 @@
+/*
+ * 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.interceptor;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.AdviceWithRouteBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.seda.SedaEndpoint;
+import org.apache.camel.reifier.RouteReifier;
+import org.junit.Test;
+
+public class AdviceWithMockMultipleEndpointsWithSkipTest extends ContextTestSupport {
+
+ // START SNIPPET: e1
+ // tag::e1[]
+ @Test
+ public void testAdvisedMockEndpointsWithSkip() throws Exception {
+ // advice the first route using the inlined AdviceWith route builder
+ // which has extended capabilities than the regular route builder
+ RouteReifier.adviceWith(context.getRouteDefinitions().get(0), context, new AdviceWithRouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ // mock sending to direct:foo and direct:bar and skip send to it
+ mockEndpointsAndSkip("direct:foo", "direct:bar");
+ }
+ });
+
+ getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
+ getMockEndpoint("mock:direct:foo").expectedMessageCount(1);
+ getMockEndpoint("mock:direct:bar").expectedMessageCount(1);
+
+ template.sendBody("direct:start", "Hello World");
+
+ assertMockEndpointsSatisfied();
+
+ // the message was not send to the direct:foo route and thus not sent to
+ // the seda endpoint
+ SedaEndpoint seda = context.getEndpoint("seda:foo", SedaEndpoint.class);
+ assertEquals(0, seda.getCurrentQueueSize());
+ }
+ // end::e1[]
+ // END SNIPPET: e1
+
+ // START SNIPPET: route
+ // tag::route[]
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start").to("direct:foo").to("direct:bar").to("mock:result");
+
+ from("direct:foo").transform(constant("Bye World")).to("seda:foo");
+ from("direct:bar").transform(constant("Hi World")).to("seda:foo");
+ }
+ };
+ }
+ // end::route[]
+ // END SNIPPET: route
+}
diff --git a/docs/user-manual/modules/ROOT/examples/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/patterns/FilterTest.java b/docs/user-manual/modules/ROOT/examples/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/patterns/FilterTest.java
new file mode 100644
index 0000000..7dde0d9
--- /dev/null
+++ b/docs/user-manual/modules/ROOT/examples/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/patterns/FilterTest.java
@@ -0,0 +1,87 @@
+/*
+ * 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.spring.javaconfig.patterns;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Produce;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spring.javaconfig.SingleRouteCamelConfiguration;
+import org.apache.camel.test.spring.CamelSpringDelegatingTestContextLoader;
+import org.apache.camel.test.spring.CamelSpringJUnit4ClassRunner;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
+
+/**
+ * Tests filtering using Spring Test and Java Config
+ */
+// START SNIPPET: example
+// tag::example[]
+@RunWith(CamelSpringJUnit4ClassRunner.class)
+@ContextConfiguration(classes = {FilterTest.ContextConfig.class}, loader = CamelSpringDelegatingTestContextLoader.class)
+public class FilterTest extends AbstractJUnit4SpringContextTests {
+
+ @EndpointInject("mock:result")
+ protected MockEndpoint resultEndpoint;
+
+ @Produce("direct:start")
+ protected ProducerTemplate template;
+
+ @DirtiesContext
+ @Test
+ public void testSendMatchingMessage() throws Exception {
+ String expectedBody = "<matched/>";
+
+ resultEndpoint.expectedBodiesReceived(expectedBody);
+
+ template.sendBodyAndHeader(expectedBody, "foo", "bar");
+
+ resultEndpoint.assertIsSatisfied();
+ }
+
+ @DirtiesContext
+ @Test
+ public void testSendNotMatchingMessage() throws Exception {
+ resultEndpoint.expectedMessageCount(0);
+
+ template.sendBodyAndHeader("<notMatched/>", "foo", "notMatchedHeaderValue");
+
+ resultEndpoint.assertIsSatisfied();
+ }
+
+ @Configuration
+ public static class ContextConfig extends SingleRouteCamelConfiguration {
+ @Override
+ @Bean
+ public RouteBuilder route() {
+ return new RouteBuilder() {
+ public void configure() {
+ from("direct:start").filter(header("foo").isEqualTo("bar")).to("mock:result");
+ }
+ };
+ }
+ }
+}
+// end::example[]
+// END SNIPPET: example
+
diff --git a/docs/user-manual/modules/ROOT/examples/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/test/CamelSpringDelegatingTestContextLoaderTest.java b/docs/user-manual/modules/ROOT/examples/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/test/CamelSpringDelegatingTestContextLoaderTest.java
new file mode 100644
index 0000000..9fe6e40
--- /dev/null
+++ b/docs/user-manual/modules/ROOT/examples/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/test/CamelSpringDelegatingTestContextLoaderTest.java
@@ -0,0 +1,87 @@
+/*
+ * 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.spring.javaconfig.test;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Produce;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spring.javaconfig.SingleRouteCamelConfiguration;
+import org.apache.camel.test.spring.CamelSpringDelegatingTestContextLoader;
+import org.apache.camel.test.spring.CamelSpringRunner;
+import org.apache.camel.test.spring.MockEndpoints;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.context.ContextConfiguration;
+
+/**
+ * Test for CamelSpringDelegatingTestContextLoader.
+ */
+//START SNIPPET: example
+// tag::example[]
+@RunWith(CamelSpringRunner.class)
+@ContextConfiguration(
+ classes = {CamelSpringDelegatingTestContextLoaderTest.TestConfig.class},
+ // Since Camel 2.11.0
+ loader = CamelSpringDelegatingTestContextLoader.class
+ )
+@MockEndpoints
+public class CamelSpringDelegatingTestContextLoaderTest {
+ @EndpointInject("mock:direct:end")
+ protected MockEndpoint endEndpoint;
+
+ @EndpointInject("mock:direct:error")
+ protected MockEndpoint errorEndpoint;
+
+ @Produce("direct:test")
+ protected ProducerTemplate testProducer;
+
+ @Configuration
+ public static class TestConfig extends SingleRouteCamelConfiguration {
+ @Bean
+ @Override
+ public RouteBuilder route() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:test").errorHandler(deadLetterChannel("direct:error")).to("direct:end");
+
+ from("direct:error").log("Received message on direct:error endpoint.");
+
+ from("direct:end").log("Received message on direct:end endpoint.");
+ }
+ };
+ }
+ }
+
+ @Test
+ public void testRoute() throws InterruptedException {
+ endEndpoint.expectedMessageCount(1);
+ errorEndpoint.expectedMessageCount(0);
+
+ testProducer.sendBody("<name>test</name>");
+
+ endEndpoint.assertIsSatisfied();
+ errorEndpoint.assertIsSatisfied();
+ }
+}
+// end::example[]
+//END SNIPPET: example
+
diff --git a/docs/user-manual/modules/ROOT/examples/components/camel-spring/src/test/java/org/apache/camel/spring/patterns/FilterTest.java b/docs/user-manual/modules/ROOT/examples/components/camel-spring/src/test/java/org/apache/camel/spring/patterns/FilterTest.java
new file mode 100644
index 0000000..2ea204a
--- /dev/null
+++ b/docs/user-manual/modules/ROOT/examples/components/camel-spring/src/test/java/org/apache/camel/spring/patterns/FilterTest.java
@@ -0,0 +1,65 @@
+/*
+ * 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.spring.patterns;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Produce;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spring.SpringRunWithTestSupport;
+import org.junit.Test;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.ContextConfiguration;
+
+/**
+ * Tests filtering using Spring Test and XML Config
+ */
+// START SNIPPET: example
+// tag::example[]
+@ContextConfiguration
+public class FilterTest extends SpringRunWithTestSupport {
+
+ @EndpointInject("mock:result")
+ protected MockEndpoint resultEndpoint;
+
+ @Produce("direct:start")
+ protected ProducerTemplate template;
+
+ @DirtiesContext
+ @Test
+ public void testSendMatchingMessage() throws Exception {
+ String expectedBody = "<matched/>";
+
+ resultEndpoint.expectedBodiesReceived(expectedBody);
+
+ template.sendBodyAndHeader(expectedBody, "foo", "bar");
+
+ resultEndpoint.assertIsSatisfied();
+ }
+
+ @DirtiesContext
+ @Test
+ public void testSendNotMatchingMessage() throws Exception {
+ resultEndpoint.expectedMessageCount(0);
+
+ template.sendBodyAndHeader("<notMatched/>", "foo", "notMatchedHeaderValue");
+
+ resultEndpoint.assertIsSatisfied();
+ }
+}
+// end::example[]
+// END SNIPPET: example
diff --git a/docs/user-manual/modules/ROOT/examples/components/camel-spring/src/test/resources/org/apache/camel/spring/patterns/FilterTest-context.xml b/docs/user-manual/modules/ROOT/examples/components/camel-spring/src/test/resources/org/apache/camel/spring/patterns/FilterTest-context.xml
new file mode 100644
index 0000000..0541bd1
--- /dev/null
+++ b/docs/user-manual/modules/ROOT/examples/components/camel-spring/src/test/resources/org/apache/camel/spring/patterns/FilterTest-context.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+<!-- START SNIPPET: example -->
+<!-- tag::example[] -->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+ ">
+
+ <camelContext xmlns="http://camel.apache.org/schema/spring">
+ <route>
+ <from uri="direct:start"/>
+ <filter>
+ <xpath>$foo = 'bar'</xpath>
+ <to uri="mock:result"/>
+ </filter>
+ </route>
+ </camelContext>
+
+</beans>
+<!-- end::example[] -->
+<!-- END SNIPPET: example -->
diff --git a/docs/user-manual/modules/ROOT/examples/components/camel-test-cdi/src/test/java/org/apache/camel/test/cdi/FilterTest.java b/docs/user-manual/modules/ROOT/examples/components/camel-test-cdi/src/test/java/org/apache/camel/test/cdi/FilterTest.java
new file mode 100644
index 0000000..4171106
--- /dev/null
+++ b/docs/user-manual/modules/ROOT/examples/components/camel-test-cdi/src/test/java/org/apache/camel/test/cdi/FilterTest.java
@@ -0,0 +1,73 @@
+/*
+ * 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.test.cdi;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Produce;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+// START SNIPPET: example
+// tag::example[]
+@RunWith(CamelCdiRunner.class)
+public class FilterTest {
+
+ @EndpointInject("mock:result")
+ protected MockEndpoint resultEndpoint;
+
+ @Produce("direct:start")
+ protected ProducerTemplate template;
+
+ @Before
+ public void before() {
+ resultEndpoint.reset();
+ }
+
+ @Test
+ public void testSendMatchingMessage() throws Exception {
+ String expectedBody = "<matched/>";
+
+ resultEndpoint.expectedBodiesReceived(expectedBody);
+
+ template.sendBodyAndHeader(expectedBody, "foo", "bar");
+
+ resultEndpoint.assertIsSatisfied();
+ }
+
+ @Test
+ public void testSendNotMatchingMessage() throws Exception {
+ resultEndpoint.expectedMessageCount(0);
+
+ template.sendBodyAndHeader("<notMatched/>", "foo", "notMatchedHeaderValue");
+
+ resultEndpoint.assertIsSatisfied();
+ }
+
+ static class ContextConfig extends RouteBuilder {
+
+ @Override
+ public void configure() {
+ from("direct:start").filter(header("foo").isEqualTo("bar")).to("mock:result");
+ }
+ }
+}
+// end::example[]
+// END SNIPPET: example
diff --git a/docs/user-manual/modules/ROOT/examples/components/camel-test-spring/src/test/java/org/apache/camel/test/spring/CamelSpringRunnerPlainTest.java b/docs/user-manual/modules/ROOT/examples/components/camel-test-spring/src/test/java/org/apache/camel/test/spring/CamelSpringRunnerPlainTest.java
new file mode 100644
index 0000000..f5d0fb6
--- /dev/null
+++ b/docs/user-manual/modules/ROOT/examples/components/camel-test-spring/src/test/java/org/apache/camel/test/spring/CamelSpringRunnerPlainTest.java
@@ -0,0 +1,113 @@
+/*
+ * 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.test.spring;
+
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Produce;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.ServiceStatus;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.engine.DefaultManagementStrategy;
+import org.apache.camel.util.StopWatch;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.annotation.DirtiesContext.ClassMode;
+import org.springframework.test.context.BootstrapWith;
+import org.springframework.test.context.ContextConfiguration;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+// tag::example[]
+@RunWith(CamelSpringRunner.class)
+// must tell Spring to bootstrap with Camel
+@BootstrapWith(CamelTestContextBootstrapper.class)
+@ContextConfiguration()
+// Put here to prevent Spring context caching across tests and test methods since some tests inherit
+// from this test and therefore use the same Spring context. Also because we want to reset the
+// Camel context and mock endpoints between test methods automatically.
+@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
+public class CamelSpringRunnerPlainTest {
+
+ @Autowired
+ protected CamelContext camelContext;
+
+ @EndpointInject(value = "mock:a")
+ protected MockEndpoint mockA;
+
+ @EndpointInject(value = "mock:b")
+ protected MockEndpoint mockB;
+
+ @Produce(value = "direct:start")
+ protected ProducerTemplate start;
+
+ @Test
+ public void testPositive() throws Exception {
+ assertEquals(ServiceStatus.Started, camelContext.getStatus());
+
+ mockA.expectedBodiesReceived("David");
+ mockB.expectedBodiesReceived("Hello David");
+
+ start.sendBody("David");
+
+ MockEndpoint.assertIsSatisfied(camelContext);
+ }
+
+ @Test
+ public void testJmx() throws Exception {
+ assertEquals(DefaultManagementStrategy.class, camelContext.getManagementStrategy().getClass());
+ }
+
+ @Test
+ public void testShutdownTimeout() throws Exception {
+ assertEquals(10, camelContext.getShutdownStrategy().getTimeout());
+ assertEquals(TimeUnit.SECONDS, camelContext.getShutdownStrategy().getTimeUnit());
+ }
+
+ @Test
+ public void testStopwatch() {
+ StopWatch stopWatch = StopWatchTestExecutionListener.getStopWatch();
+
+ assertNotNull(stopWatch);
+ assertTrue(stopWatch.taken() < 100);
+ }
+
+ @Test
+ public void testExcludedRoute() {
+ assertNotNull(camelContext.getRoute("excludedRoute"));
+ }
+
+ @Test
+ public void testProvidesBreakpoint() {
+ assertNull(camelContext.getDebugger());
+ }
+
+ @Test
+ public void testRouteCoverage() throws Exception {
+ // noop
+ }
+
+}
+// end::example[]
+
diff --git a/docs/user-manual/modules/ROOT/examples/core/camel-core/src/test/java/org/apache/camel/processor/FilterTest.java b/docs/user-manual/modules/ROOT/examples/core/camel-core/src/test/java/org/apache/camel/processor/FilterTest.java
new file mode 100644
index 0000000..3b783a5
--- /dev/null
+++ b/docs/user-manual/modules/ROOT/examples/core/camel-core/src/test/java/org/apache/camel/processor/FilterTest.java
@@ -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.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.Test;
+
+// START SNIPPET: example
+// tag::example[]
+public class FilterTest extends ContextTestSupport {
+
+ @Test
+ public void testSendMatchingMessage() throws Exception {
+ MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:result", MockEndpoint.class);
+ resultEndpoint.expectedMessageCount(1);
+ resultEndpoint.message(0).exchangeProperty(Exchange.FILTER_MATCHED).isEqualTo(true);
+
+ template.sendBodyAndHeader("direct:start", "<matched/>", "foo", "bar");
+
+ resultEndpoint.assertIsSatisfied();
+ }
+
+ @Test
+ public void testSendNotMatchingMessage() throws Exception {
+ MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:result", MockEndpoint.class);
+ resultEndpoint.expectedMessageCount(0);
+
+ template.sendBodyAndHeader("direct:start", "<notMatched/>", "foo", "notMatchedHeaderValue");
+
+ resultEndpoint.assertIsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ public void configure() {
+ from("direct:start").filter(header("foo").isEqualTo("bar")).to("mock:result");
+ }
+ };
+ }
+
+}
+// end::example[]
+// END SNIPPET: example
diff --git a/docs/user-manual/modules/ROOT/examples/core/camel-management/src/test/java/org/apache/camel/management/ManagedCustomProcessorTest.java b/docs/user-manual/modules/ROOT/examples/core/camel-management/src/test/java/org/apache/camel/management/ManagedCustomProcessorTest.java
new file mode 100644
index 0000000..ee20734
--- /dev/null
+++ b/docs/user-manual/modules/ROOT/examples/core/camel-management/src/test/java/org/apache/camel/management/ManagedCustomProcessorTest.java
@@ -0,0 +1,109 @@
+/*
+ * 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.management;
+
+import javax.management.Attribute;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.api.management.ManagedAttribute;
+import org.apache.camel.api.management.ManagedResource;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.support.service.ServiceSupport;
+import org.junit.Test;
+
+public class ManagedCustomProcessorTest extends ManagementTestSupport {
+
+ @Test
+ public void testManageCustomProcessor() throws Exception {
+ // JMX tests dont work well on AIX CI servers (hangs them)
+ if (isPlatform("aix")) {
+ return;
+ }
+
+ MBeanServer mbeanServer = getMBeanServer();
+ ObjectName on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=processors,name=\"custom\"");
+
+ getMockEndpoint("mock:result").expectedMessageCount(1);
+ getMockEndpoint("mock:result").expectedHeaderReceived("foo", "hey");
+ template.sendBody("direct:start", "Hello World");
+ assertMockEndpointsSatisfied();
+
+ String foo = (String) mbeanServer.getAttribute(on, "Foo");
+ assertEquals("hey", foo);
+
+ // change foo
+ mbeanServer.setAttribute(on, new Attribute("Foo", "changed"));
+
+ resetMocks();
+
+ getMockEndpoint("mock:result").expectedMessageCount(1);
+ getMockEndpoint("mock:result").expectedHeaderReceived("foo", "changed");
+ template.sendBody("direct:start", "Bye World");
+ assertMockEndpointsSatisfied();
+
+ String state = (String) mbeanServer.getAttribute(on, "State");
+ assertEquals("Started", state);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start").routeId("foo")
+ .process(new MyCustomProcessor()).id("custom")
+ .to("mock:result");
+ }
+ };
+ }
+
+ // tag::e1[]
+ @ManagedResource(description = "My Managed Component")
+ public static class MyCustomProcessor extends ServiceSupport implements Processor {
+ private String foo = "hey";
+
+ @ManagedAttribute
+ public String getFoo() {
+ return foo;
+ }
+
+ @ManagedAttribute
+ public void setFoo(String foo) {
+ this.foo = foo;
+ }
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader("foo", getFoo());
+ }
+
+ @Override
+ protected void doStart() throws Exception {
+ // noop
+ }
+
+ @Override
+ protected void doStop() throws Exception {
+ // noop
+ }
+ }
+ // end::e1[]
+
+}