Automatic Testing Service Mix with Pax Exam
I've been searching a way to write testing code for OSGi environment. There are Spring DM and Pax Exam that I found recently. Since Pax Exam supports JUnit 4, I prefer this one. Pax Exam works by create unique OSGi environment for each @Test method and make the test class as one of the OSGi bundle.
The challenge is that default OSGi environment is not enough to make a Spring-ready OSGi package to start. So, we need more: camel feature and camel-cxf feature. Features is related to Apache Service Mix.
For basic tutorial about Pax Exam, you need to read this. And, in order to make Pax Exam works with Apache Service Mix you need to read this
To load features from JAR files, we need to ensure that the JARs are included in dependency as pom (type=pom).
<!--
Dependencies which contains required features (like Spring context)
-->
<dependency>
<groupId>org.apache.felix.karaf</groupId>
<artifactId>apache-felix-karaf</artifactId>
<version>${felix.karaf.version}</version>
<type>pom</type>
<scope>test</scope>
</dependency>
<dependency><!-- For ActiveMQ related features -->
<groupId>org.apache.servicemix</groupId>
<artifactId>apache-servicemix</artifactId>
<version>4.2.0</version>
<type>pom</type>
<scope>test</scope>
</dependency>
<dependency><!-- For Camel related features -->
<groupId>org.apache.camel.karaf</groupId>
<artifactId>apache-camel</artifactId>
<version>2.2.0</version>
<type>pom</type>
<scope>test</scope>
</dependency>
Now, in our test configuration (which returns Option[]), be sure to include the features:
@RunWith(JUnit4TestRunner.class)
public class CalculatorTestCase extends AbstractIntegrationTest {
@Configuration
public static Option[] configuration() throws Exception {
return combine(
// Default karaf environment
Helper.getDefaultOptions(
scanFeatures(
maven().groupId("org.apache.camel.karaf").artifactId("apache-camel").
type("xml").classifier("features").versionAsInProject(), // Resolved in <dependency> tag
"camel", "camel-cxf"
)
);
}
}
Now, it's your turn Pal! Let's make quality softwares!

Comments
Post new comment