SoapUI Groovy 功能测试中使用XmlParser解析xml

1.Our API's part response:

102110_Rc8s_942203.png

2.Dependent API's part response:

103308_iSD3_942203.png

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).

3.The data accuracy script :

import com.jayway.jsonpath.JsonPath

HashMap nameMap = new HashMap()
HashMap paapiMap = new HashMap()
def response1 = context.expand('${GetAccountSectorsData_PAAPI#Response}')

//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 nameMap

//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))
        }
    }
}

//Get response data of dependent API into pmsMap

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"

//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

 

转载于:https://my.oschina.net/u/942203/blog/823479

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值