|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sourceforge.stripes.mock.MockServletContext
public class MockServletContext
Mock implementation of a ServletContext. Provides implementation the most commonly used methods, namely those to manipulate init parameters and attributes. Additional methods are provided to allow the setting of initialization parameters etc.
This mock implementation is meant only for testing purposes. As such there are certain limitations:
Constructor Summary | |
---|---|
MockServletContext(String contextName)
Simple constructor that creates a new mock ServletContext with the supplied context name. |
Method Summary | |
---|---|
void |
acceptRequest(MockHttpServletRequest request,
MockHttpServletResponse response)
Takes a request and response and runs them through the set of filters using a MockFilterChain, which if everything goes well, will eventually execute the servlet that is registered with this context. |
void |
addAllInitParameters(Map<String,String> parameters)
Adds all the values in the supplied Map to the set of init parameters. |
void |
addFilter(Class<? extends Filter> filterClass,
String filterName,
Map<String,String> initParams)
Adds a filter to the end of filter chain that will be used to filter requests. |
void |
addInitParameter(String name,
String value)
Adds an init parameter to the mock servlet context. |
Object |
getAttribute(String name)
Gets an attribute that has been set on the context (i.e. |
Enumeration<String> |
getAttributeNames()
Returns an enumeration of all the names of attributes in the context. |
ServletContext |
getContext(String url)
If the url is within this servlet context, returns this. |
String |
getContextPath()
Servlet 2.3 method. |
List<Filter> |
getFilters()
Provides access to the set of filters configured for this context. |
String |
getInitParameter(String name)
Gets the value of an init parameter with the specified name, if one exists. |
Enumeration<String> |
getInitParameterNames()
Returns an enumeration of all the initialization parameters in the context. |
int |
getMajorVersion()
Always returns 2. |
String |
getMimeType(String file)
Always returns null (i.e. |
int |
getMinorVersion()
Always returns 4. |
RequestDispatcher |
getNamedDispatcher(String name)
Returns a MockRequestDispatcher for the named servlet provided. |
String |
getRealPath(String string)
Always returns null as this is standard behaviour for WAR resources. |
RequestDispatcher |
getRequestDispatcher(String url)
Returns a MockRequestDispatcher for the url provided. |
URL |
getResource(String name)
Uses the current classloader to fetch the resource if it can. |
InputStream |
getResourceAsStream(String name)
Uses the current classloader to fetch the resource if it can. |
Set<?> |
getResourcePaths(String path)
Always returns null (i.e. |
String |
getServerInfo()
Returns a version string identifying the Mock implementation. |
Servlet |
getServlet(String string)
Deprecated method always returns null. |
String |
getServletContextName()
Returns the name of the mock context. |
Enumeration<?> |
getServletNames()
Deprecated method always returns an empty enumeration. |
Enumeration<?> |
getServlets()
Deprecated method always returns an empty enumeration. |
void |
log(Exception exception,
String message)
Logs the message and exception to System.out. |
void |
log(String message)
Logs the message to System.out. |
void |
log(String message,
Throwable throwable)
Logs the message and exception to System.out. |
void |
removeAttribute(String name)
Removes the named attribute from the context. |
void |
setAttribute(String name,
Object value)
Sets the supplied value for the attribute on the context. |
void |
setServlet(Class<? extends HttpServlet> servletClass,
String servletName,
Map<String,String> initParams)
Sets the servlet that will receive all requests in this servlet context. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public MockServletContext(String contextName)
Method Detail |
---|
public ServletContext getContext(String url)
getContext
in interface ServletContext
public String getContextPath()
getContextPath
in interface ServletContext
public int getMajorVersion()
getMajorVersion
in interface ServletContext
public int getMinorVersion()
getMinorVersion
in interface ServletContext
public String getMimeType(String file)
getMimeType
in interface ServletContext
public Set<?> getResourcePaths(String path)
getResourcePaths
in interface ServletContext
public URL getResource(String name) throws MalformedURLException
getResource
in interface ServletContext
MalformedURLException
public InputStream getResourceAsStream(String name)
getResourceAsStream
in interface ServletContext
public RequestDispatcher getRequestDispatcher(String url)
getRequestDispatcher
in interface ServletContext
public RequestDispatcher getNamedDispatcher(String name)
getNamedDispatcher
in interface ServletContext
public Servlet getServlet(String string) throws ServletException
getServlet
in interface ServletContext
ServletException
public Enumeration<?> getServlets()
getServlets
in interface ServletContext
public Enumeration<?> getServletNames()
getServletNames
in interface ServletContext
public void log(String message)
log
in interface ServletContext
public void log(Exception exception, String message)
log
in interface ServletContext
public void log(String message, Throwable throwable)
log
in interface ServletContext
public String getRealPath(String string)
getRealPath
in interface ServletContext
public String getServerInfo()
getServerInfo
in interface ServletContext
public void addInitParameter(String name, String value)
public void addAllInitParameters(Map<String,String> parameters)
public String getInitParameter(String name)
getInitParameter
in interface ServletContext
public Enumeration<String> getInitParameterNames()
getInitParameterNames
in interface ServletContext
public Object getAttribute(String name)
getAttribute
in interface ServletContext
public Enumeration<String> getAttributeNames()
getAttributeNames
in interface ServletContext
public void setAttribute(String name, Object value)
setAttribute
in interface ServletContext
public void removeAttribute(String name)
removeAttribute
in interface ServletContext
public String getServletContextName()
getServletContextName
in interface ServletContext
public void addFilter(Class<? extends Filter> filterClass, String filterName, Map<String,String> initParams)
public List<Filter> getFilters()
public void setServlet(Class<? extends HttpServlet> servletClass, String servletName, Map<String,String> initParams)
public void acceptRequest(MockHttpServletRequest request, MockHttpServletResponse response) throws Exception
Takes a request and response and runs them through the set of filters using a MockFilterChain, which if everything goes well, will eventually execute the servlet that is registered with this context.
Any exceptions that are raised during the processing of the request are simply passed through to the caller. I.e. they will be thrown from this method.
Exception
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |