Forum Discussion

ilovechiku's avatar
ilovechiku
Contributor
9 years ago

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?

  •  

     

     

    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's avatar
      nmrao
      Champion Level 3
      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.
      • ilovechiku's avatar
        ilovechiku
        Contributor

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

        can you please help.