【发布时间】:2019-08-17 06:10:29
【问题描述】:
我正在尝试在 wirkmock 中创建存根。但是当我到达端点时显示“请求不匹配”
当我使用简单的检查时它就可以工作
在代码中:
stubFor(get(urlEqualTo("/v1/test.svc"))
.withHeader("Content-Type", equalTo("application/xml"))
.withRequestBody(containing("<b:Name>Test</b:Name>"))
.willReturn(aResponse()
.withStatus(200)
.withHeader("Content-Type", "application/xml")
.withBody("Passed")));
请求:
端点
http://{{url}}/v1/test.svc
标题
Content-Type:application/xml
身体
<test xmlns="http://abc.example.com">
<request xmlns:b="http://abc.example.com/b" xmlns:i="http://abc.example.com/i">
<b:Name>Test</b:Name>
<b:Age>18</b:Age>
<b:Count>2020</b:Count>
</request>
</test>
结果:
Passed
但是当我尝试使用 xpath 检查某些值时它不起作用
在代码中:
stubFor(get(urlEqualTo("/paymentapi/paymentservice.svc"))
.withHeader("Content-Type", equalTo("application/xml"))
.withRequestBody(containing("<b:Name>Test</b:Name>"))
.withRequestBody(matchingXPath("//Age/text()",equalTo("18")))
.willReturn(aResponse()
.withStatus(200)
.withHeader("Content-Type", "application/xml")
.withBody("Passed")));
结果:
Request was not matched
=======================
-----------------------------------------------------------------------------------------------------------------------
| Closest stub | Request |
-----------------------------------------------------------------------------------------------------------------------
|
GET | GET
/vi/test.svc | /v1/test.svc
|
Content-Type: application/xml | Content-Type: application/xml
|
//Age/text() | <test xmlns="http://abc.example.com">
<request <<<<< Body does not match
| xmlns:b="http://abc.example.com/b"
| xmlns:i="http://abc.example.com/i">
<b:Name>Test</b:Name>
<b:Age>18</b:Age>
<b:Count>2020</b:Count>
</request>
</test>
|
-----------------------------------------------------------------------------------------------------------------------
谁能告诉我如何检查这个值?
【问题讨论】: