BAEL-5234 - Apache Camel Routes Testing in Spring Boot (#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>
This commit is contained in:
Jonathan Cook 2022-03-14 23:35:32 +01:00 committed by GitHub
parent f74056e1d7
commit 7681cb2d65
5 changed files with 74 additions and 0 deletions

View File

@ -0,0 +1 @@
/output/

View File

@ -44,6 +44,12 @@
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-test-spring-junit5</artifactId>
<version>${camel.version}</version>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>
@ -57,6 +63,9 @@
<goals> <goals>
<goal>repackage</goal> <goal>repackage</goal>
</goals> </goals>
<configuration>
<mainClass>com.baeldung.camel.boot.testing.GreetingsFileSpringApplication</mainClass>
</configuration>
</execution> </execution>
</executions> </executions>
</plugin> </plugin>

View File

@ -0,0 +1,19 @@
package com.baeldung.camel.boot.testing;
import org.apache.camel.builder.RouteBuilder;
import org.springframework.stereotype.Component;
@Component
public class GreetingsFileRouter extends RouteBuilder {
@Override
public void configure() throws Exception {
from("direct:start")
.routeId("greetings-route")
.setBody(constant("Hello Baeldung Readers!"))
.to("file:output");
}
}

View File

@ -0,0 +1,13 @@
package com.baeldung.camel.boot.testing;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class GreetingsFileSpringApplication {
public static void main(String[] args) {
SpringApplication.run(GreetingsFileSpringApplication.class, args);
}
}

View File

@ -0,0 +1,32 @@
package com.baeldung.camel.boot.testing;
import org.apache.camel.EndpointInject;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
import org.apache.camel.test.spring.junit5.MockEndpoints;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
@CamelSpringBootTest
@MockEndpoints("file:output")
class GreetingsFileRouterUnitTest {
@Autowired
private ProducerTemplate template;
@EndpointInject("mock:file:output")
private MockEndpoint mock;
@Test
void whenSendBody_thenGreetingReceivedSuccessfully() throws InterruptedException {
mock.expectedBodiesReceived("Hello Baeldung Readers!");
template.sendBody("direct:start", null);
mock.assertIsSatisfied();
}
}