|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.springframework.mock.web.MockServletContext
public class MockServletContext
Mock implementation of the 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).
MockServletContext(org.springframework.core.io.ResourceLoader),
XmlWebApplicationContext,
GenericWebApplicationContext,
ClassPathXmlApplicationContext,
FileSystemXmlApplicationContext| Constructor Summary | |
|---|---|
MockServletContext()
Create a new MockServletContext, using no base path and a DefaultResourceLoader (i.e. the classpath root as WAR root). |
|
MockServletContext(ResourceLoader resourceLoader)
Create a new MockServletContext, using the specified ResourceLoader and no base path. |
|
MockServletContext(String resourceBasePath)
Create a new MockServletContext, using a DefaultResourceLoader. |
|
MockServletContext(String resourceBasePath,
ResourceLoader resourceLoader)
Create a new MockServletContext. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public MockServletContext()
DefaultResourceLoaderpublic MockServletContext(String resourceBasePath)
resourceBasePath - the WAR root directory (should not end with a slash)DefaultResourceLoaderpublic MockServletContext(ResourceLoader resourceLoader)
resourceLoader - the ResourceLoader to use (or null for the default)
public MockServletContext(String resourceBasePath,
ResourceLoader resourceLoader)
resourceBasePath - the WAR root directory (should not end with a slash)resourceLoader - the ResourceLoader to use (or null for the default)| Method Detail |
|---|
protected String getResourceLocation(String path)
path - the path as specified
public void setContextPath(String contextPath)
public String getContextPath()
public void registerContext(String contextPath,
ServletContext context)
public ServletContext getContext(String contextPath)
getContext in interface ServletContextpublic int getMajorVersion()
getMajorVersion in interface ServletContextpublic int getMinorVersion()
getMinorVersion in interface ServletContextpublic String getMimeType(String filePath)
getMimeType in interface ServletContextpublic Set getResourcePaths(String path)
getResourcePaths in interface ServletContext
public URL getResource(String path)
throws MalformedURLException
getResource in interface ServletContextMalformedURLExceptionpublic InputStream getResourceAsStream(String path)
getResourceAsStream in interface ServletContextpublic RequestDispatcher getRequestDispatcher(String path)
getRequestDispatcher in interface ServletContextpublic RequestDispatcher getNamedDispatcher(String path)
getNamedDispatcher in interface ServletContextpublic Servlet getServlet(String name)
getServlet in interface ServletContextpublic Enumeration getServlets()
getServlets in interface ServletContextpublic Enumeration getServletNames()
getServletNames in interface ServletContextpublic void log(String message)
log in interface ServletContext
public void log(Exception ex,
String message)
log in interface ServletContext
public void log(String message,
Throwable ex)
log in interface ServletContextpublic String getRealPath(String path)
getRealPath in interface ServletContextpublic String getServerInfo()
getServerInfo in interface ServletContextpublic String getInitParameter(String name)
getInitParameter in interface ServletContext
public void addInitParameter(String name,
String value)
public Enumeration getInitParameterNames()
getInitParameterNames in interface ServletContextpublic Object getAttribute(String name)
getAttribute in interface ServletContextpublic Enumeration getAttributeNames()
getAttributeNames in interface ServletContext
public void setAttribute(String name,
Object value)
setAttribute in interface ServletContextpublic void removeAttribute(String name)
removeAttribute in interface ServletContextpublic void setServletContextName(String servletContextName)
public String getServletContextName()
getServletContextName in interface ServletContext
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||