MockHttpServletRequestBuilder allows for specifying content type as String value

Issue: SPR-12405
This commit is contained in:
Juergen Hoeller
2014-11-01 23:01:26 +01:00
parent 78459504e0
commit bba38b8862
2 changed files with 62 additions and 37 deletions

View File

@@ -186,11 +186,22 @@ public class MockHttpServletRequestBuilder
/**
* Set the 'Content-Type' header of the request.
* @param mediaType the content type
* @param contentType the content type
*/
public MockHttpServletRequestBuilder contentType(MediaType mediaType) {
Assert.notNull(mediaType, "'contentType' must not be null");
this.contentType = mediaType.toString();
public MockHttpServletRequestBuilder contentType(MediaType contentType) {
Assert.notNull(contentType, "'contentType' must not be null");
this.contentType = contentType.toString();
this.headers.set("Content-Type", this.contentType);
return this;
}
/**
* Set the 'Content-Type' header of the request.
* @param contentType the content type
* @since 4.1.2
*/
public MockHttpServletRequestBuilder contentType(String contentType) {
this.contentType = MediaType.parseMediaType(contentType).toString();
this.headers.set("Content-Type", this.contentType);
return this;
}