org.slim3.struts.test
Class MockHttpServletRequest

java.lang.Object
  extended by org.slim3.struts.test.MockHttpServletRequest
All Implemented Interfaces:
HttpServletRequest, ServletRequest

public class MockHttpServletRequest
extends Object
implements HttpServletRequest

A mock implementation for HttpServletRequest.

Since:
3.0
Author:
higa

Field Summary
protected  Map<String,Object> attributeMap
          The map for the attributes.
protected  String authType
          Authority type.
protected  String characterEncoding
          The character encoding.
protected  int contentLength
          The content length.
protected  String contentType
          The content type.
protected  List<Cookie> cookieList
          The list for Cookie.
protected  Map<String,List<String>> headerMap
          The map for the request header.
protected  ServletInputStream inputStream
          The input stream.
protected  String localAddr
          The local address.
protected  List<Locale> localeList
          The list for the locales.
protected  String localName
          The local name.
protected  int localPort
          The local port.
protected  String method
          The method.
protected  Map<String,String[]> parameterMap
          The map for the parameters.
protected  String pathInfo
          The path information.
protected  String pathTranslated
          The translated path.
protected  String protocol
          The protocol.
protected  String queryString
          The query string.
protected  BufferedReader reader
          The buffered reader.
protected  String remoteAddr
          The remote address.
protected  String remoteHost
          The remote host.
protected  int remotePort
          The remote port.
protected  String requestedSessionId
          The requested session identifier.
protected  boolean requestedSessionIdFromCookie
          Whether the requested session identifier comes from cookie.
protected  String scheme
          The request scheme.
protected  boolean secure
          The secure flag.
protected  String serverName
          The server name.
protected  int serverPort
          The server port.
protected  ServletContext servletContext
          The servlet context.
protected  String servletPath
          The servlet path.
protected  MockHttpSession session
          The session.
 
Fields inherited from interface javax.servlet.http.HttpServletRequest
BASIC_AUTH, CLIENT_CERT_AUTH, DIGEST_AUTH, FORM_AUTH
 
Constructor Summary
MockHttpServletRequest(ServletContext servletContext, String servletPath)
          Constructor.
 
Method Summary
 void addCookie(Cookie cookie)
          Adds the cookie.
 void addDateHeader(String name, long value)
          Adds the date header.
 void addHeader(String name, String value)
          Adds the header.
 void addIntHeader(String name, int value)
          Adds the int header.
 void addLocale(Locale locale)
          Adds the locale.
 void addParameter(String name, String value)
          Adds the request parameter.
 void addParameter(String name, String[] values)
          Adds the request parameter.
 Object getAttribute(String name)
           
 Enumeration<String> getAttributeNames()
           
 String getAuthType()
           
 String getCharacterEncoding()
           
 int getContentLength()
           
 String getContentType()
           
 String getContextPath()
           
 Cookie[] getCookies()
           
 long getDateHeader(String name)
           
 String getHeader(String name)
           
protected  List<String> getHeaderList(String name)
          Return the list for header.
 Enumeration<String> getHeaderNames()
           
 Enumeration<String> getHeaders(String name)
           
 ServletInputStream getInputStream()
           
 int getIntHeader(String name)
           
 String getLocalAddr()
           
 Locale getLocale()
           
 Enumeration<Locale> getLocales()
           
 String getLocalName()
           
 int getLocalPort()
           
 String getMethod()
           
 String getParameter(String name)
           
 Map<String,String[]> getParameterMap()
           
 Enumeration<String> getParameterNames()
           
 String[] getParameterValues(String name)
           
 String getPathInfo()
           
 String getPathTranslated()
           
 String getProtocol()
           
 String getQueryString()
           
 BufferedReader getReader()
           
 String getRealPath(String path)
           
 String getRemoteAddr()
           
 String getRemoteHost()
           
 int getRemotePort()
           
 String getRemoteUser()
           
 RequestDispatcher getRequestDispatcher(String path)
           
 String getRequestedSessionId()
           
 String getRequestURI()
           
 StringBuffer getRequestURL()
           
 String getScheme()
           
 String getServerName()
           
 int getServerPort()
           
 String getServletPath()
           
 HttpSession getSession()
           
 HttpSession getSession(boolean create)
           
 Principal getUserPrincipal()
           
 boolean isRequestedSessionIdFromCookie()
           
 boolean isRequestedSessionIdFromUrl()
           
 boolean isRequestedSessionIdFromURL()
           
 boolean isRequestedSessionIdValid()
           
 boolean isSecure()
           
 boolean isUserInRole(String arg0)
           
 void removeAttribute(String name)
           
 void removeParameter(String name)
          Removes the request parameter.
 void setAttribute(String name, Object value)
           
 void setAuthType(String authType)
          Sets the authority type.
 void setCharacterEncoding(String characterEncoding)
           
 void setContentLength(int contentLength)
          Sets the content length.
 void setContentType(String contentType)
          Sets the content type.
 void setDateHeader(String name, long value)
          Sets the date header.
 void setHeader(String name, String value)
          Sets the header.
 void setInputStream(ServletInputStream inputStream)
          Sets the input stream.
 void setIntHeader(String name, int value)
          Sets the int header.
 void setLocalAddr(String localAddr)
          Sets the local address.
 void setLocalName(String localName)
          Sets the local name.
 void setLocalPort(int localPort)
          Sets the local port.
 void setMethod(String method)
          Sets the method.
 void setParameter(String name, String value)
          Sets the request parameter.
 void setParameter(String name, String[] values)
          Sets the request parameter.
 void setPathInfo(String pathInfo)
          Sets the path information.
 void setPathTranslated(String pathTranslated)
          Sets the translated path.
 void setProtocol(String protocol)
          Sets the protocol.
 void setQueryString(String queryString)
          Sets the query string.
 void setReader(BufferedReader reader)
          Sets the buffered reader.
 void setRemoteAddr(String remoteAddr)
          Sets the remote address.
 void setRemoteHost(String remoteHost)
          Sets the remote host.
 void setRemotePort(int remotePort)
          Sets the remote port.
 void setRequestedSessionId(String requestedSessionId)
          Sets the requested session identifier.
 void setScheme(String scheme)
          Sets the scheme.
 void setSecure(boolean secure)
          Sets the secure flag.
 void setServerName(String serverName)
          Sets the server name.
 void setServerPort(int serverPort)
          Sets the server port.
 void setServletPath(String servletPath)
          Sets the servlet path.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

