Thank you so much for your reply nmrao. Can't I do the same thing without groovy? as I have above 50 rest requests.
By the way your code is not working for me, giving error 'No such Property: caseID for class:Model' , could you please tell me whats is wrong with this code?
@groovy.transform.Canonical
import groovy.json.JsonSlurper
import groovy.util.XmlSlurper
class Model {
def caseID
def name
def description
def createdOn
def buildJdbcData(row) {
row.with {
caseID = CaseID
name = Name
description = Description
createdOn = CreatedOn
}
}
def buildJsonData(Root){
caseID = CaseID
name = Name
description = Description
createdOn = CreatedOn
}
}
def jdbcResponse = context.expand('${JDBC Request#ResponseAsXml}')
def restResponse = context.expand('${Cases#Response}')
//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 json = new JsonSlurper().parseText(restResponse)
def jsonDataObjects = []
json.Root.each { Root ->
jsonDataObjects.add(new Model().buildJsonData(Root))
}
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 is failed"
Thanks,
Geeta