Integration Testing In Spring

It is very useful to be able to run integration tests of JBI artefacts being deployed within ServiceMix inside a JUnit test case either ran from inside your IDE or from inside the maven test run.

From version 3.2 onwards of ServiceMix you can accomplish this using a simple Spring.xml as follows...

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:sm="http://servicemix.apache.org/config/1.0"
       xsi:schemaLocation="
         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
         http://servicemix.apache.org/config/1.0 http://incubator.apache.org/servicemix/schema/core/servicemix-core.xsd">


  <sm:container generateRootDir="true">

    <sm:deployments>
      <sm:installSharedLibrary groupId="org.apache.servicemix" artifactId="servicemix-shared"/>
      <sm:installComponent groupId="org.apache.servicemix" artifactId="servicemix-camel"/>
      <sm:deployServiceAssembly groupId="org.apache.servicemix.samples" artifactId="camel-sa"/>
    </sm:deployments>

  </sm:container>

</beans>

This example will deploy a shared library, a component and a service assembly in a temporary ServiceMix installation; which can then be further integration tested, such as by sending messages into the NMR via Camel Mock Testing.

For more details on this example, see the Camel Example.

Version resolving

In the example above you can see we just list the maven groupId and artifactId strings for the various JBI deployment artifacts (shared libraries, components, service assemblies etc). You can if you prefer specify the full file, or specify the explicit version number.

However its common to want to just inherit the version number from the maven pom.xml. So if you omit the version property on the above deployment elements, it will search the classpath for the META-INF/maven/dependencies.properties files and look in those to try figure out the version number of the referenced groupId and artifactId.

So just add the necessary test dependencies to your maven pom.xml and you can then avoid specifying the version numbers in your spring.xml

To ensure that the META-INF/maven/dependencies.properties files are all available and contain the dependency information for the Service Assemblies we recommend you write your integration test using a packaging of itest and enable the Maven JBI plugin in your pom.xml like the camel-sa-itest module does.

Examples

  • camel-sa-itest shows how to deploy a camel based SA/SU in servicemix via Spring
  • bridge-sa-itest shows how to deploy an SA in ServiceMix via Spring with an ActiveMQ broker deployed locally for the integration test along with some Camel routing rules to create initial message flows etc.