Skip to content

Commit 13b0c32

Browse files
JonCookJonathan Cook
andauthored
BAEL-5234 - Apache Camel Routes Testing in Spring Boot (eugenp#11925)
* BAEL-4706 - Spring Boot with Spring Batch * BAEL-3948 - Fix test(s) in spring-batch which leaves repository.sqlite changed * BAEL-4736 - Convert JSONArray to List of Object using camel-jackson * BAEL-4756 - Mockito MockSettings * BAEL-4756 - Mockito MockSettings - fix spelling * BAEL-2674 - Upgrade the Okhttp article * BAEL-4204 - Adding Interceptors in OkHTTP * BAEL-4836 - Mocking Static Methods with Mockito * BAEL-4205 - A Guide to Events in OkHTTP * BAEL-5408 - Update Camel version in spring-boot-camel module * BAEL-5234 - Apache Camel Routes Testing in Spring Boot * BAEL-5234 - Apache Camel Routes Testing in Spring Boot Co-authored-by: Jonathan Cook <jcook@sciops.esa.int>
1 parent 02253ff commit 13b0c32

5 files changed

Lines changed: 74 additions & 0 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/output/

spring-boot-modules/spring-boot-camel/pom.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@
4444
<artifactId>spring-boot-starter-test</artifactId>
4545
<scope>test</scope>
4646
</dependency>
47+
<dependency>
48+
<groupId>org.apache.camel</groupId>
49+
<artifactId>camel-test-spring-junit5</artifactId>
50+
<version>${camel.version}</version>
51+
<scope>test</scope>
52+
</dependency>
4753
</dependencies>
4854

4955
<build>
@@ -57,6 +63,9 @@
5763
<goals>
5864
<goal>repackage</goal>
5965
</goals>
66+
<configuration>
67+
<mainClass>com.baeldung.camel.boot.testing.GreetingsFileSpringApplication</mainClass>
68+
</configuration>
6069
</execution>
6170
</executions>
6271
</plugin>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.baeldung.camel.boot.testing;
2+
3+
import org.apache.camel.builder.RouteBuilder;
4+
import org.springframework.stereotype.Component;
5+
6+
@Component
7+
public class GreetingsFileRouter extends RouteBuilder {
8+
9+
@Override
10+
public void configure() throws Exception {
11+
12+
from("direct:start")
13+
.routeId("greetings-route")
14+
.setBody(constant("Hello Baeldung Readers!"))
15+
.to("file:output");
16+
17+
}
18+
19+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.baeldung.camel.boot.testing;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class GreetingsFileSpringApplication {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(GreetingsFileSpringApplication.class, args);
11+
}
12+
13+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.baeldung.camel.boot.testing;
2+
3+
import org.apache.camel.EndpointInject;
4+
import org.apache.camel.ProducerTemplate;
5+
import org.apache.camel.component.mock.MockEndpoint;
6+
import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
7+
import org.apache.camel.test.spring.junit5.MockEndpoints;
8+
import org.junit.jupiter.api.Test;
9+
import org.springframework.beans.factory.annotation.Autowired;
10+
import org.springframework.boot.test.context.SpringBootTest;
11+
12+
@SpringBootTest
13+
@CamelSpringBootTest
14+
@MockEndpoints("file:output")
15+
class GreetingsFileRouterUnitTest {
16+
17+
@Autowired
18+
private ProducerTemplate template;
19+
20+
@EndpointInject("mock:file:output")
21+
private MockEndpoint mock;
22+
23+
@Test
24+
void whenSendBody_thenGreetingReceivedSuccessfully() throws InterruptedException {
25+
mock.expectedBodiesReceived("Hello Baeldung Readers!");
26+
27+
template.sendBody("direct:start", null);
28+
29+
mock.assertIsSatisfied();
30+
}
31+
32+
}

0 commit comments

Comments
 (0)