cancel
Showing results for 
Search instead for 
Did you mean: 

Mock services over JMS

New Contributor

Mock services over JMS

Hi
I've tried out the JMS support in the SoapUI 3.5 beta, and from what I can see, its not possible to generate Mock services listening over JMS.  Could you confirm that this is the case, or if not then indicate how it could done?

Many thanks
Phil
11 REPLIES 11

Re: Mock services over JMS

Hi,

If I understand you correctly you have JMS client that you want to test against mock service.
You can do this with SoapUI 3.5 .

SoapUI can send-receive against queues and publish-durable subscribe against topics. So you can for example receive message than do something with it and send back to same or another queue or topic. For this you need to create sequence of operations (Test Steps) and loop that sequence .

Can you explain more your use case, so we can help you find a solution for your problem.

Best Regards
Nebojsa
eviware.com

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓
New Contributor

Re: Mock services over JMS

Yes, its a simple use case - we have a client sending SOAP requests over MQ, placing the SOAP request in one queue and expecting a SOAP response on another queue.

We would like to test this client with different responses, using a mock service. So what we need from soapUI with JMS is a means to a) pick up a SOAP request from a queue, (b) generate the mock SOAP response and (c) put the response on the second queue.

Any guidance on how this can be done would be appreciated.

Thanks
Phil

Re: Mock services over JMS

Hi,

for this use case you need 4 test steps.
And I assume that you have created sessions in hermes which you will use in SoapUI. Otherwise please try our jms tutorial http://www.soapui.org/tutorials/jms/jms-tutorial.html

1. create Test Request step named "JMS receive" with jms endpoint that will receive message from queue, like jms://activeMQSession::-::queue_testQ1 .Also set its Timeout property to zero, so it waits until message is on queue.

2. create Groovy script test step named "groovy MOCK", where you can use received message
def response = context.expand( '${JMS receive#Response}' )

// do something to response with groovy
return response // or some mock soap message


3. create Test Request step named "JMS send" with jms endpoint that will send message to a queue, like jms://activeMQSession::queue_testQ2 . In XML tab just write this  ${groovy MOCK#result}

4. create groovy script test step named "groovy goto" and write this script

testRunner.gotoStep(0)

this way it will loop these steps

Open your Test Case window and start it.


Hope this helps

regards
Nebojsa
eviware.com

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓
Occasional Contributor

Re: Mock services over JMS

hi ,
I have made (a little bit) more elegant solution. I have in my project very nice HTTP mock with a number of response messages in it. I also have testcases using http to test services but also to test mock. I want to easy switch to JMS in my testcase, and using same http mock logic voor JMS Mock.

Make TestSuite and TestCase with next test steps;
1. testRequest named “JMS receive” – with empty request message, (like described by Nebojsa )
2. testRequest named “Send request to HTTPMock” – with this XML tab ${ JMS receive #Response} and endpoint to my http mock service.
3. testRequest named "JMS send" with jms endpoint that will send message to a reply queue, like jms://activeMQSession::queue_testQ2 . In XML tab just write this  ${ Send request to HTTPMock #Response} . In  JMS Header in CorrelationID write ${=context.testCase.testSteps["JMS receive "].testRequest.response.responseHeaders.JMSMessageID}. This wil set correlationid of response message with value from messageid of request message (Correlation pattern).
4. Goto step (like Nebojsa described).

Run you http mock , run jms (mock ) test case , and you have the same mock available on http and on jms. Switch of endpoint in testcase give you  possibility to easy test these mock’s on both transports.

Re: Mock services over JMS

Hi,

thanks for sharing this with us

It is very valuable for us and the community.

Best Regards
Nebojsa
eviware.com

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓
New Contributor

Re: Mock services over JMS

Hi,

thanks for the nice JMS mocking solution!
I have one question: how can you stop an infinite-looped testcase (like this JMS mocking testcase)? I mean, if I start the mocking test case, it works fine and handles messages and mocks great for many requests, but if there is no message in the queue to read from, soapUI is waiting for one (until the Timeout value) in the JMS receive step and the "Stops running this testcase" button doesn't stop the testcase (it's enabled, but only to push, no effects).

Do you have any ideas?

thanks in advance,
andrás
New Contributor

Re: Mock services over JMS

ok, i figured it out

the solution is setting Timeout for the JMS receive and if no message was received, goto a delay step (with groovy) and then try receiving again.
During the delay we can stop the test case execution.

thanks
andrás
Not applicable

Re: Mock services over JMS

This thread was really useful for me and helped me to get my JMS monitoring going.

Also to contribute, I took a different tack towards stopping the looping. I found that it was necessary as we were going to be starting & stopping the mock services through a command line, and didn't want to be trying to stop the monitoring by hitting that sleep period.

As suggested above by skarfiol, I gave the soap request a timeout, and the subsequent step a check. If the groovy MOCK script (step 2) finds that the request is empty, it goes back to the soap request in Step 1. I didn't add a sleep command to the script.

In order to stop it, I gave the Monitoring Test Case a property "readyToStop" that starts off as "false".
Back in the groovy MOCK script (step 2), I added a check, so if the Test Case's readyToStop property has been set to "true", then it cancels the test with the reason of "Requested to Stop".

Over in the mock services, as part of the start script, I start the Monitoring test case, and at the same time, set the Monitoring Test Case's readyToStop property to "false". As part of the stop script, it sets the readyToStop property to "true".
So when the soap request in Step 1 timesout and moves to the groovy MOCK script in Step 2, it finds that the property has changed, and it stops. If not, it checks whether the response is empty or not, and acts accordingly.
Not applicable

Re: Mock services over JMS

Many thanks for these suggestions.

I actually had to consider JMSMessageID an array to avoid the string being enclosed in square brackets: [tt:3qqzs52k]${=context.testCase.testSteps["JMS receive"].testRequest.response.responseHeaders.JMSMessageID[/tt:3qqzs52k][0][tt:3qqzs52k]}[/tt:3qqzs52k].

I'm using WebLogic as a JMS provider.
New Here?
Join us and watch the welcome video:
Watch the new interview
Top Kudoed Authors