Fork me on GitHub
Subscribe to RSS Feed

Kit Plummer
Software Engineer :: Techitect :: Evangelist
kitplummer (AIM,Yahoo!IM,Gtalk,Skype)

To the top »

Please share:

Pax Exam and ActiveMQ…Testing OSGi Bundles and JMS

I’ve been working with OSGi, specifically Apache Felix/Karaf, a lot lately. I’m also building a few services that interact via JMS. Being test-minded I was looking for a good way to automate testing of my bundles, possibly even deployed against multiple OSGi frameworks. I found PaxExam and became enamored with its great features for integration testing OSGi bundles, or multiples thereof. Pax Exam provides a great API-based scheme for declaring dependent bundles, and means for fetching them from Maven.

There’s already some great posts on using PaxExam, like this one – so I won’t get too much into that. But here’s how I was able to test a couple of Blueprint -based bundles that require a javax.jms.ConnectionFactory to be injected. I also am using ActiveMQ to run an embedded (within the test harness) JMS broker, and expose a ConnectionFactory to the OSGi service framwork.

First, I create an embedded broker in the “setup” method, and create and register the ConnectionFactory:

Note the disabling of the JMX in the broker – otherwise ActiveMQ will fail to launch because some OSGi framework initiate the same 1099 JMX port.

Use the @Configuration annotation to setup the broker’s required dependencies:

Now, any @Test cases can send messages to bundles, and listen on topics or queues which bundles produce to.

Lastly, I use the @After annotation and to shutdown the broker:

Please comment:
blog comments powered by Disqus