Forum Discussion

EllaVader's avatar
Occasional Contributor
8 years ago

comparing 2 datasources



I have a soap call that returns a bunch of results.

I then want to query the DB and compare the results from the database to the results of the soap call to make sure correct.


My first thought was to store the soap results in a datasource and then use that to loop and make a DB call to verify that result exists in the DB.  This is causing DB timeout issues all over the place as there SOAP results return over 600 rows, hence 600 DB calls.


My next thought was rather than make the DB call in a loop, just make a DB call once such that it returns all the results.  Now I have 2 sets of data that I want to compare.  My first thought was to store that DB call in another datasource and then perhaps compare them both.  Is that possible?  How would I do that?  Or does anyone have an alternate solution I could try.


Thanks in advance

5 Replies

  • Hi,


    What you could do I suppose is use the JDBC request test step which will return your database data in XML format.  Then use an XML datasource to loop through the data from the JDBC test step and compare it with the response(s) from the SOAP request test step.  Please see the below link on how to use the XML datasource.





    SmartBear Support

    • kbourdel's avatar
      Occasional Contributor


      I was following your suggestion in the stackoverflow post & running into an issue with the groovy script. I have ReadyAPI Pro, and like the original person who posted, was trying to compare 2 datasources, so tried using your script to solve the issue.


      My test case consists of:

      1. Jdbc step called JDBCRequest (retrieving the BrandGroupID from the db which should match the data in step 2). Should this step really be the JDBC response parsed to a Datasource?

      Sample of response data:

      <Row rowNumber="1">
      <Row rowNumber="2">


      2. Json step called GetAllBrandGroups (returns many data points but the only one i'm interested in is the BrandGroupID ). Should this step really be the Json response parsed to a Datasource?

      Sample of response data:

      "UniqueID": "g6s6c7A072Lm2thUjFKdqk8uAE4E41107",
      "IsUniqueIDEncrypted": true,
      "BrandGroupID": 2,
      "Brands": [ {
      "Name": "WrapperUnitTest_171_17_44_17_87672_628",
      "BrandUniqueID": "RLHlzWV072rBuAPIFfp2tE2I4QE4E41107",
      "BrandID": 18685
      "Name": "WrapperUnitTest_171_17_44_17_884",
      "Owner": "Wrapper.Unit.Test",
      "OwnerType": 1


      3. Groovy script step

      Now here is the script (below) that I fashioned after yours.

      Few questions :

      - In the object model, do I have to specify all the json datapoint/tags, even though I'm only interested in the BrandGroupID one?


      - I've added a to see if the data is writing out on the jdbc, json - jdbc is not returning data. Is this syntax correct for a JDBC step: def jdbcResponse = context.expand('${JDBCRequest#Response}')


      -When I try to run the script, I'm receiving: org.xml.sax.SAXParseException; Premature end of file. error at line: 42, which is the script line: def results = new XmlSlurper().parseText(jdbcResponse). 

      This is where I'm stuck.



      * Model object for comparing
      class Model {
      def BrandGroupID

      def buildJdbcData(row) {
      row.with {
      BrandGroupID = BRANDGROUPID

      def buildJsonData(tagInfo){
      BrandGroupID = tagInfo.@BrandGroupID


      * Creating the jdbcResponse from the response received, using fixed value for testing
      * If you want, you can assign the response received directly using below instead of current and make sure you replace the step name correctly
      * def jdbcResponse = context.expand('${JdbcStepName#Response}')
      def jdbcResponse = context.expand('${JDBCRequest#Response}')"jdbcResponse: " + jdbcResponse) //not returning any data

      * Creating the jsonResponse from the response received, using fixed value for testing
      * If you want, you can assign the response received directly using below instead of current and make sure you replace the step name correctly
      * def jsonResponse = context.expand('${JsonStepName#Response}')
      def jsonResponse = context.expand('${GetAllBrandGroups#Response}')"jsonResponse: " + jsonResponse) //returning data

      //Parsing the jdbc and build the jdbc model object list
      def results = new XmlSlurper().parseText(jdbcResponse)
      def jdbcDataObjects = []
      results.ResultSet.Row.each { row ->
      jdbcDataObjects.add(new Model().buildJdbcData(row))

      //Parsing the json and build the json model object list
      def arrayOfTagInfo = new XmlSlurper().parseText(jsonResponse)
      def jsonDataObjects = []
      arrayOfTagInfo.TagInfo.each { tagInfo ->
      jsonDataObjects.add(new Model().buildJsonData(tagInfo))

      //sorting the Data before checking for equality

      if (jdbcDataObjects.size() != jsonDataObjects.size()) {
      System.err.println("Jdbc resultset size is : ${jdbcDataObjects.size()} and Json result size is : ${jsonDataObjects.size()}")
      assert jdbcDataObjects == jsonDataObjects, "Comparison of Jdbc and Json data has failed"


      • nmrao's avatar
        Champion Level 3
        Could not go thru entire script. If you just need to compare one value, that one property is enough.
    • azhar25's avatar
      New Contributor

      Getting the following error when pasrsing the jdbcResponse.


      org.xml.sax.SAXParseException; Premature end of file.