Sunday, February 21, 2016

Configuring Mule tests to read the Mule Licence


When running unit/functional tests against a Mule application that uses EE plugins, you may get the error:

[ERROR] Couldn't validate license key!
[ERROR] ... java.lang.RuntimeException: Invalid license (org.mule.api.lifecycle.InitialisationException): de.schlichtherle.license.NoLicenseInstalledException: There is no license certificate installed for MuleSource Enterprise Edition.

Ensure that the mule licence is on the test classpath:

<!-- Add the mule licence to the test classpath. The junit tests require a mule enterprise license. -->
<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>build-helper-maven-plugin</artifactId>
  <version>1.7</version>
  <executions>
    <execution>
      <id>add-mule-license-test-resource</id>
      <phase>generate-test-sources</phase>
      <goals>
        <goal>add-test-resource</goal>
      </goals>
      <configuration>
        <resources>
          <resource>
            <directory>/opt/mule/conf</directory>
            <includes>
              <include>muleLicenseKey.lic</include>
            </includes>
          </resource>
        </resources>
      </configuration>
    </execution>
  </executions>
</plugin>

Mule will not be able to read the licence if Xalan (XSLT processor) is not on the classpath:

ERROR] ... org.springframework.beans.factory.BeanDefinitionStoreException:
... java.lang.NoClassDefFoundError: org/apache/xpath/XPathAPI (org.mule.api.lifecycle.InitialisatonException): org.apache.xpath.XPathAPI

Add xalan to the test classpath:

<dependency>
  <groupId>xalan</groupId>
  <artifactId>xalan</artifactId>
  <scope>test</scope>
</dependency>