This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push: new 6ae7f4c Polish and cleanup documentation 6ae7f4c is described below commit 6ae7f4c70b7d25d4ad80740079d7632e541cca9b Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Mon Aug 23 09:19:53 2021 +0200 Polish and cleanup documentation --- .../spring/javaconfig/patterns/FilterTest.java | 83 ------- ...CamelSpringDelegatingTestContextLoaderTest.java | 80 ------- .../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 | 112 ---------- .../org/apache/camel/processor/FilterTest.java | 59 ----- docs/user-manual/modules/ROOT/pages/testing.adoc | 238 ++++++--------------- 8 files changed, 61 insertions(+), 691 deletions(-) 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 deleted file mode 100644 index 5941689..0000000 --- a/docs/user-manual/modules/ROOT/examples/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/patterns/FilterTest.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * 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.junit5.CamelSpringTest; -import org.junit.jupiter.api.Test; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.ContextConfiguration; - -/** - * Tests filtering using Spring Test and Java Config - */ -// START SNIPPET: example -// tag::example[] -@CamelSpringTest -@ContextConfiguration(classes = FilterTest.ContextConfig.class) -public class FilterTest { - - @EndpointInject("mock:result") - protected MockEndpoint resultEndpoint; - - @Produce("direct:start") - protected ProducerTemplate template; - - @DirtiesContext - @org.junit.jupiter.api.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 deleted file mode 100644 index 9844097..0000000 --- a/docs/user-manual/modules/ROOT/examples/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/test/CamelSpringDelegatingTestContextLoaderTest.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * 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.junit5.CamelSpringTest; -import org.apache.camel.test.spring.junit5.MockEndpoints; -import org.junit.jupiter.api.Test; -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[] -@CamelSpringTest -@ContextConfiguration(classes = CamelSpringDelegatingTestContextLoaderTest.TestConfig.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-xml/src/test/java/org/apache/camel/spring/patterns/FilterTest.java b/docs/user-manual/modules/ROOT/examples/components/camel-spring-xml/src/test/java/org/apache/camel/spring/patterns/FilterTest.java deleted file mode 100644 index 6ad20f0..0000000 --- a/docs/user-manual/modules/ROOT/examples/components/camel-spring-xml/src/test/java/org/apache/camel/spring/patterns/FilterTest.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * 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.jupiter.api.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-xml/src/test/resources/org/apache/camel/spring/patterns/FilterTest-context.xml b/docs/user-manual/modules/ROOT/examples/components/camel-spring-xml/src/test/resources/org/apache/camel/spring/patterns/FilterTest-context.xml deleted file mode 100644 index 0541bd1..0000000 --- a/docs/user-manual/modules/ROOT/examples/components/camel-spring-xml/src/test/resources/org/apache/camel/spring/patterns/FilterTest-context.xml +++ /dev/null @@ -1,42 +0,0 @@ -<?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/camel-test-cdi/src/test/java/org/apache/camel/test/cdi/FilterTest.java b/docs/user-manual/modules/ROOT/examples/components/camel-test/camel-test-cdi/src/test/java/org/apache/camel/test/cdi/FilterTest.java deleted file mode 100644 index 4171106..0000000 --- a/docs/user-manual/modules/ROOT/examples/components/camel-test/camel-test-cdi/src/test/java/org/apache/camel/test/cdi/FilterTest.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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/camel-test-spring/src/test/java/org/apache/camel/test/spring/CamelSpringRunnerPlainTest.java b/docs/user-manual/modules/ROOT/examples/components/camel-test/camel-test-spring/src/test/java/org/apache/camel/test/spring/CamelSpringRunnerPlainTest.java deleted file mode 100644 index 76af1f7..0000000 --- a/docs/user-manual/modules/ROOT/examples/components/camel-test/camel-test-spring/src/test/java/org/apache/camel/test/spring/CamelSpringRunnerPlainTest.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * 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 deleted file mode 100644 index b579da9..0000000 --- a/docs/user-manual/modules/ROOT/examples/core/camel-core/src/test/java/org/apache/camel/processor/FilterTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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.builder.RouteBuilder; -import org.apache.camel.component.mock.MockEndpoint; -import org.junit.jupiter.api.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); - - 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/pages/testing.adoc b/docs/user-manual/modules/ROOT/pages/testing.adoc index cdf7486..369971a 100644 --- a/docs/user-manual/modules/ROOT/pages/testing.adoc +++ b/docs/user-manual/modules/ROOT/pages/testing.adoc @@ -2,55 +2,38 @@ = Testing Testing is a crucial activity in any piece of software development or -integration. Typically Camel Riders use various different -technologies wired together in a variety of -patterns with different -expression languages together with different forms -of Bean Integration and -Dependency Injection so its very easy +integration. Typically, Camel users would use various different +technologies wired together in a variety of EIPs with different +endpoints, languages, bean integration, and +dependency injection, so it's very easy for things to go wrong!. Testing is the crucial weapon to ensure that things work as you would expect. -Camel is a Java library so you can easily wire up tests in whatever unit -testing framework you use (JUnit 3.x (deprecated) or 4.x). -However the Camel project has tried to make the testing of Camel as easy -and powerful as possible so we have introduced the following features. +Camel is a Java library, so you can easily wire up tests in JUnit. +However, the Camel project has tried to make the testing of Camel as easy +and powerful as possible, so we have introduced the following features. -[[Testing-Testingmechanisms]] -== Testing mechanisms +== Testing modules -The following mechanisms are supported +The following modules are supported: -[width="100%",cols="1,1m,4",options="header",] +[width="100%",cols="1m,4",options="header",] |======================================================================= -|Name |Component |Description -|Camel Test |camel-test |Is a standalone Java +|Component |Description +|xref:components:others:test.adoc[camel-test] |*JUnit 4 (deprecated)*: Is a standalone Java library letting you easily create Camel test cases using a single Java -class for all your configuration and routing without using CDI or Spring for -Dependency Injection which does not -require an in-depth knowledge of CDI or Spring + Spring Test. -Supports JUnit 3.x (deprecated) and JUnit 4.x based tests. - -|CDI Testing |camel-test-cdi | Provides a JUnit 4 -runner that bootstraps a test environment using CDI so that you don't have -to be familiar with any CDI testing frameworks and can concentrate on the -testing logic of your Camel CDI applications. + -Testing frameworks like http://arquillian.org[Arquillian] -or https://ops4j1.jira.com/wiki/display/PAXEXAM4[PAX Exam], can be used -for more advanced test cases, where you need to configure your system under -test in a very fine-grained way or target specific CDI containers. - -|Spring Testing |camel-test-spring |Supports -JUnit 3.x (deprecated) or JUnit 4.x based tests that bootstrap a test -environment using Spring without needing to be familiar with Spring -Test. The plain JUnit 3.x/4.x based tests work very similar to the -test support classes in `camel-test`. Also supports Spring Test based -tests that use the declarative style of test configuration and injection -common in Spring Test. The Spring Test based tests provide feature -parity with the plain JUnit 3.x/4.x based testing approach. Notice -`camel-test-spring` is a new component in *Camel 2.10* onwards. For -older Camel release use `camel-test` which has built-in -Spring Testing. +class for all your configuration and routing without. + +|xref:components:others:test-junit5.adoc[camel-test-junit5] |*JUnit 5*: Is a standalone Java +library letting you easily create Camel test cases using a single Java +class for all your configuration and routing without. + +|xref:components:others:test-spring.adoc[camel-test-spring] | *JUnit 4 (deprecated)*: Used for testing Camel with Spring / Spring Boot +|xref:components:others:test-spring-junit5.adoc[camel-test-spring-junit5] | *JUnit 5*: Used for testing Camel with Spring / Spring Boot +|xref:components:others:test-cdi.adoc[camel-test-cdi] | Used for testing Camel on xref:components:others:cdi.adoc[CDI] + +|xref:components:others:testcontainers-junit5.adoc[camel-test-containers-junit5] | *JUnit 5*: Camel Testcontainers extends standard camel test support providing a way to create and interact with containerized applications. +|xref:components:others:testcontainers-spring-junit5.adoc[camel-test-containers-spring-junit5] | *JUnit 5*: Camel Testcontainers extends standard camel Spring test support providing a way to create and interact with containerized applications. |======================================================================= @@ -58,151 +41,42 @@ In all approaches the test classes look pretty much the same in that they all reuse the xref:bean-integration.adoc[Camel binding and injection annotations]. -[[Testing-CamelTestExample]] -=== Camel Test Example - -Here is the Camel Test -https://github.com/apache/camel/blob/main/core/camel-core/src/test/java/org/apache/camel/processor/FilterTest.java[example]: - -[source,java] ----- -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 -has no CDI or Spring dependency injection configuration but instead -overrides the `createRouteBuilder()` method. - -[[Testing-CdiTestExample]] -=== CDI Test Example - -Here is the CDI Testing -https://github.com/apache/camel/blob/main/components/camel-test-cdi/src/test/java/org/apache/camel/test/cdi/FilterTest.java[example]: - -[source,java] ----- -include::{examplesdir}/components/camel-test/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 -and the test classes that come with it. - -[[Testing-SpringTestwithXMLConfigExample]] -=== Spring Test with XML Config Example - -Here is the Spring Testing -https://github.com/apache/camel/blob/main/components/camel-spring-xml/src/test/java/org/apache/camel/spring/patterns/FilterTest.java[example -using XML Config]: - -[source,java] ----- -include::{examplesdir}/components/camel-spring-xml/src/test/java/org/apache/camel/spring/patterns/FilterTest.java[tags=example] ----- - -Notice that we use @`DirtiesContext` on the test methods to force -Spring Testing to automatically reload the -`CamelContext` after each test method - this -ensures that the tests don't clash with each other (e.g. one test method -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 -https://github.com/apache/camel/blob/main/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::{examplesdir}/components/camel-spring-xml/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 -https://github.com/apache/camel/blob/main/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/patterns/FilterTest.java[example -using Java Config]: - -[source,java] ----- -include::{examplesdir}/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/patterns/FilterTest.java[tags=example] ----- - -For more information see xref:components:others:spring-javaconfig.adoc[Spring Java -Config]. - -This is similar to the XML Config example above except that there is no -XML file and instead the nested `ContextConfig` class does all of the -configuration; so your entire test case is contained in a single Java -class. We currently have to reference by class name this class in the -`@ContextConfiguration` which is a bit ugly. Please vote for -http://jira.springframework.org/browse/SJC-238[SJC-238] to address this -and make Spring Test work more cleanly with Spring JavaConfig. - -It's totally optional but for the `ContextConfig` implementation we derive -from `SingleRouteCamelConfiguration` which is a helper Spring Java -Config class which will configure the CamelContext for us and then -register the RouteBuilder we create. - -Since *Camel 2.11.0* you can use the `CamelSpringJUnit4ClassRunner` with -`CamelSpringDelegatingTestContextLoader` like -https://github.com/apache/camel/blob/main/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` +TIP: For more details on the different testing modules, then see their respective documentation +from the links in the table above. -[source,java] ----- -include::{examplesdir}/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/test/CamelSpringDelegatingTestContextLoaderTest.java[tags=example] ----- +== Testing functionality -[[Testing-SpringTestwithXMLConfigandDeclarativeConfigurationExample]] -=== Spring Test with XML Config and Declarative Configuration Example +Camel provides a set of features that are common to use when writing unit or integration tests with Camel. -Here is a Camel test support enhanced xref:spring-testing.adoc[Spring -Testing] https://github.com/apache/camel/blob/main/components/camel-test/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::{examplesdir}/components/camel-test/camel-test-spring/src/test/java/org/apache/camel/test/spring/CamelSpringRunnerPlainTest.java[tags=example] ----- +=== Testing endpoints -Notice how a custom test runner is used with the `@RunWith` annotation -to support the features of `CamelTestSupport` through annotations on -the test class. See Spring Testing for a list -of annotations you can use in your tests. - -[[Testing-Testingendpoints]] -== Testing endpoints - -Camel provides a number of endpoints which can make testing easier. +Camel provides a number of xref:endpoint.adoc[endpoints] which can make testing easier. [width="100%",cols="1,3",options="header",] |======================================================================= |Name |Description -|xref:components::dataset-component.adoc[DataSet] |For load & soak testing this endpoint -provides a way to create huge numbers of messages for sending to -Components and asserting that they are consumed -correctly - |xref:components::mock-component.adoc[Mock] |For testing routes and mediation rules using mocks and allowing assertions to be added to an endpoint |xref:components:others:test.adoc[Test] |Creates a xref:components::mock-component.adoc[Mock] endpoint which expects to receive all the message bodies that could be polled from the given underlying endpoint + +|xref:components::dataset-component.adoc[DataSet] |For load & soak testing this endpoint +provides a way to create huge numbers of messages for sending to +Components and asserting that they are consumed +correctly + |======================================================================= The main endpoint is the xref:components::mock-component.adoc[Mock] endpoint which allows expectations to be added to different endpoints; you can then run your tests and assert that your expectations are met at the end. -[[Testing-Stubbingoutphysicaltransporttechnologies]] -== Stubbing out physical transport technologies +=== Stubbing out physical transport technologies -If you wish to test out a route but want to avoid actually using a real -physical transport (for example to unit test a transformation route +If you wish to test out a route but want to avoid actually using real physical transport +(for example to unit test a transformation route rather than performing a full integration test) then the following endpoints can be useful: @@ -213,21 +87,18 @@ endpoints can be useful: producer so that single threaded (non-SEDA) in VM invocation is performed which can be useful to mock out physical transports -|xref:components::seda-component.adoc[SEDA] |Delivers messages asynchronously to consumers via -a -http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/BlockingQueue.html[`java.util.concurrent.BlockingQueue`] -which is good for testing asynchronous transports +|xref:components::seda-component.adoc[SEDA] |Deliver messages asynchronously to consumers via +a `BlockingQueue` which is good for testing asynchronous transports |xref:components::stub-component.adoc[Stub] |Works like xref:components::stub-component.adoc[SEDA] but does not -validate the endpoint URI, which makes stubbing much easier. +validate the endpoint URI, which makes stubbing very easy. |======================================================================= -[[Testing-Testingexistingroutes]] -== Testing existing routes +=== Testing existing routes Camel provides some features to aid during testing of existing routes -where you cannot or will not use xref:components::mock-component.adoc[Mock] etc. For example -you may have a production ready route which you want to test with some +where you cannot or will not use xref:components::mock-component.adoc[Mock] etc. +For example, you may have a production ready route which you want to test with some 3rd party API which sends messages into this route. [width="100%",cols="1,3",options="header",] @@ -238,8 +109,21 @@ a certain condition has occurred. For example when the route has completed 5 messages. You can build complex expressions to match your criteria when to be notified. -|AdviceWith |Allows you to *advice* or *enhance* +|AdviceWith |Allows you to _advice_ (enhance) an existing route using a `RouteBuilder` style. -For example you can add interceptors to intercept sending outgoing -messages to assert those messages are as expected. +For example, you can send (or send and skip) message to a xref:components::mock-component.adoc[Mock] +endpoint for validating the message send by Camel is as expected. +|======================================================================= + +=== Third Party Testing libraries + +There are a number of third party testing libraries that Camel users have found useful. + +[width="100%",cols="1,3",options="header",] +|======================================================================= +|Name |Description +| https://citrusframework.org/[Citrus Integration Framework] | Framework for automated integration tests supporting a wide range of message protocols and data formats + +| https://citrusframework.org/yaks/[Citrus Yaks] | YAKS is a framework to enable Cloud Native BDD testing on Kubernetes + |=======================================================================