我必须将WebService响应与其下游服务进行比较。但是,我的响应和下游响应中的ID不相同。我在下面给出示例回复。再说一次,一个是REST服务,另一个是SOAP服务,但是我可以进行类型转换(那不是问题)
MyWebService响应:
"myWebServiceResponse": {
"webServiceSummary": {
"service": {
"serviceCd": "ABCD",
"serviceDescription": "Checking Main Service",
"hypotheticalInd": "100.0",
"realInd": "200.0"
},
"includeServicesList": [
{
"serviceCd": "XYZ",
"serviceDescription": "Checking AddOn Service",
"hypotheticalInd": "50.0",
"realInd": "60.0"
},
{
"serviceCd": "PQRS",
"serviceDescription": "Checking SecondAddOn Service",
"hypotheticalInd": "100.0",
"realInd": "200.0"
}
]
}
现在,以下是下游服务响应。我无法使用“匹配包含” ,因为myWebServiceResponse和DownstreamService中的ID不同,并且还有许多额外的参数。您可以在下面看到。
DownstreamServiceResponse:
"myDownstreamResponse": {
"webServiceDetail": {
"feature": {
"featureCd": "ABCD",
"featureName": "Checking Main Service",
"imaginaryInd": "100.0",
"actualInd": "200.0",
"extraInd1": "someRandomValue1",
},
"includefeatureList": [
{
"featureCd": "PQRS",
"featureName": "Checking SecondAddOn Service",
"imaginaryInd": "100.0",
"actualInd": "200.0",
"extraInd1": "someRandomValue1",
"extraInd2": "someRandomValue1"
},
{
"featureCd": "XYZ",
"featureName": "Checking AddOn Service",
"imaginaryInd": "50.0",
"actualInd": "60.0",
"extraInd1": "someRandomValue1",
"extraInd2": "someRandomValue1"
}
]
}
现在,我应该如何匹配这两个响应?此外,您会看到很少有参数是随机的,无法通过逐行移动进行比较。仅相同的参数值分配给CD /指示灯。而且,我想知道如何基于一个主要值提取和匹配参数。例如,我要使用“ serviceCd”:“ ABCD”并将所有与ABCD相关的参数与下游服务的参数进行比较。
答案 0 :(得分:2)
如果以下内容不清楚,请仔细阅读文档。
* def response =
"""
{
"webServiceSummary":{
"service":{
"serviceCd":"ABCD",
"serviceDescription":"Checking Main Service",
"hypotheticalInd":"100.0",
"realInd":"200.0"
},
"includeServicesList":[
{
"serviceCd":"XYZ",
"serviceDescription":"Checking AddOn Service",
"hypotheticalInd":"50.0",
"realInd":"60.0"
},
{
"serviceCd":"PQRS",
"serviceDescription":"Checking SecondAddOn Service",
"hypotheticalInd":"100.0",
"realInd":"200.0"
}
]
}
}
"""
* def source =
"""
{
"webServiceDetail":{
"feature":{
"featureCd":"ABCD",
"featureName":"Checking Main Service",
"imaginaryInd":"100.0",
"actualInd":"200.0",
"extraInd1":"someRandomValue1"
},
"includefeatureList":[
{
"featureCd":"PQRS",
"featureName":"Checking SecondAddOn Service",
"imaginaryInd":"100.0",
"actualInd":"200.0",
"extraInd1":"someRandomValue1",
"extraInd2":"someRandomValue1"
},
{
"featureCd":"XYZ",
"featureName":"Checking AddOn Service",
"imaginaryInd":"50.0",
"actualInd":"60.0",
"extraInd1":"someRandomValue1",
"extraInd2":"someRandomValue1"
}
]
}
}
"""
* def feature = source.webServiceDetail.feature
* set expected.webServiceSummary.service
| path | value |
| serviceCd | feature.featureCd |
| serviceDescription | feature.featureName |
| hypotheticalInd | feature.imaginaryInd |
| realInd | feature.actualInd |
* def mapper = function(x){ return { serviceCd: x.featureCd, serviceDescription: x.featureName, hypotheticalInd: x.imaginaryInd, realInd: x.actualInd } }
* def expectedList = karate.map(source.webServiceDetail.includefeatureList, mapper)
* set expected.webServiceSummary.includeServicesList = '#(^expectedList)'
* print expected
* match response == expected