Blueprint TestingPage edited by Claus IbsenChanges (6)
Full ContentBlueprint TestingAvailable as of Camel 2.10 Testing is a crucial part of any development or integration work. Camel supports the definition of Blueprint routes, but given Blueprint is an OSGi specific technology, writing unit tests is quite difficult. This library leverages 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. // to use camel-test-blueprint, then extend the CamelBlueprintTestSupport class, // and add your unit tests methods as shown below. public class DebugBlueprintTest extends CamelBlueprintTestSupport {
// override this method, and return the location of our Blueprint XML file to be used for testing
@Override
protected String getBlueprintDescriptor() {
return "org/apache/camel/test/blueprint/camelContext.xml";
}
// here we have regular Junit @Test method
@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();
}
}
Also notice the use of getBlueprintDescriptor to specify the location of the OSGi Blueprint XML file. And the Blueprint XML file. And link to the full file here <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd"> <camelContext 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> In order to define blueprint tests, you need to add the following dependency in your pom: <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-test-blueprint</artifactId> <version>2.10</version> <scope>test</scope> </dependency>
Change Notification Preferences
View Online
|
View Changes
|
Add Comment
|
- [CONF] Apache Camel > Blueprint Testing confluence
- [CONF] Apache Camel > Blueprint Testing confluence
- [CONF] Apache Camel > Blueprint Testing confluence
- [CONF] Apache Camel > Blueprint Testing confluence
