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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|