本文介绍了MockRestServiceServer:如何用主体模拟POST调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试通过以下方式用MockRestServiceServer
模拟POST方法:
I am trying to mock a POST method with MockRestServiceServer
in the following way:
MockRestServiceServer server = bindTo(restTemplate).build();
server.expect(requestTo("/my-api"))
.andExpect(method(POST))
.andRespond(withSuccess(expectedResponce, APPLICATION_JSON));
问题:如何在此设置中验证请求正文?
Problem: How do I verify a request body in this setup?
我浏览了文档和一些示例,仍然无法弄清楚该怎么做.
I browsed through the documentation and some examples and still can't figure out how it can be done.
推荐答案
您可以使用来验证正文:
You can use content().string to verify body:
或 content().bytes :
this.mockServer.expect(content().string("foo"))
this.mockServer.expect(content().string("foo"))
这篇关于MockRestServiceServer:如何用主体模拟POST调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!