org.apache.wicket.util.tester
Class BaseWicketTester

java.lang.Object
  extended by org.apache.wicket.util.tester.BaseWicketTester
Direct Known Subclasses:
WicketTester

public class BaseWicketTester
extends java.lang.Object

A helper class to ease unit testing of Wicket applications without the need for a servlet container. See javadoc of WicketTester for example usage. This class can be used as is, but JUnit users should use derived class WicketTester.

Since:
1.2.6
Author:
Ingram Chen, Juergen Donnerstag, Frank Bille, Igor Vaynberg
See Also:
WicketTester

Nested Class Summary
static class BaseWicketTester.StartComponentInPage
          A page that is used as the automatically created page for startComponentInPage(Class) and the other variations.
 
Constructor Summary
BaseWicketTester()
          Creates WicketTester and automatically create a WebApplication, but the tester will have no home page.
BaseWicketTester(java.lang.Class<C> homePage)
          Creates WicketTester and automatically creates a WebApplication.
BaseWicketTester(WebApplication application)
          Creates a WicketTester.
BaseWicketTester(WebApplication application, javax.servlet.ServletContext servletCtx)
          Creates a WicketTester.
BaseWicketTester(WebApplication application, java.lang.String servletContextBasePath)
          Creates a WicketTester.
 
Method Summary
 void addRequestHeader(java.lang.String key, java.lang.String value)
          Allows to set Request header value any time.
 void applyRequest()
          Rebuilds ServletWebRequest used by wicket from the mock request used to build requests.
 void assertListView(java.lang.String path, java.util.List<?> expectedList)
          assert the model of ListView use expectedList
 void assertResultPage(java.lang.Class<?> pageClass, java.lang.String filename)
          Asserts last rendered Page against an expected HTML document.
protected  Result checkUsability(Component component, boolean throwException)
          Checks whether a component is visible and/or enabled before usage
 void clickLink(java.lang.String path)
          Click the Link in the last rendered Page.
 void clickLink(java.lang.String path, boolean isAjax)
          Click the Link in the last rendered Page.
protected  Page createPage()
          Creates a BaseWicketTester.StartComponentInPage to test a component with startComponentInPage(Component, IMarkupFragment)
protected  java.lang.String createPageMarkup(java.lang.String componentId)
          Creates the markup that will be used for the automatically created BaseWicketTester.StartComponentInPage that will be used to test a component with startComponentInPage(Class, IMarkupFragment)
 void debugComponentTrees()
          Dumps the Component trees.
 void debugComponentTrees(java.lang.String filter)
          Dumps the Component trees to log.
 void destroy()
          Destroys the tester.
 void dumpPage()
          Dumps the source of last rendered Page.
 void executeAjaxEvent(Component component, java.lang.String event)
          Simulates the firing of an Ajax event.
 void executeAjaxEvent(java.lang.String componentPath, java.lang.String event)
          Simulates the firing of an Ajax event.
 void executeAjaxUrl(Url url)
           
 void executeAllTimerBehaviors(MarkupContainer container)
          Simulates the firing of all ajax timer behaviors on the page
 void executeBehavior(AbstractAjaxBehavior behavior)
          Builds and processes a request suitable for executing an AbstractAjaxBehavior.
 void executeListener(Component component)
          Builds and processes a request suitable for invoking a listener.
 void executeListener(Component component, RequestListenerInterface listener)
          Simulates processing URL that invokes specified RequestListenerInterface on component.
 void executeUrl(java.lang.String _url)
          Starts a page, a shared resource or a IRequestListener depending on what the IRequestMappers resolve for the passed url.
 WebApplication getApplication()
          Returns the Application for this environment.
 Component getComponentFromLastRenderedPage(java.lang.String path)
          Gets the component with the given path from last rendered page.
 Component getComponentFromLastRenderedPage(java.lang.String path, boolean wantVisibleInHierarchy)
          Gets the component with the given path from last rendered page.
 java.lang.String getContentDispositionFromResponseHeader()
          Retrieves the content disposition from the response header.
 int getContentLengthFromResponseHeader()
          Retrieves the content length from the response header.
 java.lang.String getContentTypeFromResponseHeader()
          Retrieves the content type from the response header.
 MockHttpSession getHttpSession()
          Returns HttpSession for this environment
 java.lang.String getLastModifiedFromResponseHeader()
          Retrieves the last-modified value from the response header.
 Page getLastRenderedPage()
           
 MockHttpServletRequest getLastRequest()
           
 MockHttpServletResponse getLastResponse()
           
 java.lang.String getLastResponseAsString()
          The last response as a string when a page is tested via startPage() methods.
 java.util.List<java.io.Serializable> getMessages(int level)
          Retrieves FeedbackMessages.
 java.util.List<MockHttpServletRequest> getPreviousRequests()
           
 java.util.List<MockHttpServletResponse> getPreviousResponses()
           
 MockHttpServletRequest getRequest()
           
 RequestCycle getRequestCycle()
           
