Ask a Question

Compare response to table values

SOLVED
ilovechiku
Contributor

Compare response to table values

I have a response(i have multiple such entries copied only one.) like below and I have a table that I need to compare it against.

{

"Items": [
{
"EmployeeId": "1",
"CompanyId": "1",
"FirstName": "SPENCER",
"LastName": "LIN"
"Status": {
"Code": "A",
"Description": "Active"
},
"BenefitClass": null,
"SupervisorId": null,
"SupervisorFirstName": null,
"SupervisorLastName": null,
"CostCenters": [
{
"Code": "01",
"Description": "Corporate"
}
]
}

 

I was able to print the results of the value in DB, like below:

/*****************************************this is the employeeId returned from DB.**************************************/
def returntripDB = getEmployeeFromDB(db,jsonRes)

returned DB value[[Id:1], [Id:113], [Id:129], [Id:130], [Id:131], [Id:134], [Id:136], [Id:140], [Id:143]]


public def getEmployeeFromDB(def database,jsonRes)
{
def query = "SELECT Id FROM [mydb].[mydb].[etable] order by etableid asc"
// log.info "QUERY for all employee id only "+query
return database.rows(query)

}

 

I want to iterate through the reponse and compare the values to the DB. How can i do this?

14 REPLIES 14
ilovechiku
Contributor

 

 

 

was able to get the reponse to print like this 

 

jsonRes.Items.EmployeeId.each
{
//groovy iterator
def valueOfEmployee=it.value

log.info myResponsevalues
}

 

the result was 

1
113
129
130
131
134
136

 

Also I was able to get the DB results like below //log.info "DB values"+returntripDB

DB values[1, 113, 129, 130, 131]

 

How can I compare these two values?

please help

nmrao
Champion Level 2

Instead of printing the values from json response, add them to an arraylist.
From jdbc also you would get arraylist.
And use assert to compare both the lists. Make sure both lists are sorted before the assert.


Regards,
Rao.

I dont have a JDBC step.. how can i add this query result to an Array ? and compare the two

can you please help.

nmrao
Champion Level 2

What I meant was that you already have result from getEmployeeFromDB to get the data.
Below assert will do the compare actual vs expected.
assert expected == actual, "Not matching"


Regards,
Rao.
bs01
Occasional Contributor

The limitation in this apporach is, if i write method to compare two values (without assertion) and want to print to results (html results), it is not possible. That is the drawback with SoapUI tool.

 

nmrao
Champion Level 2

Sorry, I did not get it right, probably? You mean so say, "Not matching" does not go to html report if actual does not match expected? Are you sure?


Regards,
Rao.
bs01
Occasional Contributor

Hi,

Regardless of 'matching or not matching', if I use log.info("My comment"), it won't be printed to Html Reports. ( Let us say, we followed your suggestion - single test step, and calling it mutliple times because only some data change.)

 

I was told, this is not possible. The result will just diplay the overall testcase result, not step-wise.

 

Instead, if I create each step as a test case, and if I use assert, then  it will go into HTML reports.

thanks

lets please stick to the original question... folks can you please help me on this its been 3 days and am hunting for the solution. This morning I have 2 issues my iterator of the reponse isnt printing results 

1.my iterator is not printing result which it did earlier

 

jsonRes.Items.EmployeeId.each
{
//groovy iterator
def valueOfEmployee=it.value
log.info myResponsevalues

}

Issue 2 : how do i add the results of database return and the above to an arrays and compare the results. Hit a blank wall.please help

nmrao
Champion Level 2

Looks like your case is similar except that data is in json instead of xml
http://stackoverflow.com/questions/31472381/dynamically-compare-rest-xml-json-response-and-jdbc-usin...

and some links to process json provided in below thread, see Message 5
http://community.smartbear.com/t5/SoapUI-Open-Source/Extracting-data-from-CData-in-SOAP-Response/m-p...

Hope these links helps.


Regards,
Rao.
cancel
Showing results for 
Search instead for 
Did you mean: