Chapter 16. Testing OSGi components
Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: Nothing works and they don’t know why.
Anonymous
This chapter covers
- The OSGi dynamic module system
- Mock testing of your modules
- In-container testing of your modules
So far, we’ve been testing everything from the Java EE spec. All the Java EE components that we’ve dealt with (JSPs, tag libraries, servlets, filters, EJBs, and so on) have been available for a long time. In this chapter we discuss a technology that became popular relatively recently and is getting more popular every day: OSGi.
We start the chapter by introducing OSGi[1] We then walk through the basic OSGi concepts and provide easy-to-grasp examples by means of the calculator application from chapter 1. In the second part of the chapter, we show how to test our OSGi calculator bundle by introducing the JUnit4OSGi framework.
1 OSGi is a registered trademark of the OSGi Alliance.
The term OSGi[2] usually refers to two things: the OSGi alliance (http://osgi.org/) and the OSGi service platform.
2 For a complete reference to OSGi we recommend OSGi in Action, by Richard S. Hall, Karl Pauls, Stuart McCulloch, and David Savage (Manning Publications, 2010).