Mocking OSGi services

The Camel Blueprint test kit allows you to mock and prototype OSGi services.

For that, the kit uses the PojoSR library.

For instance, we want to test the following route:

<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">

      <reference id="service" interface="org.apache.camel.Processor"/>

      <camelContext xmlns="http://camel.apache.org/schema/blueprint">
          <route id="test">
              <from uri="direct:input"/>
              <process ref="service"/>
              <to uri="direct:output"/>
          </route>
      </camelContext>

</blueprint>

If this route is very simple, it uses an OSGi service via the <reference/> element. In the OSGi container, the reference element is looking for the actual service in the OSGi Service Registry.

Instead ...

Get Mastering Apache Camel now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.