You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2018/09/07 07:12:36 UTC
[camel] branch master updated: Adding docs section on Spring Boot
testing with example (#2510)
This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new e34e211 Adding docs section on Spring Boot testing with example (#2510)
e34e211 is described below
commit e34e211b53fb33ceaabe4fa4e3d7700d35ec568c
Author: Tom Donohue <mo...@users.noreply.github.com>
AuthorDate: Fri Sep 7 08:12:31 2018 +0100
Adding docs section on Spring Boot testing with example (#2510)
---
.../src/main/docs/spring-boot.adoc | 52 ++++++++++++++++++++++
1 file changed, 52 insertions(+)
diff --git a/components/camel-spring-boot/src/main/docs/spring-boot.adoc b/components/camel-spring-boot/src/main/docs/spring-boot.adoc
index d8bad47..063d0b2 100644
--- a/components/camel-spring-boot/src/main/docs/spring-boot.adoc
+++ b/components/camel-spring-boot/src/main/docs/spring-boot.adoc
@@ -576,3 +576,55 @@ The Rest-DSL XML files should be Camel XML rests (not CamelContext) such as
</rest>
</rests>
----
+
+[[SpringBoot-Testing]]
+=== Testing
+For testing, Maven users will need to add the following dependencies to their `pom.xml`:
+
+[source,xml]
+----
+<dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-test</artifactId>
+ <version>${spring-boot.version}</version> <!-- Use the same version as your Spring Boot version -->
+ <scope>test</scope>
+</dependency>
+<dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-test-spring</artifactId>
+ <version>${camel.version}</version> <!-- use the same version as your Camel core version -->
+ <scope>test</scope>
+</dependency>
+----
+
+To test a Camel Spring Boot application, annotate your test class(es) with
+`@RunWith(CamelSpringBootRunner.class)`. This brings Camel's Spring Test
+support to your application, so that you can write tests using
+https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-testing.html[Spring Boot test conventions].
+
+To get the `CamelContext` or `ProducerTemplate`, you can inject them into the class in the normal Spring manner, using `@Autowired`.
+
+You can also use link:../../../../../docs/user-manual/en/spring-testing.adoc#camel-enhanced-spring-test[Camel Spring test annotations] to configure tests declaratively. This example uses the `@MockEndpoints` annotation to auto-mock an endpoint:
+
+[source,java]
+----
+@RunWith(CamelSpringBootRunner.class)
+@SpringBootTest
+@MockEndpoints("direct:end")
+public class MyApplicationTest {
+
+ @Autowired
+ private ProducerTemplate template;
+
+ @EndpointInject(uri = "mock:direct:end")
+ MockEndpoint mock;
+
+ @Test
+ public void testReceive() throws Exception {
+ mock.expectedBodiesReceived("Hello");
+ template.sendBody("direct:start", "Hello");
+ mock.assertIsSatisfied();
+ }
+
+}
+----