protected  Duration getResourcePollFrequency()
          By default Modification Watcher is disabled by default for the tests.
 MockHttpServletResponse getResponse()
           
 javax.servlet.ServletContext getServletContext()
          Returns the ServletContext for this environment
 Session getSession()
           
 TagTester getTagById(java.lang.String id)
          Retrieves a TagTester based on an DOM id.
 TagTester getTagByWicketId(java.lang.String wicketId)
          Retrieves a TagTester based on a wicket: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.String getWicketAjaxBaseUrlEncodedInLastResponse()
          This method tries to parse the last response to return the encoded base URL and will throw an exception if there none was encoded.
 Result hasLabel(java.lang.String path, java.lang.String expectedLabelText)
          assert the text of Label component.
 Result hasNoErrorMessage()
          Asserts no error-level feedback messages.
 Result hasNoInfoMessage()
          Asserts no info-level feedback messages.
 Result ifContains(java.lang.String pattern)
          assert the content of last rendered page contains(matches) regex pattern.
 Result ifContainsNot(java.lang.String pattern)
          assert the content of last rendered page contains(matches) regex pattern.
<C extends Component>
Result
isComponent(java.lang.String path, java.lang.Class<C> expectedComponentClass)
          assert component class
 Result isComponentOnAjaxResponse(Component component)
          Tests that a Component has been added to a AjaxRequestTarget, using AjaxRequestTarget#add(Component).
 Result isDisabled(java.lang.String path)
          assert component disabled.
 Result isEnabled(java.lang.String path)
          assert component enabled.
protected  Result isEqual(java.lang.Object expected, java.lang.Object actual)
           
 boolean isExposeExceptions()
           
 boolean isFollowRedirects()
           
 Result isInvisible(java.lang.String path)
          assert component invisible.
<C extends Page>
Result
isRenderedPage(java.lang.Class<C> expectedRenderedPageClass)
          Asserts the last rendered Page class.
 Result isRequired(FormComponent<?> component)
          assert component required.
 Result isRequired(java.lang.String path)
          assert component required.
 Result isResultPage(java.lang.String expectedDocument)
          Asserts last rendered Page against an expected HTML document as a String.
 boolean isUseRequestUrlAsBase()
           
 Result isVisible(java.lang.String path)
          assert component visible.
 FormTester newFormTester(java.lang.String path)
          Creates a FormTester for the Form at a given path, and fills all child FormComponents with blank Strings.
 FormTester newFormTester(java.lang.String path, boolean fillBlankString)
          Creates a FormTester for the Form at a given path.
protected  Response newServletWebResponse(ServletWebRequest servletWebRequest)
           
protected  IPageManagerProvider newTestPageManagerProvider()
           
 boolean processRequest()
           
 boolean processRequest(IRequestHandler forcedRequestHandler)
           
 boolean processRequest(MockHttpServletRequest request)
          Processes the request in mocked Wicket environment.
 boolean processRequest(MockHttpServletRequest request, IRequestHandler forcedRequestHandler)
          Processes the request in mocked Wicket environment.
protected  boolean processRequest(MockHttpServletRequest forcedRequest, IRequestHandler forcedRequestHandler, boolean redirect)
          Process the request.
 void setExposeExceptions(boolean exposeExceptions)
           
 void setFollowRedirects(boolean followRedirects)
          Sets whether responses with redirects will be followed automatically.
 void setRequest(MockHttpServletRequest request)
           
 void setUseRequestUrlAsBase(boolean setBaseUrl)
           
 Component startComponent(Component component)
          A helper method for starting a component for a test without attaching it to a Page.
