cancel
Showing results for 
Search instead for 
Did you mean: 

comparing 2 datasources

Highlighted
Occasional Contributor

comparing 2 datasources

Hello,

 

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 5
Moderator

Re: comparing 2 datasources

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.

 

http://blog.smartbear.com/api-testing/how-to-use-xml-datasources-for-response-processing-in-soapui/

 

Regards,

Marcus

SmartBear Support

Community Hero

Re: comparing 2 datasources

Please check the below link for similar one as reference, and you need to modify it for your business model.

http://stackoverflow.com/questions/31472381/dynamically-compare-rest-xml-json-response-and-jdbc-usin...


Regards,
Rao.
Occasional Contributor

Re: comparing 2 datasources

~nmrao

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">
<BRANDGROUPID>2</BRANDGROUPID>
</Row>
<Row rowNumber="2">
<BRANDGROUPID>4</BRANDGROUPID>
</Row>

 

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 log.info 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.

 

Script:

/*
* Model object for comparing
*/
@groovy.transform.Canonical
class Model {
def BrandGroupID


//jdbc
def buildJdbcData(row) {
row.with {
BrandGroupID = BRANDGROUPID
}
}

//json
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}')
log.info("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}')
log.info("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
jdbcDataObjects.sort()
jsonDataObjects.sort()

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"

 

Community Hero

Re: comparing 2 datasources

Could not go thru entire script. If you just need to compare one value, that one property is enough.


Regards,
Rao.
New Contributor

Re: comparing 2 datasources

Getting the following error when pasrsing the jdbcResponse.

 

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

New Here?
Join us and watch the welcome video:
Watch the New Interview
7Mistakes
Join the exciting event
SeptemberHubBub
Top Kudoed Authors
Join the September Hub-bub to show off, learn and win