public class MockHttpServletRequest extends Object implements javax.servlet.http.HttpServletRequest
Mock HttpServletRequest object for low-level unit tests of Struts controller components. Coarser grained tests should be implemented in terms of the Cactus framework, instead of the mock object classes.
WARNING - Only the minimal set of methods needed to
create unit tests is provided, plus additional methods to configure this
object as necessary. Methods for unsupported operations will throw
UnsupportedOperationException.
WARNING - Because unit tests operate in a single threaded environment, no synchronization is performed.
| Modifier and Type | Field and Description |
|---|---|
protected HashMap |
attributes
The set of request attributes.
|
protected String |
contentType
The Content Type for this request.
|
protected String |
contextPath
The context path for this request.
|
protected Locale |
locale
The preferred locale for this request.
|
protected String |
method
The HTTP request method.
|
protected HashMap |
parameters
The set of arrays of parameter values, keyed by parameter name.
|
protected String |
pathInfo
The extra path information for this request.
|
protected Principal |
principal
The authenticated user for this request.
|
protected String |
queryString
The query string for this request.
|
protected String |
servletPath
The servlet path for this request.
|
protected javax.servlet.http.HttpSession |
session
The HttpSession with which we are associated.
|
| Constructor and Description |
|---|
MockHttpServletRequest() |
MockHttpServletRequest(javax.servlet.http.HttpSession session) |
MockHttpServletRequest(String contextPath,
String servletPath,
String pathInfo,
String queryString) |
MockHttpServletRequest(String contextPath,
String servletPath,
String pathInfo,
String queryString,
javax.servlet.http.HttpSession session) |
protected HashMap attributes
The set of request attributes.
protected String contextPath
The context path for this request.
protected Locale locale
The preferred locale for this request.
protected HashMap parameters
The set of arrays of parameter values, keyed by parameter name.
protected String pathInfo
The extra path information for this request. v *
protected Principal principal
The authenticated user for this request.
protected String queryString
The query string for this request.
protected String servletPath
The servlet path for this request.
protected javax.servlet.http.HttpSession session
The HttpSession with which we are associated.
protected String method
The HTTP request method.
protected String contentType
The Content Type for this request.
public MockHttpServletRequest()
public MockHttpServletRequest(javax.servlet.http.HttpSession session)
public MockHttpServletRequest(String contextPath, String servletPath, String pathInfo, String queryString)
public void setHttpSession(javax.servlet.http.HttpSession session)
public void setLocale(Locale locale)
public void setMethod(String method)
public void setContentType(String contentType)
public void setPathElements(String contextPath, String servletPath, String pathInfo, String queryString)
public void setUserPrincipal(Principal principal)
public String getAuthType()
getAuthType in interface javax.servlet.http.HttpServletRequestpublic String getContextPath()
getContextPath in interface javax.servlet.http.HttpServletRequestpublic javax.servlet.http.Cookie[] getCookies()
getCookies in interface javax.servlet.http.HttpServletRequestpublic long getDateHeader(String name)
getDateHeader in interface javax.servlet.http.HttpServletRequestpublic String getHeader(String name)
getHeader in interface javax.servlet.http.HttpServletRequestpublic Enumeration getHeaderNames()
getHeaderNames in interface javax.servlet.http.HttpServletRequestpublic Enumeration getHeaders(String name)
getHeaders in interface javax.servlet.http.HttpServletRequestpublic int getIntHeader(String name)
getIntHeader in interface javax.servlet.http.HttpServletRequestpublic String getMethod()
getMethod in interface javax.servlet.http.HttpServletRequestpublic String getPathInfo()
getPathInfo in interface javax.servlet.http.HttpServletRequestpublic String getPathTranslated()
getPathTranslated in interface javax.servlet.http.HttpServletRequestpublic String getQueryString()
getQueryString in interface javax.servlet.http.HttpServletRequestpublic String getRemoteUser()
getRemoteUser in interface javax.servlet.http.HttpServletRequestpublic String getRequestedSessionId()
getRequestedSessionId in interface javax.servlet.http.HttpServletRequestpublic String getRequestURI()
getRequestURI in interface javax.servlet.http.HttpServletRequestpublic StringBuffer getRequestURL()
getRequestURL in interface javax.servlet.http.HttpServletRequestpublic String getServletPath()
getServletPath in interface javax.servlet.http.HttpServletRequestpublic javax.servlet.http.HttpSession getSession()
getSession in interface javax.servlet.http.HttpServletRequestpublic javax.servlet.http.HttpSession getSession(boolean create)
getSession in interface javax.servlet.http.HttpServletRequestpublic Principal getUserPrincipal()
getUserPrincipal in interface javax.servlet.http.HttpServletRequestpublic boolean isRequestedSessionIdFromCookie()
isRequestedSessionIdFromCookie in interface javax.servlet.http.HttpServletRequestpublic boolean isRequestedSessionIdFromUrl()
isRequestedSessionIdFromUrl in interface javax.servlet.http.HttpServletRequestpublic boolean isRequestedSessionIdFromURL()
isRequestedSessionIdFromURL in interface javax.servlet.http.HttpServletRequestpublic boolean isRequestedSessionIdValid()
isRequestedSessionIdValid in interface javax.servlet.http.HttpServletRequestpublic boolean isUserInRole(String role)
isUserInRole in interface javax.servlet.http.HttpServletRequestpublic Object getAttribute(String name)
getAttribute in interface javax.servlet.ServletRequestpublic Enumeration getAttributeNames()
getAttributeNames in interface javax.servlet.ServletRequestpublic String getCharacterEncoding()
getCharacterEncoding in interface javax.servlet.ServletRequestpublic int getContentLength()
getContentLength in interface javax.servlet.ServletRequestpublic String getContentType()
getContentType in interface javax.servlet.ServletRequestpublic javax.servlet.ServletInputStream getInputStream()
getInputStream in interface javax.servlet.ServletRequestpublic Locale getLocale()
getLocale in interface javax.servlet.ServletRequestpublic Enumeration getLocales()
getLocales in interface javax.servlet.ServletRequestpublic String getParameter(String name)
getParameter in interface javax.servlet.ServletRequestpublic Map getParameterMap()
getParameterMap in interface javax.servlet.ServletRequestpublic Enumeration getParameterNames()
getParameterNames in interface javax.servlet.ServletRequestpublic String[] getParameterValues(String name)
getParameterValues in interface javax.servlet.ServletRequestpublic String getProtocol()
getProtocol in interface javax.servlet.ServletRequestpublic BufferedReader getReader()
getReader in interface javax.servlet.ServletRequestpublic String getRealPath(String path)
getRealPath in interface javax.servlet.ServletRequestpublic String getRemoteAddr()
getRemoteAddr in interface javax.servlet.ServletRequestpublic String getRemoteHost()
getRemoteHost in interface javax.servlet.ServletRequestpublic javax.servlet.RequestDispatcher getRequestDispatcher(String path)
getRequestDispatcher in interface javax.servlet.ServletRequestpublic String getScheme()
getScheme in interface javax.servlet.ServletRequestpublic String getServerName()
getServerName in interface javax.servlet.ServletRequestpublic int getServerPort()
getServerPort in interface javax.servlet.ServletRequestpublic boolean isSecure()
isSecure in interface javax.servlet.ServletRequestpublic void removeAttribute(String name)
removeAttribute in interface javax.servlet.ServletRequestpublic void setAttribute(String name, Object value)
setAttribute in interface javax.servlet.ServletRequestpublic void setCharacterEncoding(String name)
setCharacterEncoding in interface javax.servlet.ServletRequestpublic int getLocalPort()
getLocalPort in interface javax.servlet.ServletRequestpublic String getLocalAddr()
getLocalAddr in interface javax.servlet.ServletRequestpublic String getLocalName()
getLocalName in interface javax.servlet.ServletRequestpublic int getRemotePort()
getRemotePort in interface javax.servlet.ServletRequestpublic String getRemoteName()
public javax.servlet.http.Part getPart(String name) throws IOException, IllegalStateException, javax.servlet.ServletException
getPart in interface javax.servlet.http.HttpServletRequestIOExceptionIllegalStateExceptionjavax.servlet.ServletExceptionpublic Collection<javax.servlet.http.Part> getParts() throws IOException, IllegalStateException, javax.servlet.ServletException
getParts in interface javax.servlet.http.HttpServletRequestIOExceptionIllegalStateExceptionjavax.servlet.ServletExceptionpublic void logout()
throws javax.servlet.ServletException
logout in interface javax.servlet.http.HttpServletRequestjavax.servlet.ServletExceptionpublic void login(String username, String password) throws javax.servlet.ServletException
login in interface javax.servlet.http.HttpServletRequestjavax.servlet.ServletExceptionpublic boolean authenticate(javax.servlet.http.HttpServletResponse response)
throws IOException,
javax.servlet.ServletException
authenticate in interface javax.servlet.http.HttpServletRequestIOExceptionjavax.servlet.ServletExceptionpublic javax.servlet.DispatcherType getDispatcherType()
getDispatcherType in interface javax.servlet.ServletRequestpublic javax.servlet.AsyncContext getAsyncContext()
getAsyncContext in interface javax.servlet.ServletRequestpublic boolean isAsyncSupported()
isAsyncSupported in interface javax.servlet.ServletRequestpublic boolean isAsyncStarted()
isAsyncStarted in interface javax.servlet.ServletRequestpublic javax.servlet.AsyncContext startAsync(javax.servlet.ServletRequest servletRequest,
javax.servlet.ServletResponse servletResponse)
startAsync in interface javax.servlet.ServletRequestpublic javax.servlet.AsyncContext startAsync()
startAsync in interface javax.servlet.ServletRequestpublic javax.servlet.ServletContext getServletContext()
getServletContext in interface javax.servlet.ServletRequestCopyright © 2000-2017 Apache Software Foundation. All Rights Reserved.