Forum Discussion

RPfrimmer's avatar
RPfrimmer
Occasional Contributor
14 years ago

[Resolved] Comparing JDBC results

Hi Everyone,

I'm relatively new to SoapUI and have run into a situation I'm hoping you can help me figure out.

I have a situation where I need to to compare the state of data in a database both before and after certain web service calls are performed. I've created JDBC requests that pull the required data from the database and need to compare the results.

In my case I need to validate that the results don't match. I tried using an XPath Match assertion, but I can't see how to tell it that I'm expecting the results not to match.

In my case I am validating that some date stamps used for auditing are being appropriately updated when the web service calls take place.

Below is a sample of the result set I'm working with.

<Results>
<ResultSet fetchSize="10">
<Row rowNumber="1">
<WEB_FOLIO_ID>383</WEB_FOLIO_ID>
<FOLIO_SETTLED>N</FOLIO_SETTLED>
<LAST_UPDATE>2012-02-17124735</LAST_UPDATE>
<FOLIO_LOCK/>
<SESSION_ID>1172818014</SESSION_ID>
<REINSTATED>N</REINSTATED>
<WEB_FOLIO_TXN_ID>32</WEB_FOLIO_TXN_ID>
<TXN_DATETIME>2012-02-17124731</TXN_DATETIME>
</Row>
</ResultSet>
</Results>


Any help or suggestions are welcome.

Rob

2 Replies

  • M_McDonald's avatar
    M_McDonald
    Super Contributor
    Assuming that the requests are called 'First' and 'Second', create a script assertion on the second request, and use this code:

    import java.text.SimpleDateFormat

    def fmt = new SimpleDateFormat('yyyy-MM-ddHHmmss')
    def firstUpdate = context.expand( '${First#ResponseAsXml#//LAST_UPDATE/text()}' )
    def secondUpdate = context.expand( '${ResponseAsXml#//LAST_UPDATE/text()}' )

    Date firstDate = fmt.parse(firstUpdate)
    Date secondDate = fmt.parse(secondUpdate)

    assert firstDate < secondDate

    This assumes of course that there will always be a 1-second difference in the successive LAST_UPDATE values which seems to be the maximum precision for the field.
  • RPfrimmer's avatar
    RPfrimmer
    Occasional Contributor
    Thanks, I had just started looking into trying to do it with script assertions.

    I think this will work for me with some small alterations.

    Thanks for the help