Thursday 6 April 2017

SoapUI, HermesJMS, IBM Websphere MQ automation with Maven

I was working on the project where I need to automate tests with interact with IBM websphere MQ queues. I have been able to achieve it from SoapUI and HermesJMS (I have already talked about the steps in my old post here) soon to face the next challenge to integrate with Jenkins and run the tests with scheduled builds. 
In my hope to find an existing solution on net, I looked for it on google. Unfortunately it didn't help that much as the solutions available did not help me but they gave me an idea about how to achieve the same. I am using maven for integration of my solution here.


Step 1 : HeremesJMS Configuration File

I would suggest to simplify the HermesJMS configuration file which was created in the steps performed in exercise earlier. Remove all the unnecessary elements and keep only those that you would need for your test.  Here below is my configuration file which I've used



You would notice that I've used a keyword "MQ_LIB_LOCATION" while providing the path of the IBM websphere MQ dependency jar files which are used by HermesJMS in order to create connection. While my experiment I realized that in order to be able to run my build I'll have to keep my hermes configuration file autonomous. Hence, I needed to update the file dynamically with help of "com.google.code.maven-replacer-plugin" of maven. With help of this plugin I change the path of the libraries used by HermesJMS.


Step 2 : Create Maven Project skeleton

As explained above we will have to update the Hermes configuration files dynamically, hence a separate maven project module would be needed for achieving this and another module will be used to execute the SoapUI project.

Create the master project using below command and then the modules under the master project
mvn archetype:generate -DgroupId=myorg.com -DartifactId=myapp -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
This command will create a directory "myapp" with the master project, now edit the pom file and change "packaging" parameter from "jar" to "pom" and remove the directory "src" from the master project as you will not be using it.
Once done, you can create the modules. Go to the master project directory and create the two modules with below commands
mvn archetype:generate -DgroupId=myorg.com -DartifactId=SoapProject -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
mvn archetype:generate -DgroupId=myorg.com -DartifactId=UpdateHermesJMS -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
Now the two projects are ready, you can update the pom file to meet your need. We will start with the project to update the Hermes configuration.


Step 3 : Module UpdateHermesJMS

Now is the time to setup your module to update the hermesJMS configuration to be able to run in any environment. For this add a "com.google.code.maven-replacer-plugin" plugin to the project. I have created a folder "resources" under "src/main/" where I have put the folder for hermes configuration "hermes", the package of hermes "HermesJMS" and the library files for IBM Websphere MQ which is needed by HermesJMS for connecting to websphere MQ.
Below is example from my project : 


Step 4 : Module SoapProject

You are now set to work on the final module which is going to execute the SoapUI tests. There are few elements you should focus on and we will discuss about them one by one. 

Dependencies : Since the module UpdateHermesJMS should be executed before the SoapProject in order to have your configuration ready, this project needs to be prioritized. For that we need to define this module as dependency in the SoapProject module

Another level of dependencies has to be defined at plugin level for HermesJMS and websphere MQ library. 


I hope you are already aware of the SoapUI project execution and related plugin. The only thing extra you may have to do is to define two additional global variable for your project that will be used by SoapUI to configure HermesJMS
<globalProperties>
    <value>HERMES_JMS=${basedir}/../updateHermesConf/src/main/resources/HermesJMS</value>
    <value>hermesConfig=${basedir}/../updateHermesConf/src/main/resources/hermes</value>
</globalProperties>

Step 5 : Project LoadScript

Your maven project should be ready, however your project still needs one more tweeks in order to be able to use the right HermesJMS and corresponding configuration file.
Open your SoapUI workspace, right click on the project click on "Show Project View" and go on "Load Script" on the window of the project and insert the below script to configure HermesJMS and its configuration from the variables we have defined in previous step.



Now you are all set with the project and you can integrate your maven project on Jenkins with a simple maven build.