I am new to SoapUI and have just configured a very simple MockService. Is it possible to manipulate the response so that for a particular request the response's elements are dynamically built up?
Scenario 1:
Request:
<record>
<identifier>ID1</identifier>
</record>
Response:
<response>
<child1>child 1</child1>
</response>
Scenario 2:
Request:
<record>
<identifier>ID2</identifier>
</record>
Response:
<response>
<child2>child 2</child2>
</response>
It is for a simple test and I don't need it to do any more than the above. I am currently doing the following that yields the results I want but since I am completely new to this I am sure there are better alternatives:
Response:
<response>
${dynElement}
</response>
Groovy script:
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def holder = groovyUtils.getXmlHolder(mockRequest.requestContent)
def reqRef = String.valueOf(holder.getNodeValue("//identifier"))
def child1Text = "<child1>child 1</child1>"
def child2Text = "<child2>child 2</child2>"
if (reqRef == "ID1") {
context.setProperty("dynElement", child1Text)
} else if (reqRef == "ID2") {
context.setProperty("dynElement", child2Text)
}
Instead of xpath, you could also use XmlSlurper.
def req = new XmlSlurper().parseText(mockRequest.requestContent)
def reqRef = req.record.identifier
Shamelessly ripped of from this question's answers, please don't hurt me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With