com.mockrunner.mock.web
Class MockServletContext

java.lang.Object
  extended by com.mockrunner.mock.web.MockServletContext
All Implemented Interfaces:
javax.servlet.ServletContext

public class MockServletContext
extends java.lang.Object
implements javax.servlet.ServletContext

Mock implementation of ServletContext.


Constructor Summary
MockServletContext()
           
 
Method Summary
 void addAttributeListener(javax.servlet.ServletContextAttributeListener listener)
           
 void addResourcePath(java.lang.String path, java.lang.String resourcePath)
           
 void addResourcePaths(java.lang.String path, java.util.Collection pathes)
           
 void clearAttributes()
           
 void clearInitParameters()
          Clears the init parameters.
 void clearRequestDispatcherMap()
          Clears the map of RequestDispatcher objects.
 java.lang.Object getAttribute(java.lang.String key)
           
 java.util.Enumeration getAttributeNames()
           
 javax.servlet.ServletContext getContext(java.lang.String url)
           
 java.lang.String getContextPath()
           
 java.lang.String getInitParameter(java.lang.String name)
           
 java.util.Enumeration getInitParameterNames()
           
 int getMajorVersion()
           
 java.lang.String getMimeType(java.lang.String file)
           
 int getMinorVersion()
           
 javax.servlet.RequestDispatcher getNamedDispatcher(java.lang.String name)
           
 java.lang.String getRealPath(java.lang.String path)
           
 javax.servlet.RequestDispatcher getRequestDispatcher(java.lang.String path)
           
 java.util.Map getRequestDispatcherMap()
          Returns the map of RequestDispatcher objects.
 java.net.URL getResource(java.lang.String path)
           
 java.io.InputStream getResourceAsStream(java.lang.String path)
           
 java.util.Set getResourcePaths(java.lang.String path)
           
 java.lang.String getServerInfo()
           
 javax.servlet.Servlet getServlet(java.lang.String arg0)
           
 java.lang.String getServletContextName()
           
 java.util.Enumeration getServletNames()
           
 java.util.Enumeration getServlets()
           
 void log(java.lang.Exception exc, java.lang.String message)
           
 void log(java.lang.String message)
           
 void log(java.lang.String message, java.lang.Throwable exc)
           
 void removeAttribute(java.lang.String key)
           
 void resetAll()
          Resets the state of this object to the default values
 void setAttribute(java.lang.String key, java.lang.Object value)
           
 void setContext(java.lang.String url, javax.servlet.ServletContext context)
          Sets a ServletContext that will be returned when calling getContext(java.lang.String)
 void setContextPath(java.lang.String contextPath)
           
 void setInitParameter(java.lang.String name, java.lang.String value)
          Sets an init parameter.
 void setInitParameters(java.util.Map parameters)
          Sets several init parameters.
 void setMimeType(java.lang.String file, java.lang.String type)
           
 void setRealPath(java.lang.String path, java.lang.String realPath)
           
 void setRequestDispatcher(java.lang.String path, javax.servlet.RequestDispatcher dispatcher)
          Sets a RequestDispatcher that will be returned when calling getRequestDispatcher(java.lang.String) or getNamedDispatcher(java.lang.String) with the specified path or name.
 void setResource(java.lang.String path, java.net.URL url)
           
 void setResourceAsStream(java.lang.String path, byte[] data)
           
 void setResourceAsStream(java.lang.String path, java.io.InputStream inputStream)
           
 void setServletContextName(java.lang.String servletContextName)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MockServletContext

public MockServletContext()
Method Detail

resetAll

public void resetAll()
Resets the state of this object to the default values


addAttributeListener

public void addAttributeListener(javax.servlet.ServletContextAttributeListener listener)

clearAttributes

public void clearAttributes()

getAttribute

public java.lang.Object getAttribute(java.lang.String key)
Specified by:
getAttribute in interface javax.servlet.ServletContext

getAttributeNames

public java.util.Enumeration getAttributeNames()
Specified by:
getAttributeNames in interface javax.servlet.ServletContext

removeAttribute

public void removeAttribute(java.lang.String key)
Specified by:
removeAttribute in interface javax.servlet.ServletContext

setAttribute

public void setAttribute(java.lang.String key,
                         java.lang.Object value)
Specified by:
setAttribute in interface javax.servlet.ServletContext

getNamedDispatcher

public javax.servlet.RequestDispatcher getNamedDispatcher(java.lang.String name)
Specified by:
getNamedDispatcher in interface javax.servlet.ServletContext

getRequestDispatcher

public javax.servlet.RequestDispatcher getRequestDispatcher(java.lang.String path)
Specified by:
getRequestDispatcher in interface javax.servlet.ServletContext

getRequestDispatcherMap

public java.util.Map getRequestDispatcherMap()
Returns the map of RequestDispatcher objects. The specified path maps to the corresponding RequestDispatcher object.

