Forum Discussion

Nullius's avatar
Nullius
Occasional Contributor
13 years ago

SOAP response vs JDBC response

Hi there,

Because our test data changes quite a lot, I want to make 'dynamic' assertions.
In order to test our webservice, we need to make sure the data we receive from it matches the data in the database (an MSSQL server) and results should be in the same order!
I've managed to get the connection working properly and all JDBC requests and datasource functions are working fine.

But now comes the tricky part (for me :-)):
E.g.: I get the following list from the DB (in whatever format):
Record1
--ID: 1
--Name: Test
Record2
--ID: 3
--Name: Testing


The assertion for the following SOAP response should succeed:
<Rows>
<Row>
<ID>1</ID>
<Name>Test</ID>
</Row>
<Row>
<ID>3</ID>
<Name>Testing</ID>
</Row>
</Rows>


However, for the following responses, the assertion should fail:
<Rows>
<Row>
<ID>1</ID>
<Name>Test</ID>
</Row>
</Rows>

<Rows>
<Row>
<ID>1</ID>
<Name>Testing</ID>
</Row>
<Row>
<ID>3</ID>
<Name>Test</ID>
</Row>
</Rows>

<Rows>
<Row>
<ID>3</ID>
<Name>Testing</ID>
</Row>
<Row>
<ID>1</ID>
<Name>Test</ID>
</Row>
</Rows>


I've tried to use datasources, JDBC requests, xqueries (with for loops, some loops, ...) but haven't managed to find a decent result.
I don't think the datasource loop is the correct solution because the webservice should only be called once.
Also, if possible, I'd like to do this without Groovy scripting.

However, if not possible with xqueries, Groovy scripts are welcome!

Thanks in advance :-)

2 Replies

  • Nullius's avatar
    Nullius
    Occasional Contributor
    For the following JDBC XML result:
    <Results>
    <ResultSet fetchSize="128">
    <Row rowNumber="1">
    <ID>10021</ID>
    <NAME>Test</NAME>
    </Row>
    <Row rowNumber="2">
    <ID>10022</ID>
    <NAME>Testing</NAME>
    </Row>
    <Row rowNumber="3">
    <ID>10023</ID>
    <NAME>Hello World</NAME>
    </Row>
    </ResultSet>
    </Results>


    using script
    import com.eviware.soapui.support.XmlHolder

    def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
    def holder2 = groovyUtils.getXmlHolder( "JDBC Request#ResponseAsXml" )
    // loop item nodes in response message
    for( item in holder2.getDomNodes( "//Row" ))
    log.info groovy.xml.dom.DOMCategory.xpath(item, "//ID")


    I get the following results:
    Tue Jan 10 10:57:15 CET 2012:INFO:10021
    Tue Jan 10 10:57:15 CET 2012:INFO:10021
    Tue Jan 10 10:57:15 CET 2012:INFO:10021


    I got the same behavior when trying some XPath assertions.
    Does anyone have an idea why it returns the correct number of records (3), but always 'selects' the same record?

    Tnx!
  • mandadavenkat's avatar
    mandadavenkat
    Occasional Contributor
    Try this


    def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
    def holder = groovyUtils.getXmlHolder( "JDBC_Impact_SQL#ResponseAsXml" )

    def items = holder.getNodeValues( "//ID")
    log.info( "Found " + items.length + " items.." )
    for (item in items)
    {
    log.info( item )
    }