Class MockHttpServletRequest
java.lang.Object
io.github.cdiunit.internal.servlet6.MockHttpServletRequest
- All Implemented Interfaces:
HttpSessionAware
,jakarta.servlet.http.HttpServletRequest
,jakarta.servlet.ServletRequest
public class MockHttpServletRequest
extends Object
implements jakarta.servlet.http.HttpServletRequest, HttpSessionAware
Shamelessly ripped from mockrunner.
-
Field Summary
Fields inherited from interface jakarta.servlet.http.HttpServletRequest
BASIC_AUTH, CLIENT_CERT_AUTH, DIGEST_AUTH, FORM_AUTH
-
Constructor Summary
ConstructorsConstructorDescriptionMockHttpServletRequest
(jakarta.servlet.ServletContext servletContext, jakarta.servlet.http.HttpSession httpSession) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addAttributeListener
(jakarta.servlet.ServletRequestAttributeListener listener) void
addCookie
(jakarta.servlet.http.Cookie cookie) void
void
void
addLocales
(List localeList) boolean
authenticate
(jakarta.servlet.http.HttpServletResponse response) void
void
void
Clears the parameters.void
Clears the map ofRequestDispatcher
objects.jakarta.servlet.AsyncContext
getAttribute
(String key) int
long
jakarta.servlet.http.Cookie[]
long
getDateHeader
(String key) jakarta.servlet.DispatcherType
getHeaders
(String key) jakarta.servlet.ServletInputStream
int
getIntHeader
(String key) int
getParameter
(String key) String[]
getParameterValues
(String key) jakarta.servlet.http.Part
Collection<jakarta.servlet.http.Part>
getParts()
getRealPath
(String path) int
jakarta.servlet.RequestDispatcher
getRequestDispatcher
(String path) Returns the map ofRequestDispatcher
objects.int
jakarta.servlet.ServletConnection
jakarta.servlet.ServletContext
jakarta.servlet.http.HttpSession
jakarta.servlet.http.HttpSession
getSession
(boolean create) boolean
boolean
boolean
boolean
boolean
boolean
boolean
isSecure()
boolean
isUserInRole
(String role) void
void
logout()
void
removeAttribute
(String key) void
resetAll()
Resets the state of this object to the default valuesvoid
setAsyncSupported
(boolean isAsyncSupported) void
setAttribute
(String key, Object value) void
setAuthType
(String authType) void
setBodyContent
(byte[] data) void
setBodyContent
(String bodyContent) void
setCharacterEncoding
(String characterEncoding) void
setContentLength
(long contentLength) void
setContentType
(String contentType) void
setContextPath
(String contextPath) void
void
setLocalAddr
(String localAddr) void
setLocalName
(String localName) void
setLocalPort
(int localPort) void
void
setPathInfo
(String pathInfo) void
setPathTranslated
(String pathTranslated) void
setProtocol
(String protocol) void
setQueryString
(String queryString) void
setRemoteAddr
(String remoteAddr) void
setRemoteHost
(String remoteHost) void
setRemotePort
(int remotePort) void
setRemoteUser
(String remoteUser) void
setRequestDispatcher
(String path, jakarta.servlet.RequestDispatcher dispatcher) Sets aRequestDispatcher
that will be returned when callinggetRequestDispatcher(java.lang.String)
with the specified path.void
setRequestedSessionIdFromCookie
(boolean requestedSessionIdIsFromCookie) void
setRequestURI
(String requestUri) void
setRequestURL
(String requestUrl) void
void
setServerName
(String serverName) void
setServerPort
(int serverPort) void
setServletPath
(String servletPath) void
setSession
(jakarta.servlet.http.HttpSession session) Sets theHttpSession
.void
setupAddParameter
(String key, String value) Adds a request parameter.void
setupAddParameter
(String key, String[] values) Adds a request multivalue parameter.void
setUserInRole
(String role, boolean isInRole) void
setUserPrincipal
(Principal principal) jakarta.servlet.AsyncContext
jakarta.servlet.AsyncContext
startAsync
(jakarta.servlet.ServletRequest servletRequest, jakarta.servlet.ServletResponse servletResponse) <T extends jakarta.servlet.http.HttpUpgradeHandler>
TMethods 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
getHttpServletMapping, getTrailerFields, isTrailerFieldsReady, newPushBuilder
-
Constructor Details
-
MockHttpServletRequest
public MockHttpServletRequest(jakarta.servlet.ServletContext servletContext, jakarta.servlet.http.HttpSession httpSession)
-
-
Method Details
-
resetAll
public void resetAll()Resets the state of this object to the default values -
addAttributeListener
public void addAttributeListener(jakarta.servlet.ServletRequestAttributeListener listener) -
getParameter
- Specified by:
getParameter
in interfacejakarta.servlet.ServletRequest
-
clearParameters
public void clearParameters()Clears the parameters. -
getParameterValues
- Specified by:
getParameterValues
in interfacejakarta.servlet.ServletRequest
-
setupAddParameter
Adds a request multivalue parameter.- Parameters:
key
- the parameter keyvalues
- the parameters values
-
setupAddParameter
Adds a request parameter.- Parameters:
key
- the parameter keyvalue
- the parameters value
-
getParameterNames
- Specified by:
getParameterNames
in interfacejakarta.servlet.ServletRequest
-
getParameterMap
- Specified by:
getParameterMap
in interfacejakarta.servlet.ServletRequest
-
clearAttributes
public void clearAttributes() -
getAttribute
- Specified by:
getAttribute
in interfacejakarta.servlet.ServletRequest
-
getAttributeNames
- Specified by:
getAttributeNames
in interfacejakarta.servlet.ServletRequest
-
removeAttribute
- Specified by:
removeAttribute
in interfacejakarta.servlet.ServletRequest
-
setAttribute
- Specified by:
setAttribute
in interfacejakarta.servlet.ServletRequest
-
getSession
public jakarta.servlet.http.HttpSession getSession()- Specified by:
getSession
in interfacejakarta.servlet.http.HttpServletRequest
-
changeSessionId
- Specified by:
changeSessionId
in interfacejakarta.servlet.http.HttpServletRequest
-
getSession
public jakarta.servlet.http.HttpSession getSession(boolean create) - Specified by:
getSession
in interfacejakarta.servlet.http.HttpServletRequest
-
setSession
public void setSession(jakarta.servlet.http.HttpSession session) Sets theHttpSession
.- Specified by:
setSession
in interfaceHttpSessionAware
- Parameters:
session
- theHttpSession
-
getRequestDispatcher
- Specified by:
getRequestDispatcher
in interfacejakarta.servlet.ServletRequest
-
getRequestDispatcherMap
Returns the map ofRequestDispatcher
objects. The specified path maps to the correspondingRequestDispatcher
object.- Returns:
- the map of
RequestDispatcher
objects
-
clearRequestDispatcherMap
public void clearRequestDispatcherMap()Clears the map ofRequestDispatcher
objects. -
setRequestDispatcher
Sets aRequestDispatcher
that will be returned when callinggetRequestDispatcher(java.lang.String)
with the specified path. If noRequestDispatcher
is set for the specified path,getRequestDispatcher(java.lang.String)
automatically creates a new one.- Parameters:
path
- the path for theRequestDispatcher
dispatcher
- theRequestDispatcher
object
-
getLocale
- Specified by:
getLocale
in interfacejakarta.servlet.ServletRequest
-
getLocales
- Specified by:
getLocales
in interfacejakarta.servlet.ServletRequest
-
addLocale
-
addLocales
-
getMethod
- Specified by:
getMethod
in interfacejakarta.servlet.http.HttpServletRequest
-
setMethod
-
getAuthType
- Specified by:
getAuthType
in interfacejakarta.servlet.http.HttpServletRequest
-
setAuthType
-
getDateHeader
- Specified by:
getDateHeader
in interfacejakarta.servlet.http.HttpServletRequest
-
getHeader
- Specified by:
getHeader
in interfacejakarta.servlet.http.HttpServletRequest
-
getHeaderNames
- Specified by:
getHeaderNames
in interfacejakarta.servlet.http.HttpServletRequest
-
getHeaders
- Specified by:
getHeaders
in interfacejakarta.servlet.http.HttpServletRequest
-
getIntHeader
- Specified by:
getIntHeader
in interfacejakarta.servlet.http.HttpServletRequest
-
addHeader
-
setHeader
-
clearHeaders
public void clearHeaders() -
getContextPath
- Specified by:
getContextPath
in interfacejakarta.servlet.http.HttpServletRequest
-
setContextPath
-
getPathInfo
- Specified by:
getPathInfo
in interfacejakarta.servlet.http.HttpServletRequest
-
setPathInfo
-
getPathTranslated
- Specified by:
getPathTranslated
in interfacejakarta.servlet.http.HttpServletRequest
-
setPathTranslated
-
getQueryString
- Specified by:
getQueryString
in interfacejakarta.servlet.http.HttpServletRequest
-
setQueryString
-
getRequestURI
- Specified by:
getRequestURI
in interfacejakarta.servlet.http.HttpServletRequest
-
setRequestURI
-
getRequestURL
- Specified by:
getRequestURL
in interfacejakarta.servlet.http.HttpServletRequest
-
setRequestURL
-
getServletPath
- Specified by:
getServletPath
in interfacejakarta.servlet.http.HttpServletRequest
-
setServletPath
-
getUserPrincipal
- Specified by:
getUserPrincipal
in interfacejakarta.servlet.http.HttpServletRequest
-
setUserPrincipal
-
getRemoteUser
- Specified by:
getRemoteUser
in interfacejakarta.servlet.http.HttpServletRequest
-
setRemoteUser
-
getCookies
public jakarta.servlet.http.Cookie[] getCookies()- Specified by:
getCookies
in interfacejakarta.servlet.http.HttpServletRequest
-
addCookie
public void addCookie(jakarta.servlet.http.Cookie cookie) -
getRequestedSessionId
- Specified by:
getRequestedSessionId
in interfacejakarta.servlet.http.HttpServletRequest
-
isRequestedSessionIdFromCookie
public boolean isRequestedSessionIdFromCookie()- Specified by:
isRequestedSessionIdFromCookie
in interfacejakarta.servlet.http.HttpServletRequest
-
isRequestedSessionIdFromUrl
public boolean isRequestedSessionIdFromUrl() -
isRequestedSessionIdFromURL
public boolean isRequestedSessionIdFromURL()- Specified by:
isRequestedSessionIdFromURL
in interfacejakarta.servlet.http.HttpServletRequest
-
setRequestedSessionIdFromCookie
public void setRequestedSessionIdFromCookie(boolean requestedSessionIdIsFromCookie) -
isRequestedSessionIdValid
public boolean isRequestedSessionIdValid()- Specified by:
isRequestedSessionIdValid
in interfacejakarta.servlet.http.HttpServletRequest
-
isUserInRole
- Specified by:
isUserInRole
in interfacejakarta.servlet.http.HttpServletRequest
-
setUserInRole
-
getCharacterEncoding
- Specified by:
getCharacterEncoding
in interfacejakarta.servlet.ServletRequest
-
setCharacterEncoding
- Specified by:
setCharacterEncoding
in interfacejakarta.servlet.ServletRequest
- Throws:
UnsupportedEncodingException
-
getContentLength
public int getContentLength()- Specified by:
getContentLength
in interfacejakarta.servlet.ServletRequest
-
getContentLengthLong
public long getContentLengthLong()- Specified by:
getContentLengthLong
in interfacejakarta.servlet.ServletRequest
-
setContentLength
public void setContentLength(long contentLength) -
getContentType
- Specified by:
getContentType
in interfacejakarta.servlet.ServletRequest
-
setContentType
-
getProtocol
- Specified by:
getProtocol
in interfacejakarta.servlet.ServletRequest
-
setProtocol
-
getServerName
- Specified by:
getServerName
in interfacejakarta.servlet.ServletRequest
-
setServerName
-
getServerPort
public int getServerPort()- Specified by:
getServerPort
in interfacejakarta.servlet.ServletRequest
-
setServerPort
public void setServerPort(int serverPort) -
getScheme
- Specified by:
getScheme
in interfacejakarta.servlet.ServletRequest
-
setScheme
-
getRemoteAddr
- Specified by:
getRemoteAddr
in interfacejakarta.servlet.ServletRequest
-
setRemoteAddr
-
getRemoteHost
- Specified by:
getRemoteHost
in interfacejakarta.servlet.ServletRequest
-
setRemoteHost
-
getReader
- Specified by:
getReader
in interfacejakarta.servlet.ServletRequest
- Throws:
IOException
-
getInputStream
- Specified by:
getInputStream
in interfacejakarta.servlet.ServletRequest
- Throws:
IOException
-
setBodyContent
public void setBodyContent(byte[] data) -
setBodyContent
-
getRealPath
-
isSecure
public boolean isSecure()- Specified by:
isSecure
in interfacejakarta.servlet.ServletRequest
-
getLocalAddr
- Specified by:
getLocalAddr
in interfacejakarta.servlet.ServletRequest
-
setLocalAddr
-
getLocalName
- Specified by:
getLocalName
in interfacejakarta.servlet.ServletRequest
-
setLocalName
-
getLocalPort
public int getLocalPort()- Specified by:
getLocalPort
in interfacejakarta.servlet.ServletRequest
-
setLocalPort
public void setLocalPort(int localPort) -
getRemotePort
public int getRemotePort()- Specified by:
getRemotePort
in interfacejakarta.servlet.ServletRequest
-
setRemotePort
public void setRemotePort(int remotePort) -
isAsyncSupported
public boolean isAsyncSupported()- Specified by:
isAsyncSupported
in interfacejakarta.servlet.ServletRequest
-
setAsyncSupported
public void setAsyncSupported(boolean isAsyncSupported) -
getServletContext
public jakarta.servlet.ServletContext getServletContext()- Specified by:
getServletContext
in interfacejakarta.servlet.ServletRequest
-
startAsync
- Specified by:
startAsync
in interfacejakarta.servlet.ServletRequest
- Throws:
IllegalStateException
-
startAsync
public jakarta.servlet.AsyncContext startAsync(jakarta.servlet.ServletRequest servletRequest, jakarta.servlet.ServletResponse servletResponse) throws IllegalStateException - Specified by:
startAsync
in interfacejakarta.servlet.ServletRequest
- Throws:
IllegalStateException
-
isAsyncStarted
public boolean isAsyncStarted()- Specified by:
isAsyncStarted
in interfacejakarta.servlet.ServletRequest
-
getAsyncContext
public jakarta.servlet.AsyncContext getAsyncContext()- Specified by:
getAsyncContext
in interfacejakarta.servlet.ServletRequest
-
getDispatcherType
public jakarta.servlet.DispatcherType getDispatcherType()- Specified by:
getDispatcherType
in interfacejakarta.servlet.ServletRequest
-
getRequestId
- Specified by:
getRequestId
in interfacejakarta.servlet.ServletRequest
-
getProtocolRequestId
- Specified by:
getProtocolRequestId
in interfacejakarta.servlet.ServletRequest
-
getServletConnection
public jakarta.servlet.ServletConnection getServletConnection()- Specified by:
getServletConnection
in interfacejakarta.servlet.ServletRequest
-
authenticate
public boolean authenticate(jakarta.servlet.http.HttpServletResponse response) throws IOException, jakarta.servlet.ServletException - Specified by:
authenticate
in interfacejakarta.servlet.http.HttpServletRequest
- Throws:
IOException
jakarta.servlet.ServletException
-
login
- Specified by:
login
in interfacejakarta.servlet.http.HttpServletRequest
- Throws:
jakarta.servlet.ServletException
-
logout
public void logout() throws jakarta.servlet.ServletException- Specified by:
logout
in interfacejakarta.servlet.http.HttpServletRequest
- Throws:
jakarta.servlet.ServletException
-
getParts
public Collection<jakarta.servlet.http.Part> getParts() throws IOException, jakarta.servlet.ServletException- Specified by:
getParts
in interfacejakarta.servlet.http.HttpServletRequest
- Throws:
IOException
jakarta.servlet.ServletException
-
getPart
public jakarta.servlet.http.Part getPart(String name) throws IOException, jakarta.servlet.ServletException - Specified by:
getPart
in interfacejakarta.servlet.http.HttpServletRequest
- Throws:
IOException
jakarta.servlet.ServletException
-
upgrade
public <T extends jakarta.servlet.http.HttpUpgradeHandler> T upgrade(Class<T> handlerClass) throws IOException, jakarta.servlet.ServletException - Specified by:
upgrade
in interfacejakarta.servlet.http.HttpServletRequest
- Throws:
IOException
jakarta.servlet.ServletException
-