Sunday 6 November 2016

SoapUI : Websphere MQ Test Integration

Prerequisites : 

  • MQ Queue should be accessible from outside
  • Details of Queue manager (IP, port, etc)
  • IBM Websphere MQ client installed on the machine

Configuring HermesJMS

The new version of SoapUI comes in a bundle with HermesJMS which can be installed while installing SoapUI itself. If you do not have HermesJMS installed already, you can do it after downloading it from the open source website here or here. Go to SoapUI preferences and make sure you have the home location of HermesJMS in the tools section


To launch it right click on the project in the current workspace and select "Start HermesJMS" or choose the same from Project menu(SoapUI 5.0 onward). While starting the HermesJMS you will be asked to give location of configuration file for starting HermesJMS which would be by default in the user home (something like : C:\Users\<user name>\.hermes). 


Once HermesJMS is started follow the below instructions in order to be able to connect to MQ queue
  • Go to "Options => Configuration"
  • Go to the "Providers" tab on the window and add a new group named "Websphere MQ" and add MQ related jar files as visible in the screen shot from the location <MQ Client install path>/java/lib/
  • Click on "Apply" and "OK" to save the configuration




Once the configuration is done, you can start preparing for your connection
  • Right click on "Session" from the left hand side panel and click on "New => New Session"
  • On the configuration window, check if you have the MQ jar files already added on the group.
  • Now come back to the "Sessions" tab and select "Websphere MQ" (or the name you chose for your group) from the Loader under "Connection Factory"
  • Select "com.ibm.mq.jms.MQQueueConnectionFactory" for the "Class" under "Connection Factory"
  • Now Select "IBM WebsphereMQ" as plug in. Make sure you do it after defining the loader under connection factory otherwise you will end up having an error.
  • Right click under the "Connection Factory" to add properties and add below properties
    • hostName=IP of the MQ server
    • channel= channel used for connection (in this case : SYSTEM.ADMIN.SVRCONN)
    • port=listener port of the queue manager (e.g 1441)
    • queueManager= Queue Manager's name (e.g. QMGR1)
    • transportType=1 (for client mode)
  • Update the name of the session as per your test need, once done, click on "Apply" and "OK".
  • You do not need to put any value or change anything in the "Destinations", it will be populated automatically from the queue manager in the next step



You will now see a new session in the left panel under "Sessions".
  • Right click on the new session that you have created and click on "Discover".
  • A popup will appear asking if you want to replace current set of destinations, hit "Yes" and you will have all your queues in the list as in screen shot below
 

Creating Soap Test Case with MQ Connection

To be able to make a MQ test with SoapUI, you need to have your MQ sessions ready with HermesJMS as described in step above. The MQ connection needs to have good memory settings done otherwise it will eventually run out of memory and SoapUI may stop functioning properly.

Setting SoapUI Memory Configuration

  • Make sure all SoapUI sessions are closed.
  • Go to the bin directory under SoapUI installation location. For example : C:\Program Files\SmartBear\SoapUI-5.0.0\bin
  • Edit file "soapui.bat" and change the entry for JAVA_OPTS and upgrade the memory settings as shown in the screen below
  • Save the file and close it.
  • Start SoapUI, it will be using the new memory settings.

How to add MQ Test

  • Step 1 :
    • Open or create a new SoapUI project.
    • Right click on available interface from the project and choose "Add JMS Endpoint". It will open the below popup dialog
  • Step 2 :
    • Set the correct hermesJMS configuration file (hermes-config.xml) then select configured MQ session as per your configuration.
    • Select a destination queue name from "Send/Publish destination" to where you want to inject MQ message
    • Select a source queue name in "Receive/Subscribe destination" from where you want to receive your acknowledgment message.
    • Note : You can keep either of the drop down lists empty as per your specific use case. For example
      • Select queue name only in "Send/Publish destination", if it is send only JMS connection
      • Select queue name only in "Receive/Subscribe destination" if it is receive only JMS
      • Select both queue names if you have send and receive queue both available in same queue manager and the response in synchronous response
  • Step 3: Inject order
    • Create a new Soap Request and remove the default content of the request.
    • Right click on request content area and select "Load From (Ctrl + L)" and choose the request XML file to be injected in MQ Queue. Or, Copy-paste the content to the request from original xml request. 
    • Select the JMS end point as per your test need.  Example : jms://QMGR1::queue_INQUEUE
    • Run the test to inject order 
  • Step 4: Receive order 
    • Create a new Soap Request and remove the default content of the request.
    • Remove the content of the request
    • Select the JMS end point for retrieval. Example : jms://QMGR2::-::queue_OUTQUEUE
    • Run the test to read the message. 
  • Step 5:
    • Receiving an order will wait for the message to be read. If there is no message then it will continue to wait
    • To avoid such a situation, we can always put a timeout from the TestRequest properties
    • Set timeout in miliseconds to the test request from "Timeout" property.
 
 
 
For more information about using JMS with SoapUI, you can refer to the links below
  • https://www.soapui.org/jms/getting-started.html
  • https://www.soapui.org/documentation/jms/config.html
  • https://www.soapui.org/jms/working-with-jms-messages.html
  • https://www.soapui.org/jms/validating-jms-responses.html

1 comment:

  1. Looking at this article as a potential to a Spring Boot automated Integration test that would use this approach via a maven SoapUI plugin in order to create a temporary queue so the JmsTemplate could post IBM MQ message and a listener could pull the message.

    ReplyDelete