How to simulate an asynchronous web service with mock services in soapUI
I'm trying to simulate an asynchronous service. The service must send an ack response and then after some time invoke a callback service.
I have been trying different scripts based on some post thai I have found using testcase to invoke the callback service, but I haven't been able to get that the service sends the response before the invokation of the callback service.
Does it exits a way to run a test case and then send a response without wait that the test case finishes?
Thank you very much
Hi,
Yes, this can be done effectively by:
- setup a mock to handle the initial request.
- When this mock is called, use Groovy script to call a TestCase asynchnously:
(this example was for a quote service, these are parameters to pass to the call back TestCase)
def map = new StringToObjectMap()
map.put("messageID", requestMessageId)
map.put("quoteId", "12345")
map.put("amount", "777")
def testSuite = context.mockService.project.
getTestSuiteByName("TestSuite - Async Call & Callback")
def callBackTestCase = testSuite.getTestCaseByName("Callback
TestCase")
def callBackRequest = (WsdlTestRequestStep) callBackTestCase.getTe
stStepsOfType(WsdlTestRequestStep.class).get(0)
callBackRequest.testRequest.setEndpoint(replyTo)
callBackTestCase.run(map, true) //true here means call asynchronously i.e. dont wait to the TestCase to finish first3. The mock script should finish and you can add a suitable ack response to the mock.
4. In the TestCase that is called, you can then add a Request TestStep to simulate your call back. You can add a delay TestStep before the request TestStep if you want more delay for the callback.
Please let me know if you need more explanation of this. There is a SOAP worked example of this approach from my SoapUI Cookbook, think this is part of a free sample chapter 4 (recipe: Testing asynchronous SOAP service callbacks)
Hope this helps,
Cheers,
Rupert