servletContext

protected ServletContext servletContext
The servlet context.


servletPath

protected String servletPath
The servlet path.


authType

protected String authType
Authority type.


cookieList

protected List<Cookie> cookieList
The list for Cookie.


headerMap

protected Map<String,List<String>> headerMap
The map for the request header.


method

protected String method
The method.


pathInfo

protected String pathInfo
The path information.


pathTranslated

protected String pathTranslated
The translated path.


queryString

protected String queryString
The query string.


session

protected MockHttpSession session
The session.


scheme

protected String scheme
The request scheme.


serverPort

protected int serverPort
The server port.


protocol

protected String protocol
The protocol.


serverName

protected String serverName
The server name.


attributeMap

protected Map<String,Object> attributeMap
The map for the attributes.


characterEncoding

protected String characterEncoding
The character encoding.


contentLength

protected int contentLength
The content length.


contentType

protected String contentType
The content type.


parameterMap

protected Map<String,String[]> parameterMap
The map for the parameters.


requestedSessionId

protected String requestedSessionId
The requested session identifier.


requestedSessionIdFromCookie

protected boolean requestedSessionIdFromCookie
Whether the requested session identifier comes from cookie.


inputStream

protected ServletInputStream inputStream
The input stream.


reader

protected BufferedReader reader
The buffered reader.


remoteAddr

protected String remoteAddr
The remote address.


remoteHost

protected String remoteHost
The remote host.


remotePort

protected int remotePort
The remote port.


localAddr

protected String localAddr
The local address.


localName

protected String localName
The local name.


localPort

protected int localPort
The local port.


localeList

protected List<Locale> localeList
The list for the locales.


secure

protected boolean secure
The secure flag.

Constructor Detail

MockHttpServletRequest

public MockHttpServletRequest(ServletContext servletContext,
                              String servletPath)
                       throws NullPointerException
Constructor.

Parameters:
servletContext - the servlet context
servletPath - the servlet path
Throws:
NullPointerException - if the servletContext parameter is null or if the servletPath parameter is null
Method Detail

getAuthType

public String getAuthType()
Specified by:
getAuthType in interface HttpServletRequest

setAuthType

public void setAuthType(String authType)
Sets the authority type.

Parameters:
authType - the authority type

getCookies

public Cookie[] getCookies()
Specified by:
getCookies in interface HttpServletRequest

addCookie

public void addCookie(Cookie cookie)
Adds the cookie.

Parameters:
cookie - the cookie

getHeader

public String getHeader(String name)
Specified by:
getHeader in interface HttpServletRequest

getDateHeader

public long getDateHeader(String name)
Specified by:
getDateHeader in interface HttpServletRequest

getIntHeader

public int getIntHeader(String name)
Specified by:
getIntHeader in interface HttpServletRequest

getHeaders

public Enumeration<String> getHeaders(String name)
Specified by:
getHeaders in interface HttpServletRequest

getHeaderNames

