This is an automated email from the ASF dual-hosted git repository. zregvart pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
commit bf2531bf17a853aa1ea499989d4c5baa72701fe8 Author: Zoran Regvart <[email protected]> AuthorDate: Mon Jul 15 17:24:38 2019 +0200 CAMEL-13589: copy over examples Antora requires that any `include::`-ed examples are in the `examples` directory within a module[1]. To make this work for Camel we have to copy the `.java` or `.xml` files referenced are copied over to the module from the source tree of the Maven module. Since several `.adoc` files both within the user manual and in the component documentation reference files out of their own module using relative paths to included files soon becomes an issue. That's why having them absolute to the repository root makes more sense. This adds changes to the `docs/gulpfile.js` to find all `include::`-ed examples referenced from `.adoc` files and copy them over to the corresponding module (user manual or component reference). It also changes the paths in `include::`s to absolute for the above stated reason. Also makes the links point to the github repository via absolute URLs. [1] https://docs.antora.org/antora/2.0/modules/#module-overview --- .../camel-mock/src/main/docs/mock-component.adoc | 16 +-- .../src/main/docs/quickfix-component.adoc | 2 +- .../org/apache/camel/processor/FilterTest.java | 4 + .../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 | 124 ++++++++++++++++++++ ...dviceWithMockMultipleEndpointsWithSkipTest.java | 73 ++++++++++++ .../modules/ROOT/pages/mock-component.adoc | 16 +-- .../modules/ROOT/pages/quickfix-component.adoc | 2 +- docs/gulpfile.js | 42 ++++++- docs/package.json | 3 +- .../camel/component/jms/jmsRouteUsingSpring.xml | 41 +++++++ .../spring/javaconfig/patterns/FilterTest.java | 86 ++++++++++++++ ...CamelSpringDelegatingTestContextLoaderTest.java | 88 ++++++++++++++ .../apache/camel/spring/patterns}/FilterTest.java | 49 ++++---- .../camel/spring/patterns/FilterTest-context.xml | 42 +++++++ .../camel/test/blueprint/DebugBlueprintTest.java | 75 ++++++++++++ .../apache/camel/test/blueprint/camelContext.xml | 41 +++++++ .../org/apache/camel/test/cdi}/FilterTest.java | 51 +++++--- .../test/spring/CamelSpringRunnerPlainTest.java | 128 ++++++++++++++++++++ .../org/apache/camel/processor/FilterTest.java | 4 + .../modules/ROOT/pages/configuring-camel.adoc | 2 +- docs/user-manual/modules/ROOT/pages/testing.adoc | 36 +++--- docs/yarn.lock | 7 ++ 27 files changed, 1203 insertions(+), 76 deletions(-) diff --git a/components/camel-mock/src/main/docs/mock-component.adoc b/components/camel-mock/src/main/docs/mock-component.adoc index 28e0749..5388d43 100644 --- a/components/camel-mock/src/main/docs/mock-component.adoc +++ b/components/camel-mock/src/main/docs/mock-component.adoc @@ -266,7 +266,7 @@ Suppose you have the given route below: [source,java] .*Route* ---- -include::../../test/java/org/apache/camel/processor/interceptor/AdviceWithMockEndpointsTest.java[tags=route] +include::{examplesdir}/core/camel-core/src/test/java/org/apache/camel/processor/interceptor/AdviceWithMockEndpointsTest.java[tags=route] ---- You can then use the `adviceWith` feature in Camel to mock all the @@ -275,7 +275,7 @@ endpoints in a given route from your unit test, as shown below: [source,java] .*`adviceWith` mocking all endpoints* ---- -include::../../test/java/org/apache/camel/processor/interceptor/AdviceWithMockEndpointsTest.java[tags=e1] +include::{examplesdir}/core/camel-core/src/test/java/org/apache/camel/processor/interceptor/AdviceWithMockEndpointsTest.java[tags=e1] ---- Notice that the mock endpoints is given the URI `mock:<endpoint>`, for @@ -300,7 +300,7 @@ example to mock all `log` endpoints you do as shown: [source,java] .*`adviceWith` mocking only log endpoints using a pattern* ---- -include::../../test/java/org/apache/camel/processor/interceptor/AdviceWithMockEndpointsTest.java[tags=e2] +include::{examplesdir}/core/camel-core/src/test/java/org/apache/camel/processor/interceptor/AdviceWithMockEndpointsTest.java[tags=e2] ---- The pattern supported can be a wildcard or a regular expression. See @@ -330,7 +330,7 @@ instead. [source,java] .*`isMockEndpoints` using camel-test kit* ---- -include::../../../../components/camel-test/src/test/java/org/apache/camel/test/patterns/IsMockEndpointsJUnit4Test.java[tags=e1] +include::{examplesdir}/components/camel-test/src/test/java/org/apache/camel/test/patterns/IsMockEndpointsJUnit4Test.java[tags=e1] ---- @@ -347,7 +347,7 @@ Suppose we have the route in the `camel-route.xml` file: [source,xml] .*camel-route.xml* ---- -include::../../../../components/camel-spring/src/test/resources/org/apache/camel/spring/mock/camel-route.xml[tags=e1] +include::{examplesdir}/components/camel-spring/src/test/resources/org/apache/camel/spring/mock/camel-route.xml[tags=e1] ---- Then we create a new XML file as follows, where we include the @@ -358,7 +358,7 @@ Camel to mock all endpoints: [source,xml] .*test-camel-route.xml* ---- -include::../../../../components/camel-spring/src/test/resources/org/apache/camel/spring/mock/InterceptSendToMockEndpointStrategyTest.xml[tags=e1] +include::{examplesdir}/components/camel-spring/src/test/resources/org/apache/camel/spring/mock/InterceptSendToMockEndpointStrategyTest.xml[tags=e1] ---- Then in your unit test you load the new XML file @@ -389,7 +389,7 @@ Kit]. The example below will skip sending to the two endpoints [source,java] .*adviceWith mock and skip sending to endpoints* ---- -include::../../test/java/org/apache/camel/processor/interceptor/AdviceWithMockMultipleEndpointsWithSkipTest.java[tags=e1] +include::{examplesdir}/core/camel-core/src/test/java/org/apache/camel/processor/interceptor/AdviceWithMockMultipleEndpointsWithSkipTest.java[tags=e1] ---- The same example using the Test Kit @@ -397,7 +397,7 @@ The same example using the Test Kit [source,java] .*isMockEndpointsAndSkip using camel-test kit* ---- -include::../../../../components/camel-test/src/test/java/org/apache/camel/test/patterns/IsMockEndpointsAndSkipJUnit4Test.java[tags=e1] +include::{examplesdir}/components/camel-test/src/test/java/org/apache/camel/test/patterns/IsMockEndpointsAndSkipJUnit4Test.java[tags=e1] ---- === Limiting the number of messages to keep diff --git a/components/camel-quickfix/src/main/docs/quickfix-component.adoc b/components/camel-quickfix/src/main/docs/quickfix-component.adoc index ee69825..4033a09 100644 --- a/components/camel-quickfix/src/main/docs/quickfix-component.adoc +++ b/components/camel-quickfix/src/main/docs/quickfix-component.adoc @@ -458,7 +458,7 @@ settings for both sessions. [source,xml] ---- -include::../../test/resources/org/apache/camel/component/quickfixj/QuickfixjSpringTest-context.xml[tags=e1] +include::{examplesdir}/components/camel-quickfix/src/test/resources/org/apache/camel/component/quickfixj/QuickfixjSpringTest-context.xml[tags=e1] ---- ### Exception handling diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/FilterTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/FilterTest.java index 2367e5b..ae4024a 100644 --- a/core/camel-core/src/test/java/org/apache/camel/processor/FilterTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/processor/FilterTest.java @@ -22,6 +22,8 @@ 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 @@ -54,3 +56,5 @@ public class FilterTest extends ContextTestSupport { } } +// end::example[] +// END SNIPPET: example 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..b7763ed --- /dev/null +++ b/docs/components/modules/ROOT/examples/core/camel-core/src/test/java/org/apache/camel/processor/interceptor/AdviceWithMockEndpointsTest.java @@ -0,0 +1,124 @@ +/* + * 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..0bf0f92 --- /dev/null +++ b/docs/components/modules/ROOT/examples/core/camel-core/src/test/java/org/apache/camel/processor/interceptor/AdviceWithMockMultipleEndpointsWithSkipTest.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.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/components/modules/ROOT/pages/mock-component.adoc b/docs/components/modules/ROOT/pages/mock-component.adoc index 28e0749..5388d43 100644 --- a/docs/components/modules/ROOT/pages/mock-component.adoc +++ b/docs/components/modules/ROOT/pages/mock-component.adoc @@ -266,7 +266,7 @@ Suppose you have the given route below: [source,java] .*Route* ---- -include::../../test/java/org/apache/camel/processor/interceptor/AdviceWithMockEndpointsTest.java[tags=route] +include::{examplesdir}/core/camel-core/src/test/java/org/apache/camel/processor/interceptor/AdviceWithMockEndpointsTest.java[tags=route] ---- You can then use the `adviceWith` feature in Camel to mock all the @@ -275,7 +275,7 @@ endpoints in a given route from your unit test, as shown below: [source,java] .*`adviceWith` mocking all endpoints* ---- -include::../../test/java/org/apache/camel/processor/interceptor/AdviceWithMockEndpointsTest.java[tags=e1] +include::{examplesdir}/core/camel-core/src/test/java/org/apache/camel/processor/interceptor/AdviceWithMockEndpointsTest.java[tags=e1] ---- Notice that the mock endpoints is given the URI `mock:<endpoint>`, for @@ -300,7 +300,7 @@ example to mock all `log` endpoints you do as shown: [source,java] .*`adviceWith` mocking only log endpoints using a pattern* ---- -include::../../test/java/org/apache/camel/processor/interceptor/AdviceWithMockEndpointsTest.java[tags=e2] +include::{examplesdir}/core/camel-core/src/test/java/org/apache/camel/processor/interceptor/AdviceWithMockEndpointsTest.java[tags=e2] ---- The pattern supported can be a wildcard or a regular expression. See @@ -330,7 +330,7 @@ instead. [source,java] .*`isMockEndpoints` using camel-test kit* ---- -include::../../../../components/camel-test/src/test/java/org/apache/camel/test/patterns/IsMockEndpointsJUnit4Test.java[tags=e1] +include::{examplesdir}/components/camel-test/src/test/java/org/apache/camel/test/patterns/IsMockEndpointsJUnit4Test.java[tags=e1] ---- @@ -347,7 +347,7 @@ Suppose we have the route in the `camel-route.xml` file: [source,xml] .*camel-route.xml* ---- -include::../../../../components/camel-spring/src/test/resources/org/apache/camel/spring/mock/camel-route.xml[tags=e1] +include::{examplesdir}/components/camel-spring/src/test/resources/org/apache/camel/spring/mock/camel-route.xml[tags=e1] ---- Then we create a new XML file as follows, where we include the @@ -358,7 +358,7 @@ Camel to mock all endpoints: [source,xml] .*test-camel-route.xml* ---- -include::../../../../components/camel-spring/src/test/resources/org/apache/camel/spring/mock/InterceptSendToMockEndpointStrategyTest.xml[tags=e1] +include::{examplesdir}/components/camel-spring/src/test/resources/org/apache/camel/spring/mock/InterceptSendToMockEndpointStrategyTest.xml[tags=e1] ---- Then in your unit test you load the new XML file @@ -389,7 +389,7 @@ Kit]. The example below will skip sending to the two endpoints [source,java] .*adviceWith mock and skip sending to endpoints* ---- -include::../../test/java/org/apache/camel/processor/interceptor/AdviceWithMockMultipleEndpointsWithSkipTest.java[tags=e1] +include::{examplesdir}/core/camel-core/src/test/java/org/apache/camel/processor/interceptor/AdviceWithMockMultipleEndpointsWithSkipTest.java[tags=e1] ---- The same example using the Test Kit @@ -397,7 +397,7 @@ The same example using the Test Kit [source,java] .*isMockEndpointsAndSkip using camel-test kit* ---- -include::../../../../components/camel-test/src/test/java/org/apache/camel/test/patterns/IsMockEndpointsAndSkipJUnit4Test.java[tags=e1] +include::{examplesdir}/components/camel-test/src/test/java/org/apache/camel/test/patterns/IsMockEndpointsAndSkipJUnit4Test.java[tags=e1] ---- === Limiting the number of messages to keep diff --git a/docs/components/modules/ROOT/pages/quickfix-component.adoc b/docs/components/modules/ROOT/pages/quickfix-component.adoc index ee69825..4033a09 100644 --- a/docs/components/modules/ROOT/pages/quickfix-component.adoc +++ b/docs/components/modules/ROOT/pages/quickfix-component.adoc @@ -458,7 +458,7 @@ settings for both sessions. [source,xml] ---- -include::../../test/resources/org/apache/camel/component/quickfixj/QuickfixjSpringTest-context.xml[tags=e1] +include::{examplesdir}/components/camel-quickfix/src/test/resources/org/apache/camel/component/quickfixj/QuickfixjSpringTest-context.xml[tags=e1] ---- ### Exception handling diff --git a/docs/gulpfile.js b/docs/gulpfile.js index 1fda5de..900c920 100644 --- a/docs/gulpfile.js +++ b/docs/gulpfile.js @@ -21,6 +21,9 @@ const map = require('map-stream') const path = require('path'); const rename = require('gulp-rename'); const sort = require('gulp-sort'); +const through2 = require('through2'); +const File = require('vinyl') +const fs = require('fs'); function deleteComponentSymlinks() { return del(['components/modules/ROOT/pages/*', '!components/modules/ROOT/pages/index.adoc']); @@ -123,10 +126,47 @@ function createUserManualNav() { .pipe(dest('user-manual/modules/ROOT/')) } +const extractExamples = function(file, enc, next) { + const asciidoc = file.contents.toString(); + const includes = /(?:include::\{examplesdir\}\/)([^[]+)/g; + let example; + let exampleFiles = new Set() + while (example = includes.exec(asciidoc)) { + let examplePath = path.resolve(path.join('..', example[1])); + exampleFiles.add(examplePath); + } + + exampleFiles.forEach(examplePath => this.push(new File({ + base: path.resolve('..'), + path: examplePath, + contents: fs.createReadStream(examplePath) + }))); + + return next(); +} + +function deleteExamples(){ + return del(['user-manual/modules/ROOT/examples/', 'components/modules/ROOT/examples/']); +} + +function createUserManualExamples() { + return src('user-manual/modules/ROOT/**/*.adoc') + .pipe(through2.obj(extractExamples)) + .pipe(dest('user-manual/modules/ROOT/examples/')); +} + +function createComponentExamples() { + return src('../components/{*,*/*}/src/main/docs/*.adoc') + .pipe(through2.obj(extractExamples)) + .pipe(dest('components/modules/ROOT/examples/')); +} + const symlinks = parallel(series(deleteComponentSymlinks, createComponentSymlinks), series(deleteUserManualSymlinks, createUserManualSymlinks)); const nav = parallel(createComponentNav, createUserManualNav); +const examples = series(deleteExamples, createUserManualExamples, createComponentExamples); exports.symlinks = symlinks; exports.nav = nav; -exports.default = series(symlinks, nav); +exports.examples = examples; +exports.default = series(symlinks, nav, examples); diff --git a/docs/package.json b/docs/package.json index 0b07e16..bd4a208 100644 --- a/docs/package.json +++ b/docs/package.json @@ -8,6 +8,7 @@ "gulp-inject": "^5.0.2", "gulp-rename": "^1.4.0", "gulp-sort": "^2.0.0", - "map-stream": "^0.0.7" + "map-stream": "^0.0.7", + "through2": "^3.0.1" } } diff --git a/docs/user-manual/modules/ROOT/examples/components/camel-jms/src/test/resources/org/apache/camel/component/jms/jmsRouteUsingSpring.xml b/docs/user-manual/modules/ROOT/examples/components/camel-jms/src/test/resources/org/apache/camel/component/jms/jmsRouteUsingSpring.xml new file mode 100644 index 0000000..b3d2d54 --- /dev/null +++ b/docs/user-manual/modules/ROOT/examples/components/camel-jms/src/test/resources/org/apache/camel/component/jms/jmsRouteUsingSpring.xml @@ -0,0 +1,41 @@ +<?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: example --> + <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"> + <jmxAgent id="agent" disabled="true"/> + </camelContext> + + <bean id="activemq" class="org.apache.camel.component.jms.JmsComponent"> + <property name="connectionFactory"> + <bean class="org.apache.activemq.ActiveMQConnectionFactory"> + <property name="brokerURL" value="vm://localhost?broker.persistent=false&broker.useJmx=false"/> + </bean> + </property> + </bean> + <!-- END SNIPPET: example --> + +</beans> 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..501c83a --- /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,86 @@ +/* + * 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 { + @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..7e41757 --- /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,88 @@ +/* + * 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.CamelSpringJUnit4ClassRunner; +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/core/camel-core/src/test/java/org/apache/camel/processor/FilterTest.java b/docs/user-manual/modules/ROOT/examples/components/camel-spring/src/test/java/org/apache/camel/spring/patterns/FilterTest.java similarity index 54% copy from core/camel-core/src/test/java/org/apache/camel/processor/FilterTest.java copy to docs/user-manual/modules/ROOT/examples/components/camel-spring/src/test/java/org/apache/camel/spring/patterns/FilterTest.java index 2367e5b..2ea204a 100644 --- a/core/camel-core/src/test/java/org/apache/camel/processor/FilterTest.java +++ b/docs/user-manual/modules/ROOT/examples/components/camel-spring/src/test/java/org/apache/camel/spring/patterns/FilterTest.java @@ -14,43 +14,52 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.processor; +package org.apache.camel.spring.patterns; -import org.apache.camel.ContextTestSupport; -import org.apache.camel.Exchange; -import org.apache.camel.builder.RouteBuilder; +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; -public class FilterTest extends ContextTestSupport { +/** + * 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 { - MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:result", MockEndpoint.class); - resultEndpoint.expectedMessageCount(1); - resultEndpoint.message(0).exchangeProperty(Exchange.FILTER_MATCHED).isEqualTo(true); + String expectedBody = "<matched/>"; + + resultEndpoint.expectedBodiesReceived(expectedBody); - template.sendBodyAndHeader("direct:start", "<matched/>", "foo", "bar"); + template.sendBodyAndHeader(expectedBody, "foo", "bar"); resultEndpoint.assertIsSatisfied(); } + @DirtiesContext @Test public void testSendNotMatchingMessage() throws Exception { - MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:result", MockEndpoint.class); resultEndpoint.expectedMessageCount(0); - template.sendBodyAndHeader("direct:start", "<notMatched/>", "foo", "notMatchedHeaderValue"); + template.sendBodyAndHeader("<notMatched/>", "foo", "notMatchedHeaderValue"); resultEndpoint.assertIsSatisfied(); } - - 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/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-blueprint/src/test/java/org/apache/camel/test/blueprint/DebugBlueprintTest.java b/docs/user-manual/modules/ROOT/examples/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/DebugBlueprintTest.java new file mode 100644 index 0000000..ade5182 --- /dev/null +++ b/docs/user-manual/modules/ROOT/examples/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/DebugBlueprintTest.java @@ -0,0 +1,75 @@ +/* + * 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.blueprint; + +import org.apache.camel.Exchange; +import org.apache.camel.model.ProcessorDefinition; +import org.junit.Test; + +// START SNIPPET: example +// tag::example[] +// to use camel-test-blueprint, then extend the CamelBlueprintTestSupport class, +// and add your unit tests methods as shown below. +public class DebugBlueprintTest extends CamelBlueprintTestSupport { + + private boolean debugBeforeMethodCalled; + private boolean debugAfterMethodCalled; + + // override this method, and return the location of our Blueprint XML file to be used for testing + @Override + protected String getBlueprintDescriptor() { + return "org/apache/camel/test/blueprint/camelContext.xml"; + } + + // here we have regular JUnit @Test method + @Test + public void testRoute() throws Exception { + + // set mock expectations + getMockEndpoint("mock:a").expectedMessageCount(1); + + // send a message + template.sendBody("direct:start", "World"); + + // assert mocks + assertMockEndpointsSatisfied(); + + // assert on the debugBefore/debugAfter methods below being called as we've enabled the debugger + assertTrue(debugBeforeMethodCalled); + assertTrue(debugAfterMethodCalled); + } + + @Override + public boolean isUseDebugger() { + // must enable debugger + return true; + } + + @Override + protected void debugBefore(Exchange exchange, org.apache.camel.Processor processor, ProcessorDefinition<?> definition, String id, String label) { + log.info("Before " + definition + " with body " + exchange.getIn().getBody()); + debugBeforeMethodCalled = true; + } + + @Override + protected void debugAfter(Exchange exchange, org.apache.camel.Processor processor, ProcessorDefinition<?> definition, String id, String label, long timeTaken) { + log.info("After " + definition + " with body " + exchange.getIn().getBody()); + debugAfterMethodCalled = true; + } +} +// end::example[] +// END SNIPPET: example diff --git a/docs/user-manual/modules/ROOT/examples/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/camelContext.xml b/docs/user-manual/modules/ROOT/examples/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/camelContext.xml new file mode 100644 index 0000000..a7763c9 --- /dev/null +++ b/docs/user-manual/modules/ROOT/examples/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/camelContext.xml @@ -0,0 +1,41 @@ +<?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[] --> +<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation=" + http://www.osgi.org/xmlns/blueprint/v1.0.0 https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd"> + + <camelContext xmlns="http://camel.apache.org/schema/blueprint"> + + <route> + <from uri="direct:start"/> + <transform> + <simple>Hello ${body}</simple> + </transform> + <to uri="mock:a"/> + </route> + + </camelContext> + +</blueprint> +<!-- end::example[] --> +<!-- END SNIPPET: example --> diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/FilterTest.java b/docs/user-manual/modules/ROOT/examples/components/camel-test-cdi/src/test/java/org/apache/camel/test/cdi/FilterTest.java similarity index 54% copy from core/camel-core/src/test/java/org/apache/camel/processor/FilterTest.java copy to docs/user-manual/modules/ROOT/examples/components/camel-test-cdi/src/test/java/org/apache/camel/test/cdi/FilterTest.java index 2367e5b..4171106 100644 --- a/core/camel-core/src/test/java/org/apache/camel/processor/FilterTest.java +++ b/docs/user-manual/modules/ROOT/examples/components/camel-test-cdi/src/test/java/org/apache/camel/test/cdi/FilterTest.java @@ -14,43 +14,60 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.processor; +package org.apache.camel.test.cdi; -import org.apache.camel.ContextTestSupport; -import org.apache.camel.Exchange; +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; -public class FilterTest extends ContextTestSupport { +// 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 { - MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:result", MockEndpoint.class); - resultEndpoint.expectedMessageCount(1); - resultEndpoint.message(0).exchangeProperty(Exchange.FILTER_MATCHED).isEqualTo(true); + String expectedBody = "<matched/>"; - template.sendBodyAndHeader("direct:start", "<matched/>", "foo", "bar"); + resultEndpoint.expectedBodiesReceived(expectedBody); + + template.sendBodyAndHeader(expectedBody, "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"); + template.sendBodyAndHeader("<notMatched/>", "foo", "notMatchedHeaderValue"); resultEndpoint.assertIsSatisfied(); } - protected RouteBuilder createRouteBuilder() { - return new RouteBuilder() { - public void configure() { - from("direct:start").filter(header("foo").isEqualTo("bar")).to("mock:result"); - } - }; - } + 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..64c829b --- /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,128 @@ +/* + * 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; + +// START SNIPPET: e1 +// 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; + + @Autowired + protected CamelContext camelContext2; + + @EndpointInject(value = "mock:a", context = "camelContext") + protected MockEndpoint mockA; + + @EndpointInject(value = "mock:b", context = "camelContext") + protected MockEndpoint mockB; + + @EndpointInject(value = "mock:c", context = "camelContext2") + protected MockEndpoint mockC; + + @Produce(value = "direct:start", context = "camelContext") + protected ProducerTemplate start; + + @Produce(value = "direct:start2", context = "camelContext2") + protected ProducerTemplate start2; + + @Test + public void testPositive() throws Exception { + assertEquals(ServiceStatus.Started, camelContext.getStatus()); + assertEquals(ServiceStatus.Started, camelContext2.getStatus()); + + mockA.expectedBodiesReceived("David"); + mockB.expectedBodiesReceived("Hello David"); + mockC.expectedBodiesReceived("David"); + + start.sendBody("David"); + start2.sendBody("David"); + + MockEndpoint.assertIsSatisfied(camelContext); + MockEndpoint.assertIsSatisfied(camelContext2); + } + + @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()); + assertNull(camelContext2.getDebugger()); + } + + @Test + public void testRouteCoverage() throws Exception { + // noop + } + +} +// end::example[] +// END SNIPPET: e1 diff --git a/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 similarity index 96% copy from core/camel-core/src/test/java/org/apache/camel/processor/FilterTest.java copy to docs/user-manual/modules/ROOT/examples/core/camel-core/src/test/java/org/apache/camel/processor/FilterTest.java index 2367e5b..ae4024a 100644 --- a/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 @@ -22,6 +22,8 @@ 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 @@ -54,3 +56,5 @@ public class FilterTest extends ContextTestSupport { } } +// end::example[] +// END SNIPPET: example diff --git a/docs/user-manual/modules/ROOT/pages/configuring-camel.adoc b/docs/user-manual/modules/ROOT/pages/configuring-camel.adoc index c6d85b1..716f3e0 100644 --- a/docs/user-manual/modules/ROOT/pages/configuring-camel.adoc +++ b/docs/user-manual/modules/ROOT/pages/configuring-camel.adoc @@ -51,7 +51,7 @@ injection. You can configure a component via Spring using the following mechanism: -include::../../../components/camel-jms/src/test/resources/org/apache/camel/component/jms/jmsRouteUsingSpring.xml[] +include::{examplesdir}/components/camel-jms/src/test/resources/org/apache/camel/component/jms/jmsRouteUsingSpring.xml[] Which allows you to configure a component using some name (activemq in the above example), then you can refer to the component using diff --git a/docs/user-manual/modules/ROOT/pages/testing.adoc b/docs/user-manual/modules/ROOT/pages/testing.adoc index 62613f7..552225d 100644 --- a/docs/user-manual/modules/ROOT/pages/testing.adoc +++ b/docs/user-manual/modules/ROOT/pages/testing.adoc @@ -88,11 +88,11 @@ injection annotations]. ===== Camel Test Example Here is the Camel Test -xref:../../../../../components/camel-test/src/test/java/org/apache/camel/test/patterns/FilterTest.java[example]: +https://github.com/apache/camel/blob/master/core/camel-core/src/test/java/org/apache/camel/processor/FilterTest.java[example]: [source,java] ---- -include::../../../components/camel-test/src/test/java/org/apache/camel/test/patterns/FilterTest.java[tags=example] +include::{examplesdir}/core/camel-core/src/test/java/org/apache/camel/processor/FilterTest.java[tags=example] ---- Notice how it derives from the Camel helper class `CamelTestSupport` but @@ -103,11 +103,11 @@ overrides the `createRouteBuilder()` method. ===== CDI Test Example Here is the CDI Testing -xref:../../../../../components/camel-test-cdi/src/test/java/org/apache/camel/test/cdi/FilterTest.java[example]: +https://github.com/apache/camel/blob/master/components/camel-test-cdi/src/test/java/org/apache/camel/test/cdi/FilterTest.java[example]: [source,java] ---- -include::../../../components/camel-test-cdi/src/test/java/org/apache/camel/test/cdi/FilterTest.java[tags=example] +include::{examplesdir}/components/camel-test-cdi/src/test/java/org/apache/camel/test/cdi/FilterTest.java[tags=example] ---- You can find more testing patterns illustrated in the `camel-example-cdi-test` example @@ -117,12 +117,12 @@ and the test classes that come with it. ===== Spring Test with XML Config Example Here is the Spring Testing -xref:../../../../../components/camel-spring/src/test/java/org/apache/camel/spring/patterns/FilterTest.java[example +https://github.com/apache/camel/blob/master/components/camel-spring/src/test/java/org/apache/camel/spring/patterns/FilterTest.java[example using XML Config]: [source,java] ---- -include::../../../components/camel-spring/src/test/java/org/apache/camel/spring/patterns/FilterTest.java[tags=example] +include::{examplesdir}/components/camel-spring/src/test/java/org/apache/camel/spring/patterns/FilterTest.java[tags=example] ---- Notice that we use @`DirtiesContext` on the test methods to force @@ -133,24 +133,24 @@ sending to an endpoint that is then reused in another test method). Also notice the use of `@ContextConfiguration` to indicate that by default we should look for the -xref:../../../../../components/camel-spring/src/test/resources/org/apache/camel/spring/patterns/FilterTest-context.xml[`FilterTest-context.xml` +https://github.com/apache/camel/blob/master/components/camel-spring/src/test/resources/org/apache/camel/spring/patterns/FilterTest-context.xml[`FilterTest-context.xml` on the classpath] to configure the test case which looks like this: [source,xml] ---- -include::../../../components/camel-spring/src/test/resources/org/apache/camel/spring/patterns/FilterTest-context.xml[tags=example] +include::{examplesdir}/components/camel-spring/src/test/resources/org/apache/camel/spring/patterns/FilterTest-context.xml[tags=example] ---- [[Testing-SpringTestwithJavaConfigExample]] ===== Spring Test with Java Config Example Here is the Spring Testing -xref:../../../../../components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/patterns/FilterTest.java[example +https://github.com/apache/camel/blob/master/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/patterns/FilterTest.java[example using Java Config]: [source,java] ---- -include::../../../components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/patterns/FilterTest.java[tags=example] +include::{examplesdir}/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/patterns/FilterTest.java[tags=example] ---- For more information see xref:spring-java-config.adoc[Spring Java @@ -171,27 +171,27 @@ register the RouteBuilder we create. Since *Camel 2.11.0* you can use the `CamelSpringJUnit4ClassRunner` with `CamelSpringDelegatingTestContextLoader` like -xref:../../../../../components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/test/CamelSpringDelegatingTestContextLoaderTest.java[example +https://github.com/apache/camel/blob/master/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/test/CamelSpringDelegatingTestContextLoaderTest.java[example using Java Config with `CamelSpringJUnit4ClassRunner`]: Since *Camel 2.18.0* `CamelSpringJUnit4ClassRunner` is deprecated. you can use the `CamelSpringRunner` [source,java] ---- -include::../../../components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/test/CamelSpringDelegatingTestContextLoaderTest.java[tags=example] +include::{examplesdir}/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/test/CamelSpringDelegatingTestContextLoaderTest.java[tags=example] ---- [[Testing-SpringTestwithXMLConfigandDeclarativeConfigurationExample]] ===== Spring Test with XML Config and Declarative Configuration Example Here is a Camel test support enhanced xref:spring-testing.adoc[Spring -Testing] xref:../../../../../components/camel-test-spring/src/test/java/org/apache/camel/test/spring/CamelSpringRunnerPlainTest.java[example +Testing] https://github.com/apache/camel/blob/master/components/camel-test-spring/src/test/java/org/apache/camel/test/spring/CamelSpringRunnerPlainTest.java[example using XML Config and pure Spring Test based configuration of the Camel Context]: [source,java] ---- -include::../../../components/camel-test-spring/src/test/java/org/apache/camel/test/spring/CamelSpringRunnerPlainTest.java[tags=example] +include::{examplesdir}/components/camel-test-spring/src/test/java/org/apache/camel/test/spring/CamelSpringRunnerPlainTest.java[tags=example] ---- Notice how a custom test runner is used with the `@RunWith` annotation @@ -203,22 +203,22 @@ of annotations you can use in your tests. ===== Blueprint Test Here is the Blueprint Testing -xref:../../../../../components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/DebugBlueprintTest.java[example +https://github.com/apache/camel/blob/master/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/DebugBlueprintTest.java[example using XML Config]: [source,java] ---- -include::../../../components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/DebugBlueprintTest.java[tags=example] +include::{examplesdir}/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/DebugBlueprintTest.java[tags=example] ---- Also notice the use of `getBlueprintDescriptors` to indicate that by default we should look for the -xref:../../../../../components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/camelContext.xml[`camelContext.xml` +https://github.com/apache/camel/blob/master/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/camelContext.xml[`camelContext.xml` in the package] to configure the test case which looks like this: [source,xml] ---- -include::../../../components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/camelContext.xml[tags=example] +include::{examplesdir}/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/camelContext.xml[tags=example] ---- [[Testing-Testingendpoints]] diff --git a/docs/yarn.lock b/docs/yarn.lock index 16578d1..0c3462e 100644 --- a/docs/yarn.lock +++ b/docs/yarn.lock @@ -2380,6 +2380,13 @@ through2@^3.0.0: readable-stream "2 || 3" xtend "~4.0.1" +through2@^3.0.1: + version "3.0.1" + resolved "https://registry.yarnpkg.com/through2/-/through2-3.0.1.tgz#39276e713c3302edf9e388dd9c812dd3b825bd5a" + integrity sha512-M96dvTalPT3YbYLaKaCuwu+j06D/8Jfib0o/PxbVt6Amhv3dUAtW6rTV1jPgJSBG83I/e04Y6xkVdVhSRhi0ww== + dependencies: + readable-stream "2 || 3" + through@2, through@~2.3, through@~2.3.1: version "2.3.8" resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5"
