regex - 如何在wiremock的请求映射中使用主体模式
问题描述
我有两个如下的 xml 请求,只是想得到响应。Response1 如果请求正文包含节点 A、B、C 并且不包含 D。Response2 如果 A、B、C、D 都包含在请求中。
有人可以帮我解决这个问题。
如果有人可以帮助我使用正文模式获得关于请求匹配的好文章,或者正文模式有哪些不同的选项,那也会很有帮助。
提前致谢!!
我试过包含和优先级,但这没有帮助。
要求1:
<TestService>
<A> test </A>
<B> testB</B>
<C> testC </C>
<XYZ> test </XYZ>
</TestService>
要求2:
<TestService>
<A> test </A>
<B> testB</B>
<C> testC </C>
<XYZQ> test test</XYZQ>
<D> testD</D>
</TestService>
解决方案
在 WireMock 中,它可能会以 2 条规则结束,每种情况一个:
标签存在时的规则:
{
"request": {
"method": "ANY",
"url": "/xmltag",
"bodyPatterns" : [ {
"matchesXPath" : "/TestService[count(//D) = 1]"
} ]
},
"response": {
"status": 200,
"body": "<root><tag>D</tag></root>"
}
}
然后是没有 D 标签时的另一个:
{
"request": {
"method": "ANY",
"url": "/xmltag",
"bodyPatterns" : [ {
"matchesXPath" : "/TestService[count(//D) = 0]"
} ]
},
"response": {
"status": 200,
"body": "<root><tag>No D found</tag></root>"
}
}
推荐阅读
- python-3.x - Selenium python 评分星星点击
- javascript - 条件更改为 true 后,ng-show 不显示
- swiftui - 抑制冗长的控制台输出 - SwiftUI / MacOS Monterey
- flutter - 带有标签栏和网格视图的 Flutter sliver 应用栏
- rxjs - 绅士,一个 RxJs 计时器,它等待进程在下一个间隔之前完成执行
- elasticsearch - ETL - 弹性负载指标日志捕获
- angular - 使用 simple-json-replay-server 时出现错误 404 Not found 错误
- android - Webview 中的支付网关
- r - 如何使用 dplyr R 选择名称为日期的列
- oracle - 从 Oracle SQL 日期导入 SQOOP 以 unix 时间格式存储后,如何导出回 ORACLE