Returns:
the map of RequestDispatcher objects

clearRequestDispatcherMap

public void clearRequestDispatcherMap()
Clears the map of RequestDispatcher objects.


setRequestDispatcher

public void setRequestDispatcher(java.lang.String path,
                                 javax.servlet.RequestDispatcher dispatcher)
Sets a RequestDispatcher that will be returned when calling getRequestDispatcher(java.lang.String) or getNamedDispatcher(java.lang.String) with the specified path or name. If no RequestDispatcher is set for the specified path, getRequestDispatcher(java.lang.String) and getNamedDispatcher(java.lang.String) automatically create a new one.

Parameters:
path - the path for the RequestDispatcher
dispatcher - the RequestDispatcher object

getContext

public javax.servlet.ServletContext getContext(java.lang.String url)
Specified by:
getContext in interface javax.servlet.ServletContext

setContext

public void setContext(java.lang.String url,
                       javax.servlet.ServletContext context)
Sets a ServletContext that will be returned when calling getContext(java.lang.String)

Parameters:
url - the URL
context - the ServletContext

clearInitParameters

public void clearInitParameters()
Clears the init parameters.


getInitParameter

public java.lang.String getInitParameter(java.lang.String name)
Specified by:
getInitParameter in interface javax.servlet.ServletContext

setInitParameter

public void setInitParameter(java.lang.String name,
                             java.lang.String value)
Sets an init parameter.

Parameters:
name - the name
value - the value

setInitParameters

public void setInitParameters(java.util.Map parameters)
Sets several init parameters.

Parameters:
parameters - the parameter map

getInitParameterNames

public java.util.Enumeration getInitParameterNames()
Specified by:
getInitParameterNames in interface javax.servlet.ServletContext

getMajorVersion

public int getMajorVersion()
Specified by:
getMajorVersion in interface javax.servlet.ServletContext

getMinorVersion

public int getMinorVersion()
Specified by:
getMinorVersion in interface javax.servlet.ServletContext

getMimeType

public java.lang.String getMimeType(java.lang.String file)
Specified by:
getMimeType in interface javax.servlet.ServletContext

setMimeType

public void setMimeType(java.lang.String file,
                        java.lang.String type)

getRealPath

public java.lang.String getRealPath(java.lang.String path)
Specified by:
getRealPath in interface javax.servlet.ServletContext

setRealPath

public void setRealPath(java.lang.String path,
                        java.lang.String realPath)

getResource

public java.net.URL getResource(java.lang.String path)
                         throws java.net.MalformedURLException
Specified by:
getResource in interface javax.servlet.ServletContext
Throws:
java.net.MalformedURLException

setResource

public void setResource(java.lang.String path,
                        java.net.URL url)

getResourceAsStream

public java.io.InputStream getResourceAsStream(java.lang.String path)
Specified by:
getResourceAsStream in interface javax.servlet.ServletContext

setResourceAsStream

public void setResourceAsStream(java.lang.String path,
                                java.io.InputStream inputStream)

setResourceAsStream

public void setResourceAsStream(java.lang.String path,
                                byte[] data)

getResourcePaths

public java.util.Set getResourcePaths(java.lang.String path)
Specified by:
getResourcePaths in interface javax.servlet.ServletContext

addResourcePaths

public void addResourcePaths(java.lang.String path,
                             java.util.Collection pathes)

addResourcePath

public void addResourcePath(java.lang.String path,
                            java.lang.String resourcePath)

getServerInfo

public java.lang.String getServerInfo()
Specified by:
getServerInfo in interface javax.servlet.ServletContext

getServlet

public javax.servlet.Servlet getServlet(java.lang.String arg0)
                                 throws javax.servlet.ServletException
Specified by:
getServlet in interface javax.servlet.ServletContext
Throws:
javax.servlet.ServletException

getServletContextName

public java.lang.String getServletContextName()
Specified by:
getServletContextName in interface javax.servlet.ServletContext

setServletContextName

public void setServletContextName(java.lang.String servletContextName)

getContextPath

public java.lang.String getContextPath()
Specified by:
getContextPath in interface javax.servlet.ServletContext

setContextPath

public void setContextPath(java.lang.String contextPath)

getServletNames

public java.util.Enumeration getServletNames()
Specified by:
getServletNames in interface javax.servlet.ServletContext

getServlets

public java.util.Enumeration getServlets()
Specified by:
getServlets in interface javax.servlet.ServletContext

log

public void log(java.lang.Exception exc,
                java.lang.String message)
Specified by:
log in interface javax.servlet.ServletContext

log

public void log(java.lang.String message,
                java.lang.Throwable exc)
Specified by:
log in interface javax.servlet.ServletContext

log

public void log(java.lang.String message)
Specified by:
log in interface javax.servlet.ServletContext