MockRestServiceServer: how to mock a POST call with a body?

Sasha Shpota :

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.

user7294900 :

You can use content().string to verify body:

.andExpect(content().string(expectedContent))

Or content().bytes:

this.mockServer.expect(content().bytes("foo".getBytes()))

this.mockServer.expect(content().string("foo"))

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=124707&siteId=1