Applies to ReadyAPI 3.3.1, last modified on August 11, 2020

You can use a Groovy Script test step to work with queues, topics and other JMS entities.

Reading Messages From Server Queue

The following code demonstrates how to read messages from a server queue by using a HermesJMS session:

Groovy

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.*


//Establishing the JMS connection
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);

// Obtaining the session and queue
Session queueSession = jmsConnectionHolder.getSession();
Queue queueSend = jmsConnectionHolder.getQueue( jmsConnectionHolder.getJmsEndpoint().getSend() );
Queue queueBrowse = jmsConnectionHolder.getQueue( jmsConnectionHolder.getJmsEndpoint().getReceive() );

// Performing some actions
MessageProducer messageProducer = queueSession.createProducer( queueSend );
TextMessage textMessageSend = queueSession.createTextMessage();
textMessageSend.setText( "A JMS message sent from ReadyAPI.");
messageProducer.send( textMessageSend );
textMessageSend.setText( "Another JMS message sent from ReadyAPI.");
messageProducer.send( textMessageSend );

// Logging elements
QueueBrowser qb = queueSession.createBrowser(queueBrowse);
Enumeration en = qb.getEnumeration();
while(en.hasMoreElements())
{
    TextMessage tm = (TextMessage)en.nextElement();
    log.info tm.getText()
}
jmsConnectionHolder.closeAll() // Make sure to close the session and connection

Setting JMS Headers for Test Steps

The following code demonstrates how to set the JMS header’s value in a specific test step:

Groovy

// Replace the test step’s name with the one you need
def myTestStep = testRunner.testCase.getTestStepByName("The sample test step")

def msgID = "foo4711"// Specify the value for header

myTestStep.testRequest.JMSHeaderConfig.messageSelector = "JMSCorrelationID = '${msgID}'"// Setting the header’s value

See Also

JMS Integration
Installing HermesJMS

Highlight search results