org.slim3.struts.test
Class MockServletContext

java.lang.Object
  extended by org.slim3.struts.test.MockServletContext
All Implemented Interfaces:
Serializable, ServletContext

public class MockServletContext
extends Object
implements ServletContext, Serializable

A mock implementation for ServletContext.

Since:
3.0
Author:
higa
See Also:
Serialized Form

Field Summary
protected  Map<String,Object> attributeTable
          The map for the attributes.
protected  String contextPath
          The context path.
protected  Map<String,String> initParameterMap
          The map for the initial parameters.
static int MAJOR_VERSION
          Major Version
static int MINOR_VERSION
          Minor Version
protected  Map<String,String> realPathMap
          The map for initial parameters.
protected  Map<String,URL> resourceMap
          The map for resource.
protected  Map<String,Set<String>> resourcePathsMap
          The map for resource paths.
static String SERVER_INFO
          Server Info
protected  String servletContextName
          The servlet context name.
 
Constructor Summary
MockServletContext()
          Constructor.
 
Method Summary
 void addRealPath(String path, String realPath)
          Adds the real path.
 void addResource(String path, URL url)
          Adds the URL resource.
 void addResourcePaths(String path, Set<String> resourcePaths)
          Adds the resource paths.
 Object getAttribute(String name)
           
 Enumeration<String> getAttributeNames()
           
 ServletContext getContext(String path)
           
 String getContextPath()
           
 String getInitParameter(String name)
           
 Enumeration<String> getInitParameterNames()
           
 int getMajorVersion()
           
 String getMimeType(String file)
           
 int getMinorVersion()
           
 RequestDispatcher getNamedDispatcher(String name)
           
 String getRealPath(String path)
           
 RequestDispatcher getRequestDispatcher(String path)
           
 URL getResource(String path)
           
 InputStream getResourceAsStream(String path)
           
 Set<String> getResourcePaths(String path)
           
 String getServerInfo()
           
 Servlet getServlet(String name)
           
 String getServletContextName()
           
 Enumeration<String> getServletNames()
           
 Enumeration<Servlet> getServlets()
           
 void log(Exception ex, String message)
           
 void log(String message)
           
 void log(String message, Throwable t)
           
 void removeAttribute(String name)
           
 void removeInitParameter(String name)
          Removes the initial parameter.
 void setAttribute(String name, Object value)
           
 void setContextPath(String contextPath)
          Sets the context path.
 void setInitParameter(String name, String value)
          Sets the initial parameter.
 void setServletContextName(String servletContextName)
          Sets the servlet context name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAJOR_VERSION

public static final int MAJOR_VERSION
Major Version

See Also:
Constant Field Values

MINOR_VERSION

public static final int MINOR_VERSION
Minor Version

See Also:
Constant Field Values

SERVER_INFO

public static final String SERVER_INFO
Server Info

See Also:
Constant Field Values

servletContextName

protected String servletContextName
The servlet context name.


contextPath

protected String contextPath
The context path.


initParameterMap

protected Map<String,String> initParameterMap
The map for the initial parameters.


attributeTable

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


resourcePathsMap

protected Map<String,Set<String>> resourcePathsMap
The map for resource paths.


resourceMap

protected Map<String,URL> resourceMap
The map for resource.


realPathMap

protected Map<String,String> realPathMap
The map for initial parameters.

Constructor Detail

MockServletContext

public MockServletContext()
Constructor.

Method Detail

getContext

public ServletContext getContext(String path)
Specified by:
getContext in interface ServletContext

getMajorVersion

public int getMajorVersion()
Specified by:
getMajorVersion in interface ServletContext

getMinorVersion

public int getMinorVersion()
Specified by:
getMinorVersion in interface ServletContext

getMimeType

public String getMimeType(String file)
Specified by:
getMimeType in interface ServletContext

getResourcePaths

public Set<String> getResourcePaths(String path)
Specified by:
getResourcePaths in interface ServletContext

addResourcePaths

public void addResourcePaths(String path,
                             Set<String> resourcePaths)
Adds the resource paths.

Parameters:
path - the path
resourcePaths - the resource paths

getResource

public URL getResource(String path)
Specified by:
getResource in interface ServletContext

addResource

public void addResource(String path,
                        URL url)
Adds the URL resource.

Parameters:
path - the path
url - the URL resource

getResourceAsStream

public InputStream getResourceAsStream(String path)
Specified by:
getResourceAsStream in interface ServletContext

getRequestDispatcher

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

getNamedDispatcher

public RequestDispatcher getNamedDispatcher(String name)
Specified by:
getNamedDispatcher in interface ServletContext

getServlet

public Servlet getServlet(String name)
                   throws ServletException
Specified by:
getServlet in interface ServletContext
Throws:
ServletException

getServlets

public Enumeration<Servlet> getServlets()
Specified by:
getServlets in interface ServletContext

getServletNames

public Enumeration<String> getServletNames()
Specified by:
getServletNames in interface ServletContext

log

public void log(String message)
Specified by:
log in interface ServletContext

log

public void log(Exception ex,
                String message)
Specified by:
log in interface ServletContext

log

public void log(String message,
                Throwable t)
Specified by:
log in interface ServletContext

getRealPath

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

addRealPath

public void addRealPath(String path,
                        String realPath)
Adds the real path.

Parameters:
path - the context relative path
realPath - the real path

getServerInfo

public String getServerInfo()
Specified by:
getServerInfo in interface ServletContext
See Also:
ServletContext.getServerInfo()

getInitParameter

public String getInitParameter(String name)
Specified by:
getInitParameter in interface ServletContext

getInitParameterNames

public Enumeration<String> getInitParameterNames()
Specified by:
getInitParameterNames in interface ServletContext

setInitParameter

public void setInitParameter(String name,
                             String value)
Sets the initial parameter.

Parameters:
name - the parameter name
value - the value

removeInitParameter

public void removeInitParameter(String name)
Removes the initial parameter.

Parameters:
name - the parameter name

getAttribute

public Object getAttribute(String name)
Specified by:
getAttribute in interface ServletContext
See Also:
ServletContext.getAttribute(java.lang.String)

getAttributeNames

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

setAttribute

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

removeAttribute

public void removeAttribute(String name)
Specified by:
removeAttribute in interface ServletContext
See Also:
ServletContext.removeAttribute(java.lang.String)

getServletContextName

public String getServletContextName()
Specified by:
getServletContextName in interface ServletContext
See Also:
ServletContext.getServletContextName()

setServletContextName

public void setServletContextName(String servletContextName)
Sets the servlet context name.

Parameters:
servletContextName - the servlet context name

getContextPath

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

setContextPath

public void setContextPath(String contextPath)
Sets the context path.

Parameters:
contextPath - the context path


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