Automating Integration Tests with WebSphere Liberty and Maven

I spent some hours to figure out how to deploy my webapp to the Liberty from my Maven project.

I looked into the feature restConnector-1.0 . restConnector provides a REST based JMX MBeans interface to WebSphere Liberty.  You add  <feature>restConnector-1.0</feature> to your server, and make sure you have a user set in the admin role.

<administrator-role>
 <user>admin</user>
</administrator-role>

You need to add write access for the administrator-role user.  You’ll need to specify a relative path (use the Liberty Directory Locations) or use the absolute path (it’s a bit more complicated).

 <remoteFileAccess>
   <writeDir>${server.output.dir}/dropins</writeDir>
 </remoteFileAccess>

You can login and see the various APIs [ https://localhost:9443/IBMJMXConnectorREST/api ] or check the documentation [API1][API2][MBean]  .  You’ll want to check any upload with https://localhost:9443/IBMJMXConnectorREST/file/status

I used it with maven-antrun-plugin to execute against curl.

<plugin>
 <artifactId>maven-antrun-plugin</artifactId>
 <version>1.8</version>
 <executions>
 <execution>
 <id>upload-pre-integration</id>
 <phase>pre-integration-test</phase>
 <goals>
 <goal>run</goal>
 </goals>
 <configuration>
 <target name="post-war-to-server" unless="maven.test.skip">
 <!-- Remove War File from the Server -->
 <exec executable="curl">
 <arg
 line="-u 'admin:dmin' -H 'Content-Type: application/war' -X DELETE 'https://localhost:9443/IBMJMXConnectorREST/file/%24%7Bserver.output.dir%7D%2Fdropins%2Ftransformation.war?recursiveDelete=true' 
 --insecure -v" />
 </exec>
 <!-- Should check that this is a 204 -->
 
 <!-- Post the War file to the Server -->
 <!-- Expand the War file on the Server -->
 <exec executable="curl">
 <arg
 line="-u 'admin:admin' -H 'Content-Type: application/war' -X POST 'https://localhost:9443/IBMJMXConnectorREST/file/%24%7Bserver.output.dir%7D%2Fdropins%2Ftransformation.war?expandOnCompletion=true' 
 --data-binary '@target/example.war' --insecure -v" />
 </exec>
 
 </target>

 </configuration>
 </execution>
 </executions>
 </plugin>

Execute maven with mvn clean integration-test package in order to trigger the deployment during the integration-test.

Leave a Reply

Your email address will not be published. Required fields are marked *