[Spring Boot] Testing Apache Camel SEDA Endpoint
Recently, I found myself being surround by a legacy system full of Apache Camel. Looking at the documentation, writing test codes seemed promising with mock endpoints provided by Apache Camel. However, writing integration tests did not go nearly as smooth as I imagined. So I am leaving some notes here to hopefully make my life easier in the future.
First, create a bean which sends something to a route (seda endpoint).
At first, I tried with a servlet. This worked well during runtime being able to make requests to
GET http://localhost:8080/service/hello. However, this approach did not work well for tests as I could not find a good way to make a servlet request with
So I ended up converting the above servlet endpoint to a REST endpoint.
To make the app to run successfully, I had to get rid of these configurations and dependency.
InternalDispatcher produces to seda queue, the route defined below will run. It basically prints to console and unmarshals to a custom data format.
Regarding the first test case
I found it easier to make a request to a REST endpoint using
MockMvc rather than making a request to servlet endpoint. This is why I switched from
SampleController.java in the implementation.
With seda queue, it was possible to poll from the queue right after producing to it. This allows me to assert the contents of the request message that
Regarding the second test case
Because of the fact that consumers run on different threads than producers using seda, it was difficult to produce and check the consumed result immediately. Fortunately, I was able to find a work around to replace a specific route for testing. By switching seda to direct, it was possible to obtain the result of the consumer and assert against it.