Package org.apache.struts.mock
Class MockServletContext
java.lang.Object
org.apache.struts.mock.MockServletContext
- All Implemented Interfaces:
ServletContext
Mock ServletContext 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.
- Version:
- $Rev$ $Date: 2005-05-07 12:11:38 -0400 (Sat, 07 May 2005) $
-
Field Summary
Modifier and TypeFieldDescriptionThe set of servlet context attributes.The set of context initialization parameters.Fields inherited from interface jakarta.servlet.ServletContext
ORDERED_LIBS, TEMPDIR
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addInitParameter
(String name, String value) addJspFile
(String servletName, String jspFile) void
addListener
(Class<? extends EventListener> listenerClass) void
addListener
(String className) <T extends EventListener>
voidaddListener
(T t) addServlet
(String servletName, Servlet servlet) addServlet
(String servletName, Class<? extends Servlet> servletClass) addServlet
(String servletName, String className) <T extends Filter>
TcreateFilter
(Class<T> clazz) <T extends EventListener>
TcreateListener
(Class<T> clazz) <T extends Servlet>
TcreateServlet
(Class<T> clazz) void
declareRoles
(String... roleNames) getAttribute
(String name) getContext
(String uripath) int
int
getFilterRegistration
(String filterName) Map
<String, ? extends FilterRegistration> getInitParameter
(String name) int
getMimeType
(String file) int
getNamedDispatcher
(String name) getRealPath
(String path) getRequestDispatcher
(String path) getResource
(String path) getResourceAsStream
(String path) getResourcePaths
(String path) getServlet
(String name) Deprecated.Deprecated.getServletRegistration
(String servletName) Map
<String, ? extends ServletRegistration> Deprecated.int
void
Deprecated.void
void
void
removeAttribute
(String name) void
setAttribute
(String name, Object value) boolean
setInitParameter
(String name, String value) void
void
setRequestCharacterEncoding
(String encoding) void
setResponseCharacterEncoding
(String encoding) void
setSessionTimeout
(int sessionTimeout) void
setSessionTrackingModes
(Set<SessionTrackingMode> sessionTrackingModes)
-
Field Details
-
attributes
The set of servlet context attributes. -
parameters
The set of context initialization parameters.
-
-
Constructor Details
-
MockServletContext
public MockServletContext()
-
-
Method Details
-
addInitParameter
-
setLog
-
getContextPath
- Specified by:
getContextPath
in interfaceServletContext
-
getContext
- Specified by:
getContext
in interfaceServletContext
-
getMajorVersion
public int getMajorVersion()- Specified by:
getMajorVersion
in interfaceServletContext
-
getMinorVersion
public int getMinorVersion()- Specified by:
getMinorVersion
in interfaceServletContext
-
getEffectiveMajorVersion
public int getEffectiveMajorVersion()- Specified by:
getEffectiveMajorVersion
in interfaceServletContext
-
getEffectiveMinorVersion
public int getEffectiveMinorVersion()- Specified by:
getEffectiveMinorVersion
in interfaceServletContext
-
getMimeType
- Specified by:
getMimeType
in interfaceServletContext
-
getResourcePaths
- Specified by:
getResourcePaths
in interfaceServletContext
-
getResource
- Specified by:
getResource
in interfaceServletContext
- Throws:
MalformedURLException
-
getResourceAsStream
- Specified by:
getResourceAsStream
in interfaceServletContext
-
getRequestDispatcher
- Specified by:
getRequestDispatcher
in interfaceServletContext
-
getNamedDispatcher
- Specified by:
getNamedDispatcher
in interfaceServletContext
-
getServlet
Deprecated.- Specified by:
getServlet
in interfaceServletContext
- Throws:
ServletException
-
getServlets
Deprecated.- Specified by:
getServlets
in interfaceServletContext
-
getServletNames
Deprecated.- Specified by:
getServletNames
in interfaceServletContext
-
log
- Specified by:
log
in interfaceServletContext
-
log
Deprecated.- Specified by:
log
in interfaceServletContext
-
log
- Specified by:
log
in interfaceServletContext
-
getRealPath
- Specified by:
getRealPath
in interfaceServletContext
-
getServerInfo
- Specified by:
getServerInfo
in interfaceServletContext
-
getInitParameter
- Specified by:
getInitParameter
in interfaceServletContext
-
getInitParameterNames
- Specified by:
getInitParameterNames
in interfaceServletContext
-
setInitParameter
- Specified by:
setInitParameter
in interfaceServletContext
-
getAttribute
- Specified by:
getAttribute
in interfaceServletContext
-
getAttributeNames
- Specified by:
getAttributeNames
in interfaceServletContext
-
setAttribute
- Specified by:
setAttribute
in interfaceServletContext
-
removeAttribute
- Specified by:
removeAttribute
in interfaceServletContext
-
getServletContextName
- Specified by:
getServletContextName
in interfaceServletContext
-
addServlet
- Specified by:
addServlet
in interfaceServletContext
-
addServlet
- Specified by:
addServlet
in interfaceServletContext
-
addServlet
public ServletRegistration.Dynamic addServlet(String servletName, Class<? extends Servlet> servletClass) - Specified by:
addServlet
in interfaceServletContext
-
addJspFile
- Specified by:
addJspFile
in interfaceServletContext
-
createServlet
- Specified by:
createServlet
in interfaceServletContext
- Throws:
ServletException
-
getServletRegistration
- Specified by:
getServletRegistration
in interfaceServletContext
-
getServletRegistrations
- Specified by:
getServletRegistrations
in interfaceServletContext
-
addFilter
- Specified by:
addFilter
in interfaceServletContext
-
addFilter
- Specified by:
addFilter
in interfaceServletContext
-
addFilter
- Specified by:
addFilter
in interfaceServletContext
-
createFilter
- Specified by:
createFilter
in interfaceServletContext
- Throws:
ServletException
-
getFilterRegistration
- Specified by:
getFilterRegistration
in interfaceServletContext
-
getFilterRegistrations
- Specified by:
getFilterRegistrations
in interfaceServletContext
-
getSessionCookieConfig
- Specified by:
getSessionCookieConfig
in interfaceServletContext
-
setSessionTrackingModes
- Specified by:
setSessionTrackingModes
in interfaceServletContext
-
getDefaultSessionTrackingModes
- Specified by:
getDefaultSessionTrackingModes
in interfaceServletContext
-
getEffectiveSessionTrackingModes
- Specified by:
getEffectiveSessionTrackingModes
in interfaceServletContext
-
addListener
- Specified by:
addListener
in interfaceServletContext
-
addListener
- Specified by:
addListener
in interfaceServletContext
-
addListener
- Specified by:
addListener
in interfaceServletContext
-
createListener
- Specified by:
createListener
in interfaceServletContext
- Throws:
ServletException
-
getJspConfigDescriptor
- Specified by:
getJspConfigDescriptor
in interfaceServletContext
-
getClassLoader
- Specified by:
getClassLoader
in interfaceServletContext
-
declareRoles
- Specified by:
declareRoles
in interfaceServletContext
-
getVirtualServerName
- Specified by:
getVirtualServerName
in interfaceServletContext
-
getSessionTimeout
public int getSessionTimeout()- Specified by:
getSessionTimeout
in interfaceServletContext
-
setSessionTimeout
public void setSessionTimeout(int sessionTimeout) - Specified by:
setSessionTimeout
in interfaceServletContext
-
getRequestCharacterEncoding
- Specified by:
getRequestCharacterEncoding
in interfaceServletContext
-
setRequestCharacterEncoding
- Specified by:
setRequestCharacterEncoding
in interfaceServletContext
-
getResponseCharacterEncoding
- Specified by:
getResponseCharacterEncoding
in interfaceServletContext
-
setResponseCharacterEncoding
- Specified by:
setResponseCharacterEncoding
in interfaceServletContext
-