Forum Discussion

rad's avatar
rad
Occasional Contributor
9 years ago

Validating a SOAP response XML against a JDBC response XML

I am using SoapUi 5.2 and I am trying to validate a SOAP response XML  against a JDBC test response  Both belon to same test case. Both of these have the same content and but the nodes are named differently. I need to assrt it as PASS if the corresponding node values are same

 

For eg: In JDBC 

Results>
<ResultSet fetchSize="0">
<Row rowNumber="1">
<ALTSHIPTOKEYID>27</ALTSHIPTOKEYID>
<ACCOUNTNUMBER>10022</ACCOUNTNUMBER>

</Row>

</resultSet>

 

</results>

 

SOAP:

<UpdateAccountShipToResult >
<a:ShipTo>

 

<a:ShipToID>27</a:ShipToID>

<a:AccountNumber>10022</a:AccountNumber>

</a:ShipTo>

 

 

Is there a way to validate both these XML  using groovy? 

3 Replies

  • nmrao's avatar
    nmrao
    Champion Level 3
    First of all the soap response needs to be adhered to wsdl/schema, it can be added as an assertion.

    To your question, yes it can be done using groovy. And I believe there can be multiple ways.

    a. have soap request, jdbc step, then groovy step. then process both the responses to assert.

    b. Have groovy step, and also have soap and jdbc steps. Call other two steps as from groovy so that you can have total control in the script itself as objects.

    Coming to your doubt - node names different. It should be a matter as long as you understand both the formats of response.
    Get all the values from soap response to be asserted with jdbc using xpath, similarly get all the values from jdbc using xpath and then do the assertion for each element.
    • rad's avatar
      rad
      Occasional Contributor

      Thanks for your reply!

       

      As you mentioned, I have soap request and jdbcc step and I have assertions added to both. I am quite new to groovy, so I am not familiar to calling test steps within the script and do a compare. 

       

       

      Here is a sample script I tried to obtain my node values from soap request . The X path mentioned in the GetNodeValues works only when I give the path upto the node . This does not work for me since the response is pretty huge and i can validate every single node separately

       

      def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)

      def holder= groovyUtils.getXmlHolder("Max -UpdateAccountShipTo#Response")

      holder.namespaces["ns1"]="http://tigerpaw.com/service/"
      holder.namespaces["a"]="http://tigerpaw.com/contract/"
      for (item in holder.getNodeValues("//ns1:UpdateAccountShipToResponse/ns1:UpdateAccountShipToResult/a:ShipTo"))

      log.info "item/:[$item]"

       

      This outputs item:[]

       

      Howvere if I i modify getNodeValues ("//ns1:UpdateAccountShipToResponse/ns1:UpdateAccountShipToResult/a:ShipTo/a:Name"

       

      outputs item [Name]

      • nmrao's avatar
        nmrao
        Champion Level 3
        If that xml is too large get each value and compare, alternative could be transform one of the response to other format so that both can be compared using some library like xmlunit or so.
        In order to transform an xml into other format, you need to write an xslt file.