Package com.avoka.tm.test
Class MockRequest
- java.lang.Object
-
- com.avoka.tm.test.MockRequest
-
- All Implemented Interfaces:
javax.servlet.http.HttpServletRequest,javax.servlet.ServletRequest
public class MockRequest extends Object implements javax.servlet.http.HttpServletRequest
Mock implementation of HttpServletRequest.
Implements all of the methods from the standard HttpServletRequest class plus helper methods to aid setting up a request.
This class was adapted from Apache Click.
- Since:
- 5.0
- See Also:
HttpServletRequest
-
-
Field Summary
Fields Modifier and Type Field Description static StringREMOTE_USERThe REMOTE_USER header.
-
Constructor Summary
Constructors Constructor Description MockRequest()Create new MockRequest.MockRequest(Locale locale)Create new MockRequest for the specified local.MockRequest(Locale locale, String contextPath, String servletPath, javax.servlet.ServletContext servletContext, javax.servlet.http.HttpSession session)Create a new MockRequest for the specified arguments.MockRequest(Locale locale, javax.servlet.ServletContext servletContext)Create a new MockRequest for the specified locale and servletContext.MockRequest(Locale locale, javax.servlet.ServletContext servletContext, javax.servlet.http.HttpSession session)Create a new MockRequest for the specified arguments.MockRequest(javax.servlet.ServletContext servletContext)Create a new MockRequest for the specified context.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description MockRequestaddCookie(javax.servlet.http.Cookie cookie)Add a new cookie.MockRequestaddHeader(String name, String value)Add a header to the request.booleanauthenticate(javax.servlet.http.HttpServletResponse response)StringchangeSessionId()javax.servlet.AsyncContextgetAsyncContext()ObjectgetAttribute(String name)Get an attribute.Enumeration<String>getAttributeNames()Get the names of all of the values.StringgetAuthType()Get the auth type.StringgetCharacterEncoding()Get the current character encoding.intgetContentLength()Return the length of the content.longgetContentLengthLong()StringgetContentType()If useMultiPartContentType set as true return the correct content-type.StringgetContextPath()Returns the portion of the request URI that indicates the context of the request.javax.servlet.http.Cookie[]getCookies()Get all of the cookies for this request.longgetDateHeader(String name)Get the given header as a date.javax.servlet.DispatcherTypegetDispatcherType()StringgetForward()Returns the url that was forwarded to, otherwise return null.StringgetHeader(String name)Get the given header value.Enumeration<String>getHeaderNames()Get the names of all of the headers.Map<String,List<String>>getHeaders()Return the map of headers for this request.Enumeration<String>getHeaders(String name)Get enumeration of all header values with the given name.List<String>getIncludes()Returns the list of server side included url's.javax.servlet.ServletInputStreamgetInputStream()Returns an input stream if there has been added some uploaded files.intgetIntHeader(String name)Get the given header as an int.StringgetLocalAddr()Return the local address, "127.0.0.1".LocalegetLocale()Get the locale of the request.Enumeration<Locale>getLocales()Return all the accepted locales.StringgetLocalName()Return the local name, "127.0.0.1".intgetLocalPort()Return the local port, 80.StringgetMethod()Get the method.StringgetParameter(String name)Get the request parameter with the given name.Map<String,String[]>getParameterMap()Get the map of all of the parameters.Enumeration<String>getParameterNames()Get the names of all of the parameters.String[]getParameterValues(String name)Get the values for the given parameter.javax.servlet.http.PartgetPart(String name)Collection<javax.servlet.http.Part>getParts()StringgetPathInfo()Get the path info.StringgetPathTranslated()Always returns null.StringgetProtocol()Get the protocol.StringgetQueryString()Get the query string part of the request.BufferedReadergetReader()This feature is not implemented at this time as we are not supporting binary servlet input.StringgetRealPath(String name)Deprecated.Use ServletContext.getRealPath(String) instead.StringgetRemoteAddr()Get the remote address of the client.StringgetRemoteHost()Get the remote host.intgetRemotePort()Return the remote port, 80.StringgetRemoteUser()Return the name of theuserPrincipalif set, otherwise the value of the "REMOTE_USER" header.javax.servlet.RequestDispatchergetRequestDispatcher(String path)Returns a RequestDispatcher for the specified path.StringgetRequestedSessionId()Get the requested session id.StringgetRequestURI()Returns context path and servlet path concatenated, typically /applicationClassName/applicationClassName.StringBuffergetRequestURL()Returns (an attempt at) a reconstructed URL based on it's constituent parts.StringgetScheme()Get the scheme http, https, or ftp.StringgetServerName()Get the host server name to which the request was sent.intgetServerPort()Returns the port number to which the request was sent.javax.servlet.ServletContextgetServletContext()Return the servlet context.StringgetServletPath()Return a String containing the name or path of the servlet being called.javax.servlet.http.HttpSessiongetSession()Returns the current HttpSession associated with this request.javax.servlet.http.HttpSessiongetSession(boolean create)Returns the current HttpSession associated with this request.PrincipalgetUserPrincipal()Get the user principal.voidinitialize()Reset the request back to a default state.booleanisAsyncStarted()booleanisAsyncSupported()booleanisPost()Return whether the request is a post or not.booleanisRequestedSessionIdFromCookie()Check whether session id is from a cookie.booleanisRequestedSessionIdFromUrl()Check whether session id is from a url rewrite.booleanisRequestedSessionIdFromURL()Check whether session id is from a url rewrite.booleanisRequestedSessionIdValid()Check whether the session id is valid.booleanisSecure()Always returns false.booleanisUserInRole(String role)Returns true if theauthenticated useris included in the given role, false otherwise.voidlogin(String username, String password)voidlogout()voidremoveAttribute(String name)Remove the given attribute.MockRequestremoveParameter(String name)Remove the specified parameter.voidreset()Delegate to initialize method.voidsetAttribute(String name, Object o)Set the given attribute.voidsetAuthType(String authType)Set the auth type.voidsetCharacterEncoding(String encoding)Set the character encoding.MockRequestsetContentType(String contentType)Set the request content type.MockRequestsetContextPath(String contextPath)Set the portion of the request URI that indicates the context of the request.voidsetCookies(javax.servlet.http.Cookie[] theCookies)Set the cookies.MockRequestsetHeader(String name, String value)Set request header value.MockRequestsetHeader(String name, String... values)Set request header values.MockRequestsetHttpSession(javax.servlet.http.HttpSession session)Set the request's session instance.MockRequestsetMethod(String method)Set the method.MockRequestsetParameter(String name, String value)Set a parameter.MockRequestsetParameter(String name, String[] values)Set the specified parameter name to the array of strings.MockRequestsetParameters(Map<String,Object> parameters)Sets a map of parameters.MockRequestsetPathInfo(String path)Set the path that this request is supposed to be serving.voidsetRequestURL(String requestURL)Provide a convenience method for setting the request URL.MockRequestsetScheme(String scheme)Set the request's scheme, for example http, https, or ftp.MockRequestsetServerName(String serverName)Sets the host server name to which the request was sent.MockRequestsetServerPort(int serverPort)Set the port number to which the request was sent.MockRequestsetServletContext(javax.servlet.ServletContext servletContext)Set the request's servletContext instance.MockRequestsetServletPath(String servletPath)Set the string containing the name or path of the servlet being called.MockRequestsetSession(javax.servlet.http.HttpSession session)Set the current HttpSession associated with this request.MockRequestsetUseMultiPartContentType(boolean useMultiPartContentType)True will force Request to generate multiPart ContentType and ContentLength.MockRequestsetUserPrincipal(Principal userPrincipal)Set the user principal.javax.servlet.AsyncContextstartAsync()javax.servlet.AsyncContextstartAsync(javax.servlet.ServletRequest servletRequest, javax.servlet.ServletResponse servletResponse)StringtoString()Returns the String representation of the mock request.javax.servlet.http.HttpUpgradeHandlerupgrade(Class handlerClass)
-
-
-
Field Detail
-
REMOTE_USER
public static final String REMOTE_USER
The REMOTE_USER header.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
MockRequest
public MockRequest()
Create new MockRequest.
-
MockRequest
public MockRequest(Locale locale)
Create new MockRequest for the specified local.- Parameters:
locale- locale for this request
-
MockRequest
public MockRequest(javax.servlet.ServletContext servletContext)
Create a new MockRequest for the specified context.- Parameters:
servletContext- the servletContext for this request
-
MockRequest
public MockRequest(Locale locale, javax.servlet.ServletContext servletContext)
Create a new MockRequest for the specified locale and servletContext.- Parameters:
locale- locale for this requestservletContext- the servletContext for this request
-
MockRequest
public MockRequest(Locale locale, javax.servlet.ServletContext servletContext, javax.servlet.http.HttpSession session)
Create a new MockRequest for the specified arguments.- Parameters:
locale- The request locale, or null to use the default localesession- The session objectservletContext- The current servlet context
-
MockRequest
public MockRequest(Locale locale, String contextPath, String servletPath, javax.servlet.ServletContext servletContext, javax.servlet.http.HttpSession session)
Create a new MockRequest for the specified arguments.- Parameters:
locale- The request locale, or null to use the default localecontextPath- the request context pathservletPath- the request servlet pathservletContext- The current servlet contextsession- the request session
-
-
Method Detail
-
setServletContext
public MockRequest setServletContext(javax.servlet.ServletContext servletContext)
Set the request's servletContext instance.- Parameters:
servletContext- the new ServletContext instance- Returns:
- the MockRequest object
-
setHttpSession
public MockRequest setHttpSession(javax.servlet.http.HttpSession session)
Set the request's session instance.- Parameters:
session- the new HttpSession instance- Returns:
- the MockRequest object
-
addCookie
public MockRequest addCookie(javax.servlet.http.Cookie cookie)
Add a new cookie.- Parameters:
cookie- The cookie- Returns:
- the MockRequest object
-
addHeader
public MockRequest addHeader(String name, String value)
Add a header to the request.- Parameters:
name- the name of the header to addvalue- the value- Returns:
- the MockRequest object
-
setHeader
public MockRequest setHeader(String name, String value)
Set request header value. The existing header value will be replaced.- Parameters:
name- the name of the header to setvalue- the header value- Returns:
- the MockRequest object
-
setHeader
public MockRequest setHeader(String name, String... values)
Set request header values. The existing header values will be replaced.- Parameters:
name- the name of the header to setvalues- the header values- Returns:
- the MockRequest object
-
getAttribute
public Object getAttribute(String name)
Get an attribute.- Specified by:
getAttributein interfacejavax.servlet.ServletRequest- Parameters:
name- The attribute name- Returns:
- The value, or null
-
getAttributeNames
public Enumeration<String> getAttributeNames()
Get the names of all of the values.- Specified by:
getAttributeNamesin interfacejavax.servlet.ServletRequest- Returns:
- The names
-
getAuthType
public String getAuthType()
Get the auth type.- Specified by:
getAuthTypein interfacejavax.servlet.http.HttpServletRequest- Returns:
- The auth type
-
getCharacterEncoding
public String getCharacterEncoding()
Get the current character encoding.- Specified by:
getCharacterEncodingin interfacejavax.servlet.ServletRequest- Returns:
- The character encoding
-
setUseMultiPartContentType
public MockRequest setUseMultiPartContentType(boolean useMultiPartContentType)
True will force Request to generate multiPart ContentType and ContentLength.- Parameters:
useMultiPartContentType- true if the request is multi-part, false otherwise- Returns:
- the MockRequest object
-
getContentLength
public int getContentLength()
Return the length of the content. This is always -1 except if useMultiPartContentType set as true. Then the length will be the length of the generated request.- Specified by:
getContentLengthin interfacejavax.servlet.ServletRequest- Returns:
- -1 if useMultiPartContentType is false. Else the length of the generated request.
-
setContentType
public MockRequest setContentType(String contentType)
Set the request content type.- Parameters:
contentType- the request content type.- Returns:
- the MockRequest object
-
getContentType
public String getContentType()
If useMultiPartContentType set as true return the correct content-type. If the contentType property is defined then this value will be returned.- Specified by:
getContentTypein interfacejavax.servlet.ServletRequest- Returns:
- The correct multipart content-type if useMultiPartContentType is true. Else null.
-
getCookies
public javax.servlet.http.Cookie[] getCookies()
Get all of the cookies for this request.- Specified by:
getCookiesin interfacejavax.servlet.http.HttpServletRequest- Returns:
- The cookies
-
getDateHeader
public long getDateHeader(String name)
Get the given header as a date.- Specified by:
getDateHeaderin interfacejavax.servlet.http.HttpServletRequest- Parameters:
name- The header name- Returns:
- The date, or -1 if header not found
-
getHeader
public String getHeader(String name)
Get the given header value.- Specified by:
getHeaderin interfacejavax.servlet.http.HttpServletRequest- Parameters:
name- The header name- Returns:
- The header value or null
-
getHeaderNames
public Enumeration<String> getHeaderNames()
Get the names of all of the headers.- Specified by:
getHeaderNamesin interfacejavax.servlet.http.HttpServletRequest- Returns:
- The header names
-
getHeaders
public Enumeration<String> getHeaders(String name)
Get enumeration of all header values with the given name.- Specified by:
getHeadersin interfacejavax.servlet.http.HttpServletRequest- Parameters:
name- The name- Returns:
- The header values
-
getHeaders
public Map<String,List<String>> getHeaders()
Return the map of headers for this request.- Returns:
- the map of headers for this request
-
getInputStream
public javax.servlet.ServletInputStream getInputStream() throws IOExceptionReturns an input stream if there has been added some uploaded files.- Specified by:
getInputStreamin interfacejavax.servlet.ServletRequest- Returns:
- The input stream
- Throws:
IOException- If an I/O related problem occurs
-
getIntHeader
public int getIntHeader(String name)
Get the given header as an int.- Specified by:
getIntHeaderin interfacejavax.servlet.http.HttpServletRequest- Parameters:
name- The header name- Returns:
- The header value or -1 if header not found
-
getLocale
public Locale getLocale()
Get the locale of the request. Attempts to decode the Accept-Language header and if not found returns the default locale of the JVM.- Specified by:
getLocalein interfacejavax.servlet.ServletRequest- Returns:
- The locale
-
getLocales
public Enumeration<Locale> getLocales()
Return all the accepted locales. This implementation always returns just one.- Specified by:
getLocalesin interfacejavax.servlet.ServletRequest- Returns:
- The locales
-
getMethod
public String getMethod()
Get the method. The returned string will be in upper case eg. POST.- Specified by:
getMethodin interfacejavax.servlet.http.HttpServletRequest- Returns:
- The method
-
getParameter
public String getParameter(String name)
Get the request parameter with the given name.- Specified by:
getParameterin interfacejavax.servlet.ServletRequest- Parameters:
name- The parameter name- Returns:
- The parameter value, or null
-
getParameterMap
public Map<String,String[]> getParameterMap()
Get the map of all of the parameters.- Specified by:
getParameterMapin interfacejavax.servlet.ServletRequest- Returns:
- The parameters
-
getParameterNames
public Enumeration<String> getParameterNames()
Get the names of all of the parameters.- Specified by:
getParameterNamesin interfacejavax.servlet.ServletRequest- Returns:
- The parameter names
-
getParameterValues
public String[] getParameterValues(String name)
Get the values for the given parameter.- Specified by:
getParameterValuesin interfacejavax.servlet.ServletRequest- Parameters:
name- The name of the parameter- Returns:
- The return values
-
getPathInfo
public String getPathInfo()
Get the path info.- Specified by:
getPathInfoin interfacejavax.servlet.http.HttpServletRequest- Returns:
- The path info
-
getPathTranslated
public String getPathTranslated()
Always returns null.- Specified by:
getPathTranslatedin interfacejavax.servlet.http.HttpServletRequest- Returns:
- null
-
getProtocol
public String getProtocol()
Get the protocol.- Specified by:
getProtocolin interfacejavax.servlet.ServletRequest- Returns:
- Always HTTP/1.1
-
getQueryString
public String getQueryString()
Get the query string part of the request.- Specified by:
getQueryStringin interfacejavax.servlet.http.HttpServletRequest- Returns:
- The query string
-
getReader
public BufferedReader getReader() throws IOException
This feature is not implemented at this time as we are not supporting binary servlet input. This functionality may be added in the future.- Specified by:
getReaderin interfacejavax.servlet.ServletRequest- Returns:
- The reader
- Throws:
IOException- If an I/O related problem occurs
-
getRealPath
public String getRealPath(String name)
Deprecated.Use ServletContext.getRealPath(String) instead.Deprecated method - should not be used.- Specified by:
getRealPathin interfacejavax.servlet.ServletRequest- Parameters:
name- The name- Returns:
- The path
-
getRemoteAddr
public String getRemoteAddr()
Get the remote address of the client.- Specified by:
getRemoteAddrin interfacejavax.servlet.ServletRequest- Returns:
- Always 127.0.0.1
-
getRemoteHost
public String getRemoteHost()
Get the remote host.- Specified by:
getRemoteHostin interfacejavax.servlet.ServletRequest- Returns:
- Always localhost
-
getRemoteUser
public String getRemoteUser()
Return the name of the
userPrincipalif set, otherwise the value of the "REMOTE_USER" header.To set the remote user, create an instance of a
MockPrincipaland set it on the request through the methodsetUserPrincipal(java.security.Principal).- Specified by:
getRemoteUserin interfacejavax.servlet.http.HttpServletRequest- Returns:
- the name of the remote user
-
getLocalAddr
public String getLocalAddr()
Return the local address, "127.0.0.1".- Specified by:
getLocalAddrin interfacejavax.servlet.ServletRequest- Returns:
- "127.0.0.1" as the local address
-
getLocalName
public String getLocalName()
Return the local name, "127.0.0.1".- Specified by:
getLocalNamein interfacejavax.servlet.ServletRequest- Returns:
- "127.0.0.1" as the local name
-
getLocalPort
public int getLocalPort()
Return the local port, 80.- Specified by:
getLocalPortin interfacejavax.servlet.ServletRequest- Returns:
- 80 as the local port
-
getRemotePort
public int getRemotePort()
Return the remote port, 80.- Specified by:
getRemotePortin interfacejavax.servlet.ServletRequest- Returns:
- 80 as the remote port
-
getRequestDispatcher
public javax.servlet.RequestDispatcher getRequestDispatcher(String path)
Returns a RequestDispatcher for the specified path. The dispatcher will not dispatch to the resource. It only records the specified path so that one can test if the correct path was dispatched to.- Specified by:
getRequestDispatcherin interfacejavax.servlet.ServletRequest- Parameters:
path- a String specifying the pathname to the resource- Returns:
- a dispatcher for the specified path
-
getRequestedSessionId
public String getRequestedSessionId()
Get the requested session id. Always returns the id of the current session.- Specified by:
getRequestedSessionIdin interfacejavax.servlet.http.HttpServletRequest- Returns:
- The session id
-
getRequestURI
public String getRequestURI()
Returns context path and servlet path concatenated, typically /applicationClassName/applicationClassName.- Specified by:
getRequestURIin interfacejavax.servlet.http.HttpServletRequest- Returns:
- The path value
- See Also:
HttpServletRequest.getRequestURI()
-
setRequestURL
public void setRequestURL(String requestURL)
Provide a convenience method for setting the request URL.- Parameters:
requestURL- the request URL to set
-
getRequestURL
public StringBuffer getRequestURL()
Returns (an attempt at) a reconstructed URL based on it's constituent parts. If the requestURL property is set this value will be returned instead.- Specified by:
getRequestURLin interfacejavax.servlet.http.HttpServletRequest- Returns:
- a StringBuffer object containing the reconstructed URL
- See Also:
HttpServletRequest.getRequestURL()
-
isPost
public boolean isPost()
Return whether the request is a post or not.- Returns:
- true if the request is a post, false otherwise
-
getScheme
public String getScheme()
Get the scheme http, https, or ftp.- Specified by:
getSchemein interfacejavax.servlet.ServletRequest- Returns:
- the scheme used by this request
-
setScheme
public MockRequest setScheme(String scheme)
Set the request's scheme, for example http, https, or ftp.- Parameters:
scheme- the request's scheme- Returns:
- the MockRequest object
-
getServerName
public String getServerName()
Get the host server name to which the request was sent.- Specified by:
getServerNamein interfacejavax.servlet.ServletRequest- Returns:
- always the host server name
-
setServerName
public MockRequest setServerName(String serverName)
Sets the host server name to which the request was sent.- Parameters:
serverName- the server name the request was sent to- Returns:
- the MockRequest object
-
getServerPort
public int getServerPort()
Returns the port number to which the request was sent.- Specified by:
getServerPortin interfacejavax.servlet.ServletRequest- Returns:
- the server port to which the request was sent
-
setServerPort
public MockRequest setServerPort(int serverPort)
Set the port number to which the request was sent.- Parameters:
serverPort- the port number to which the request was sent- Returns:
- the MockRequest object
-
getContextPath
public String getContextPath()
Returns the portion of the request URI that indicates the context of the request.- Specified by:
getContextPathin interfacejavax.servlet.http.HttpServletRequest- Returns:
- the portion of the request URI that indicates the context of the request.
-
setContextPath
public MockRequest setContextPath(String contextPath)
Set the portion of the request URI that indicates the context of the request.- Parameters:
contextPath- the portion of the request URI that indicates the context of the request.- Returns:
- the MockRequest object
-
getServletContext
public javax.servlet.ServletContext getServletContext()
Return the servlet context.- Specified by:
getServletContextin interfacejavax.servlet.ServletRequest- Returns:
- the servlet context.
- Since:
- Servlet 3.0
-
getServletPath
public String getServletPath()
Return a String containing the name or path of the servlet being called.- Specified by:
getServletPathin interfacejavax.servlet.http.HttpServletRequest- Returns:
- The servlet path
-
setServletPath
public MockRequest setServletPath(String servletPath)
Set the string containing the name or path of the servlet being called.- Parameters:
servletPath- a String containing the name or path of the servlet being called- Returns:
- the MockRequest object
-
getSession
public javax.servlet.http.HttpSession getSession()
Returns the current HttpSession associated with this request.- Specified by:
getSessionin interfacejavax.servlet.http.HttpServletRequest- Returns:
- the session associated with this request
-
setSession
public MockRequest setSession(javax.servlet.http.HttpSession session)
Set the current HttpSession associated with this request.- Parameters:
session- the HttpSession to associate with this request- Returns:
- the MockRequest object
-
getSession
public javax.servlet.http.HttpSession getSession(boolean create)
Returns the current HttpSession associated with this request.- Specified by:
getSessionin interfacejavax.servlet.http.HttpServletRequest- Parameters:
create- if true creates a new session if one does not exist- Returns:
- the current HttpSession associated with this request.
-
getUserPrincipal
public Principal getUserPrincipal()
Get the user principal. If no user principal was set this method will create a user principal for thegetRemoteUser().- Specified by:
getUserPrincipalin interfacejavax.servlet.http.HttpServletRequest- Returns:
- the user principal
-
setUserPrincipal
public MockRequest setUserPrincipal(Principal userPrincipal)
Set the user principal.- Parameters:
userPrincipal- the user principal- Returns:
- the MockRequest object
-
initialize
public final void initialize()
Reset the request back to a default state.
-
reset
public void reset()
Delegate to initialize method.
-
isRequestedSessionIdFromCookie
public boolean isRequestedSessionIdFromCookie()
Check whether session id is from a cookie. Always returns true.- Specified by:
isRequestedSessionIdFromCookiein interfacejavax.servlet.http.HttpServletRequest- Returns:
- Always true
-
isRequestedSessionIdFromUrl
public boolean isRequestedSessionIdFromUrl()
Check whether session id is from a url rewrite. Always returns false.- Specified by:
isRequestedSessionIdFromUrlin interfacejavax.servlet.http.HttpServletRequest- Returns:
- Always false
-
isRequestedSessionIdFromURL
public boolean isRequestedSessionIdFromURL()
Check whether session id is from a url rewrite. Always returns false.- Specified by:
isRequestedSessionIdFromURLin interfacejavax.servlet.http.HttpServletRequest- Returns:
- Always false
-
isRequestedSessionIdValid
public boolean isRequestedSessionIdValid()
Check whether the session id is valid.- Specified by:
isRequestedSessionIdValidin interfacejavax.servlet.http.HttpServletRequest- Returns:
- Always true
-
isSecure
public boolean isSecure()
Always returns false.- Specified by:
isSecurein interfacejavax.servlet.ServletRequest- Returns:
- Always false
-
isUserInRole
public boolean isUserInRole(String role)
Returns true if the
authenticated useris included in the given role, false otherwise.To mock up roles for a user, create a
user principaland set the necessary roles. SeeMockPrincipalfor an example.- Specified by:
isUserInRolein interfacejavax.servlet.http.HttpServletRequest- Parameters:
role- the role name- Returns:
- true if the user is included in the specified role, false otherwise
-
removeAttribute
public void removeAttribute(String name)
Remove the given attribute.- Specified by:
removeAttributein interfacejavax.servlet.ServletRequest- Parameters:
name- The name of the attribute
-
setAttribute
public void setAttribute(String name, Object o)
Set the given attribute.- Specified by:
setAttributein interfacejavax.servlet.ServletRequest- Parameters:
name- The attribute nameo- The value to set
-
setAuthType
public void setAuthType(String authType)
Set the auth type.- Parameters:
authType- The auth type
-
setCharacterEncoding
public void setCharacterEncoding(String encoding) throws UnsupportedEncodingException
Set the character encoding.- Specified by:
setCharacterEncodingin interfacejavax.servlet.ServletRequest- Parameters:
encoding- The character encoding- Throws:
UnsupportedEncodingException- If encoding not supported
-
setCookies
public void setCookies(javax.servlet.http.Cookie[] theCookies)
Set the cookies.- Parameters:
theCookies- The cookies
-
setMethod
public MockRequest setMethod(String method)
Set the method.- Parameters:
method- The method- Returns:
- the MockRequest object
-
setParameter
public MockRequest setParameter(String name, String value)
Set a parameter.- Parameters:
name- The namevalue- The value- Returns:
- the MockRequest object
-
setParameter
public MockRequest setParameter(String name, String[] values)
Set the specified parameter name to the array of strings.- Parameters:
name- name of the parametervalues- the parameter values- Returns:
- the MockRequest object
-
removeParameter
public MockRequest removeParameter(String name)
Remove the specified parameter.- Parameters:
name- the parameter name to remove- Returns:
- the MockRequest object
-
setParameters
public MockRequest setParameters(Map<String,Object> parameters)
Sets a map of parameters.- Parameters:
parameters- the parameters to set- Returns:
- the MockRequest object
-
setPathInfo
public MockRequest setPathInfo(String path)
Set the path that this request is supposed to be serving. The path is relative to the web application root and should start with a / character- Parameters:
path- specifies the request path to serve- Returns:
- the MockRequest object
-
getForward
public String getForward()
Returns the url that was forwarded to, otherwise return null. javax.servlet.ServletResponse)- Returns:
- url that was forwarded to
-
getIncludes
public List<String> getIncludes()
Returns the list of server side included url's. javax.servlet.ServletResponse)- Returns:
- list of urls that were included
-
toString
public String toString()
Returns the String representation of the mock request.
-
getAsyncContext
public javax.servlet.AsyncContext getAsyncContext()
- Specified by:
getAsyncContextin interfacejavax.servlet.ServletRequest- Returns:
- null
- See Also:
ServletRequest.getAsyncContext()
-
getContentLengthLong
public long getContentLengthLong()
- Specified by:
getContentLengthLongin interfacejavax.servlet.ServletRequest- Returns:
- 0
- See Also:
ServletRequest.getContentLengthLong()
-
getDispatcherType
public javax.servlet.DispatcherType getDispatcherType()
- Specified by:
getDispatcherTypein interfacejavax.servlet.ServletRequest- Returns:
- null
- See Also:
ServletRequest.getDispatcherType()
-
isAsyncStarted
public boolean isAsyncStarted()
- Specified by:
isAsyncStartedin interfacejavax.servlet.ServletRequest- Returns:
- false
- See Also:
ServletRequest.isAsyncStarted()
-
isAsyncSupported
public boolean isAsyncSupported()
- Specified by:
isAsyncSupportedin interfacejavax.servlet.ServletRequest- Returns:
- false
- See Also:
ServletRequest.isAsyncSupported()
-
startAsync
public javax.servlet.AsyncContext startAsync()
- Specified by:
startAsyncin interfacejavax.servlet.ServletRequest- Returns:
- the (re)initialized AsyncContext
- See Also:
ServletRequest.startAsync()
-
startAsync
public javax.servlet.AsyncContext startAsync(javax.servlet.ServletRequest servletRequest, javax.servlet.ServletResponse servletResponse)- Specified by:
startAsyncin interfacejavax.servlet.ServletRequest- Parameters:
servletRequest- the ServletRequest used to initialize the AsyncContextservletResponse- the ServletResponse used to initialize the AsyncContext- Returns:
- null
- See Also:
ServletRequest.startAsync(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
-
authenticate
public boolean authenticate(javax.servlet.http.HttpServletResponse response) throws IOException- Specified by:
authenticatein interfacejavax.servlet.http.HttpServletRequest- Parameters:
response- TheHttpServletResponseassociated with thisHttpServletRequest- Returns:
- false
- Throws:
IOException- never thrown
-
changeSessionId
public String changeSessionId()
- Specified by:
changeSessionIdin interfacejavax.servlet.http.HttpServletRequest- Returns:
- null
-
getPart
public javax.servlet.http.Part getPart(String name) throws IOException
- Specified by:
getPartin interfacejavax.servlet.http.HttpServletRequest- Parameters:
name- the part name- Returns:
- null
- Throws:
IOException- never thrown
-
getParts
public Collection<javax.servlet.http.Part> getParts() throws IOException
- Specified by:
getPartsin interfacejavax.servlet.http.HttpServletRequest- Returns:
- null
- Throws:
IOException- never thrown- See Also:
HttpServletRequest.getParts()
-
login
public void login(String username, String password)
- Specified by:
loginin interfacejavax.servlet.http.HttpServletRequest- Parameters:
username- TheStringvalue corresponding to the login identifier of the user.password- The passwordStringcorresponding to the identified user.- See Also:
HttpServletRequest.login(java.lang.String, java.lang.String)
-
logout
public void logout()
- Specified by:
logoutin interfacejavax.servlet.http.HttpServletRequest- See Also:
HttpServletRequest.logout()
-
upgrade
public javax.servlet.http.HttpUpgradeHandler upgrade(Class handlerClass) throws IOException
- Specified by:
upgradein interfacejavax.servlet.http.HttpServletRequest- Parameters:
handlerClass- TheHttpUpgradeHandlerclass used for the upgrade.- Returns:
- null
- Throws:
IOException- never thrown- See Also:
HttpServletRequest.upgrade(java.lang.Class)
-
-