<C extends Component>
C
startComponentInPage(C component)
          Process a component.
<C extends Component>
C
startComponentInPage(C component, IMarkupFragment pageMarkup)
          Process a component.
<C extends Component>
C
startComponentInPage(java.lang.Class<C> componentClass)
          Process a component.
<C extends Component>
C
startComponentInPage(java.lang.Class<C> componentClass, IMarkupFragment pageMarkup)
          Process a component.
<C extends Page>
C
startPage(java.lang.Class<C> pageClass)
          Renders a Page from its default constructor.
<C extends Page>
C
startPage(java.lang.Class<C> pageClass, PageParameters parameters)
          Renders a Page from its default constructor.
 Page startPage(IPageProvider pageProvider)
          Renders the page specified by given IPageProvider.
 Page startPage(ITestPageSource testPageSource)
          Deprecated. since 1.5 use startPage(Page) instead
 Page startPage(Page page)
          Renders the page.
<C extends Panel>
C
startPanel(java.lang.Class<C> panelClass)
          Renders a Panel from a Panel(String id) constructor.
 Panel startPanel(ITestPanelSource testPanelSource)
          Deprecated. since 1.5 use startComponentInPage(Class, IMarkupFragment) instead
 ResourceReference startResource(IResource resource)
          Simulates a request to a mounted IResource
 ResourceReference startResourceReference(ResourceReference reference)
          Simulates a request to a mounted ResourceReference
 ResourceReference startResourceReference(ResourceReference reference, PageParameters pageParameters)
          Simulates a request to a mounted ResourceReference
 void submitForm(Form<?> form)
           
 void submitForm(java.lang.String path)
          Submits the Form in the last rendered Page.
 Url urlFor(AjaxLink<?> link)
           
 Url urlFor(IRequestHandler handler)
          Encodes the IRequestHandler to Url.
 java.lang.String urlFor(Link<?> link)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BaseWicketTester

public BaseWicketTester()
Creates WicketTester and automatically create a WebApplication, but the tester will have no home page.


BaseWicketTester

public BaseWicketTester(java.lang.Class<C> homePage)
Creates WicketTester and automatically creates a WebApplication.

Type Parameters:
C -
Parameters:
homePage - a home page Class

BaseWicketTester

public BaseWicketTester(WebApplication application)
Creates a WicketTester.

Parameters:
application - a WicketTester WebApplication object

BaseWicketTester

public BaseWicketTester(WebApplication application,
                        java.lang.String servletContextBasePath)
Creates a WicketTester.

Parameters:
application - a WicketTester WebApplication object
servletContextBasePath - the absolute path on disk to the web application's contents (e.g. war root) - may be null

BaseWicketTester

public BaseWicketTester(WebApplication application,
                        javax.servlet.ServletContext servletCtx)
Creates a WicketTester.

Parameters:
application - a WicketTester WebApplication object
servletCtx - the servlet context used as backend
Method Detail

getResourcePollFrequency

protected 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

newServletWebResponse

protected 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 -

getSession

public Session getSession()
Returns:
session

getHttpSession

public MockHttpSession getHttpSession()
Returns HttpSession for this environment

Returns:
session

getApplication

public WebApplication getApplication()
Returns the Application for this environment.

Returns:
application

getServletContext

public javax.servlet.ServletContext getServletContext()
Returns the ServletContext for this environment

Returns:
servlet context

destroy

public void destroy()
Destroys the tester. Restores ThreadContext to state before instance of WicketTester was 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,
                              IRequestHandler forcedRequestHandler)
Processes the request in mocked Wicket environment.

Parameters:
request - request to process
forcedRequestHandler - optional parameter to override parsing the request URL and force IRequestHandler
Returns:
true, if process was executed successfully

processRequest

public boolean processRequest(IRequestHandler forcedRequestHandler)
Parameters:
forcedRequestHandler -
Returns:
true, if process was executed successfully

processRequest

