My new website on Artificial Intelligence and Machine Learning

Selecting a response based on the request using SOAP UI

To mock a service, Everyone knows based on request we can give static response always. Here I want to show that how can we create dynamic multiple responses using SOAP UI based out of request.

Selecting a response based on the request

This script is specified at the MockOperation level and uses the script code to extract the input values from the incoming request. Based on some validations it returns the name of the MockResponse to return to the client. The script is as follows:
Aim of Script: In request we have name property based name property we are returning different responses like R1, R2 and R3.

  • If name is "AA" then response R1
  • Else if name is "BB" then response R2
  • Else response is R3.
def temp="XX";
def groovyUtils=new
def xml=new XmlSlurper().parseText(mockRequest.requestContent)
        def v=it.toString()"===============""==================="+it.text());
      "===================matching tag=========================="+it.text());
if(temp=='AA'){"if R1");
}else if(temp=='BB'){"else if Response 1");
}else{"else Response 1");

a.Create SOAP Project in SOAPUI

Soap ui project

b. Import wsdl into the project

soapui import wsdl

c. Here we can see operation is "doAction". Right click on request and create mock service.

soaupui mock service using doaction

d. Mock service name is given as MultipleResponses. Our aim to create multiple responses for single request. Click on operation and create responses like below.

create soapui mock resonse

e. Already I have created two responses, creating one more response (R3) for operation.

soapui multiple mock resopnses for single request

f. Responses R1, R2 and R3 are ready

soapui multiple mock resopnses are ready

g. Now step is to write script for to handle request. Click on operation and change dispatch to SCRIPT.

soapui script to handle multiple response

h. Copy that script whatever I have provided before creating SOAP project.

paste scipt in soapui script console

i. Change the target URL for request to MultipleResponse

change soap ui target url

j. Provide URL

provide soapui url

k. Start the mock server for "MultipleResponses". start soapui mockservice server

l. This is my R1 response

soapui first response

m. Execute request

soap ui Execute request