How to create SoapUI HTTP MockService from WSDL

Environment

SoapUI 3.6

Steps

Step 1. New SoapUI Project→[Project Name]→[Select WSDL]→Check “Create MockService”→OK

Step 2. Check operations→[Port Number]→OK

Step 3. Create response results for each test case

Step 4. Right click on an operation→Show MockOperation Editor

Dispatch Mode
SEQUENCE: 循序回傳Response
RANDOM: 隨機回傳Response
XPATH: 依據XPATH所指定的欄位,導向與其值同名的Response
QUERY_MATCH:依據XPATH所指定的欄位,其值符合預期值則導向指定的Response
SCRIPT: 依Script邏輯決定導向何Response

XPATH Example

Click “selects the dispatch path from the last request” (need to execute the request first)→[Select XPATH to be used for dispatching the request].

If the XPATH value equals to the response name, the corresponding response will be returned; otherwise the Default Response will be returned.

For example, if the “id” value = “success”, the “success” response will be triggered.

declare namespace aim='http://....xsd';
//aim:queryRequest[1]/aim:ServiceRequest[1]/aim:id[1]

QUERY_MATCH Example

Click “Add a new match”→[Match Name]→XPATH→Click “selects the dispatch path from the last request” (need to execute the request first)→[Select XPATH to be used for dispatching the request]→specify [Expected Value]→specify [Dispatch to].

If the XPATH value equals to the expected value, the corresponding response will be returned; otherwise the Default Response will be returned.

For example, if the “id” value = “100”, the “success” response will be triggered.

XPATH:
declare namespace aim='http://....xsd';
//aim:queryRequest[1]/aim:ServiceRequest[1]/aim:id[1]

Expected Value:
100

Dispatch to:
success

SCRIPT Example

For example, if the “id” value = “100”, dispatch to “success”; if the “id” value = “200”, dispatch to “fail” response; otherwise, dispatch to “other” response.

// Method 1:
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context);
def holder = groovyUtils.getXmlHolder(mockRequest.getRequestContent());
// Method 2:
def req = new XmlSlurper().parseText(mockRequest.requestContent);
// two ways to call mockRequest requestContent

def id = req.Body.queryRequest.ServiceRequest.id;

log.info "id #${id}";

if (id == "100") {
 return "success";
} else if (id == "200") {
 return "fail";
} else {
 return "others"; 
}

References

https://www.soapui.org/soap-mocking/creating-dynamic-mockservices.html

http://www.soapui.org/getting-started/mock-services.html

http://www.soapui.org/soap-mocking/mockoperations-and-responses.html

http://www.soapui.org/scripting—properties/tips—tricks.html

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s