Unit testing Camel Blueprint routes

Last week, while in Vegas, I discussed with my colleague Scott Cranton and he told me that something that was really making our users tend to stick with Spring-DM when using Camel Blueprint routes was that unit testing those routes was not possible.

So I hacked a small support library for Camel, leveraging PojoSR which provides a service registry without using a fully compliant OSGi container. This allows defining real unit tests (as opposed to integration tests using Pax Exam.

See the below example.

public class DebugBlueprintTest extends CamelBlueprintTestSupport {

    protected Collection<URL> getBlueprintDescriptors() {
        return Collections.singleton(getClass().getResource("camelContext.xml"));

    public void testRoute() throws Exception {
        // set mock expectations

        // send a message
        template.sendBody("direct:start", "World");

        // assert mocks

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">

 <camelcontext autostartup="true" id="camelContext" trace="true" xmlns="http://camel.apache.org/schema/blueprint">

   <from uri="direct:start"/>
    <simple>Hello ${body}</simple>
   <to uri="mock:a"/>



Guillaume Nodet said…
Those classes are all part of the camel-test-blueprint artifact so adding it as a dependency should be sufficient to write tests.
I've also improved the camel blueprint archetype to generate a similar small test.
Jon said…
Hi Giullaume,

Where is the camel-test-blueprint jar? I can only find a 2.1.0-SNAPSHOT version in camel's snapshots maven repo.

The dependency is documented on the Camel site under http://camel.apache.org/blueprint-testing.html - however only camel-testing seems to be available when you look in the release repo's.

I am trying to use the snapshot version but am getting a NoSuchMethodException on IOHelper.close(...) method which i suspect is because i've got camel-... 2.9.1 in my path instead of 2.1.0.

Is there a version compatible with 2.9.1? Is there a release version somewhere?

Guillaume Nodet said…
The snapshots are available in the apache snapshot repository with the 2.10-SNAPSHOT (and not 2.1.0-SNAPSHOT) at the following location:

Popular posts from this blog

Camel Endpoint DSL

ActiveMQ Pooling

Apache Karaf