MockMultipartHttpServletRequest pre-defines method "POST" and content type "multipart/form-data"

This commit is contained in:
Juergen Hoeller
2010-08-15 22:46:15 +00:00
parent 1841b14b21
commit 5b0448c609
3 changed files with 32 additions and 13 deletions

View File

@@ -32,14 +32,14 @@ import org.springframework.web.multipart.MultipartHttpServletRequest;
* {@link org.springframework.web.multipart.MultipartHttpServletRequest} interface.
*
* <p>Useful for testing application controllers that access multipart uploads.
* The {@link org.springframework.mock.web.MockMultipartFile} can be used to populate these mock requests
* The {@link MockMultipartFile} can be used to populate these mock requests
* with files.
*
* @author Juergen Hoeller
* @author Eric Crampton
* @author Arjen Poutsma
* @since 2.0
* @see org.springframework.mock.web.MockMultipartFile
* @see MockMultipartFile
*/
public class MockMultipartHttpServletRequest extends MockHttpServletRequest implements MultipartHttpServletRequest {
@@ -47,9 +47,15 @@ public class MockMultipartHttpServletRequest extends MockHttpServletRequest impl
new LinkedMultiValueMap<String, MultipartFile>();
public MockMultipartHttpServletRequest() {
setMethod("POST");
setContentType("multipart/form-data");
}
/**
* Add a file to this request. The parameter name from the multipart
* form is taken from the {@link org.springframework.web.multipart.MultipartFile#getName()}.
* form is taken from the {@link MultipartFile#getName()}.
* @param file multipart file to be added
*/
public void addFile(MultipartFile file) {
@@ -83,4 +89,4 @@ public class MockMultipartHttpServletRequest extends MockHttpServletRequest impl
return new LinkedMultiValueMap<String, MultipartFile>(this.multipartFiles);
}
}
}