This project demonstrates a number of mechanisms for testing OSGi artifacts based on SpringDM that are intended to be deployed against ServiceMix. It is intended to demonstrate:
- integration testing of OSGi bundles and Karaf features being deployed into a Karaf container
- integration testing of Spring-DM Camel routes
- unit testing of the same Camel routes outside of an OSGi container
The integration testing approach expands on that defined in Advanced integration testing with Pax Exam Karaf.
The Maven projects contained within are as follows:
servicemix-test-utils
- Contains utility classes for use with Pax Exam Karaf, that simplify the configuration of an integration with ServiceMix.dm-integration-testing/dm-bundle
- Contains a SpringDM bundle with a Camel route to be tested. Includes a pax-exam integration test for the bundle to check that it deploys as expected.dm-integration-testing/dm-features
- Defines afeatures.xml
which deploys thedm-bundle
; tests the feature as a pax-exam integration test.
When building the project for the first time, run $> mvn install
.
Integration tests are executed by the maven-failsafe-plugin at the integration-test
phase, which is run after packaging but before deployment; any project which fails at this stage will not have its artifacts deployed.
The convention applied is the default of the plugin, which defines integration tests in the src/test/java
directory, with names matching *ITCase.java
. This avoids clashes with the standard JUnit conventions (*Test.java
) applied to unit tests via the maven-surefire-plugin. Build artifacts are sourced from the target
directory.
The dm-bundle
project defines a number of files of interest that provide maximum reuse of the core source artifacts, while enabling ease of testing:
- the
src/main/resources/META-INF/spring
is automatically scanned by the SpringDM framework when the bundle is deployed in a container for any files matching*.xml
; these are then treated as standard Springbeans
definitions. The project defines two files (this definition is a standard way of doing things):dm-bundle-context.xml
- this is a standard Spring file with a Camel context that defines a route. Spring${}
property placeholders are used, but the file intentionally does not define aPropertyPlaceHolderConfigurer
.dm-bundle-osgi-context.xml
- this defines the SpringDM OSGi bits (defined via theosgi
andosgix
namespaces). When loaded into a container, this will provide all of the necessary hooks into the configuration service and service registry.
- the
src/test/resources/
directory is used to define configuration that will be used by unit tests only. It contains:dm-bundle-test-context.xml
- a substitute forMETA-INF/spring/dm-bundle-osgi-context.xml
; to be used in conjunction withMETA-INF/spring/dm-bundle-context.xml
. It defines aPropertyPlaceHolderConfigurer
that will fill in the${}
placeholders.test.properties
- the properties used to fill those placeholders.