public Enumeration<String> getHeaderNames()
Specified by:
getHeaderNames in interface HttpServletRequest

setHeader

public void setHeader(String name,
                      String value)
Sets the header.

Parameters:
name - the name
value - the value

setDateHeader

public void setDateHeader(String name,
                          long value)
Sets the date header.

Parameters:
name - the name
value - the value

setIntHeader

public void setIntHeader(String name,
                         int value)
Sets the int header.

Parameters:
name - the name
value - the value

addHeader

public void addHeader(String name,
                      String value)
Adds the header.

Parameters:
name - the name
value - the value

addDateHeader

public void addDateHeader(String name,
                          long value)
Adds the date header.

Parameters:
name - the name
value - the value

addIntHeader

public void addIntHeader(String name,
                         int value)
Adds the int header.

Parameters:
name - the name
value - the value

getHeaderList

protected List<String> getHeaderList(String name)
Return the list for header.

Parameters:
name - the name
Returns:
the list for header

getMethod

public String getMethod()
Specified by:
getMethod in interface HttpServletRequest

setMethod

public void setMethod(String method)
Sets the method.

Parameters:
method - the method

getPathInfo

public String getPathInfo()
Specified by:
getPathInfo in interface HttpServletRequest

setPathInfo

public void setPathInfo(String pathInfo)
Sets the path information.

Parameters:
pathInfo - the path information

getPathTranslated

public String getPathTranslated()
Specified by:
getPathTranslated in interface HttpServletRequest

setPathTranslated

public void setPathTranslated(String pathTranslated)
Sets the translated path.

Parameters:
pathTranslated - the translated path

getContextPath

public String getContextPath()
Specified by:
getContextPath in interface HttpServletRequest

getQueryString

public String getQueryString()
Specified by:
getQueryString in interface HttpServletRequest

setQueryString

public void setQueryString(String queryString)
Sets the query string.

Parameters:
queryString - the query string

getRemoteUser

public String getRemoteUser()
Specified by:
getRemoteUser in interface HttpServletRequest

isUserInRole

public boolean isUserInRole(String arg0)
Specified by:
isUserInRole in interface HttpServletRequest

getUserPrincipal

public Principal getUserPrincipal()
Specified by:
getUserPrincipal in interface HttpServletRequest

getRequestedSessionId

public String getRequestedSessionId()
Specified by:
getRequestedSessionId in interface HttpServletRequest

setRequestedSessionId

public void setRequestedSessionId(String requestedSessionId)
Sets the requested session identifier.

Parameters:
requestedSessionId - the requested session identifier

getRequestURI

public String getRequestURI()
Specified by:
getRequestURI in interface HttpServletRequest

getRequestURL

public StringBuffer getRequestURL()
Specified by:
getRequestURL in interface HttpServletRequest

getServletPath

public String getServletPath()
Specified by:
getServletPath in interface HttpServletRequest

setServletPath

public void setServletPath(String servletPath)
Sets the servlet path.

Parameters:
servletPath - the servlet path

getSession

public HttpSession getSession(boolean create)
Specified by:
getSession in interface HttpServletRequest

getSession

public HttpSession getSession()
Specified by:
getSession in interface HttpServletRequest

isRequestedSessionIdValid

public boolean isRequestedSessionIdValid()
Specified by:
isRequestedSessionIdValid in interface HttpServletRequest

isRequestedSessionIdFromCookie

public boolean isRequestedSessionIdFromCookie()
Specified by:
isRequestedSessionIdFromCookie in interface HttpServletRequest

isRequestedSessionIdFromURL

public boolean isRequestedSessionIdFromURL()
Specified by:
isRequestedSessionIdFromURL in interface HttpServletRequest

isRequestedSessionIdFromUrl

public boolean isRequestedSessionIdFromUrl()
Specified by:
isRequestedSessionIdFromUrl in interface HttpServletRequest

getAttribute

public Object getAttribute(String name)
Specified by:
getAttribute in interface ServletRequest

getAttributeNames

public Enumeration<String> getAttributeNames()
Specified by:
getAttributeNames in interface ServletRequest

setAttribute

public void setAttribute(String name,
                         Object value)
Specified by:
setAttribute in interface ServletRequest

removeAttribute

public void removeAttribute(String name)
Specified by:
removeAttribute in interface ServletRequest

getCharacterEncoding

public String getCharacterEncoding()
Specified by:
getCharacterEncoding in interface ServletRequest

setCharacterEncoding

public void setCharacterEncoding(String characterEncoding)
                          throws UnsupportedEncodingException
Specified by:
setCharacterEncoding in interface ServletRequest
Throws:
UnsupportedEncodingException

getContentLength

public int getContentLength()
Specified by:
getContentLength in interface ServletRequest

setContentLength

