1.Our API's part response:json
2.Dependent API's part response:api
The mapping between this two responses:
For example: sector5->@ConsumerDefensive, sector4->Healthcare .....(this is defined in the $.data.columns, i don't wanna to paste it in the blog).app
3.The data accuracy script :jsonp
import com.jayway.jsonpath.JsonPaththis
HashMap nameMap = new HashMap()
HashMap paapiMap = new HashMap()
def response1 = context.expand('${GetAccountSectorsData_PAAPI#Response}')spa
//Get name mapping between this two responses
JsonPath.read(response1, 'data.columns').each{ map->
if(map.id.startsWith("sector")){
nameMap.put(map.id, map.name.replaceAll(" ",""))
}
}
//log.info nameMaporm
//Get our response into paapiMap
JsonPath.read(response1, '$.data.rows').each{ row->
row.keySet().each{ key->
if(key.startsWith("sector")){
paapiMap.put(row.id+"_"+nameMap.get(key), row.get(key))
}
}
}blog
//Get response data of dependent API into pmsMapip
HashMap pmsMap = new HashMap()
accountId = context.expand('${#TestCase#accountId}')
def response2 = context.expand('${GetAccountSectorsData_DataAPI#Response}')
def rootNode = new XmlParser().parseText(response2)
//Get client information
rootNode.Accounts.Account.each{
if(it.@Id == accountId){
it.StockSectors[0].each{
it.SubStockSector.each{
it.attributes().each{ key,value->
pmsMap.put(accountId+"_"+key, value)
}
}
}
}
}
//log.info paapiMap
//log.info pmsMap
//log.info paapiMap.size()
//log.info pmsMap.size()
assert paapiMap.size()==pmsMap.size(), "The paapi holding's size should be the same with dataapi's size"get
//Compare data in paapiMap and dataapiMap ArrayList failMessageList = new ArrayList() pmsMap.each{ key, value-> Double paapiValue = paapiMap.get(key) if(paapiValue != value.toDouble()){ failMessageList.add([key, value, paapiValue]) } } log.info failMessageList assert failMessageList.size()==0, "The differences between PMSAPI and PAAPI are : " + failMessageList