Package org.springframework.mock.web
Class MockMultipartHttpServletRequest
java.lang.Object
org.springframework.mock.web.MockHttpServletRequest
org.springframework.mock.web.MockMultipartHttpServletRequest
- All Implemented Interfaces:
HttpServletRequest
,ServletRequest
,MultipartHttpServletRequest
,MultipartRequest
public class MockMultipartHttpServletRequest
extends MockHttpServletRequest
implements MultipartHttpServletRequest
Mock implementation of the
MultipartHttpServletRequest
interface.
As of Spring 6.0, this set of mocks is designed on a Servlet 6.0 baseline.
Useful for testing application controllers that access multipart uploads.
MockMultipartFile
can be used to populate these mock requests with files.
- Since:
- 2.0
- Author:
- Juergen Hoeller, Eric Crampton, Arjen Poutsma
- See Also:
-
Field Summary
Fields inherited from class org.springframework.mock.web.MockHttpServletRequest
DEFAULT_PROTOCOL, DEFAULT_REMOTE_ADDR, DEFAULT_REMOTE_HOST, DEFAULT_SCHEME, DEFAULT_SERVER_ADDR, DEFAULT_SERVER_NAME, DEFAULT_SERVER_PORT
Fields inherited from interface jakarta.servlet.http.HttpServletRequest
BASIC_AUTH, CLIENT_CERT_AUTH, DIGEST_AUTH, FORM_AUTH
-
Constructor Summary
ConstructorDescriptionCreate a newMockMultipartHttpServletRequest
with a defaultMockServletContext
.MockMultipartHttpServletRequest
(ServletContext servletContext) Create a newMockMultipartHttpServletRequest
with the suppliedServletContext
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addFile
(MultipartFile file) Add a file to this request.Return the contents plus description of an uploaded file in this request, ornull
if it does not exist.Return aMap
of the multipart files contained in this request.Return anIterator
of String objects containing the parameter names of the multipart files contained in this request.Return the contents plus description of uploaded files in this request, or an empty list if it does not exist.Return aMultiValueMap
of the multipart files contained in this request.getMultipartContentType
(String paramOrFileName) Determine the content type of the specified request part.getMultipartHeaders
(String paramOrFileName) Return the headers for the specified part of the multipart request.Return this request's headers as a convenient HttpHeaders instance.Return this request's method as a convenient HttpMethod instance.Methods inherited from class org.springframework.mock.web.MockHttpServletRequest
addHeader, addParameter, addParameter, addParameters, addPart, addPreferredLocale, addUserRole, authenticate, changeSessionId, checkActive, clearAttributes, close, getAsyncContext, getAttribute, getAttributeNames, getAuthType, getCharacterEncoding, getContentAsByteArray, getContentAsString, getContentLength, getContentLengthLong, getContentType, getContextPath, getCookies, getDateHeader, getDispatcherType, getHeader, getHeaderNames, getHeaders, getHttpServletMapping, getInputStream, getIntHeader, getLocalAddr, getLocale, getLocales, getLocalName, getLocalPort, getMethod, getParameter, getParameterMap, getParameterNames, getParameterValues, getPart, getParts, getPathInfo, getPathTranslated, getProtocol, getProtocolRequestId, getQueryString, getReader, getRemoteAddr, getRemoteHost, getRemotePort, getRemoteUser, getRequestDispatcher, getRequestedSessionId, getRequestId, getRequestURI, getRequestURL, getScheme, getServerName, getServerPort, getServletConnection, getServletContext, getServletPath, getSession, getSession, getUriTemplate, getUserPrincipal, invalidate, isActive, isAsyncStarted, isAsyncSupported, isRequestedSessionIdFromCookie, isRequestedSessionIdFromURL, isRequestedSessionIdValid, isSecure, isUserInRole, login, logout, removeAllParameters, removeAttribute, removeHeader, removeParameter, setAsyncContext, setAsyncStarted, setAsyncSupported, setAttribute, setAuthType, setCharacterEncoding, setContent, setContentType, setContextPath, setCookies, setDispatcherType, setHttpServletMapping, setLocalAddr, setLocalName, setLocalPort, setMethod, setParameter, setParameter, setParameters, setPathInfo, setPreferredLocales, setProtocol, setQueryString, setRemoteAddr, setRemoteHost, setRemotePort, setRemoteUser, setRequestedSessionId, setRequestedSessionIdFromCookie, setRequestedSessionIdFromURL, setRequestedSessionIdValid, setRequestURI, setScheme, setSecure, setServerName, setServerPort, setServletPath, setSession, setUriTemplate, setUserPrincipal, startAsync, startAsync, upgrade
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface jakarta.servlet.http.HttpServletRequest
authenticate, changeSessionId, getAuthType, getContextPath, getCookies, getDateHeader, getHeader, getHeaderNames, getHeaders, getHttpServletMapping, getIntHeader, getMethod, getPart, getParts, getPathInfo, getPathTranslated, getQueryString, getRemoteUser, getRequestedSessionId, getRequestURI, getRequestURL, getServletPath, getSession, getSession, getTrailerFields, getUserPrincipal, isRequestedSessionIdFromCookie, isRequestedSessionIdFromURL, isRequestedSessionIdValid, isTrailerFieldsReady, isUserInRole, login, logout, newPushBuilder, upgrade
Methods inherited from interface jakarta.servlet.ServletRequest
getAsyncContext, getAttribute, getAttributeNames, getCharacterEncoding, getContentLength, getContentLengthLong, getContentType, getDispatcherType, getInputStream, getLocalAddr, getLocale, getLocales, getLocalName, getLocalPort, getParameter, getParameterMap, getParameterNames, getParameterValues, getProtocol, getProtocolRequestId, getReader, getRemoteAddr, getRemoteHost, getRemotePort, getRequestDispatcher, getRequestId, getScheme, getServerName, getServerPort, getServletConnection, getServletContext, isAsyncStarted, isAsyncSupported, isSecure, removeAttribute, setAttribute, setCharacterEncoding, startAsync, startAsync
-
Constructor Details
-
MockMultipartHttpServletRequest
public MockMultipartHttpServletRequest()Create a newMockMultipartHttpServletRequest
with a defaultMockServletContext
. -
MockMultipartHttpServletRequest
Create a newMockMultipartHttpServletRequest
with the suppliedServletContext
.- Parameters:
servletContext
- the ServletContext that the request runs in (may benull
to use a defaultMockServletContext
)
-
-
Method Details
-
addFile
Add a file to this request. The parameter name from the multipart form is taken from theMultipartFile.getName()
.- Parameters:
file
- multipart file to be added
-
getFileNames
Description copied from interface:MultipartRequest
Return anIterator
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.- Specified by:
getFileNames
in interfaceMultipartRequest
- Returns:
- the names of the files
-
getFile
Description copied from interface:MultipartRequest
Return the contents plus description of an uploaded file in this request, ornull
if it does not exist.- Specified by:
getFile
in interfaceMultipartRequest
- Parameters:
name
- a String specifying the parameter name of the multipart file- Returns:
- the uploaded content in the form of a
MultipartFile
object
-
getFiles
Description copied from interface:MultipartRequest
Return the contents plus description of uploaded files in this request, or an empty list if it does not exist.- Specified by:
getFiles
in interfaceMultipartRequest
- Parameters:
name
- a String specifying the parameter name of the multipart file- Returns:
- the uploaded content in the form of a
MultipartFile
list
-
getFileMap
Description copied from interface:MultipartRequest
Return aMap
of the multipart files contained in this request.- Specified by:
getFileMap
in interfaceMultipartRequest
- Returns:
- a map containing the parameter names as keys, and the
MultipartFile
objects as values
-
getMultiFileMap
Description copied from interface:MultipartRequest
Return aMultiValueMap
of the multipart files contained in this request.- Specified by:
getMultiFileMap
in interfaceMultipartRequest
- Returns:
- a map containing the parameter names as keys, and a list of
MultipartFile
objects as values
-
getMultipartContentType
Description copied from interface:MultipartRequest
Determine the content type of the specified request part.- Specified by:
getMultipartContentType
in interfaceMultipartRequest
- Parameters:
paramOrFileName
- the name of the part- Returns:
- the associated content type, or
null
if not defined
-
getRequestMethod
Description copied from interface:MultipartHttpServletRequest
Return this request's method as a convenient HttpMethod instance.- Specified by:
getRequestMethod
in interfaceMultipartHttpServletRequest
-
getRequestHeaders
Description copied from interface:MultipartHttpServletRequest
Return this request's headers as a convenient HttpHeaders instance.- Specified by:
getRequestHeaders
in interfaceMultipartHttpServletRequest
-
getMultipartHeaders
Description copied from interface:MultipartHttpServletRequest
Return the headers for the specified part of the multipart request.If the underlying implementation supports access to part headers, then all headers are returned. Otherwise, for example, for a file upload, the returned headers may expose a 'Content-Type' if available.
- Specified by:
getMultipartHeaders
in interfaceMultipartHttpServletRequest
-