|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.wicket.protocol.http.mock.MockServletContext
public class MockServletContext
Mock implementation of the servlet context for testing purposes. This implementation supports all of the standard context methods except that request dispatching just indicates what is being dispatched to, rather than doing the actual dispatch.
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.
| Constructor Summary | |
|---|---|
MockServletContext(Application application,
String path)
Create the mock object. |
|
| Method Summary | |
|---|---|
void |
addInitParameter(String name,
String value)
Add an init parameter. |
void |
addMimeType(String fileExtension,
String mimeType)
Add a new recognized mime type. |
Object |
getAttribute(String name)
Get an attribute with the given name. |
Enumeration<String> |
getAttributeNames()
Get all of the attribute names. |
javax.servlet.ServletContext |
getContext(String name)
Get the context for the given URL path |
String |
getContextPath()
|
String |
getInitParameter(String name)
Get the init parameter with the given name. |
Enumeration<String> |
getInitParameterNames()
Get the name of all of the init parameters. |
int |
getMajorVersion()
|
String |
getMimeType(String name)
Get the mime type for the given file. |
int |
getMinorVersion()
|
javax.servlet.RequestDispatcher |
getNamedDispatcher(String name)
Wicket does not use the RequestDispatcher, so this implementation just returns a dummy value. |
String |
getRealPath(String name)
Get the real file path of the given resource name. |
javax.servlet.RequestDispatcher |
getRequestDispatcher(String name)
Wicket does not use the RequestDispatcher, so this implementation just returns a dummy value. |
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. |
Set<String> |
getResourcePaths(String name)
Get the resource paths starting from the web app root directory and then relative to the the given name. |
String |
getServerInfo()
Get the server info. |
javax.servlet.Servlet |
getServlet(String name)
NOT USED - Servlet Spec requires that this always returns null. |
String |
getServletContextName()
Return the name of the servlet context. |
Enumeration<String> |
getServletNames()
NOT USED - Servlet spec requires that this always returns null. |
Enumeration<javax.servlet.Servlet> |
getServlets()
NOT USED - Servlet spec requires that this always returns null. |
void |
log(Exception e,
String msg)
As part of testing we always log to the console. |
void |
log(String msg)
As part of testing we always log to the console. |
void |
log(String msg,
Throwable cause)
As part of testing we always log to the console. |
void |
removeAttribute(String name)
Remove an attribute with the given name. |
void |
setAttribute(String name,
Object o)
Set an attribute. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public MockServletContext(Application application,
String path)
System.getProperty("user.dir") +
"/src/webapp"
application - The application that this context is forpath - The path to the root of the web application| Method Detail |
|---|
public void addInitParameter(String name,
String value)
name - The parameter namevalue - The parameter value
public 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 javax.servlet.ServletContextname - The attribute name
public Enumeration<String> getAttributeNames()
getAttributeNames in interface javax.servlet.ServletContextpublic javax.servlet.ServletContext getContext(String name)
getContext in interface javax.servlet.ServletContextname - The url path
public String getInitParameter(String name)
getInitParameter in interface javax.servlet.ServletContextname - The name
public Enumeration<String> getInitParameterNames()
getInitParameterNames in interface javax.servlet.ServletContextpublic int getMajorVersion()
getMajorVersion in interface javax.servlet.ServletContextpublic String getMimeType(String name)
getMimeType in interface javax.servlet.ServletContextname - The name to get the mime type for
public int getMinorVersion()
getMinorVersion in interface javax.servlet.ServletContextpublic javax.servlet.RequestDispatcher getNamedDispatcher(String name)
getNamedDispatcher in interface javax.servlet.ServletContextname - The name of the servlet or JSP
public String getRealPath(String name)
getRealPath in interface javax.servlet.ServletContextname - The name
public javax.servlet.RequestDispatcher getRequestDispatcher(String name)
getRequestDispatcher in interface javax.servlet.ServletContextname - The name of the resource to get the dispatcher for
public URL getResource(String name)
throws MalformedURLException
getResource in interface javax.servlet.ServletContextname - The name of the resource to get
MalformedURLException - If the URL is invalidpublic InputStream getResourceAsStream(String name)
getResourceAsStream in interface javax.servlet.ServletContextname - The name of the resource to get
public Set<String> getResourcePaths(String name)
getResourcePaths in interface javax.servlet.ServletContextname - The starting name
public String getServerInfo()
getServerInfo in interface javax.servlet.ServletContext
public javax.servlet.Servlet getServlet(String name)
throws javax.servlet.ServletException
getServlet in interface javax.servlet.ServletContextname - Not used
javax.servlet.ServletException - Not usedpublic String getServletContextName()
getServletContextName in interface javax.servlet.ServletContextpublic Enumeration<String> getServletNames()
getServletNames in interface javax.servlet.ServletContextpublic Enumeration<javax.servlet.Servlet> getServlets()
getServlets in interface javax.servlet.ServletContext
public void log(Exception e,
String msg)
log in interface javax.servlet.ServletContexte - The exception to logmsg - The message to logpublic void log(String msg)
log in interface javax.servlet.ServletContextmsg - The message to log
public void log(String msg,
Throwable cause)
log in interface javax.servlet.ServletContextmsg - The message to logcause - The cause exceptionpublic void removeAttribute(String name)
removeAttribute in interface javax.servlet.ServletContextname - The name
public void setAttribute(String name,
Object o)
setAttribute in interface javax.servlet.ServletContextname - The name of the attributeo - The valuepublic String getContextPath()
getContextPath in interface javax.servlet.ServletContext
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||