I'm using MockRestServiceServer
to mock an external webservice xml response.
That already works fine, but how can I also mock the http header inside the response, not only the response body?
@MockBean
private RestTemplate restTemplate;
private MockRestServiceServer mockServer;
@Before
public void createServer() throws Exception {
mockServer = MockRestServiceServer.createServer(restTemplate);
}
@Test
public void test() {
String xml = loadFromFile("productsResponse.xml");
mockServer.expect(MockRestRequestMatchers.anything()).andRespond(MockRestResponseCreators.withSuccess(xml, MediaType.APPLICATION_XML));
}
Just follow your withSuccess
method with headers
method.
mockServer
.expect(...)
.andRespond(withSuccess().headers(...));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With