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?
我正在使用MockRestServiceServer来模拟外部webservice xml响应。这已经可以正常工作,但我怎样才能模拟响应中的http标头,而不仅仅是响应体?
@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));
}
1 个解决方案
#1
2
Just follow your withSuccess
method with headers
method.
只需使用带有headers方法的withSuccess方法即可。
mockServer
.expect(...)
.andRespond(withSuccess().headers(...));
#1
2
Just follow your withSuccess
method with headers
method.
只需使用带有headers方法的withSuccess方法即可。
mockServer
.expect(...)
.andRespond(withSuccess().headers(...));