Malvon
Malvon

Reputation: 1621

How to Test for None Existing Data Elements in SoapUI's Response Against JDBC Request's

If a user wants to do data validation against a result set returned by JDBC step in SoapUI, but the Soap Response does not contain a corresponding data element, SoapUI provides no default way of creating an assertion for such element in Soap Response, i.e. assuming the JDBC step returns the following when executing a SQL query:

<Results>
   <ResultSet fetchSize="10">
       <Row rowNumber="1">
           <ProdName>Prod Name</ProdName>
           <ProdId>#2332</ProdId>
           <ProdCat/>
       </Row>
   </ResultSet>
<Results>

In this case, the row in the database does not have a value for <ProdCat> (NULL). SoapUI provides no way of suppressing the generation of this XML element (<ProdCat>) in the JDBC Request step.

In case of Soap Response, assuming the web service provider generates the following (disregarding namespaces to simplify):

<soap:Envelope xmlns:soap="http://www.w3.org/2033/05/soap-envelope">
   <soap:Body>
       ...
       <Product>
           <ProductName>Prod Name</ProductName>
           <ProductId>#2332</ProductId>
       </Product>
   </soap:Body>
</soap:Envelope>

(Note that all the sub-elements of <Product> are optional) The SoapUI obviously would be missing the data element <ProductCategory>. If we attempt to create an assertion for this data element in case the next time the JDBC step returns a value for the same record, that has been updated (<ProdCat>), a default Content Match assertion for <ProductCategory> would fail, i.e.

XPath Expression (actual)
//.../Product[1]/ProductCategory[1]/text()

XPath Expected Result (expected)
${JDBC Request Product#ResponseAsXML#//Results[1]/Row[1]/ProdCat[1]}

Executing this assertion will get you the following error:

[//.../Product[1]/ProductCategory[1]/text()]: Exception:Missing content for xpath [//.../Product[1]/ProductCategory[1]/text()] in Response

The question is, how to create an assertion that works for all the elements (in the accepted Schema in the Soap Response) regardless of whether they are being returned or not?

Upvotes: 0

Views: 2155

Answers (1)

Malvon
Malvon

Reputation: 1621

Since the actual expression node does not exist (//.../Product[1]/ProductCategory[1]/text()), but the expected expression (${JDBC Request Product#ResponseAsXML#//Results[1]/Row[1]/ProdCat[1]}) returns an empty string (e.g. <ProdCat/> -- this being the JDBC step output), we have to make sure that both expressions evaluate to an identical value. For this, we can do the following:

concat(//.../Product[1]/ProductCategory[1]/text(), '')

${JDBC Request Product#ResponseAsXML#concat(//Results[1]/Row[1]/ProdCat[1], '')}

By doing so, whether the data element exists in the Soap Response or not and/or contains an empty string (column in the database could contain an empty string rather than a mere NULL), the Content Match assertion would always work in this case; even if the record is updated to contain an actual value for <ProdCat> element later on. This still works if the parent elements of <ProductCategory>, e.g. <Product>, do not exist.

Upvotes: 1

Related Questions