java.lang.Object | |
↳ | org.springframework.mock.web.MockServletContext |
Mock implementation of the javax.servlet.ServletContext interface.
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).
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Create a new MockServletContext, using no base path and a
DefaultResourceLoader (i.e.
| |||||||||||
Create a new MockServletContext, using a DefaultResourceLoader.
| |||||||||||
Create a new MockServletContext, using the specified ResourceLoader
and no base path.
| |||||||||||
Create a new MockServletContext.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Build a full resource location for the given path,
prepending the resource base path of this MockServletContext.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() | |||||||||||
![]() |
Create a new MockServletContext, using no base path and a DefaultResourceLoader (i.e. the classpath root as WAR root).
Create a new MockServletContext, using a DefaultResourceLoader.
resourceBasePath | the WAR root directory (should not end with a slash) |
---|
Create a new MockServletContext, using the specified ResourceLoader and no base path.
resourceLoader | the ResourceLoader to use (or null for the default) |
---|
Create a new MockServletContext.
resourceBasePath | the WAR root directory (should not end with a slash) |
---|---|
resourceLoader | the ResourceLoader to use (or null for the default) |
Build a full resource location for the given path, prepending the resource base path of this MockServletContext.
path | the path as specified |
---|