public void setContentLength(int contentLength)
Sets the content length.

Parameters:
contentLength - the content length

getContentType

public String getContentType()
Specified by:
getContentType in interface ServletRequest

setContentType

public void setContentType(String contentType)
Sets the content type.

Parameters:
contentType -

getInputStream

public ServletInputStream getInputStream()
                                  throws IOException
Specified by:
getInputStream in interface ServletRequest
Throws:
IOException

setInputStream

public void setInputStream(ServletInputStream inputStream)
Sets the input stream.

Parameters:
inputStream - the input stream

getParameter

public String getParameter(String name)
Specified by:
getParameter in interface ServletRequest

getParameterNames

public Enumeration<String> getParameterNames()
Specified by:
getParameterNames in interface ServletRequest

getParameterValues

public String[] getParameterValues(String name)
Specified by:
getParameterValues in interface ServletRequest

getParameterMap

public Map<String,String[]> getParameterMap()
Specified by:
getParameterMap in interface ServletRequest

addParameter

public void addParameter(String name,
                         String value)
Adds the request parameter.

Parameters:
name - the name
value - the value

addParameter

public void addParameter(String name,
                         String[] values)
Adds the request parameter.

Parameters:
name - the name
values - the value

setParameter

public void setParameter(String name,
                         String value)
Sets the request parameter.

Parameters:
name - the name
value - the value

setParameter

public void setParameter(String name,
                         String[] values)
Sets the request parameter.

Parameters:
name - the name
values - the value

removeParameter

public void removeParameter(String name)
Removes the request parameter.

Parameters:
name - the name

getProtocol

public String getProtocol()
Specified by:
getProtocol in interface ServletRequest

setProtocol

public void setProtocol(String protocol)
Sets the protocol.

Parameters:
protocol - the protocol

getScheme

public String getScheme()
Specified by:
getScheme in interface ServletRequest

setScheme

public void setScheme(String scheme)
Sets the scheme.

Parameters:
scheme - the scheme

getServerName

public String getServerName()
Specified by:
getServerName in interface ServletRequest

setServerName

public void setServerName(String serverName)
Sets the server name.

Parameters:
serverName - the server name

getServerPort

public int getServerPort()
Specified by:
getServerPort in interface ServletRequest

setServerPort

public void setServerPort(int serverPort)
Sets the server port.

Parameters:
serverPort - the server port

getReader

public BufferedReader getReader()
                         throws IOException
Specified by:
getReader in interface ServletRequest
Throws:
IOException

setReader

public void setReader(BufferedReader reader)
Sets the buffered reader.

Parameters:
reader - the buffered reader

getRemoteAddr

public String getRemoteAddr()
Specified by:
getRemoteAddr in interface ServletRequest

setRemoteAddr

public void setRemoteAddr(String remoteAddr)
Sets the remote address.

Parameters:
remoteAddr - the remote address

getRemoteHost

public String getRemoteHost()
Specified by:
getRemoteHost in interface ServletRequest

setRemoteHost

public void setRemoteHost(String remoteHost)
Sets the remote host.

Parameters:
remoteHost - the remote host

getLocalAddr

public String getLocalAddr()
Specified by:
getLocalAddr in interface ServletRequest

setLocalAddr

public void setLocalAddr(String localAddr)
Sets the local address.

Parameters:
localAddr - the local address

getLocalName

public String getLocalName()
Specified by:
getLocalName in interface ServletRequest

setLocalName

public void setLocalName(String localName)
Sets the local name.

Parameters:
localName - the local name

getLocalPort

public int getLocalPort()
Specified by:
getLocalPort in interface ServletRequest

setLocalPort

public void setLocalPort(int localPort)
Sets the local port.

Parameters:
localPort - the local port

getRemotePort

public int getRemotePort()
Specified by:
getRemotePort in interface ServletRequest

setRemotePort

public void setRemotePort(int remotePort)
Sets the remote port.

Parameters:
remotePort - the remote port

getLocale

public Locale getLocale()
Specified by:
getLocale in interface ServletRequest

addLocale

public void addLocale(Locale locale)
Adds the locale.

Parameters:
locale - the locale

getLocales

public Enumeration<Locale> getLocales()
Specified by:
getLocales in interface ServletRequest

isSecure

public boolean isSecure()
Specified by:
isSecure in interface ServletRequest

setSecure

public void setSecure(boolean secure)
Sets the secure flag.

Parameters:
secure - the secure flag

getRequestDispatcher

public RequestDispatcher getRequestDispatcher(String path)
Specified by:
getRequestDispatcher in interface ServletRequest

getRealPath

public String getRealPath(String path)
Specified by:
getRealPath in interface ServletRequest


Copyright © 2008-2009 The Slim3 project. All Rights Reserved.