|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectwicket.Application
wicket.protocol.http.WebApplication
wicket.protocol.http.MockWebApplication
public class MockWebApplication
This class provides a mock implementation of a Wicket HTTP based application that can be used for testing. It emulates all of the functionality of an HttpServlet in a controlled, single-threaded environment. It is supported with mock objects for WebSession, HttpServletRequest, HttpServletResponse and ServletContext.
In its most basic usage you can just create a new MockWebApplication. This should be sufficient to allow you to construct components and pages and so on for testing. To use certain features such as localization you must also call setupRequestAndResponse().
The application takes an optional path attribute that defines a directory on the disk which will correspond to the root of the WAR bundle. This can then be used for locating non-application resources.
To actually test the processing of a particular page or component you can also call processRequestCycle() to do all the normal work of a Wicket request.
Between calling setupRequestAndResponse() and processRequestCycle() you can get hold of any of the objects for initialisation. The servlet request object has some handy convenience methods for initialising the request to invoke certain types of pages and components.
After completion of processRequestCycle() you will probably just be testing component states. However, you also have full access to the response document (or binary data) and result codes via the servlet response object.
IMPORTANT NOTES
| Field Summary |
|---|
| Fields inherited from class wicket.Application |
|---|
CONFIGURATION, CONTEXTPATH, DEPLOYMENT, DEVELOPMENT |
| Constructor Summary | |
|---|---|
MockWebApplication(java.lang.String path)
Create the mock http application that can be used for testing. |
|
| Method Summary | |
|---|---|
WebRequestCycle |
createRequestCycle()
Create and process the request cycle using the current request and response information. |
java.lang.Class |
getHomePage()
Application subclasses must specify a home page class by implementing this abstract method. |
Page |
getLastRenderedPage()
Get the page that was just rendered by the last request cycle processing. |
java.util.Map |
getParametersForNextRequest()
Gets the parameters to be set on the next request. |
Page |
getPreviousRenderedPage()
Get the page that was previously |
javax.servlet.ServletContext |
getServletContext()
Get the context object so that we can apply configurations to it. |
MockHttpServletRequest |
getServletRequest()
Get the request object so that we can apply configurations to it. |
MockHttpServletResponse |
getServletResponse()
Get the response object so that we can apply configurations to it. |
MockHttpSession |
getServletSession()
Get the session object so that we can apply configurations to it. |
WebRequest |
getWicketRequest()
Get the wicket request object. |
WebResponse |
getWicketResponse()
Get the wicket response object. |
WebSession |
getWicketSession()
Get the wicket session. |
protected ISessionStore |
newSessionStore()
Creates a new session facade. |
void |
processRequestCycle()
Create and process the request cycle using the current request and response information. |
void |
processRequestCycle(Component component)
Initialize a new WebRequestCycle and all its dependent objects |
void |
processRequestCycle(WebRequestCycle cycle)
Create and process the request cycle using the current request and response information. |
void |
setHomePage(java.lang.Class clazz)
Sets the home page for this mock application |
void |
setParametersForNextRequest(java.util.Map parametersForNextRequest)
Sets the parameters to be set on the next request. |
void |
setupRequestAndResponse()
Reset the request and the response back to a starting state and recreate the necessary wicket request, response and session objects. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public MockWebApplication(java.lang.String path)
path - The absolute path on disk to the web application contents
(e.g. war root) - may be nullMockServletContext| Method Detail |
|---|
public Page getLastRenderedPage()
public Page getPreviousRenderedPage()
public javax.servlet.ServletContext getServletContext()
MockServletContext,
so it is fine to cast the result to this class in order to get access to
the set methods.
public MockHttpServletRequest getServletRequest()
public MockHttpServletResponse getServletResponse()
public MockHttpSession getServletSession()
public WebRequest getWicketRequest()
public WebResponse getWicketResponse()
public WebSession getWicketSession()
public void processRequestCycle(Component component)
component - public void processRequestCycle()
public void processRequestCycle(WebRequestCycle cycle)
cycle - public WebRequestCycle createRequestCycle()
public void setupRequestAndResponse()
public java.util.Map getParametersForNextRequest()
public void setParametersForNextRequest(java.util.Map parametersForNextRequest)
parametersForNextRequest - the parameters to be set on the next requestpublic java.lang.Class getHomePage()
Application
getHomePage in class ApplicationApplication.getHomePage()public void setHomePage(java.lang.Class clazz)
clazz - protected ISessionStore newSessionStore()
Application
newSessionStore in class WebApplicationWebApplication.newSessionStore()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||