Forum Discussion

pocayoke's avatar
pocayoke
New Contributor
10 years ago

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 t...
  • rupert_anderson's avatar
    10 years ago

    Hi,

     

    Yes, this can be done effectively by:

     

    1. setup a mock to handle the initial request.
    2. 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 first

     

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