use of org.springframework.http.converter.FormHttpMessageConverter in project spring-framework by spring-projects.
the class ContentRequestMatchers method formData.
/**
* Parse the body as form data and compare to the given {@code MultiValueMap}.
* @since 4.3
*/
public RequestMatcher formData(final MultiValueMap<String, String> expectedContent) {
return new RequestMatcher() {
@Override
public void match(final ClientHttpRequest request) throws IOException, AssertionError {
HttpInputMessage inputMessage = new HttpInputMessage() {
@Override
public InputStream getBody() throws IOException {
MockClientHttpRequest mockRequest = (MockClientHttpRequest) request;
return new ByteArrayInputStream(mockRequest.getBodyAsBytes());
}
@Override
public HttpHeaders getHeaders() {
return request.getHeaders();
}
};
FormHttpMessageConverter converter = new FormHttpMessageConverter();
assertEquals("Request content", expectedContent, converter.read(null, inputMessage));
}
};
}
use of org.springframework.http.converter.FormHttpMessageConverter in project spring-framework by spring-projects.
the class MockHttpServletRequestBuilder method parseFormData.
private MultiValueMap<String, String> parseFormData(final MediaType mediaType) {
HttpInputMessage message = new HttpInputMessage() {
@Override
public InputStream getBody() throws IOException {
return new ByteArrayInputStream(content);
}
@Override
public HttpHeaders getHeaders() {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(mediaType);
return headers;
}
};
try {
return new FormHttpMessageConverter().read(null, message);
} catch (IOException ex) {
throw new IllegalStateException("Failed to parse form data in request body", ex);
}
}
Aggregations