如何从没有任何数组名称的 JSON 数组内容中放心地验证响应?
How to validate response in rest-assured from JSON array content which doesn't have any array name?
我觉得很难。
如何使用 Rest-Assured 从响应中验证以下内容?
{
"code":268,
"name":"Result-Code",
"value":2001,
"type":"UNSIGNED32",
"group":[
],
"grouped":false
},
如果这是我的回复:
[
{
"avps":[
{
"code":263,
"name":"Session-Id",
"value":"ocstest;766666665;766666665",
"type":"UTF8STRING",
"group":[
],
"grouped":false
},
{
"code":260,
"name":"Vendor-Specific-Application-Id",
"value":"<Grouped>",
"type":"GROUPED",
"group":[
{
"code":265,
"name":"Supported-Vendor-Id",
"value":0,
"type":"UNSIGNED32",
"group":[
],
"grouped":false
},
{
"code":258,
"name":"Auth-Application-Id",
"value":4,
"type":"UNSIGNED32",
"group":[
],
"grouped":false
},
{
"code":259,
"name":"Acct-Application-Id",
"value":0,
"type":"UNSIGNED32",
"group":[
],
"grouped":false
}
],
"grouped":true
},
{
"code":268,
"name":"Result-Code",
"value":2001,
"type":"UNSIGNED32",
"group":[
],
"grouped":false
},
{
"code":416,
"name":"CC-Request-Type",
"value":1,
"type":"INT32",
"group":[
],
"grouped":false
},
{
"code":415,
"name":"CC-Request-Number",
"value":0,
"type":"UNSIGNED32",
"group":[
],
"grouped":false
},
{
"code":431,
"name":"Granted-Service-Unit",
"value":"<Grouped>",
"type":"GROUPED",
"group":[
{
"code":420,
"name":"CC-Time",
"value":240,
"type":"UNSIGNED32",
"group":[
],
"grouped":false
}
],
"grouped":true
}
]
},
{
"avps":[
{
"code":263,
"name":"Session-Id",
"value":"ocstest;766666665;766666665",
"type":"UTF8STRING",
"group":[
],
"grouped":false
},
{
"code":260,
"name":"Vendor-Specific-Application-Id",
"value":"<Grouped>",
"type":"GROUPED",
"group":[
{
"code":265,
"name":"Supported-Vendor-Id",
"value":0,
"type":"UNSIGNED32",
"group":[
],
"grouped":false
},
{
"code":258,
"name":"Auth-Application-Id",
"value":4,
"type":"UNSIGNED32",
"group":[
],
"grouped":false
},
{
"code":259,
"name":"Acct-Application-Id",
"value":0,
"type":"UNSIGNED32",
"group":[
],
"grouped":false
}
],
"grouped":true
},
{
"code":268,
"name":"Result-Code",
"value":5004,
"type":"UNSIGNED32",
"group":[
],
"grouped":false
},
{
"code":416,
"name":"CC-Request-Type",
"value":2,
"type":"INT32",
"group":[
],
"grouped":false
},
{
"code":415,
"name":"CC-Request-Number",
"value":1,
"type":"UNSIGNED32",
"group":[
],
"grouped":false
}
]
},
{
"avps":[
{
"code":263,
"name":"Session-Id",
"value":"ocstest;766666666;788888888",
"type":"UTF8STRING",
"group":[
],
"grouped":false
},
{
"code":260,
"name":"Vendor-Specific-Application-Id",
"value":"<Grouped>",
"type":"GROUPED",
"group":[
{
"code":265,
"name":"Supported-Vendor-Id",
"value":0,
"type":"UNSIGNED32",
"group":[
],
"grouped":false
},
{
"code":258,
"name":"Auth-Application-Id",
"value":4,
"type":"UNSIGNED32",
"group":[
],
"grouped":false
},
{
"code":259,
"name":"Acct-Application-Id",
"value":0,
"type":"UNSIGNED32",
"group":[
],
"grouped":false
}
],
"grouped":true
},
{
"code":268,
"name":"Result-Code",
"value":5002,
"type":"UNSIGNED32",
"group":[
],
"grouped":false
},
{
"code":416,
"name":"CC-Request-Type",
"value":3,
"type":"INT32",
"group":[
],
"grouped":false
},
{
"code":415,
"name":"CC-Request-Number",
"value":2,
"type":"UNSIGNED32",
"group":[
],
"grouped":false
}
]
}]
我不确定这是否是最有效的方法 - 但我能够使用以下方法验证 'Result-Code'..
avps.findAll { 'Result-Code' in it.name }.value[0][2]", is(2001)
谢谢
我觉得很难。 如何使用 Rest-Assured 从响应中验证以下内容?
{
"code":268,
"name":"Result-Code",
"value":2001,
"type":"UNSIGNED32",
"group":[
],
"grouped":false
},
如果这是我的回复:
[
{
"avps":[
{
"code":263,
"name":"Session-Id",
"value":"ocstest;766666665;766666665",
"type":"UTF8STRING",
"group":[
],
"grouped":false
},
{
"code":260,
"name":"Vendor-Specific-Application-Id",
"value":"<Grouped>",
"type":"GROUPED",
"group":[
{
"code":265,
"name":"Supported-Vendor-Id",
"value":0,
"type":"UNSIGNED32",
"group":[
],
"grouped":false
},
{
"code":258,
"name":"Auth-Application-Id",
"value":4,
"type":"UNSIGNED32",
"group":[
],
"grouped":false
},
{
"code":259,
"name":"Acct-Application-Id",
"value":0,
"type":"UNSIGNED32",
"group":[
],
"grouped":false
}
],
"grouped":true
},
{
"code":268,
"name":"Result-Code",
"value":2001,
"type":"UNSIGNED32",
"group":[
],
"grouped":false
},
{
"code":416,
"name":"CC-Request-Type",
"value":1,
"type":"INT32",
"group":[
],
"grouped":false
},
{
"code":415,
"name":"CC-Request-Number",
"value":0,
"type":"UNSIGNED32",
"group":[
],
"grouped":false
},
{
"code":431,
"name":"Granted-Service-Unit",
"value":"<Grouped>",
"type":"GROUPED",
"group":[
{
"code":420,
"name":"CC-Time",
"value":240,
"type":"UNSIGNED32",
"group":[
],
"grouped":false
}
],
"grouped":true
}
]
},
{
"avps":[
{
"code":263,
"name":"Session-Id",
"value":"ocstest;766666665;766666665",
"type":"UTF8STRING",
"group":[
],
"grouped":false
},
{
"code":260,
"name":"Vendor-Specific-Application-Id",
"value":"<Grouped>",
"type":"GROUPED",
"group":[
{
"code":265,
"name":"Supported-Vendor-Id",
"value":0,
"type":"UNSIGNED32",
"group":[
],
"grouped":false
},
{
"code":258,
"name":"Auth-Application-Id",
"value":4,
"type":"UNSIGNED32",
"group":[
],
"grouped":false
},
{
"code":259,
"name":"Acct-Application-Id",
"value":0,
"type":"UNSIGNED32",
"group":[
],
"grouped":false
}
],
"grouped":true
},
{
"code":268,
"name":"Result-Code",
"value":5004,
"type":"UNSIGNED32",
"group":[
],
"grouped":false
},
{
"code":416,
"name":"CC-Request-Type",
"value":2,
"type":"INT32",
"group":[
],
"grouped":false
},
{
"code":415,
"name":"CC-Request-Number",
"value":1,
"type":"UNSIGNED32",
"group":[
],
"grouped":false
}
]
},
{
"avps":[
{
"code":263,
"name":"Session-Id",
"value":"ocstest;766666666;788888888",
"type":"UTF8STRING",
"group":[
],
"grouped":false
},
{
"code":260,
"name":"Vendor-Specific-Application-Id",
"value":"<Grouped>",
"type":"GROUPED",
"group":[
{
"code":265,
"name":"Supported-Vendor-Id",
"value":0,
"type":"UNSIGNED32",
"group":[
],
"grouped":false
},
{
"code":258,
"name":"Auth-Application-Id",
"value":4,
"type":"UNSIGNED32",
"group":[
],
"grouped":false
},
{
"code":259,
"name":"Acct-Application-Id",
"value":0,
"type":"UNSIGNED32",
"group":[
],
"grouped":false
}
],
"grouped":true
},
{
"code":268,
"name":"Result-Code",
"value":5002,
"type":"UNSIGNED32",
"group":[
],
"grouped":false
},
{
"code":416,
"name":"CC-Request-Type",
"value":3,
"type":"INT32",
"group":[
],
"grouped":false
},
{
"code":415,
"name":"CC-Request-Number",
"value":2,
"type":"UNSIGNED32",
"group":[
],
"grouped":false
}
]
}]
我不确定这是否是最有效的方法 - 但我能够使用以下方法验证 'Result-Code'..
avps.findAll { 'Result-Code' in it.name }.value[0][2]", is(2001)
谢谢