Class BaseWicketTester
- java.lang.Object
-
- org.apache.wicket.util.tester.BaseWicketTester
-
- Direct Known Subclasses:
WicketTester
public class BaseWicketTester extends java.lang.ObjectA helper class to ease unit testing of Wicket applications without the need for a servlet container. See javadoc ofWicketTesterfor example usage. This class can be used as is, but JUnit users should use derived classWicketTester.- Since:
- 1.2.6
- Author:
- Ingram Chen, Juergen Donnerstag, Frank Bille, Igor Vaynberg
- See Also:
WicketTester
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classBaseWicketTester.StartComponentInPageA page that is used as the automatically created page forstartComponentInPage(Class)and the other variations.classBaseWicketTester.TestFilterConfig
-
Constructor Summary
Constructors Constructor Description BaseWicketTester()CreatesWicketTesterand automatically create aWebApplication, but the tester will have no home page.BaseWicketTester(java.lang.Class<C> homePage)CreatesWicketTesterand automatically creates aWebApplication.BaseWicketTester(WebApplication application)Creates aWicketTester.BaseWicketTester(WebApplication application, boolean init)Creates aWicketTester.BaseWicketTester(WebApplication application, java.lang.String servletContextBasePath)Creates aWicketTester.BaseWicketTester(WebApplication application, javax.servlet.ServletContext servletCtx)Creates aWicketTester.BaseWicketTester(WebApplication application, javax.servlet.ServletContext servletCtx, boolean init)Creates aWicketTester.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddRequestHeader(java.lang.String key, java.lang.String value)Allows to set Request header value any time.voidapplyRequest()RebuildsServletWebRequestused by wicket from the mock request used to build requests.ComponentassertExists(java.lang.String path)voidassertNotExists(java.lang.String path)voidassertResultPage(java.lang.Class<?> pageClass, java.lang.String filename)Asserts last renderedPageagainst an expected HTML document.protected ResultcheckUsability(Component component, boolean throwException)Checks whether a component is visible and/or enabled before usagevoidcleanupFeedbackMessages()Cleans up feedback messages.protected voidcleanupFeedbackMessages(IFeedbackMessageFilter filter)Cleans up feedback messages given the specified filter.voidclearFeedbackMessages()Removes all feedback messagesvoidclickLink(java.lang.String path)Click theLinkin the last rendered Page.voidclickLink(java.lang.String path, boolean isAjax)Click theLinkin the last rendered Page.protected java.lang.StringcreateOriginHeader()Build value to Origin header based on RequestCycle Urlprotected PagecreatePage()Creates aPageto test a component withstartComponentInPage(Component, IMarkupFragment)protected java.lang.StringcreatePageMarkup(java.lang.String componentId)Creates the markup that will be used for the automatically createdPagethat will be used to test a component withstartComponentInPage(Class, IMarkupFragment)voiddebugComponentTrees()Dumps theComponenttrees.voiddebugComponentTrees(java.lang.String filter)Dumps theComponenttrees to log.voiddestroy()Destroys the tester.voiddumpPage()Dumps the source of last renderedPage.voidexecuteAjaxEvent(java.lang.String componentPath, java.lang.String event)Simulates the firing of an Ajax event.voidexecuteAjaxEvent(Component component, java.lang.String event)Simulates the firing of an Ajax event.voidexecuteAjaxUrl(org.apache.wicket.request.Url url)voidexecuteAllTimerBehaviors(MarkupContainer page)Simulates the firing of all ajax timer behaviors on the pagevoidexecuteBehavior(AbstractAjaxBehavior behavior)Builds and processes a request suitable for executing anAbstractAjaxBehavior.voidexecuteListener(Component component)Simulates processing URL that invokes anIRequestListeneron a component.voidexecuteUrl(java.lang.String _url)Starts a page, a shared resource or aIRequestListenerdepending on what theIRequestMappers resolve for the passed url.WebApplicationgetApplication()Returns theApplicationfor this environment.ComponentgetComponentFromLastRenderedPage(java.lang.String path)Gets the component with the given path from last rendered page.ComponentgetComponentFromLastRenderedPage(java.lang.String path, boolean wantVisibleInHierarchy)ComponentgetComponentFromLastRenderedPage(java.lang.String path, boolean wantVisibleInHierarchy, boolean failOnAbsent)Gets the component with the given path from last rendered page.java.lang.StringgetContentDispositionFromResponseHeader()Retrieves the content disposition from the response header.intgetContentLengthFromResponseHeader()Retrieves the content length from the response header.java.lang.StringgetContentTypeFromResponseHeader()Retrieves the content type from the response header.java.util.List<FeedbackMessage>getFeedbackMessages(IFeedbackMessageFilter filter)RetrievesFeedbackMessages.MockHttpSessiongetHttpSession()ReturnsHttpSessionfor this environmentjava.lang.StringgetLastModifiedFromResponseHeader()Retrieves the last-modified value from the response header.PagegetLastRenderedPage()MockHttpServletRequestgetLastRequest()MockHttpServletResponsegetLastResponse()java.lang.StringgetLastResponseAsString()The last response as a string when a page is tested viastartPage()methods.java.util.List<java.io.Serializable>getMessages(int level)RetrievesFeedbackMessages.java.util.List<MockHttpServletRequest>getPreviousRequests()java.util.List<MockHttpServletResponse>getPreviousResponses()MockHttpServletRequestgetRequest()RequestCyclegetRequestCycle()protected org.apache.wicket.util.time.DurationgetResourcePollFrequency()By default Modification Watcher is disabled by default for the tests.MockHttpServletResponsegetResponse()javax.servlet.ServletContextgetServletContext()Returns theServletContextfor this environmentSessiongetSession()TagTestergetTagById(java.lang.String id)Retrieves aTagTesterbased on an DOM id.TagTestergetTagByWicketId(java.lang.String wicketId)Retrieves aTagTesterbased on awicket:id.java.util.List<TagTester>getTagsByWicketId(java.lang.String wicketId)Modified version of BaseWicketTester#getTagByWicketId(String) that returns all matching tags instead of just the first.java.lang.StringgetWicketAjaxBaseUrlEncodedInLastResponse()This method tries to parse the last response to return the encoded base URL and will throw an exception if there none was encoded.ResulthasLabel(java.lang.String path, java.lang.String expectedLabelText)assert the text ofLabelcomponent.ResulthasNoErrorMessage()Asserts no error-level feedback messages.ResulthasNoFeedbackMessage(int level)Asserts there are no feedback messages with the given level.ResulthasNoInfoMessage()Asserts no info-level feedback messages.ResultifContains(java.lang.String pattern)assert the content of last rendered page contains(matches) regex pattern.ResultifContainsNot(java.lang.String pattern)assert the content of last rendered page contains(matches) regex pattern.voidinvokeListener(Component component)Simulates invoking anIRequestListeneron a component.voidinvokeListener(Component component, Behavior behavior)Simulates invoking anIRequestListeneron a component.<C extends Component>
ResultisComponent(java.lang.String path, java.lang.Class<C> expectedComponentClass)assert component classResultisComponentOnAjaxResponse(Component component)Tests that aComponenthas been added to aAjaxRequestTarget, usingIPartialPageRequestHandler.add(org.apache.wicket.Component...).ResultisDisabled(java.lang.String path)assert component disabled.ResultisEnabled(java.lang.String path)assert component enabled.protected ResultisEqual(java.lang.Object expected, java.lang.Object actual)booleanisExposeExceptions()booleanisFollowRedirects()ResultisInvisible(java.lang.String path)assert component invisible.ResultisNotRequired(java.lang.String path)Asserts that a component is not required.ResultisNotRequired(FormComponent<?> component)Asserts that a component is not required.<C extends Page>
ResultisRenderedPage(java.lang.Class<C> expectedRenderedPageClass)Asserts the last renderedPageclass.ResultisRequired(java.lang.String path)assert component required.ResultisRequired(FormComponent<?> component)assert component required.ResultisResultPage(java.lang.String expectedDocument)Asserts last renderedPageagainst an expected HTML document as aString.booleanisUseRequestUrlAsBase()ResultisVisible(java.lang.String path)assert component visible.FormTesternewFormTester(java.lang.String path)Creates aFormTesterfor theFormat a given path, and fills all childFormComponents with blankStrings.FormTesternewFormTester(java.lang.String path, boolean fillBlankString)Creates aFormTesterfor theFormat a given path.protected org.apache.wicket.request.ResponsenewServletWebResponse(ServletWebRequest servletWebRequest)protected IPageManagerProvidernewTestPageManagerProvider()booleanprocessRequest()booleanprocessRequest(MockHttpServletRequest request)Processes the request in mocked Wicket environment.booleanprocessRequest(MockHttpServletRequest request, org.apache.wicket.request.IRequestHandler forcedRequestHandler)Processes the request in mocked Wicket environment.protected booleanprocessRequest(MockHttpServletRequest forcedRequest, org.apache.wicket.request.IRequestHandler forcedRequestHandler, boolean redirect)Process the request.booleanprocessRequest(org.apache.wicket.request.IRequestHandler forcedRequestHandler)protected java.util.LocaleservletRequestLocale()voidsetExposeExceptions(boolean exposeExceptions)voidsetFollowRedirects(boolean followRedirects)Sets whether responses with redirects will be followed automatically.voidsetLastResponse(MockHttpServletResponse response)voidsetRequest(MockHttpServletRequest request)voidsetUseRequestUrlAsBase(boolean setBaseUrl)<C extends Component>
CstartComponentInPage(C component)Process a component.<C extends Component>
CstartComponentInPage(C component, IMarkupFragment pageMarkup)Process a component.<C extends Component>
CstartComponentInPage(java.lang.Class<C> componentClass)Process a component.<C extends Component>
CstartComponentInPage(java.lang.Class<C> componentClass, IMarkupFragment pageMarkup)Process a component.<C extends Page>
CstartPage(java.lang.Class<C> pageClass)Renders aPagefrom its default constructor.<C extends Page>
CstartPage(java.lang.Class<C> pageClass, org.apache.wicket.request.mapper.parameter.PageParameters parameters)Renders aPagefrom its default constructor.PagestartPage(IPageProvider pageProvider)Renders the page specified by givenIPageProvider.<T extends Page>
TstartPage(T page)Renders the page.ResourceReferencestartResource(IResource resource)Simulates a request to a mountedIResourceResourceReferencestartResourceReference(ResourceReference reference)Simulates a request to a mountedResourceReferenceResourceReferencestartResourceReference(ResourceReference reference, org.apache.wicket.request.mapper.parameter.PageParameters pageParameters)Simulates a request to a mountedResourceReferencevoidsubmitForm(java.lang.String path)voidsubmitForm(Form<?> form)Submit the given form in the last renderedPageorg.apache.wicket.request.UrlurlFor(AjaxLink<?> link)java.lang.StringurlFor(Link<?> link)org.apache.wicket.request.UrlurlFor(org.apache.wicket.request.IRequestHandler handler)Encodes theIRequestHandlertoUrl.
-
-
-
Constructor Detail
-
BaseWicketTester
public BaseWicketTester()
CreatesWicketTesterand automatically create aWebApplication, but the tester will have no home page.
-
BaseWicketTester
public BaseWicketTester(java.lang.Class<C> homePage)
CreatesWicketTesterand automatically creates aWebApplication.- Type Parameters:
C-- Parameters:
homePage- a home pageClass
-
BaseWicketTester
public BaseWicketTester(WebApplication application)
Creates aWicketTester.- Parameters:
application- aWicketTesterWebApplicationobject
-
BaseWicketTester
public BaseWicketTester(WebApplication application, java.lang.String servletContextBasePath)
Creates aWicketTester.- Parameters:
application- aWicketTesterWebApplicationobjectservletContextBasePath- the absolute path on disk to the web application's contents (e.g. war root) - may benull
-
BaseWicketTester
public BaseWicketTester(WebApplication application, javax.servlet.ServletContext servletCtx)
Creates aWicketTester.- Parameters:
application- aWicketTesterWebApplicationobjectservletCtx- the servlet context used as backend
-
BaseWicketTester
public BaseWicketTester(WebApplication application, boolean init)
Creates aWicketTester.- Parameters:
application- aWicketTesterWebApplicationobjectinit- force the application to be initialized (default = true)
-
BaseWicketTester
public BaseWicketTester(WebApplication application, javax.servlet.ServletContext servletCtx, boolean init)
Creates aWicketTester.- Parameters:
application- aWicketTesterWebApplicationobjectservletCtx- the servlet context used as backendinit- force the application to be initialized (default = true)
-
-
Method Detail
-
getResourcePollFrequency
protected org.apache.wicket.util.time.Duration getResourcePollFrequency()
By default Modification Watcher is disabled by default for the tests.- Returns:
- the duration between two checks for changes in the resources
-
newTestPageManagerProvider
protected IPageManagerProvider newTestPageManagerProvider()
- Returns:
- page manager provider
-
getLastRenderedPage
public Page getLastRenderedPage()
- Returns:
- last rendered page
-
servletRequestLocale
protected java.util.Locale servletRequestLocale()
-
cleanupFeedbackMessages
public void cleanupFeedbackMessages()
Cleans up feedback messages. This usually happens on detach, but is disabled in unit testing so feedback messages can be examined.
-
clearFeedbackMessages
public void clearFeedbackMessages()
Removes all feedback messages
-
cleanupFeedbackMessages
protected void cleanupFeedbackMessages(IFeedbackMessageFilter filter)
Cleans up feedback messages given the specified filter.- Parameters:
filter- filter used to cleanup messages, accepted messages will be removed
-
newServletWebResponse
protected org.apache.wicket.request.Response newServletWebResponse(ServletWebRequest servletWebRequest)
- Parameters:
servletWebRequest-- Returns:
- servlet web response
-
getRequest
public MockHttpServletRequest getRequest()
- Returns:
- request object
-
setRequest
public void setRequest(MockHttpServletRequest request)
- Parameters:
request-
-
setLastResponse
public void setLastResponse(MockHttpServletResponse response)
- Parameters:
response-
-
getSession
public Session getSession()
- Returns:
- session
-
getHttpSession
public MockHttpSession getHttpSession()
ReturnsHttpSessionfor this environment- Returns:
- session
-
getApplication
public WebApplication getApplication()
Returns theApplicationfor this environment.- Returns:
- application
-
getServletContext
public javax.servlet.ServletContext getServletContext()
Returns theServletContextfor this environment- Returns:
- servlet context
-
destroy
public void destroy()
Destroys the tester. RestoresThreadContextto state before instance ofWicketTesterwas created.
-
processRequest
public boolean processRequest()
- Returns:
- true, if process was executed successfully
-
processRequest
public boolean processRequest(MockHttpServletRequest request)
Processes the request in mocked Wicket environment.- Parameters:
request- request to process- Returns:
- true, if process was executed successfully
-
processRequest
public boolean processRequest(MockHttpServletRequest request, org.apache.wicket.request.IRequestHandler forcedRequestHandler)
Processes the request in mocked Wicket environment.- Parameters:
request- request to processforcedRequestHandler- optional parameter to override parsing the request URL and forceIRequestHandler- Returns:
- true, if process was executed successfully
-
processRequest
public boolean processRequest(org.apache.wicket.request.IRequestHandler forcedRequestHandler)
- Parameters:
forcedRequestHandler-- Returns:
- true, if process was executed successfully
-
processRequest
protected boolean processRequest(MockHttpServletRequest forcedRequest, org.apache.wicket.request.IRequestHandler forcedRequestHandler, boolean redirect)
Process the request. This is a fairly central function and is almost always invoked for executing the request.You may subclass processRequest it, to monitor or change any pre-configured value. Request headers can be configured more easily by calling
addRequestHeader(String, String).- Parameters:
forcedRequest- Can be null.forcedRequestHandler- Can be null.redirect-- Returns:
- true, if process was executed successfully
-
addRequestHeader
public final void addRequestHeader(java.lang.String key, java.lang.String value)Allows to set Request header value any time. They'll be applied (add/modify) on process executionprocessRequest(MockHttpServletRequest, IRequestHandler, boolean). They are reset immediately after and thus are not re-used for a sequence of requests.Deletion (not replace) of pre-configured header value can be achieved by subclassing
processRequest(MockHttpServletRequest, IRequestHandler, boolean)and modifying the request header directly.- Parameters:
key-value-
-
startPage
public Page startPage(IPageProvider pageProvider)
Renders the page specified by givenIPageProvider. After render the page instance can be retrieved usinggetLastRenderedPage()and the rendered document will be available ingetLastResponse(). Depending onRequestCycleSettings.RenderStrategyinvoking this method can mean that a redirect will happen before the actual render.- Parameters:
pageProvider-- Returns:
- last rendered page
-
startPage
public <T extends Page> T startPage(T page)
Renders the page.- Parameters:
page-- Returns:
- Page
- See Also:
startPage(IPageProvider)
-
startResource
public ResourceReference startResource(IResource resource)
Simulates a request to a mountedIResource- Parameters:
resource- the resource to test- Returns:
- the used
ResourceReferencefor the simulation
-
startResourceReference
public ResourceReference startResourceReference(ResourceReference reference)
Simulates a request to a mountedResourceReference- Parameters:
reference- the resource reference to test- Returns:
- the tested resource reference
-
startResourceReference
public ResourceReference startResourceReference(ResourceReference reference, org.apache.wicket.request.mapper.parameter.PageParameters pageParameters)
Simulates a request to a mountedResourceReference- Parameters:
reference- the resource reference to testpageParameters- the parameters passed to the resource reference- Returns:
- the tested resource reference
-
getLastResponse
public MockHttpServletResponse getLastResponse()
- Returns:
- last response or
null> if no response has been produced yet.
-
getLastResponseAsString
public java.lang.String getLastResponseAsString()
The last response as a string when a page is tested viastartPage()methods.In case the processed component was not a
Pagethen the automatically created page markup gets removed. If you need the whole returned markup in this case usegetLastResponse().getDocument()- Returns:
- last response as String.
-
getWicketAjaxBaseUrlEncodedInLastResponse
public java.lang.String getWicketAjaxBaseUrlEncodedInLastResponse() throws java.io.IOException, java.text.ParseExceptionThis method tries to parse the last response to return the encoded base URL and will throw an exception if there none was encoded.- Returns:
- Wicket-Ajax-BaseURL set on last response by
AbstractDefaultAjaxBehavior - Throws:
java.io.IOExceptionjava.text.ParseException
-
getPreviousRequests
public java.util.List<MockHttpServletRequest> getPreviousRequests()
- Returns:
- list of prior requests
-
getPreviousResponses
public java.util.List<MockHttpServletResponse> getPreviousResponses()
- Returns:
- list of prior responses
-
setFollowRedirects
public void setFollowRedirects(boolean followRedirects)
Sets whether responses with redirects will be followed automatically.- Parameters:
followRedirects-
-
isFollowRedirects
public boolean isFollowRedirects()
- Returns:
trueif redirect responses will be followed automatically,falseotherwise.
-
urlFor
public org.apache.wicket.request.Url urlFor(org.apache.wicket.request.IRequestHandler handler)
Encodes theIRequestHandlertoUrl. It should be safe to call this method outside request thread as log as no registeredIRequestMapperrequires aRequestCycle.- Parameters:
handler-- Returns:
Urlfor handler.
-
urlFor
public java.lang.String urlFor(Link<?> link)
- Parameters:
link-- Returns:
- url for Link
-
executeListener
public void executeListener(Component component)
Simulates processing URL that invokes anIRequestListeneron a component. After the listener is invoked the page containing the component will be rendered (with an optional redirect - depending onRequestCycleSettings.RenderStrategy).- Parameters:
component-
-
invokeListener
public void invokeListener(Component component)
Simulates invoking anIRequestListeneron a component. As opposed to theexecuteListener(Component)method, current request/response objects will be used After the listener is invoked the page containing the component will be rendered (with an optional redirect - depending onRequestCycleSettings.RenderStrategy).- Parameters:
component-
-
invokeListener
public void invokeListener(Component component, Behavior behavior)
Simulates invoking anIRequestListeneron a component. As opposed to theexecuteListener(Component)method, current request/response objects will be used After the listener is invoked the page containing the component will be rendered (with an optional redirect - depending onRequestCycleSettings.RenderStrategy).- Parameters:
component-behavior-
-
executeBehavior
public void executeBehavior(AbstractAjaxBehavior behavior)
Builds and processes a request suitable for executing anAbstractAjaxBehavior.- Parameters:
behavior- anAbstractAjaxBehaviorto execute
-
createOriginHeader
protected java.lang.String createOriginHeader()
Build value to Origin header based on RequestCycle Url- Returns:
- Origin header
-
urlFor
public org.apache.wicket.request.Url urlFor(AjaxLink<?> link)
- Parameters:
link-- Returns:
- Url
-
executeAjaxUrl
public void executeAjaxUrl(org.apache.wicket.request.Url url)
- Parameters:
url-
-
startPage
public final <C extends Page> C startPage(java.lang.Class<C> pageClass)
Renders aPagefrom its default constructor.- Type Parameters:
C-- Parameters:
pageClass- a testPageclass with default constructor- Returns:
- the rendered
Page
-
startPage
public final <C extends Page> C startPage(java.lang.Class<C> pageClass, org.apache.wicket.request.mapper.parameter.PageParameters parameters)
Renders aPagefrom its default constructor.- Type Parameters:
C-- Parameters:
pageClass- a testPageclass with default constructorparameters- the parameters to use for the class.- Returns:
- the rendered
Page
-
newFormTester
public FormTester newFormTester(java.lang.String path)
Creates aFormTesterfor theFormat a given path, and fills all childFormComponents with blankStrings.- Parameters:
path- path toFormComponent- Returns:
- a
FormTesterinstance for testing theForm - See Also:
newFormTester(String, boolean)
-
newFormTester
public FormTester newFormTester(java.lang.String path, boolean fillBlankString)
Creates aFormTesterfor theFormat a given path.- Parameters:
path- path toFormComponentfillBlankString- specifies whether to fill all childFormComponents with blankStrings- Returns:
- a
FormTesterinstance for testing theForm - See Also:
FormTester
-
startComponentInPage
public final <C extends Component> C startComponentInPage(java.lang.Class<C> componentClass)
Process a component. A web page will be automatically created with the markup created increatePageMarkup(String).Note: the instantiated component will have an auto-generated id. To reach any of its children use their relative path to the component itself. For example if the started component has a child a Link component with id "link" then after starting the component you can click it with:
tester.clickLink("link")- Type Parameters:
C- the type of the component- Parameters:
componentClass- the class of the component to be tested- Returns:
- The component processed
- See Also:
startComponentInPage(org.apache.wicket.Component)
-
startComponentInPage
public final <C extends Component> C startComponentInPage(java.lang.Class<C> componentClass, IMarkupFragment pageMarkup)
Process a component. A web page will be automatically created with thepageMarkupprovided. In case pageMarkup is null, the markup will be automatically created withcreatePageMarkup(String).Note: the instantiated component will have an auto-generated id. To reach any of its children use their relative path to the component itself. For example if the started component has a child a Link component with id "link" then after starting the component you can click it with:
tester.clickLink("link")- Type Parameters:
C- the type of the component- Parameters:
componentClass- the class of the component to be testedpageMarkup- the markup for the Page that will be automatically created. May benull.- Returns:
- The component processed
-
startComponentInPage
public final <C extends Component> C startComponentInPage(C component)
Process a component. A web page will be automatically created with markup created by thecreatePageMarkup(String).Note: the component id is set by the user. To reach any of its children use this id + their relative path to the component itself. For example if the started component has id compId and a Link child component component with id "link" then after starting the component you can click it with:
tester.clickLink("compId:link")- Type Parameters:
C- the type of the component- Parameters:
component- the component to be tested- Returns:
- The component processed
- See Also:
startComponentInPage(Class)
-
startComponentInPage
public final <C extends Component> C startComponentInPage(C component, IMarkupFragment pageMarkup)
Process a component. A web page will be automatically created with thepageMarkupprovided. In casepageMarkupis null, the markup will be automatically created withcreatePageMarkup(String).Note: the component id is set by the user. To reach any of its children use this id + their relative path to the component itself. For example if the started component has id compId and a Link child component component with id "link" then after starting the component you can click it with:
tester.clickLink("compId:link")- Type Parameters:
C- the type of the component- Parameters:
component- the component to be testedpageMarkup- the markup for the Page that will be automatically created. May benull.- Returns:
- The component processed
-
createPageMarkup
protected java.lang.String createPageMarkup(java.lang.String componentId)
Creates the markup that will be used for the automatically createdPagethat will be used to test a component withstartComponentInPage(Class, IMarkupFragment)- Parameters:
componentId- the id of the component to be tested- Returns:
- the markup for the
PageasString. Cannot benull.
-
createPage
protected Page createPage()
Creates aPageto test a component withstartComponentInPage(Component, IMarkupFragment)- Returns:
- a
Pagewhich will contain the component under test as a single child
-
getComponentFromLastRenderedPage
public Component getComponentFromLastRenderedPage(java.lang.String path, boolean wantVisibleInHierarchy)
-
getComponentFromLastRenderedPage
public Component getComponentFromLastRenderedPage(java.lang.String path, boolean wantVisibleInHierarchy, boolean failOnAbsent)
Gets the component with the given path from last rendered page. This method fails in case the component couldn't be found.- Parameters:
path- Path to componentwantVisibleInHierarchy- if true component needs to be visible in hierarchy elsenullis returned- Returns:
- The component at the path
- See Also:
MarkupContainer.get(String)
-
getComponentFromLastRenderedPage
public Component getComponentFromLastRenderedPage(java.lang.String path)
Gets the component with the given path from last rendered page. This method fails in case the component couldn't be found, and it will return null if the component was found, but is not visible.- Parameters:
path- Path to component- Returns:
- The component at the path
- See Also:
MarkupContainer.get(String)
-
hasLabel
public Result hasLabel(java.lang.String path, java.lang.String expectedLabelText)
assert the text ofLabelcomponent.- Parameters:
path- path toLabelcomponentexpectedLabelText- expected label text- Returns:
- a
Result
-
isComponent
public <C extends Component> Result isComponent(java.lang.String path, java.lang.Class<C> expectedComponentClass)
assert component class- Type Parameters:
C-- Parameters:
path- path to componentexpectedComponentClass- expected component class- Returns:
- a
Result
-
isVisible
public Result isVisible(java.lang.String path)
assert component visible.- Parameters:
path- path to component- Returns:
- a
Result
-
isInvisible
public Result isInvisible(java.lang.String path)
assert component invisible.- Parameters:
path- path to component- Returns:
- a
Result
-
isEnabled
public Result isEnabled(java.lang.String path)
assert component enabled.- Parameters:
path- path to component- Returns:
- a
Result
-
isDisabled
public Result isDisabled(java.lang.String path)
assert component disabled.- Parameters:
path- path to component- Returns:
- a
Result
-
assertExists
public Component assertExists(java.lang.String path)
-
assertNotExists
public void assertNotExists(java.lang.String path)
-
isRequired
public Result isRequired(java.lang.String path)
assert component required.- Parameters:
path- path to component- Returns:
- a
Result
-
isRequired
public Result isRequired(FormComponent<?> component)
assert component required.- Parameters:
component- a form component- Returns:
- a
Result
-
isNotRequired
public Result isNotRequired(java.lang.String path)
Asserts that a component is not required.- Parameters:
path- path to component- Returns:
- a
Result
-
isNotRequired
public Result isNotRequired(FormComponent<?> component)
Asserts that a component is not required.- Parameters:
component- a form component- Returns:
- a
Result
-
ifContains
public Result ifContains(java.lang.String pattern)
assert the content of last rendered page contains(matches) regex pattern.- Parameters:
pattern- reqex pattern to match- Returns:
- a
Result
-
ifContainsNot
public Result ifContainsNot(java.lang.String pattern)
assert the content of last rendered page contains(matches) regex pattern.- Parameters:
pattern- reqex pattern to match- Returns:
- a
Result
-
clickLink
public void clickLink(java.lang.String path)
Click theLinkin the last rendered Page.Simulate that AJAX is enabled.
- Parameters:
path- Click theLinkin the last rendered Page.- See Also:
clickLink(String, boolean)
-
clickLink
public void clickLink(java.lang.String path, boolean isAjax)Click theLinkin the last rendered Page.This method also works for
AjaxLink,AjaxFallbackLinkandAjaxSubmitLink.On AjaxLinks and AjaxFallbackLinks the onClick method is invoked with a valid AjaxRequestTarget. In that way you can test the flow of your application when using AJAX.
When clicking an AjaxSubmitLink the form, which the AjaxSubmitLink is attached to is first submitted, and then the onSubmit method on AjaxSubmitLink is invoked. If you have changed some values in the form during your test, these will also be submitted. This should not be used as a replacement for the
FormTesterto test your forms. It should be used to test that the code in your onSubmit method in AjaxSubmitLink actually works.This method is also able to simulate that AJAX (javascript) is disabled on the client. This is done by setting the isAjax parameter to false. If you have an AjaxFallbackLink you can then check that it doesn't fail when invoked as a normal link.
- Parameters:
path- path toLinkcomponentisAjax- Whether to simulate that AJAX (javascript) is enabled or not. If it's false then AjaxLink and AjaxSubmitLink will fail, since it wouldn't work in real life. AjaxFallbackLink will be invoked with null as the AjaxRequestTarget parameter.
-
submitForm
public void submitForm(Form<?> form)
Submit the given form in the last renderedPageNote: Form request parameters have to be set explicitly.
- Parameters:
form- path to component
-
submitForm
public void submitForm(java.lang.String path)
Submits theFormin the last renderedPage.Note: Form request parameters have to be set explicitely.
- Parameters:
path- path to component
-
isRenderedPage
public <C extends Page> Result isRenderedPage(java.lang.Class<C> expectedRenderedPageClass)
Asserts the last renderedPageclass.- Type Parameters:
C-- Parameters:
expectedRenderedPageClass- expected class of last rendered page- Returns:
- a
Result
-
assertResultPage
public void assertResultPage(java.lang.Class<?> pageClass, java.lang.String filename) throws java.lang.ExceptionAsserts last renderedPageagainst an expected HTML document.Use
-Dwicket.replace.expected.results=trueto automatically replace the expected output file.- Parameters:
pageClass- used to load theFile(relative toclazzpackage)filename- expected outputFilename- Throws:
java.lang.Exception
-
isResultPage
public Result isResultPage(java.lang.String expectedDocument)
Asserts last renderedPageagainst an expected HTML document as aString.- Parameters:
expectedDocument- expected output- Returns:
- a
Result
-
hasNoErrorMessage
public Result hasNoErrorMessage()
Asserts no error-level feedback messages.- Returns:
- a
Result - See Also:
hasNoFeedbackMessage(int)
-
hasNoInfoMessage
public Result hasNoInfoMessage()
Asserts no info-level feedback messages.- Returns:
- a
Result - See Also:
hasNoFeedbackMessage(int)
-
hasNoFeedbackMessage
public Result hasNoFeedbackMessage(int level)
Asserts there are no feedback messages with the given level.- Parameters:
level- the level of the feedback message- Returns:
- a
Result
-
getMessages
public java.util.List<java.io.Serializable> getMessages(int level)
RetrievesFeedbackMessages.- Parameters:
level- level of feedback message, for example:FeedbackMessage.DEBUG or FeedbackMessage.INFO.. etc- Returns:
Listof messages (asStrings)- See Also:
FeedbackMessage
-
getFeedbackMessages
public java.util.List<FeedbackMessage> getFeedbackMessages(IFeedbackMessageFilter filter)
RetrievesFeedbackMessages.- Parameters:
filter- A filter that decides which messages to collect- Returns:
Listof messages (asStrings)- See Also:
FeedbackMessage
-
dumpPage
public void dumpPage()
Dumps the source of last renderedPage.
-
debugComponentTrees
public void debugComponentTrees()
Dumps theComponenttrees.
-
debugComponentTrees
public void debugComponentTrees(java.lang.String filter)
Dumps theComponenttrees to log. Show only theComponents whose paths contain the filterString.- Parameters:
filter- a filterString
-
isComponentOnAjaxResponse
public Result isComponentOnAjaxResponse(Component component)
Tests that aComponenthas been added to aAjaxRequestTarget, usingIPartialPageRequestHandler.add(org.apache.wicket.Component...). This method actually tests that aComponentis on the Ajax response sent back to the client.PLEASE NOTE! This method doesn't actually insert the
Componentin the client DOM tree, using JavaScript. But it shouldn't be needed because you have to trust that the Wicket Ajax JavaScript just works.- Parameters:
component- theComponentto test- Returns:
- a
Result
-
executeAjaxEvent
public void executeAjaxEvent(java.lang.String componentPath, java.lang.String event)Simulates the firing of an Ajax event.- Parameters:
componentPath- theComponentpathevent- the event which we simulate being fired. Ifeventisnull, the test will fail.- Since:
- 1.2.3
- See Also:
executeAjaxEvent(Component, String)
-
executeAllTimerBehaviors
public void executeAllTimerBehaviors(MarkupContainer page)
Simulates the firing of all ajax timer behaviors on the page- Parameters:
page- the page which timers will be executed
-
executeAjaxEvent
public void executeAjaxEvent(Component component, java.lang.String event)
Simulates the firing of an Ajax event. You add an Ajax event to aComponentby using:... component.add(new AjaxEventBehavior("ondblclick") { public void onEvent(AjaxRequestTarget) {} }); ...You can then test that the code insideonEventactually does what it's supposed to, using theWicketTester:... tester.executeAjaxEvent(component, "ondblclick"); // Test that the code inside onEvent is correct. ...This also works withAjaxFormSubmitBehavior, where it will "submit" theFormbefore executing the command.PLEASE NOTE! This method doesn't actually insert the
Componentin the client DOM tree, using JavaScript.- Parameters:
component- theComponentthat has theAjaxEventBehaviorwe want to test. If theComponentisnull, the test will fail.event- the event to simulate being fired. Ifeventisnull, the test will fail.
-
getTagByWicketId
public TagTester getTagByWicketId(java.lang.String wicketId)
Retrieves aTagTesterbased on awicket:id. If moreComponents exist with the samewicket:idin the markup, only the first one is returned.- Parameters:
wicketId- thewicket:idto search for- Returns:
- the
TagTesterfor the tag which has the givenwicket:id
-
getTagsByWicketId
public java.util.List<TagTester> getTagsByWicketId(java.lang.String wicketId)
Modified version of BaseWicketTester#getTagByWicketId(String) that returns all matching tags instead of just the first.- Parameters:
wicketId-- Returns:
- List of Tags
-
getTagById
public TagTester getTagById(java.lang.String id)
Retrieves aTagTesterbased on an DOM id. If moreComponents exist with the same id in the markup, only the first one is returned.- Parameters:
id- the DOM id to search for.- Returns:
- the
TagTesterfor the tag which has the given DOM id
-
getContentTypeFromResponseHeader
public java.lang.String getContentTypeFromResponseHeader()
Retrieves the content type from the response header.- Returns:
- the content type from the response header
-
getContentLengthFromResponseHeader
public int getContentLengthFromResponseHeader()
Retrieves the content length from the response header.- Returns:
- the content length from the response header
-
getLastModifiedFromResponseHeader
public java.lang.String getLastModifiedFromResponseHeader()
Retrieves the last-modified value from the response header.- Returns:
- the last-modified value from the response header
-
getContentDispositionFromResponseHeader
public java.lang.String getContentDispositionFromResponseHeader()
Retrieves the content disposition from the response header.- Returns:
- the content disposition from the response header
-
applyRequest
public void applyRequest()
RebuildsServletWebRequestused by wicket from the mock request used to build requests. Sometimes this method is useful when changes need to be checked without processing a request.
-
isEqual
protected final Result isEqual(java.lang.Object expected, java.lang.Object actual)
- Parameters:
expected-actual-- Returns:
- fail with message if not equal
-
checkUsability
protected Result checkUsability(Component component, boolean throwException)
Checks whether a component is visible and/or enabled before usage- Parameters:
component-throwException-- Returns:
- result
-
getRequestCycle
public RequestCycle getRequestCycle()
- Returns:
- request cycle
-
getResponse
public MockHttpServletResponse getResponse()
- Returns:
- servlet response
-
getLastRequest
public MockHttpServletRequest getLastRequest()
- Returns:
- last request
-
isExposeExceptions
public boolean isExposeExceptions()
- Returns:
- true, if exceptions are exposed
-
setExposeExceptions
public void setExposeExceptions(boolean exposeExceptions)
- Parameters:
exposeExceptions-
-
isUseRequestUrlAsBase
public boolean isUseRequestUrlAsBase()
- Returns:
- useRequestUrlAsBase
-
setUseRequestUrlAsBase
public void setUseRequestUrlAsBase(boolean setBaseUrl)
- Parameters:
setBaseUrl-
-
executeUrl
public void executeUrl(java.lang.String _url)
Starts a page, a shared resource or aIRequestListenerdepending on what theIRequestMappers resolve for the passed url.- Parameters:
_url- the url to resolve and execute
-
-