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 {
 @Override
 protected Collection<URL> getBlueprintDescriptors() {
 return Collections.singleton(getClass().getResource("camelContext.xml"));
 }
 @Test
 public void testRoute() throws Exception {
 // set mock expectations
 getMockEndpoint("mock:a").expectedMessageCount(1);
 // send a message
 template.sendBody("direct:start", "World");
 // assert mocks
 assertMockEndpointsSatisfied();
 }
}
<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">
 <route>
 <from uri="direct:start"/>
 <transform>
 <simple>Hello ${body}</simple>
 </transform>
 <to uri="mock:a"/>
 </route>
 </camelcontext>
</blueprint>

Comments

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?

Regards,
Jon
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:
https://repository.apache.org/content/groups/snapshots/org/apache/camel/camel-test-blueprint/2.10-SNAPSHOT/

Popular posts from this blog

SSH Server in Java

ServiceMix Kernel is a small container based on OSGi. The latest release allows external clients to connect to it and issue commands using a simple protocol implemented on top of TCP or SSL. However, this remoting protocol has some drawbacks as the internals makes it unable to do another remote login from a remote session. In addition to that, completion and history do not really work great. So I've been thinking about using the SSH protocol, which is widely used, secured, with tons of different clients available. Unfortunately, no SSH server is available in Java. Over the past weeks, I've been working on implementing this SSH server, based on the IEFT specifications, the JSch SSH client library, and the OpenSSH server source code. The server itself is based on Apache Mina which is a great framework for using NIO. The project is available at http://code.google.com/p/sshd/ and although there are lots of limitations right now, the basics of the SSH protocol work. I plan t...

Apache Karaf

ApacheCon was really interesting this year! Recently, a lot of people have expressed a real interest in ServiceMix Kernel , our generic OSGi distribution for server side applications. We've been discussing moving this subproject into Apache Felix for several reasons: raise the visibility and awareness on ServiceMix Kernel attract a broader community Several Apache projects are planning to use ServiceMix Kernel as their container: this includes Apache James , Apache Directory and Apache ActiveMQ . The Apache Sling community is also willing to contribute to this effort along with some other groups like the OPS4J project. During this discussion, a name as been proposed by Jamie Goodyear: Apache Karaf . A carafe is a small container used for serving wine and other drinks (http://en.wikipedia.org/wiki/Carafe). In similarity to the name the Kernel allows applications to be more easily handled, and improves their characteristics (much like a bottle of wine left to breath in a dec...

Camel Endpoint DSL

Camel Endpoint DSL One of the new features of Camel 3.0  is an Endpoint DSL.  This new API aims to provide a type safe replacement for the URLs that are used in Camel to designate the consumer or producer endpoints.  These URLs provide 3 things: the scheme of the URL identifies the component to use, a unique name or id for the endpoint, and a set of parameters to customize the endpoint behavior. Here is an example of an FTP consumer endpoint definition: from( "ftp://foo@myserver?password=secret& recursive=true& ftpClient.dataTimeout=30000& ftpClientConfig.serverLanguageCode=fr" ) .to( "bean:doSomething" ); There are several drawbacks with such constructs : no type safety, bad readability and no simple completion. So we now use the meta model, which is currently extracted from the source using an annotation processor and written in various JSON files, to generate a fluent DSL for each endpoint.  The same...