protected boolean processRequest(MockHttpServletRequest forcedRequest,
                                 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 execution processRequest(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 given IPageProvider. After render the page instance can be retrieved using getLastRenderedPage() and the rendered document will be available in getLastResponse(). Depending on IRequestCycleSettings.RenderStrategy invoking this method can mean that a redirect will happen before the actual render.

Parameters:
pageProvider -
Returns:
last rendered page

startPage

public Page startPage(Page page)
Renders the page.

Parameters:
page -
Returns:
Page
See Also:
startPage(IPageProvider)

startResource

public ResourceReference startResource(IResource resource)
Simulates a request to a mounted IResource

Parameters:
resource - the resource to test
Returns:
the used ResourceReference for the simulation

startResourceReference

public ResourceReference startResourceReference(ResourceReference reference)
Simulates a request to a mounted ResourceReference

Parameters:
reference - the resource reference to test
Returns:
the tested resource reference

startResourceReference

public ResourceReference startResourceReference(ResourceReference reference,
                                                PageParameters pageParameters)
Simulates a request to a mounted ResourceReference

Parameters:
reference - the resource reference to test
pageParameters - 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 via startPage() methods.

In case the processed component was not a BaseWicketTester.StartComponentInPage then the automatically created page markup gets removed. If you need the whole returned markup in this case use getLastResponse().getDocument()

Returns:
last response as String.

getWicketAjaxBaseUrlEncodedInLastResponse

public java.lang.String getWicketAjaxBaseUrlEncodedInLastResponse()
                                                           throws java.io.IOException,
                                                                  ResourceStreamNotFoundException,
                                                                  java.text.ParseException
This 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.IOException
ResourceStreamNotFoundException
java.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:
true if redirect responses will be followed automatically, false otherwise.

urlFor

public Url urlFor(IRequestHandler handler)
Encodes the IRequestHandler to Url. It should be safe to call this method outside request thread as log as no registered IRequestMapper requires a RequestCycle.

Parameters:
handler -
Returns:
Url for handler.

urlFor

public java.lang.String urlFor(Link<?> link)
Parameters:
link -
Returns:
url for Link

startPage

@Deprecated
public final Page startPage(ITestPageSource testPageSource)
Deprecated. since 1.5 use startPage(Page) instead

Renders a Page defined in TestPageSource. This is usually used when a page does not have default constructor. For example, a ViewBook page requires a Book instance:
 tester.startPage(new TestPageSource()
 {
        public Page getTestPage()
        {
                Book mockBook = new Book("myBookName");
                return new ViewBook(mockBook);
        }
 });
 

Parameters:
testPageSource - a Page factory that creates a test page instance
Returns:
the rendered Page

executeListener

public void executeListener(Component component,
                            RequestListenerInterface listener)
Simulates processing URL that invokes specified RequestListenerInterface on component. After the listener interface is invoked the page containing the component will be rendered (with an optional redirect - depending on IRequestCycleSettings.RenderStrategy).

Parameters:
component -
listener -

executeListener

public void executeListener(Component component)
Builds and processes a request suitable for invoking a listener. The Component must implement any of the known IListener interfaces.

Parameters:
component - the listener to invoke

executeBehavior

public void executeBehavior(AbstractAjaxBehavior behavior)
Builds and processes a request suitable for executing an AbstractAjaxBehavior.

Parameters:
behavior - an AbstractAjaxBehavior to execute

urlFor

public Url urlFor(AjaxLink<?> link)
Parameters:
link -
Returns:
Url

executeAjaxUrl

public void executeAjaxUrl(Url url)
Parameters:
url -

startPage

public final <C extends Page> C startPage(java.lang.Class<C> pageClass)
Renders a Page from its default constructor.

Type Parameters:
C -
Parameters:
pageClass - a test Page class with default constructor
Returns:
the rendered Page

startPage

public final <C extends Page> C startPage(java.lang.Class<C> pageClass,
                                          PageParameters parameters)
Renders a Page from its default constructor.

Type Parameters:
C -
Parameters:
pageClass - a test Page class with default constructor
parameters - the parameters to use for the class.
Returns:
the rendered Page

newFormTester

public FormTester newFormTester(java.lang.String path)
Creates a FormTester for the Form at a given path, and fills all child FormComponents with blank Strings.

Parameters:
path - path to FormComponent
Returns:
a FormTester instance for testing the Form
See Also:
newFormTester(String, boolean)

newFormTester

public FormTester newFormTester(java.lang.String path,
                                boolean fillBlankString)
Creates a FormTester for the Form at a given path.

Parameters:
path - path to FormComponent
fillBlankString - specifies whether to fill all child FormComponents with blank Strings
Returns:
a FormTester instance for testing the Form
See Also:
FormTester

startPanel

@Deprecated
public final Panel startPanel(ITestPanelSource testPanelSource)
Deprecated. since 1.5 use startComponentInPage(Class, IMarkupFragment) instead

Renders a Panel defined in TestPanelSource. The usage is similar to startPage(ITestPageSource). Please note that testing Panel must use the supplied panelId as a Component id.
 tester.startPanel(new TestPanelSource()
 {
        public Panel getTestPanel(String panelId)
        {
                MyData mockMyData = new MyData();
                return new MyPanel(panelId, mockMyData);
        }
 });
 
Note that when try to access a component, e.g. via accessLabel(), the 'path' parameter must be relative to the panel. Not relative to the Page which will automatically be added for you.

Parameters:
testPanelSource - a Panel factory that creates test Panel instances
Returns:
a rendered Panel

startPanel

public final <C extends Panel> C startPanel(java.lang.Class<C> panelClass)
Renders a Panel from a Panel(String id) constructor.

Note that when try to access a component, e.g. via accessLabel(), the 'path' parameter must be relative to the panel. Not relative to the Page which will automatically be added for you.

Type Parameters:
C - the type of the component
Parameters:
panelClass - a test Panel class with Panel(String id) constructor
Returns:
a rendered Panel

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 in createPageMarkup(String).

Type Parameters:
C - the type of the component
Parameters:
componentClass - the class of the component to be tested
Returns:
The component processed

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 the pageMarkup provided. In case pageMarkup is null, the markup will be automatically created with createPageMarkup(String).

Type Parameters:
C - the type of the component
Parameters:
componentClass - the class of the component to be tested
pageMarkup - the markup for the Page that will be automatically created. May be null.
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 the createPageMarkup(String).

Type Parameters:
C - the type of the component
Parameters:
component - the component to be tested
Returns:
The component processed

startComponentInPage

public final <C extends Component> C startComponentInPage(C component,
                                                          IMarkupFragment pageMarkup)
Process a component. A web page will be automatically created with the pageMarkup provided. In case pageMarkup is null, the markup will be automatically created with createPageMarkup(String).

Type Parameters:
C - the type of the component
Parameters:
component - the component to be tested
pageMarkup - the markup for the Page that will be automatically created. May be null.
Returns:
The component processed

createPageMarkup

protected java.lang.String createPageMarkup(java.lang.String componentId)
Creates the markup that will be used for the automatically created BaseWicketTester.StartComponentInPage that will be used to test a component with startComponentInPage(Class, IMarkupFragment)

Parameters:
componentId - the id of the component to be tested
Returns:
the markup for the BaseWicketTester.StartComponentInPage as String. Cannot be null.

createPage

protected Page createPage()
Creates a BaseWicketTester.StartComponentInPage to test a component with startComponentInPage(Component, IMarkupFragment)

Returns:
a BaseWicketTester.StartComponentInPage which will contain the component under test as a single child

startComponent

public Component startComponent(Component component)
A helper method for starting a component for a test without attaching it to a Page. Components which are somehow dependent on the page structure can not be currently tested with this method. Example: UserDataView view = new UserDataView("view", new ListDataProvider(userList)); tester.startComponent(view); assertEquals(4, view.size());

Parameters:
component -
Returns:
the processed component
See Also:
startComponentInPage(Class)

getComponentFromLastRenderedPage

public Component getComponentFromLastRenderedPage(java.lang.String path,
                                                  boolean wantVisibleInHierarchy)
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 component
wantVisibleInHierarchy - if true component needs to be VisibleInHierarchy else null is 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 of Label component.

Parameters:
path - path to Label component
expectedLabelText - 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 component
expectedComponentClass - 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

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

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

assertListView

public void assertListView(java.lang.String path,
                           java.util.List<?> expectedList)
assert the model of ListView use expectedList

Parameters:
path - path to ListView component
expectedList - expected list in the model of ListView

clickLink

public void clickLink(java.lang.String path)
Click the Link in the last rendered Page.

Simulate that AJAX is enabled.

Parameters:
path - Click the Link in the last rendered Page.
See Also:
clickLink(String, boolean)

clickLink

public void clickLink(java.lang.String path,
                      boolean isAjax)
Click the Link in the last rendered Page.

This method also works for AjaxLink, AjaxFallbackLink and AjaxSubmitLink.

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 FormTester to 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 to Link component
isAjax - 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)
Parameters:
form -

submitForm

public void submitForm(java.lang.String path)
Submits the Form in the last rendered Page.

Parameters:
path - path to Form component

isRenderedPage

public <C extends Page> Result isRenderedPage(java.lang.Class<C> expectedRenderedPageClass)
Asserts the last rendered Page class.

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.Exception
Asserts last rendered Page against an expected HTML document.

Use -Dwicket.replace.expected.results=true to automatically replace the expected output file.

Parameters:
pageClass - used to load the File (relative to clazz package)
filename - expected output File name
Throws:
java.lang.Exception

isResultPage

public Result isResultPage(java.lang.String expectedDocument)
                    throws java.lang.Exception
Asserts last rendered Page against an expected HTML document as a String.

Parameters:
expectedDocument - expected output
Returns:
a Result
Throws:
java.lang.Exception

hasNoErrorMessage

public Result hasNoErrorMessage()
Asserts no error-level feedback messages.

Returns:
a Result

hasNoInfoMessage

public Result hasNoInfoMessage()
Asserts no info-level feedback messages.

Returns:
a Result

getMessages

public java.util.List<java.io.Serializable> getMessages(int level)
Retrieves FeedbackMessages.

Parameters:
level - level of feedback message, for example: FeedbackMessage.DEBUG or FeedbackMessage.INFO.. etc
Returns:
List of messages (as Strings)
See Also:
FeedbackMessage

dumpPage

public void dumpPage()
Dumps the source of last rendered Page.


debugComponentTrees

public void debugComponentTrees()
Dumps the Component trees.


debugComponentTrees

public void debugComponentTrees(java.lang.String filter)
Dumps the Component trees to log. Show only the Components whose paths contain the filter String.

Parameters:
filter - a filter String

isComponentOnAjaxResponse

public Result isComponentOnAjaxResponse(Component component)
Tests that a Component has been added to a AjaxRequestTarget, using AjaxRequestTarget#add(Component). This method actually tests that a Component is on the Ajax response sent back to the client.

PLEASE NOTE! This method doesn't actually insert the Component in 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 - the Component to 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 - the Component path
event - the event which we simulate being fired. If event is null, the test will fail.
Since:
1.2.3
See Also:
executeAjaxEvent(Component, String)

executeAllTimerBehaviors

public void executeAllTimerBehaviors(MarkupContainer container)
Simulates the firing of all ajax timer behaviors on the page

Parameters:
wt -
container -

executeAjaxEvent

public void executeAjaxEvent(Component component,
                             java.lang.String event)
Simulates the firing of an Ajax event. You add an Ajax event to a Component by using:
     ...
     component.add(new AjaxEventBehavior("ondblclick") {
         public void onEvent(AjaxRequestTarget) {}
     });
     ...
 
You can then test that the code inside onEvent actually does what it's supposed to, using the WicketTester:
     ...
     tester.executeAjaxEvent(component, "ondblclick");
     // Test that the code inside onEvent is correct.
     ...
 
This also works with AjaxFormSubmitBehavior, where it will "submit" the Form before executing the command.

PLEASE NOTE! This method doesn't actually insert the Component in the client DOM tree, using JavaScript.

Parameters:
component - the Component that has the AjaxEventBehavior we want to test. If the Component is null, the test will fail.
event - the event to simulate being fired. If event is null, the test will fail.

getTagByWicketId

public TagTester getTagByWicketId(java.lang.String wicketId)
Retrieves a TagTester based on a wicket:id. If more Components exist with the same wicket:id in the markup, only the first one is returned.

Parameters:
wicketId - the wicket:id to search for
Returns:
the TagTester for the tag which has the given wicket: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 a TagTester based on an DOM id. If more Components exist with the same id in the markup, only the first one is returned.

Parameters:
id - the DOM id to search for.
Returns:
the TagTester for 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()
Rebuilds ServletWebRequest used 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 -
useRequestUrlAsBase -

executeUrl

public void executeUrl(java.lang.String _url)
Starts a page, a shared resource or a IRequestListener depending on what the IRequestMappers resolve for the passed url.

Parameters:
_url - the url to resolve and execute


Copyright © 2006-2011 Apache Software Foundation. All Rights Reserved.