Forum Discussion
16 years ago
From some basic sample project I found a while back:
There are probably tons of other ways to do this, but I've found scripting to be the most powerful/straightforward thing in soapUI.
In the mock service, under the operation that you're preforming, change dispatch to script and add in these lines:
This code will check the value of the first "name" element in your request and if it's "Billy" then it will respond with "OtherResponse"
I hope this is enough to get you started with the rest of it.
Learning about XPath: http://www.w3schools.com/xpath/default.asp
Documentation on DOM nodes: http://java.sun.com/j2se/1.4.2/docs/api/org/w3c/dom/Node.html
There are probably tons of other ways to do this, but I've found scripting to be the most powerful/straightforward thing in soapUI.
In the mock service, under the operation that you're preforming, change dispatch to script and add in these lines:
//String representation of the request message
def soapMSG = mockRequest.getRequestContent()
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
//Deserializes the string into a tree structure for XPath functionality
def holder = groovyUtils.getXmlHolder( soapMSG )
//XPath query to get the node you care about (see below)
String myXPath = "//name"
//DOM Node that can contain attributes, a value, child nodes, etc. (see below)
def node = holder.getDomNode( myXPath )
String nodeValue = node.getNodeValue()
if(nodeValue == "Billy"){
return "OtherResponse"
}
This code will check the value of the first "name" element in your request and if it's "Billy" then it will respond with "OtherResponse"
I hope this is enough to get you started with the rest of it.
Learning about XPath: http://www.w3schools.com/xpath/default.asp
Documentation on DOM nodes: http://java.sun.com/j2se/1.4.2/docs/api/org/w3c/dom/Node.html