How to simulate an asynchronous web service with mock services in soapUI
- 10 years ago
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