Sunday, November 8, 2015

Adding dispatch logic to SOAPUI mock services

There might be instances, where you have few variations of a response that needs to be sent based on a logic. You could do this by adding a dispatch script including your logic like below.

1.Go to required service's process interface and change DISPATCH option to 'script'.

In this example I will be dispatching a specific response based on an element of the incoming request.

Following is the sample script .

// create XmlHolder for request content

def holder = new mockRequest.requestContent )
def arg1 = holder["//category"]

//if above element is empty
if( ! arg1 ))
 return "Invalid Input Response"

if(arg1 == "Books" )
return "SendBooksReponse"

else if(arg1 == "Articles")
return "SendArticlesResponse"

So here what we are returning would be the relevant mock response's name.

No comments:

Post a Comment