|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.wicket.protocol.http.MockWebApplication
public class MockWebApplication
This class provides a mock implementation of a Wicket HTTP based tester 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 and provide your Wicket Application object. 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 tester 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-tester 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 initialization. The servlet request object has some handy convenience methods for Initializing 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
Constructor Summary | |
---|---|
MockWebApplication(WebApplication application,
java.lang.String path)
Create the mock http tester that can be used for testing. |
Method Summary | |
---|---|
WebRequestCycle |
createRequestCycle()
Create and process the request cycle using the current request and response information. |
void |
destroy()
clears this mock application |
WebApplication |
getApplication()
Gets the application object. |
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 |
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. |
boolean |
initializeHttpSessionAsTemporary()
Callback to signal the application to create temporary sessions instead of normal sessions. |
javax.servlet.ServletContext |
newServletContext(java.lang.String path)
Used to create a new mock servlet context. |
void |
postProcessRequestCycle(WebRequestCycle cycle)
|
void |
processRequestCycle()
Create and process the request cycle using the current request and response information. |
void |
processRequestCycle(java.lang.Class pageClass)
Initialize a new WebRequestCycle and all its dependent objects |
void |
processRequestCycle(java.lang.Class pageClass,
PageParameters params)
Initialize a new WebRequestCycle and all its dependent objects |
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 |
setParametersForNextRequest(java.util.Map parametersForNextRequest)
Sets the parameters to be set on the next request. |
WebRequestCycle |
setupRequestAndResponse()
Reset the request and the response back to a starting state and recreate the necessary wicket request, response and session objects. |
WebRequestCycle |
setupRequestAndResponse(boolean isAjax)
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(WebApplication application, java.lang.String path)
application
- The wicket application objectpath
- The absolute path on disk to the web tester contents (e.g. war root) - may be nullMockServletContext
Method Detail |
---|
public boolean initializeHttpSessionAsTemporary()
Session.bind()
. Default
returns false.
public javax.servlet.ServletContext newServletContext(java.lang.String path)
path
- The absolute path on disk to the web tester contents (e.g. war root) - may be null
public final WebApplication getApplication()
public Page getLastRenderedPage()
public Page getPreviousRenderedPage()
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(java.lang.Class pageClass)
pageClass
- public void processRequestCycle(java.lang.Class pageClass, PageParameters params)
pageClass
- params
- public void processRequestCycle()
public void processRequestCycle(WebRequestCycle cycle)
cycle
- public final void postProcessRequestCycle(WebRequestCycle cycle)
cycle
- public WebRequestCycle createRequestCycle()
public WebRequestCycle setupRequestAndResponse(boolean isAjax)
isAjax
- indicates whether the request should be initialized as an ajax request (ajax
header "Wicket-Ajax" is set)public WebRequestCycle setupRequestAndResponse()
public java.util.Map getParametersForNextRequest()
public void setParametersForNextRequest(java.util.Map parametersForNextRequest)
parametersForNextRequest
- the parameters to be set on the next requestpublic void destroy()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |