apache-camelIntegration testing on existing routes with Apache-Camel and Spring (And DBUnit)


Introduction

The point of this wiki is to show you how to execute integration tests using Apache Camel.

More precisely, doing this you will be able to launch an existing route from beginning to end (With or without your real database) or intercept the exchange between each part of the route and test if your headers or body are correct or not.

The project I have been doing this on uses classic Spring with xml configuration and DBUnit to mock a test database. Hope this will give you a few leads.

Parameters

Parameter/FunctionDetails
ExchangeThe exchange is used inside the camel processor to pass objects between parts of your route
CamelContextThe camel context is used in the test to manually start and stop the context.
ProducerTemplateAllows you to send messages in your route, setting the complete exchange manually or sending dummy headers/body
AdviceWithHelps you redefine an existing route with the current context
WeaveByIdUsed inside the advice with configuration, tells pieces of your route how to behave (Can also use weaveByToString)
MockEndpointThe mockendpoint is a point you define for your test. In your weaveById, you can tell your route to its usual processing and go into a mockEnpoint rather than following the usual route. This way you can check the message count, the exchange status ...

Remarks

Some definitions given here are not perfectly accurate, but they will help you understand the code above. Here are a few links for more detailed information :

This particular way of testing is pretty hard to find, even on stack overflow. This is pretty specific but don't hesitate to ask for more details, maybe I'll be able to help.