|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.click.servlet.MockServletContext
Mock implementation of ServletContext
.
Field Summary | |
static String |
DEFAULT_CONTEXT_PATH
The servlet context default context path, "/mock". |
Constructor Summary | |
MockServletContext()
Default constructor for this mock object. |
|
MockServletContext(String contextPath,
String webappPath)
Create the mock object. |
|
MockServletContext(String contextPath,
String webappPath,
String tempPath)
Create the mock object. |
Method Summary | |
void |
addInitParameter(String name,
String value)
Add an init parameter. |
void |
addInitParameters(Map initParameters)
Add the map of init parameters. |
void |
addMimeType(String fileExtension,
String mimeType)
Add a new recognized mime type. |
void |
createTempDir()
Creates a temporary directory as specified by getTempPath() . |
void |
createWebappRoot()
Creates the web application root File getWebappRoot() . |
Object |
getAttribute(String name)
Get an attribute with the given name. |
Enumeration |
getAttributeNames()
Get all of the attribute names. |
ServletContext |
getContext(String name)
Get the context for the given URL path. |
String |
getContextPath()
Return the servlet context path. |
String |
getInitParameter(String name)
Get the init parameter with the given name. |
Enumeration |
getInitParameterNames()
Get the name of all of the init parameters. |
int |
getMajorVersion()
Return the major version of the Servlet spec that this package supports, defaults to 2. |
String |
getMimeType(String name)
Get the mime type for the given file. |
int |
getMinorVersion()
Return the minor version of the Servlet spec that this package supports, defaults to 3. |
RequestDispatcher |
getNamedDispatcher(String name)
Returns a RequestDispatcher for the specified name. |
String |
getRealPath(String name)
Get the real file path of the given resource name. |
RequestDispatcher |
getRequestDispatcher(String path)
Returns a RequestDispatcher for the specified path. |
URL |
getResource(String name)
Get the URL for a particular resource that is relative to the web app root directory. |
InputStream |
getResourceAsStream(String name)
Get an input stream for a particular resource that is relative to the web app root directory or the current classpath. |
Set |
getResourcePaths(String name)
Get the resource paths starting from the web app root directory and then relative to the given name. |
String |
getServerInfo()
Get the server info. |
Servlet |
getServlet(String name)
NOT USED - Servlet Spec requires that this always returns null. |
String |
getServletContextName()
Return the name of the servlet context. |
Enumeration |
getServletNames()
NOT USED - Servlet spec requires that this always returns null. |
Enumeration |
getServlets()
NOT USED - Servlet spec requires that this always returns null. |
String |
getTempPath()
Return the temporary path where files are stored during test runs. |
String |
getWebappPath()
Return the web application path where resources like javascript, css and images can be picked up. |
File |
getWebappRoot()
Return the web application root File where resources like javascript, css and images can be picked up. |
void |
log(Exception e,
String msg)
Log the exception to System.err and the message to System.out. |
void |
log(String msg)
Log the message to System.out. |
void |
log(String msg,
Throwable cause)
Log the cause to System.err and the message to System.out. |
void |
removeAttribute(String name)
Remove an attribute with the given name. |
void |
setAttribute(String name,
Object o)
Set an attribute. |
void |
setContextPath(String contextPath)
Sets the servlet context path. |
void |
setServletContextName(String servletContextName)
Set the servlet context name to the specified value. |
void |
setTempPath(String tempPath)
Set the temporary path where files are stored during test runs. |
void |
setWebappPath(String webappPath)
Sets the mock web application path to the specified webappPath. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final String DEFAULT_CONTEXT_PATH
Constructor Detail |
public MockServletContext()
public MockServletContext(String contextPath, String webappPath)
System.getProperty("user.dir") + "/src/webapp"
In addition to setting the web root directory, this constructor also sets
up a temporary work directory for things like file uploads.
Note this temporary work directory is set as the value of the
ServletContext attribute 'javax.servlet.context.tempdir'.
The temporary work directory defaults to
System.getProperty("java.io.tmpdir").
contextPath
- the servlet context pathwebappPath
- The path to the root of the web applicationpublic MockServletContext(String contextPath, String webappPath, String tempPath)
System.getProperty("user.dir") + "/src/webapp"
In addition to setting the web root directory, this constructor also sets
up a temporary work directory for things like file uploads.
Note this temporary work directory is set as the value of the
ServletContext attribute 'javax.servlet.context.tempdir'.
contextPath
- the servlet context pathwebappPath
- the path to the root of the web applicationtempPath
- the temporary work directoryMethod Detail |
public void createWebappRoot()
getWebappRoot()
.
IllegalStateException
- if the getWebappPath()
cannot
be foundpublic void createTempDir()
getTempPath()
.
IllegalStateException
- if the getTempPath()
is not validpublic void setServletContextName(String servletContextName)
servletContextName
- the servlet context namepublic String getTempPath()
public void setTempPath(String tempPath)
tempPath
- the temporary path where files are stored during test
runspublic String getWebappPath()
public File getWebappRoot()
public void setWebappPath(String webappPath)
getTempPath()
. If getTempPath()
is not set, this method will default tempPath to:
System.getProperty("java.io.tmpdir").
webappPath
- set the context web application pathpublic void addInitParameter(String name, String value)
name
- The parameter namevalue
- The parameter valuepublic void addInitParameters(Map initParameters)
initParameters
- A map of init parameterspublic void addMimeType(String fileExtension, String mimeType)
fileExtension
- The file extension (e.g. "jpg")mimeType
- The mime type (e.g. "image/jpeg")public Object getAttribute(String name)
getAttribute
in interface ServletContext
name
- The attribute name
public Enumeration getAttributeNames()
getAttributeNames
in interface ServletContext
public ServletContext getContext(String name)
getContext
in interface ServletContext
name
- The url path
public String getContextPath()
public void setContextPath(String contextPath)
contextPath
- the servlet context pathpublic String getInitParameter(String name)
getInitParameter
in interface ServletContext
name
- The name
public Enumeration getInitParameterNames()
getInitParameterNames
in interface ServletContext
public int getMajorVersion()
getMajorVersion
in interface ServletContext
public String getMimeType(String name)
ClickUtils.getMimeType(String)
.
getMimeType
in interface ServletContext
name
- The name to get the mime type for
public int getMinorVersion()
getMinorVersion
in interface ServletContext
public String getRealPath(String name)
getRealPath
in interface ServletContext
name
- The name
public RequestDispatcher getRequestDispatcher(String path)
getRequestDispatcher
in interface ServletContext
path
- a String specifying the pathname to the resource
public RequestDispatcher getNamedDispatcher(String name)
getNamedDispatcher
in interface ServletContext
name
- a String specifying the name of a servlet to wrap
public URL getResource(String name) throws MalformedURLException
getResource
in interface ServletContext
name
- The name of the resource to get
MalformedURLException
- If the URL is invalidpublic InputStream getResourceAsStream(String name)
getResourceAsStream
in interface ServletContext
name
- The name of the resource to get
public Set getResourcePaths(String name)
getResourcePaths
in interface ServletContext
name
- The starting name
IllegalArgumentException
- if the specified name does not start
with a "/" characterpublic String getServerInfo()
getServerInfo
in interface ServletContext
public Servlet getServlet(String name) throws ServletException
getServlet
in interface ServletContext
name
- Not used
ServletException
- Not usedpublic String getServletContextName()
getServletContextName
in interface ServletContext
public Enumeration getServletNames()
getServletNames
in interface ServletContext
public Enumeration getServlets()
getServlets
in interface ServletContext
public void log(Exception e, String msg)
log
in interface ServletContext
e
- The exception to logmsg
- The message to logpublic void log(String msg)
log
in interface ServletContext
msg
- The message to logpublic void log(String msg, Throwable cause)
log
in interface ServletContext
msg
- The message to logcause
- The cause exceptionpublic void removeAttribute(String name)
removeAttribute
in interface ServletContext
name
- The namepublic void setAttribute(String name, Object o)
setAttribute
in interface ServletContext
name
- The name of the attributeo
- The value
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |