Forum Discussion

CRW123456's avatar
CRW123456
New Contributor
15 years ago

Script assertion for CDATA payload

soapUI v3.6.1
I am attempting to implement assertions on CDATA payload as outlined in http://soapui.org/Functional-Testing/working-with-cdata.html.

Here is snippet of my message:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ia:GenericProxyServiceResponse xmlns:ia="http://www.xxx.com/xxx">
<responseHeader>
...
</responseHeader>
<responseData>
<![CDATA[
<NS1:retrievePaymentScheduleResponse xmlns:NS1="http://eigns.xxx.com/PaymentScheduleFacade">
<NS1:retrievePaymentScheduleResponseBody>
<NS1:paymentScheduleResponse>
<NS1:paymentPlanCode>D3</NS1:paymentPlanCode>
...
]]>
</responseData>
...


Here is my script:

import com.eviware.soapui.support.XmlHolder

def cdataHolder = new XmlHolder(messageExchange.responseContentAsXml)
def payload = cdataHolder.getDomNode("//responseData")
assert payload != null
log.info(">>> payload.toString() = " + payload.toString())
log.info(">>> payload.hasChildNodes()=" + payload.hasChildNodes())
def payloadHolder = new XmlHolder(payload)
assert payloadHolder != null
payloadHolder.declareNamespace("ns", "http://eigns.xxx.com/PaymentScheduleFacade")
log.info(">>> payloadHolder.isEmpty()=" + payloadHolder.isEmpty())
log.info(">>> payloadHolder.size() = " + payloadHolder.size())
def keys = payloadHolder.keySet()
log.info(">>> keys=" + keys)
log.info(payloadHolder.getNodeValue("/ns:retrievePaymentScheduleResponse/ns:retrievePaymentScheduleResponseBody/ns:PaymentScheduleResponse[1]/ns:paymentPlanCode"))
log.info(payloadHolder["//ns:PaymentScheduleResponse[1]/ns:paymentPlanCode"].toString())


Note that I've added logging statements to help debug. Here is the output:

Wed Sep 28 10:30:25 EDT 2011:INFO:>>> payload.toString() = <?xml version="1.0" encoding="UTF-8"?>
<responseData xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ia="http://www.xxx.com/xxx">
&lt;NS1:retrievePaymentScheduleResponse xmlns:NS1="http://eigns.xxx.com/PaymentScheduleFacade"&gt;
&lt;NS1:retrievePaymentScheduleResponseBody&gt;
&lt;NS1:paymentScheduleResponse&gt;
&lt;NS1:paymentPlanCode&gt;D3&lt;/NS1:paymentPlanCode&gt;
...
</responseData>
Wed Sep 28 10:30:25 EDT 2011:INFO:>>> payload.hasChildNodes()=true
Wed Sep 28 10:30:25 EDT 2011:INFO:>>> payloadHolder.isEmpty()=false
Wed Sep 28 10:30:25 EDT 2011:INFO:>>> payloadHolder.size() = 0
Wed Sep 28 10:30:25 EDT 2011:INFO:>>> keys=null
Wed Sep 28 10:30:25 EDT 2011:INFO:null
Wed Sep 28 10:30:25 EDT 2011:INFO:[]


So, it looks to me as if payload is getting created and contains nodes but payloadHolder is not getting initialized as expected -- it's size is zero and the keySet null. Hence, I can't get to any of the elements within the CDATA section of the message. What am I doing wrong? Is the behavior I'm expecting available in this version of soapUI? Any help would be appreciated.

Thanks,
Curtis ...

1 Reply

  • CRW123456's avatar
    CRW123456
    New Contributor
    I finally got a chance to return to this today. It ends up that I was pretty close to a working solution but I was counting on various methods in XmlHolder to determine success. But, I've now found that the methods values(), size(), keySet(), isEmpty(), entrySet() & clear() do not have meaningful implementations. So, I got things to work by ignoring these methods and just going after the data using getNodeValue(), etc.