java - 空手道 DSL 断言嵌套 json
问题描述
{"serviceName":"Legal Entity account for given input account.","requestTime":1545426348945,"responseTime":1545426348949,"timeTaken":4,"responseCode":0,"responseMessage":"Success","pageSize":100,"pageNumber":0,"accounts":{"transferDate":1549429200000,"migrationWave":"5","searchedLEAccount":{"accountNumber":"41477514","cbdNumber":"12345678","bic":"CHASGBXxX","poolAccount":"Y","sweepMasterAccount":"Y","status":"DORMANT","branchId":"000000071","branchName":"LONDON","leAccountType":"OLD"},"linkedLEAccount":{"accountNumber":"6541245045","cbdNumber":"854321","bic":"CHASLUY","status":"DORMANT","branchId":"000000055","branchName":"S.A","leAccountType":"NEW"}}}
我正在尝试获取所有 accountNumber 并验证它们是否是数字。我究竟做错了什么?
When method Post
Then status 200
And match response != null
And match response contains {serviceName: 'Legal Entity account for given input account.' }
And match response.accounts.searchedLEAccount contains { accountNumber: '#notnull' }
And match response.accounts.searchedLEAccount contains { accountNumber: '#present' }
And match response.accounts.searchedLEAccount contains { accountNumber: '#number' }
解决方案
在一行中:
* match each $..accountNumber == '#regex \\d+'
提示:仔细阅读文档并理解 Json-Path。
这是完整的示例,您可以将其粘贴到新示例中Scenario
并查看工作:
* def response =
"""
{
"serviceName":"Legal Entity account for given input account.",
"requestTime":1545426348945,
"responseTime":1545426348949,
"timeTaken":4,
"responseCode":0,
"responseMessage":"Success",
"pageSize":100,
"pageNumber":0,
"accounts":{
"transferDate":1549429200000,
"migrationWave":"5",
"searchedLEAccount":{
"accountNumber":"41477514",
"cbdNumber":"12345678",
"bic":"CHASGBXxX",
"poolAccount":"Y",
"sweepMasterAccount":"Y",
"status":"DORMANT",
"branchId":"000000071",
"branchName":"LONDON",
"leAccountType":"OLD"
},
"linkedLEAccount":{
"accountNumber":"6541245045",
"cbdNumber":"854321",
"bic":"CHASLUY",
"status":"DORMANT",
"branchId":"000000055",
"branchName":"S.A",
"leAccountType":"NEW"
}
}
}
"""
* match each $..accountNumber == '#regex \\d+'
推荐阅读
- gitlab - GITLAB CI:文件外壳无法获取环境变量
- sockets - TCP socket server 使用 in6addr_any,client 无法连接使用 c,只使用本地 ipv6
- r - R中的条件嵌套IF
- python-3.x - 在 Python scikit learn 中为 12 个随机森林创建循环
- amazon-web-services - 如何使用 Docker 在 Airflow 中使用 .env 变量设置 S3 连接?
- informatica - SUBSTR 在 informatica 中
- sql - 按顺序加入 2 个表
- java - Java:澄清“长期选择的争论”场景
- email - 当谷歌表格中的字符串匹配时如何使用谷歌应用程序脚本发送电子邮件警报(单元格更改未编辑)
- reactjs - 如何管理多个下拉菜单的状态