有没有办法捕获用wirerock存根的post请求的主体?我正在寻找类似于Mockito的ArgumentCaptor
的东西。
我有以下存根:
stubFor(post(urlPathEqualTo(getUploadEndpoint())).willReturn(().withStatus(HttpStatus.OK.value())));
我希望能够看到实际的请求是如何执行的,获得它的主体并Assert它。
我尝试在存根中使用.withRequestBody(equalToXml(...))
,因为主体是XML的String表示,但这对我不起作用,因为equalToXml
太严格了,例如不允许没有周围标记的自由文本。
3条答案
按热度按时间whitzsjs1#
我设法通过这样做找到了解决方案:我给存根赋予了UUID
我收集了这个端点上发生的所有服务器事件
然后我使用XMLUnit来Assert这个主体。看起来可以完成这项工作,但如果有其他解决方案,我也会考虑。
cbjzeqam2#
或者,您可以使用API查找与 predicate 匹配的请求:
然后,您可以Assert关于匹配请求的任何内容。
w7t8yxp53#
您可以使用该API执行verify that a request was made with the expected body。
有关XPath匹配的示例,请参见WireMock /请求匹配/ XPath。