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:
Mock implementation of ServletContext
.
WARNING - Before you can get meaningful results from calls to the getResource()
, getResourceAsStream()
, getResourcePaths()
, or getRealPath()
methods, you must configure the documentRoot
property, passing in a File
object pointing at a directory that simulates a web application structure.
Mock implementation of ServletContext
.
WARNING - Before you can get meaningful results from calls to the getResource()
, getResourceAsStream()
, getResourcePaths()
, or getRealPath()
methods, you must configure the documentRoot
property, passing in a File
object pointing at a directory that simulates a web application structure.
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: 421119 $ $Date: 2005-05-07 12:11:38 -0400 (Sat, 07 May 2005)$The context can be configured with a path parameter that should point to an absolute directory location that represents the place where the contents of the WAR bundle are located. Setting this value allows all of the resource location functionality to work as in a fully functioning web application. This value is not set then not resource location functionality will work and instead null will always be returned. @author Chris Turner
The context can be configured with a path parameter that should point to an absolute directory location that represents the place where the contents of the WAR bundle are located. Setting this value allows all of the resource location functionality to work as in a fully functioning web application. This value is not set then not resource location functionality will work and instead null will always be returned. @author Chris Turner
The context can be configured with a path parameter that should point to an absolute directory location that represents the place where the contents of the WAR bundle are located. Setting this value allows all of the resource location functionality to work as in a fully functioning web application. This value is not set then not resource location functionality will work and instead null will always be returned. Adapted from Apache Wicket @author Chris Turner (Wicket)
Used for testing the Spring web framework; only rarely necessary for testing application controllers. As long as application components don't explicitly access the ServletContext, ClassPathXmlApplicationContext or FileSystemXmlApplicationContext can be used to load the context files for testing, even for DispatcherServlet context definitions.
For setting up a full WebApplicationContext in a test environment, you can use XmlWebApplicationContext (or GenericWebApplicationContext), passing in an appropriate MockServletContext instance. You might want to configure your MockServletContext with a FileSystemResourceLoader in that case, to make your resource paths interpreted as relative file system locations.
A common setup is to point your JVM working directory to the root of your web application directory, in combination with filesystem-based resource loading. This allows to load the context files as used in the web application, with relative paths getting interpreted correctly. Such a setup will work with both FileSystemXmlApplicationContext (which will load straight from the file system) and XmlWebApplicationContext with an underlying MockServletContext (as long as the MockServletContext has been configured with a FileSystemResourceLoader). @author Rod Johnson @author Juergen Hoeller @since 1.0.2 @see #MockServletContext(org.springframework.core.io.ResourceLoader) @see org.springframework.web.context.support.XmlWebApplicationContext @see org.springframework.web.context.support.GenericWebApplicationContext @see org.springframework.context.support.ClassPathXmlApplicationContext @see org.springframework.context.support.FileSystemXmlApplicationContext
As of Spring 4.0, this set of mocks is designed on a Servlet 3.0 baseline.
Compatible with Servlet 3.0 but can be configured to expose a specific version through {@link #setMajorVersion}/ {@link #setMinorVersion}; default is 3.0. Note that Servlet 3.0 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.
Used for testing the Spring web framework; only rarely necessary for testing application controllers. As long as application components don't explicitly access the {@code ServletContext}, {@code ClassPathXmlApplicationContext} or{@code FileSystemXmlApplicationContext} can be used to load the context filesfor testing, even for {@code DispatcherServlet} context definitions.
For setting up a full {@code WebApplicationContext} in a test environment,you can use {@code AnnotationConfigWebApplicationContext}, {@code XmlWebApplicationContext}, or {@code GenericWebApplicationContext}, passing in an appropriate {@code MockServletContext} instance. You might wantto configure your {@code MockServletContext} with a {@code FileSystemResourceLoader}in that case to ensure that resource paths are interpreted as relative filesystem locations.
A common setup is to point your JVM working directory to the root of your web application directory, in combination with filesystem-based resource loading. This allows to load the context files as used in the web application, with relative paths getting interpreted correctly. Such a setup will work with both {@code FileSystemXmlApplicationContext} (which will load straight from thefilesystem) and {@code XmlWebApplicationContext} with an underlying{@code MockServletContext} (as long as the {@code MockServletContext} has beenconfigured with a {@code FileSystemResourceLoader}). @author Rod Johnson @author Juergen Hoeller @author Sam Brannen @since 1.0.2 @see #MockServletContext(org.springframework.core.io.ResourceLoader) @see org.springframework.web.context.support.AnnotationConfigWebApplicationContext @see org.springframework.web.context.support.XmlWebApplicationContext @see org.springframework.web.context.support.GenericWebApplicationContext @see org.springframework.context.support.ClassPathXmlApplicationContext @see org.springframework.context.support.FileSystemXmlApplicationContext
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|