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>

1 comments:
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.
Post a Comment