open class MockServletContext : ServletContext
Mock implementation of the javax.servlet.ServletContext interface.
As of Spring 5.0, this set of mocks is designed on a Servlet 4.0 baseline.
Compatible with Servlet 3.1 but can be configured to expose a specific version through #setMajorVersion/#setMinorVersion; default is 3.1. Note that Servlet 3.1 support is limited: servlet, filter and listener registration methods are not supported; neither is JSP configuration. We generally do not recommend to unit test your ServletContainerInitializers and WebApplicationInitializers which is where those registration methods would be used.
For setting up a full WebApplicationContext in a test environment, you can use AnnotationConfigWebApplicationContext, XmlWebApplicationContext, or GenericWebApplicationContext, passing in a corresponding MockServletContext instance. Consider configuring your MockServletContext with a FileSystemResourceLoader in order to interpret resource paths as relative filesystem locations.
Author
Rod Johnson
Author
Juergen Hoeller
Author
Sam Brannen
Since
1.0.2
See Also
#MockServletContext(org.springframework.core.io.ResourceLoader)org.springframework.web.context.support.AnnotationConfigWebApplicationContextorg.springframework.web.context.support.XmlWebApplicationContextorg.springframework.web.context.support.GenericWebApplicationContext
MockServletContext()
Create a new MockServletContext(resourceBasePath: String)
Create a new MockServletContext(resourceLoader: ResourceLoader)
Create a new MockServletContext(resourceBasePath: String, resourceLoader: ResourceLoader)
Create a new Registers a MockRequestDispatcher for the Servlet named 'default'. |
open fun addFilter(filterName: String, className: String): Dynamicopen fun addFilter(filterName: String, filter: Filter): Dynamicopen fun addFilter(filterName: String, filterClass: Class<out Filter>): Dynamic |
|
open fun addInitParameter(name: String, value: String): Unit |
|
open fun addJspFile(servletName: String, jspFile: String): Dynamic |
|
open fun addListener(listenerClass: Class<out EventListener>): Unitopen fun addListener(className: String): Unitopen fun <T : EventListener> addListener(t: T): Unit |
|
open fun addMimeType(fileExtension: String, mimeType: MediaType): Unit
Adds a mime type mapping for use by |
|
open fun addServlet(servletName: String, className: String): Dynamicopen fun addServlet(servletName: String, servlet: Servlet): Dynamicopen fun addServlet(servletName: String, servletClass: Class<out Servlet>): Dynamic |
|
open fun <T : Filter> createFilter(c: Class<T>): T |
|
open fun <T : EventListener> createListener(c: Class<T>): T |
|
open fun <T : Servlet> createServlet(c: Class<T>): T |
|
open fun declareRoles(vararg roleNames: String): Unit |
|
open fun getAttribute(name: String): Any |
|
open fun getAttributeNames(): Enumeration<String> |
|
open fun getClassLoader(): ClassLoader |
|
open fun getContext(contextPath: String): ServletContext |
|
open fun getContextPath(): String |
|
open fun getDeclaredRoles(): MutableSet<String> |
|
open fun getDefaultServletName(): String
Get the name of the default Defaults to 'default'. |
|
open fun getDefaultSessionTrackingModes(): MutableSet<SessionTrackingMode> |
|
open fun getEffectiveMajorVersion(): Int |
|
open fun getEffectiveMinorVersion(): Int |
|
open fun getEffectiveSessionTrackingModes(): MutableSet<SessionTrackingMode> |
|
open fun getFilterRegistration(filterName: String): FilterRegistration
This method always returns |
|
open fun getFilterRegistrations(): MutableMap<String, out FilterRegistration>
This method always returns an empty map. |
|
open fun getInitParameter(name: String): String |
|
open fun getInitParameterNames(): Enumeration<String> |
|
open fun getJspConfigDescriptor(): JspConfigDescriptor |
|
open fun getMajorVersion(): Int |
|
open fun getMimeType(filePath: String): String |
|
open fun getMinorVersion(): Int |
|
open fun getNamedDispatcher(path: String): RequestDispatcher |
|
open fun getRealPath(path: String): String |
|
open fun getRequestCharacterEncoding(): String |
|
open fun getRequestDispatcher(path: String): RequestDispatcher |
|
open fun getResource(path: String): URL |
|
open fun getResourceAsStream(path: String): InputStream |
|
open fun getResourcePaths(path: String): MutableSet<String> |
|
open fun getResponseCharacterEncoding(): String |
|
open fun getServerInfo(): String |
|
open fun |
|
open fun getServletContextName(): String |
|
open fun |
|
open fun getServletRegistration(servletName: String): ServletRegistration
This method always returns |
|
open fun getServletRegistrations(): MutableMap<String, out ServletRegistration>
This method always returns an empty map. |
|
open fun |
|
open fun getSessionCookieConfig(): SessionCookieConfig |
|
open fun getSessionTimeout(): Int |
|
open fun getVirtualServerName(): String |
|
open fun log(message: String): Unitopen fun open fun log(message: String, ex: Throwable): Unit |
|
open fun registerContext(contextPath: String, context: ServletContext): Unit |
|
open fun registerNamedDispatcher(name: String, requestDispatcher: RequestDispatcher): Unit
Register a RequestDispatcher (typically a MockRequestDispatcher) that acts as a wrapper for the named Servlet. |
|
open fun removeAttribute(name: String): Unit |
|
open fun setAttribute(name: String, value: Any): Unit |
|
open fun setContextPath(contextPath: String): Unit |
|
open fun setDefaultServletName(defaultServletName: String): Unit
Set the name of the default Also |
|
open fun setEffectiveMajorVersion(effectiveMajorVersion: Int): Unit |
|
open fun setEffectiveMinorVersion(effectiveMinorVersion: Int): Unit |
|
open fun setInitParameter(name: String, value: String): Boolean |
|
open fun setMajorVersion(majorVersion: Int): Unit |
|
open fun setMinorVersion(minorVersion: Int): Unit |
|
open fun setRequestCharacterEncoding(requestCharacterEncoding: String): Unit |
|
open fun setResponseCharacterEncoding(responseCharacterEncoding: String): Unit |
|
open fun setServletContextName(servletContextName: String): Unit |
|
open fun setSessionTimeout(sessionTimeout: Int): Unit |
|
open fun setSessionTrackingModes(sessionTrackingModes: MutableSet<SessionTrackingMode>): Unit |
|
open fun unregisterNamedDispatcher(name: String): Unit
Unregister the RequestDispatcher with the given name. |