01 March 2010 - 3.5 |
In soapUI 3.5 we introduce support for JMS messaging allowing you
to send and receive both text and binary messages.
For this purpose
SoapUI integrates with the HermesJMS open source
application which
supports many different JMS providers.
For the purpose of this tutorial we will need to download the new SoapUI 3.5 installer which integrates the installer of HermesJMS.
If you want to use binary distributions you need to install HermesJMS 1.14 manually (download here) and set its path to Preferences->Tools.
When starting the new soapUI installer you will get an option that you can select to install HermesJMS also. This is mandatory if you want to try this tutorial (unless you already have HermesJMS 1.14 or later installed).
Also for the purpose of this tutorial we will need ActiveMQ (a free JMS implementation). Download it from the server here . Unpack it and start activemq.bat file under bin folder. This will start activemq server on your local machine.
For purpose of this tutorial we will create one session in HermesJMS.
Open the Preferences editor and choose the Providers tab first at the bottom. Select Classpath Groups on the right and choose 'Add Group', type the name 'ActiveMQ-5.2'
Than add these two jar files also by clicking on 'Add JAR(s)', activemq-core-5.2.0.jar and geronimo-j2ee-management_1.0_spec-1.0.jar. (These jar files can be found in %actvemq_home%/lib folder).
Now choose the session tab in HermesJMS and make sure that your editor looks like this.
Here you can COPY-PASTE serviceURL: service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi
We have now created a session in HermesJMS named activeMQSession with two queues and two topics which we can use from within soapUI.
Now that we have configured our session in HermesJMS, lets go back to soapUI and use the sample project that goes with the soapUI installation %soapui_home%/Tutorials/sample-soapui-project.xml
Open the project and left click on interface SampleServiceSoapBinding and choose 'Add JMS Endpoint'
The following popup dialog will open
First set the Hermes Config path to the folder where hermes-config.xml is (usually .hermes), than select the above configured session and last the queue/topic for sending/publishing and queue/topic for receiving/subscribing. You can choose send/publish only by leaving Receive Queue field blank and also receive/subscribe only by leaving Send Queue/Topic blank.
Example:
All combinations are allowed. Available queues and topics depend on what we have configured in HermesJMS, so if we add another queue for example it will be available in this combo box also. You can add as many JMS endpoints this way as you need.
Next we need to create a new TestSuite and TestCase and add a Soap TestRequest. Select the operation to invoke (for example the Request login), which opens the editor with a corresponding default message. Select an endpoint where the send queue and receive queues are the same and submit the request.
Special note for TIBCO EMS users: Add tibjmsadmin.jar and tibjms.jar to %SoapUI%\bin\ext folder, and restart SoapUI application after that.
As you can see, the message we sent is shown in the response window since we sent and received from the same JMS queue (for the purpose of this example). You can specify JMS Headers as well as Durable Subscription Name, Time to Live (miliseconds), CliendID and you can filter messages with Message Selector. Response has a JMS inspector showing all JMS Headers.
You can also set custom JMS Properties for your request;
Another important thing to set is the Timeout property
where you set the time to wait ( in milliseconds ) for the receiving/subscribing queue/topic. If this is not set or set to zero it will wait to infinity.
Also here you can specify username and password if needed.
Since the response is a standard XML message, all XML-related assertions apply (XPath, XQuery, etc), but also two new assertions are available for JMS testing; JMS Status and JMS Timeout. The JMS Status assertion will check for JMS specific errors (for example connection errors) and the JMS Timeout assertion will check that the message is received within the configured timeout.
The method described above allows us to send/publish and receive/subscribe jms text messages, but we can also use the first request attachment to specify the payload of the message; if the content type of the attachment is text, plain or xml then this attachment will be sent as a text message, otherwise it will be sent as bytes message. Correspondingly, when receiving a bytes message its payload will be shown as a response attachment..
Note that only the first attachment is treated as the payload for the message.
Another important thing we have to mention is that you can also use Groovy Script Test Step if you want something else to do with your queues and topics. Here is one example of how to use our API to browse messages from one queue without receiving it.
import com.eviware.soapui.impl.wsdl.submit.transports.jms.JMSConnectionHolder import com.eviware.soapui.impl.wsdl.submit.transports.jms.util.HermesUtils import com.eviware.soapui.impl.wsdl.submit.transports.jms.JMSEndpoint import hermes.Hermes import javax.jms.* def jmsEndpoint = new JMSEndpoint("jms://activeMQSession::queue_testQ1::queue_testQ1"); def hermes = HermesUtils.getHermes( context.testCase.testSuite.project, jmsEndpoint.sessionName) def jmsConnectionHolder = new JMSConnectionHolder( jmsEndpoint, hermes, false, null ,null ,null); Session queueSession = jmsConnectionHolder.getSession(); Queue queueSend = jmsConnectionHolder.getQueue( jmsConnectionHolder.getJmsEndpoint().getSend() ); Queue queueBrowse = jmsConnectionHolder.getQueue( jmsConnectionHolder.getJmsEndpoint().getReceive() ); MessageProducer messageProducer =queueSession.createProducer( queueSend ); TextMessage textMessageSend = queueSession.createTextMessage(); textMessageSend.setText( "jms message from groovy"); messageProducer.send( textMessageSend ); textMessageSend.setText( "another jms message from groovy"); messageProducer.send( textMessageSend ); QueueBrowser qb = queueSession.createBrowser(queueBrowse); Enumeration en= qb.getEnumeration(); while(en.hasMoreElements()){ TextMessage tm = (TextMessage)en.nextElement(); log.info tm.getText() } jmsConnectionHolder.closeAll()// don't forget to close session and connection
Also we need to mention that you can use Rest Request Test Step and Http Request Test Step to send its first attachment as TexMessage or BytesMessage over jms endpoint.
That's it for now, we hope that you will find this tutorial helpful to jump start your JMS testing with soapUI.
Happy testing, and please don't hesitate to give us your feedback!