I'm using SoapUI to mock a service, and I'm returning different stored XMl's based on the request using a groovy script.
import com.eviware.soapui.support.GroovyUtils
import groovy.xml.XmlUtil
def groovyUtils = new GroovyUtils(context)
def xmlParser = new XmlParser()
def responseContent
def requestXmlHolder = groovyUtils.getXmlHolder(mockRequest.getRequestContent())
requestXmlHolder.declareNamespace("v01", "http://www.zoot.com/data_type/ZE_Messaging/v01")
def email = (requestXmlHolder.getNodeValue("//v01:Request[1]/v01:Email[1]"))
def responsePath = "C:/MockService/Responses"
switch(email){
case ~/(?i).*acceptall.*/:
responseContent = xmlParser.parse( responsePath + "/acceptall-response.xml" )
break
case ~/(?i).*acceptspl.*/:
responseContent = xmlParser.parse( responsePath + "/acceptspl-response.xml" )
break
case ~/(?i).*acceptmpl.*/:
responseContent = xmlParser.parse( responsePath + "/acceptmpl-response.xml" )
break
case ~/(?i).*decline.*/:
responseContent = xmlParser.parse( responsePath + "/decline-response.xml" )
break
default:
responseContent = xmlParser.parse( responsePath + "/custom-response.xml" )
break
}
context.content = XmlUtil.serialize(responseContent)
This works fine, but now I'm trying to update one of the nodes of this response before, more precisely I'd like to add the current date in that script as there's a node in the xml which looks like
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v01="http://www.whatever.com/data_type/ZE_Messaging/v01">
<soapenv:Header/>
<soapenv:Body>
<v01:Response>
<v01:RequestID>eeee</v01:RequestID>
<v01:TransactionID>?</v01:TransactionID>
<v01:CostumerID>?</v01:CostumerID>
<v01:TransactionDateTime>?</v01:TransactionDateTime>
<v01:FirstName>?</v01:FirstName>
<v01:MiddleName>?</v01:MiddleName>
<v01:Name>?</v01:Name>
<v01:MaidenName>?</v01:MaidenName>
<v01:Gender>?</v01:Gender>
<v01:DateOfBirth>?</v01:DateOfBirth>
<v01:Decision>ACCEPTALL</v01:Decision>
<v01:DecisionText>?</v01:DecisionText>
<v01:DecisionReasonCodes>?</v01:DecisionReasonCodes>
<v01:ErrorCode>?</v01:ErrorCode>
<v01:ErrorDescription>?</v01:ErrorDescription>
<v01:AdditionalDetails>
<v01:Data category="?" attribute="?">?</v01:Data>
</v01:AdditionalDetails>
</v01:Response>
</soapenv:Body>
</soapenv:Envelope>
In the script if I do this, just before setting the context.content
def soapenv = new groovy.xml.Namespace("http://schemas.xmlsoap.org/soap/envelope/")
def v01 = new groovy.xml.Namespace("http://www.whatever.com/data_type/ZE_Messaging/v01")
log.info responseContent[soapenv.Body][v01.Response][v01.RequestID].text()
I will get the 'eeee'
So basically what I need is how to set that to a different thing from what I getting from the file itself before setting that context.content