Json – Dynamically compare Rest XML/JSON response and JDBC using groovy array in SoapUI

groovyjsonrestsoapuixml

In SoapUI, I have a JDBC Test Step that returns the following data:

<Results>
<ResultSet fetchSize="128">
    <Row rowNumber="1">
        <ID>1</ID>
        <NAME>TestName1</NAME>
        <DESCRIPTION/>
        <TYPE>Bool</TYPE>
        <ISPRODUCTTAG>true</ISPRODUCTTAG>
        <ISLOCATIONTAG>false</ISLOCATIONTAG>
        <SUBSECTION>Default Sub Section</SUBSECTION>
        <SECTION>Default Section</SECTION>
        <SUBGROUP>Default Sub Group</SUBGROUP>
        <GROUP>Default Group</GROUP>
    </Row>
    <Row rowNumber="2">
        <ID>2</ID>
        <NAME>TestName2</NAME>
        <DESCRIPTION/>
        <TYPE>Bool</TYPE>
        <ISPRODUCTTAG>true</ISPRODUCTTAG>
        <ISLOCATIONTAG>false</ISLOCATIONTAG>
        <SUBSECTION>Default Sub Section</SUBSECTION>
        <SECTION>Default Section</SECTION>
        <SUBGROUP>Default Sub Group</SUBGROUP>
        <GROUP>Default Group</GROUP>
    </Row>
    </Row>
</ResultSet>

I have an REST API XML Response that contains the following data:

    <ArrayOfTagInfo>
   <TagInfo id="1" name="TestName1" type="Bool" isProductTag="true" isLocationTag="false" subsection="Default Sub Section" section="Default Section" subgroup="Default Sub Group" group="Default Group"/>
   <TagInfo id="2" name="TestName2" type="Bool" isProductTag="true" isLocationTag="false" subsection="Default Sub Section" section="Default Section" subgroup="Default Sub Group" group="Default Group"/>
</ArrayOfTagInfo>

I would like to be able to compare(assert) both the Database Values and the Response Values (response can be in XML or JSON depending on the Request Accept Header) using groovy arrays if possible as the data returned from the database can be very large.

Can anyone help?

Best Answer

If you have SoapUI-Pro, you should be able to accomplish all this with no Groovy.

  1. Make the REST call to retrieve all your data.
  2. Start a DataSource step that parses the XML.
  3. Make a JDBC call that select the correct ID of the row you want to verify. Make all the assertions in here.
  4. Loop back to #2.
Related Topic