You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »

Integration Testing In Maven

It is very useful to be able to run integration tests of JBI artefacts being deployed within ServiceMix inside a JUnit test case. Form version 3.2.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 JBI Maven Plugin in your pom.xml like the camel-sa-itest module does.

  • No labels