public class

MockMultipartHttpServletRequest

extends MockHttpServletRequest
implements MultipartHttpServletRequest
java.lang.Object
   ↳ org.springframework.mock.web.MockHttpServletRequest
     ↳ org.springframework.mock.web.MockMultipartHttpServletRequest

Class Overview

Mock implementation of the MultipartHttpServletRequest interface.

Useful for testing application controllers that access multipart uploads. The MockMultipartFile can be used to populate these mock requests with files.

Summary

[Expand]
Inherited Constants
From class org.springframework.mock.web.MockHttpServletRequest
From interface javax.servlet.http.HttpServletRequest
Public Constructors
MockMultipartHttpServletRequest()
Public Methods
void addFile(MultipartFile file)
Add a file to this request.
MultipartFile getFile(String name)
Return the contents plus description of an uploaded file in this request, or null if it does not exist.
Map<StringMultipartFile> getFileMap()
Return a Map of the multipart files contained in this request.
Iterator<String> getFileNames()
Return an Iterator of String objects containing the parameter names of the multipart files contained in this request.
List<MultipartFile> getFiles(String name)
Return the contents plus description of uploaded files in this request, or an empty list if it does not exist.
MultiValueMap<StringMultipartFile> getMultiFileMap()
Return a MultiValueMap of the multipart files contained in this request.
[Expand]
Inherited Methods
From class org.springframework.mock.web.MockHttpServletRequest
From class java.lang.Object
From interface javax.servlet.ServletRequest
From interface javax.servlet.http.HttpServletRequest
From interface org.springframework.web.multipart.MultipartRequest

Public Constructors

public MockMultipartHttpServletRequest ()

Public Methods

public void addFile (MultipartFile file)

Add a file to this request. The parameter name from the multipart form is taken from the getName().

Parameters
file multipart file to be added

public MultipartFile getFile (String name)

Return the contents plus description of an uploaded file in this request, or null if it does not exist.

Parameters
name a String specifying the parameter name of the multipart file
Returns

public Map<StringMultipartFile> getFileMap ()

Return a Map of the multipart files contained in this request.

Returns
  • a map containing the parameter names as keys, and the MultipartFile objects as values

public Iterator<String> getFileNames ()

Return an Iterator of String objects containing the parameter names of the multipart files contained in this request. These are the field names of the form (like with normal parameters), not the original file names.

Returns
  • the names of the files

public List<MultipartFile> getFiles (String name)

Return the contents plus description of uploaded files in this request, or an empty list if it does not exist.

Parameters
name a String specifying the parameter name of the multipart file
Returns

public MultiValueMap<StringMultipartFile> getMultiFileMap ()

Return a MultiValueMap of the multipart files contained in this request.

Returns
  • a map containing the parameter names as keys, and a list of MultipartFile objects as values