- Direct Known Subclasses:
WicketTester
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:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
A page that is used as the automatically created page forstartComponentInPage(Class)
and the other variations.class
-
Constructor Summary
ConstructorDescriptionCreatesWicketTester
and automatically create aWebApplication
, but the tester will have no home page.BaseWicketTester
(Class<C> homePage) CreatesWicketTester
and automatically creates aWebApplication
.BaseWicketTester
(WebApplication application) Creates aWicketTester
.BaseWicketTester
(WebApplication application, boolean init) Creates aWicketTester
.BaseWicketTester
(WebApplication application, jakarta.servlet.ServletContext servletCtx) Creates aWicketTester
.BaseWicketTester
(WebApplication application, jakarta.servlet.ServletContext servletCtx, boolean init) Creates aWicketTester
.BaseWicketTester
(WebApplication application, String servletContextBasePath) Creates aWicketTester
. -
Method Summary
Modifier and TypeMethodDescriptionfinal void
addRequestHeader
(String key, String value) Allows to set Request header value any time.void
RebuildsServletWebRequest
used by wicket from the mock request used to build requests.assertExists
(String path) void
assertNotExists
(String path) void
assertResultPage
(Class<?> pageClass, String filename) Asserts last renderedPage
against an expected HTML document.protected Result
checkUsability
(Component component, boolean throwException) Checks whether a component is visible and/or enabled before usagevoid
Cleans up feedback messages.protected void
Cleans up feedback messages given the specified filter.void
Removes all feedback messagesvoid
Click theLink
in the last rendered Page.void
Click theLink
in the last rendered Page.protected String
Build value to Origin header based on RequestCycle Urlprotected Page
Creates aPage
to test a component withstartComponentInPage(Component, IMarkupFragment)
protected String
createPageMarkup
(String componentId) Creates the markup that will be used for the automatically createdPage
that will be used to test a component withstartComponentInPage(Class, IMarkupFragment)
void
Dumps theComponent
trees.void
debugComponentTrees
(String filter) Dumps theComponent
trees to log.void
destroy()
Destroys the tester.void
dumpPage()
Dumps the source of last renderedPage
.void
executeAjaxEvent
(String componentPath, String event) Simulates the firing of an Ajax event.void
executeAjaxEvent
(Component component, String event) Simulates the firing of an Ajax event.void
executeAjaxUrl
(Url url) void
Simulates the firing of all ajax timer behaviors on the pagevoid
executeBehavior
(AbstractAjaxBehavior behavior) Builds and processes a request suitable for executing anAbstractAjaxBehavior
.void
executeListener
(Component component) Simulates processing URL that invokes anIRequestListener
on a component.void
executeUrl
(String _url) Starts a page, a shared resource or aIRequestListener
depending on what theIRequestMapper
s resolve for the passed url.getAllComponentsByWicketId
(String wicketId) Returns theApplication
for this environment.Gets the component with the given path from last rendered page.getComponentFromLastRenderedPage
(String path, boolean wantVisibleInHierarchy) getComponentFromLastRenderedPage
(String path, boolean wantVisibleInHierarchy, boolean failOnAbsent) Gets the component with the given path from last rendered page.Retrieves the content disposition from the response header.int
Retrieves the content length from the response header.Retrieves the content type from the response header.RetrievesFeedbackMessages
.getFirstComponentByWicketId
(String wicketId) Returns the firstComponent
(breadth-first search) matching the given Wicket-ID.ReturnsHttpSession
for this environmentRetrieves the last-modified value from the response header.The last response as a string when a page is tested viastartPage()
methods.getMessages
(int level) RetrievesFeedbackMessages
.protected Duration
By default Modification Watcher is disabled by default for the tests.jakarta.servlet.ServletContext
Returns theServletContext
for this environmentgetTagById
(String id) Retrieves aTagTester
based on an DOM id.getTagByWicketId
(String wicketId) Retrieves aTagTester
based on awicket:id
.getTagsByWicketId
(String wicketId) Modified version of BaseWicketTester#getTagByWicketId(String) that returns all matching tags instead of just the first.This method tries to parse the last response to return the encoded base URL and will throw an exception if there none was encoded.assert the text ofLabel
component.Asserts no error-level feedback messages.hasNoFeedbackMessage
(int level) Asserts there are no feedback messages with the given level.Asserts no info-level feedback messages.ifContains
(String pattern) assert the content of last rendered page contains(matches) regex pattern.ifContainsNot
(String pattern) assert the content of last rendered page contains(matches) regex pattern.void
invokeListener
(Component component) Simulates invoking anIRequestListener
on a component.void
invokeListener
(Component component, Behavior behavior) Simulates invoking anIRequestListener
on a component.isComponent
(String path, Class<C> expectedComponentClass) assert component classisComponentOnAjaxResponse
(Component component) Tests that aComponent
has been added to aAjaxRequestTarget
, usingIPartialPageRequestHandler.add(org.apache.wicket.Component...)
.isDisabled
(String path) assert component disabled.assert component enabled.protected final Result
boolean
boolean
isInvisible
(String path) assert component invisible.isNotRequired
(String path) Asserts that a component is not required.isNotRequired
(FormComponent<?> component) Asserts that a component is not required.isRenderedPage
(Class<C> expectedRenderedPageClass) Asserts the last renderedPage
class.isRequired
(String path) assert component required.isRequired
(FormComponent<?> component) assert component required.isResultPage
(String expectedDocument) Asserts last renderedPage
against an expected HTML document as aString
.boolean
assert component visible.newFormTester
(String path) Creates aFormTester
for theForm
at a given path, and fills all childFormComponent
s with blankString
s.newFormTester
(String path, boolean fillBlankString) Creates aFormTester
for theForm
at a given path.protected Response
newServletWebResponse
(ServletWebRequest servletWebRequest) protected IPageManagerProvider
boolean
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.boolean
processRequest
(IRequestHandler forcedRequestHandler) protected Locale
void
setExposeExceptions
(boolean exposeExceptions) void
setFollowRedirects
(boolean followRedirects) Sets whether responses with redirects will be followed automatically.void
setLastResponse
(MockHttpServletResponse response) void
setRequest
(MockHttpServletRequest request) void
setUseRequestUrlAsBase
(boolean setBaseUrl) final <C extends Component>
CstartComponentInPage
(C component) Process a component.final <C extends Component>
CstartComponentInPage
(C component, IMarkupFragment pageMarkup) Process a component.final <C extends Component>
CstartComponentInPage
(Class<C> componentClass) Process a component.final <C extends Component>
CstartComponentInPage
(Class<C> componentClass, IMarkupFragment pageMarkup) Process a component.final <C extends Page>
CRenders aPage
from its default constructor.final <C extends Page>
CstartPage
(Class<C> pageClass, PageParameters parameters) Renders aPage
from its default constructor.startPage
(IPageProvider pageProvider) Renders the page specified by givenIPageProvider
.<T extends Page>
TstartPage
(T page) Renders the page.startResource
(IResource resource) Simulates a request to a mountedIResource
startResourceReference
(ResourceReference reference) Simulates a request to a mountedResourceReference
startResourceReference
(ResourceReference reference, PageParameters pageParameters) Simulates a request to a mountedResourceReference
void
submitForm
(String path) void
submitForm
(Form<?> form) Submit the given form in the last renderedPage
urlFor
(IRequestHandler handler) Encodes theIRequestHandler
toUrl
.
-
Constructor Details
-
BaseWicketTester
public BaseWicketTester()CreatesWicketTester
and automatically create aWebApplication
, but the tester will have no home page. -
BaseWicketTester
CreatesWicketTester
and automatically creates aWebApplication
.- Type Parameters:
C
-- Parameters:
homePage
- a home pageClass
-
BaseWicketTester
Creates aWicketTester
.- Parameters:
application
- aWicketTester
WebApplication
object
-
BaseWicketTester
Creates aWicketTester
.- Parameters:
application
- aWicketTester
WebApplication
objectservletContextBasePath
- the absolute path on disk to the web application's contents (e.g. war root) - may benull
-
BaseWicketTester
Creates aWicketTester
.- Parameters:
application
- aWicketTester
WebApplication
objectservletCtx
- the servlet context used as backend
-
BaseWicketTester
Creates aWicketTester
.- Parameters:
application
- aWicketTester
WebApplication
objectinit
- force the application to be initialized (default = true)
-
BaseWicketTester
public BaseWicketTester(WebApplication application, jakarta.servlet.ServletContext servletCtx, boolean init) Creates aWicketTester
.- Parameters:
application
- aWicketTester
WebApplication
objectservletCtx
- the servlet context used as backendinit
- force the application to be initialized (default = true)
-
-
Method Details
-
getResourcePollFrequency
By default Modification Watcher is disabled by default for the tests.- Returns:
- the duration between two checks for changes in the resources
-
newTestPageManagerProvider
- Returns:
- page manager provider
-
getLastRenderedPage
- Returns:
- last rendered page
-
servletRequestLocale
-
cleanupFeedbackMessages
Cleans up feedback messages. This usually happens on detach, but is disabled in unit testing so feedback messages can be examined. -
clearFeedbackMessages
Removes all feedback messages -
cleanupFeedbackMessages
Cleans up feedback messages given the specified filter.- Parameters:
filter
- filter used to cleanup messages, accepted messages will be removed
-
newServletWebResponse
- Parameters:
servletWebRequest
-- Returns:
- servlet web response
-
getRequest
- Returns:
- request object
-
setRequest
- Parameters:
request
-
-
setLastResponse
- Parameters:
response
-
-
getSession
- Returns:
- session
-
getHttpSession
ReturnsHttpSession
for this environment- Returns:
- session
-
getApplication
Returns theApplication
for this environment.- Returns:
- application
-
getServletContext
Returns theServletContext
for this environment- Returns:
- servlet context
-
destroy
Destroys the tester. RestoresThreadContext
to state before instance ofWicketTester
was created. -
processRequest
- Returns:
- true, if process was executed successfully
-
processRequest
Processes the request in mocked Wicket environment.- Parameters:
request
- request to process- Returns:
- true, if process was executed successfully
-
processRequest
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
- 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
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
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.RenderStrategy
invoking this method can mean that a redirect will happen before the actual render.- Parameters:
pageProvider
-- Returns:
- last rendered page
-
startPage
Renders the page.- Parameters:
page
-- Returns:
- Page
- See Also:
-
startResource
Simulates a request to a mountedIResource
- Parameters:
resource
- the resource to test- Returns:
- the used
ResourceReference
for the simulation
-
startResourceReference
Simulates a request to a mountedResourceReference
- 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 mountedResourceReference
- Parameters:
reference
- the resource reference to testpageParameters
- the parameters passed to the resource reference- Returns:
- the tested resource reference
-
getLastResponse
- Returns:
- last response or
null
if no response has been produced yet.
-
getLastResponseAsString
The last response as a string when a page is tested viastartPage()
methods.In case the processed component was not a
Page
then 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
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:
IOException
ParseException
-
getPreviousRequests
- Returns:
- list of prior requests
-
getPreviousResponses
- Returns:
- list of prior responses
-
setFollowRedirects
Sets whether responses with redirects will be followed automatically.- Parameters:
followRedirects
-
-
isFollowRedirects
- Returns:
true
if redirect responses will be followed automatically,false
otherwise.
-
urlFor
Encodes theIRequestHandler
toUrl
. It should be safe to call this method outside request thread as log as no registeredIRequestMapper
requires aRequestCycle
.- Parameters:
handler
-- Returns:
Url
for handler.
-
urlFor
- Parameters:
link
-- Returns:
- url for Link
-
executeListener
Simulates processing URL that invokes anIRequestListener
on 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
Simulates invoking anIRequestListener
on 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
Simulates invoking anIRequestListener
on 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
Builds and processes a request suitable for executing anAbstractAjaxBehavior
.- Parameters:
behavior
- anAbstractAjaxBehavior
to execute
-
createOriginHeader
Build value to Origin header based on RequestCycle Url- Returns:
- Origin header
-
urlFor
- Parameters:
link
-- Returns:
- Url
-
executeAjaxUrl
- Parameters:
url
-
-
startPage
Renders aPage
from its default constructor.- Type Parameters:
C
-- Parameters:
pageClass
- a testPage
class with default constructor- Returns:
- the rendered
Page
-
startPage
Renders aPage
from its default constructor.- Type Parameters:
C
-- Parameters:
pageClass
- a testPage
class with default constructorparameters
- the parameters to use for the class.- Returns:
- the rendered
Page
-
newFormTester
Creates aFormTester
for theForm
at a given path, and fills all childFormComponent
s with blankString
s.- Parameters:
path
- path toFormComponent
- Returns:
- a
FormTester
instance for testing theForm
- See Also:
-
newFormTester
Creates aFormTester
for theForm
at a given path.- Parameters:
path
- path toFormComponent
fillBlankString
- specifies whether to fill all childFormComponent
s with blankString
s- Returns:
- a
FormTester
instance for testing theForm
- See Also:
-
startComponentInPage
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
public final <C extends Component> C startComponentInPage(Class<C> componentClass, IMarkupFragment pageMarkup) Process a component. A web page will be automatically created with thepageMarkup
provided. 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
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
Process a component. A web page will be automatically created with thepageMarkup
provided. In casepageMarkup
is 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
Creates the markup that will be used for the automatically createdPage
that will be used to test a component withstartComponentInPage(Class, IMarkupFragment)
-
createPage
Creates aPage
to test a component withstartComponentInPage(Component, IMarkupFragment)
- Returns:
- a
Page
which will contain the component under test as a single child
-
getComponentFromLastRenderedPage
-
getComponentFromLastRenderedPage
public Component getComponentFromLastRenderedPage(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 elsenull
is returned- Returns:
- The component at the path
- See Also:
-
getComponentFromLastRenderedPage
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:
-
getFirstComponentByWicketId
Returns the firstComponent
(breadth-first search) matching the given Wicket-ID. If no suchComponent
exists it returnsOptional.empty()
- Parameters:
wicketId
- the Wicket-ID of theComponent
to be found- Returns:
- Optional of the component,
Optional.empty()
if no matching component can be found or wicketId is null or blank.
-
getAllComponentsByWicketId
Returns aList
of allComponent
s matching the given Wicket-ID. Returns an empty list if no such component can be found or the Wicket-ID is null.- Parameters:
wicketId
- the Wicket-ID of the components to be found- Returns:
- A list of all
Component
s that have the given Wicket-ID, an empty List if no such component can be found. Returns an empty List of wicketId is null or blank.
-
hasLabel
assert the text ofLabel
component.- Parameters:
path
- path toLabel
componentexpectedLabelText
- expected label text- Returns:
- a
Result
-
isComponent
assert component class- Type Parameters:
C
-- Parameters:
path
- path to componentexpectedComponentClass
- expected component class- Returns:
- a
Result
-
isVisible
assert component visible.- Parameters:
path
- path to component- Returns:
- a
Result
-
isInvisible
assert component invisible.- Parameters:
path
- path to component- Returns:
- a
Result
-
isEnabled
assert component enabled.- Parameters:
path
- path to component- Returns:
- a
Result
-
isDisabled
assert component disabled.- Parameters:
path
- path to component- Returns:
- a
Result
-
assertExists
-
assertNotExists
-
isRequired
assert component required.- Parameters:
path
- path to component- Returns:
- a
Result
-
isRequired
assert component required.- Parameters:
component
- a form component- Returns:
- a
Result
-
isNotRequired
Asserts that a component is not required.- Parameters:
path
- path to component- Returns:
- a
Result
-
isNotRequired
Asserts that a component is not required.- Parameters:
component
- a form component- Returns:
- a
Result
-
ifContains
assert the content of last rendered page contains(matches) regex pattern.- Parameters:
pattern
- reqex pattern to match- Returns:
- a
Result
-
ifContainsNot
assert the content of last rendered page contains(matches) regex pattern.- Parameters:
pattern
- reqex pattern to match- Returns:
- a
Result
-
clickLink
Click theLink
in the last rendered Page.Simulate that AJAX is enabled.
- Parameters:
path
- Click theLink
in the last rendered Page.- See Also:
-
clickLink
Click theLink
in the last rendered Page.This method also works for
AjaxLink
,AjaxFallbackLink
andAjaxSubmitLink
.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 toLink
componentisAjax
- 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
Submit the given form in the last renderedPage
Note: Form request parameters have to be set explicitly.
- Parameters:
form
- path to component
-
submitForm
Submits theForm
in the last renderedPage
.Note: Form request parameters have to be set explicitely.
- Parameters:
path
- path to component
-
isRenderedPage
Asserts the last renderedPage
class.- Type Parameters:
C
-- Parameters:
expectedRenderedPageClass
- expected class of last rendered page- Returns:
- a
Result
-
assertResultPage
Asserts last renderedPage
against an expected HTML document.Use
-Dwicket.replace.expected.results=true
to automatically replace the expected output file.- Parameters:
pageClass
- used to load theFile
(relative toclazz
package)filename
- expected outputFile
name- Throws:
Exception
-
isResultPage
Asserts last renderedPage
against an expected HTML document as aString
.- Parameters:
expectedDocument
- expected output- Returns:
- a
Result
-
hasNoErrorMessage
Asserts no error-level feedback messages.- Returns:
- a
Result
- See Also:
-
hasNoInfoMessage
Asserts no info-level feedback messages.- Returns:
- a
Result
- See Also:
-
hasNoFeedbackMessage
Asserts there are no feedback messages with the given level.- Parameters:
level
- the level of the feedback message- Returns:
- a
Result
-
getMessages
RetrievesFeedbackMessages
.- Parameters:
level
- level of feedback message, for example:FeedbackMessage.DEBUG or FeedbackMessage.INFO.. etc
- Returns:
List
of messages (asString
s)- See Also:
-
getFeedbackMessages
RetrievesFeedbackMessages
.- Parameters:
filter
- A filter that decides which messages to collect- Returns:
List
of messages (asString
s)- See Also:
-
dumpPage
Dumps the source of last renderedPage
. -
debugComponentTrees
Dumps theComponent
trees. -
debugComponentTrees
Dumps theComponent
trees to log. Show only theComponent
s whose paths contain the filterString
.- Parameters:
filter
- a filterString
-
isComponentOnAjaxResponse
Tests that aComponent
has been added to aAjaxRequestTarget
, usingIPartialPageRequestHandler.add(org.apache.wicket.Component...)
. This method actually tests that aComponent
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
- theComponent
to test- Returns:
- a
Result
-
executeAjaxEvent
Simulates the firing of an Ajax event.- Parameters:
componentPath
- theComponent
pathevent
- the event which we simulate being fired. Ifevent
isnull
, the test will fail.- Since:
- 1.2.3
- See Also:
-
executeAllTimerBehaviors
Simulates the firing of all ajax timer behaviors on the page- Parameters:
page
- the page which timers will be executed
-
executeAjaxEvent
Simulates the firing of an Ajax event. You add an Ajax event to aComponent
by using:... component.add(new AjaxEventBehavior("ondblclick") { public void onEvent(AjaxRequestTarget) {} }); ...
You can then test that the code insideonEvent
actually 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" theForm
before executing the command.PLEASE NOTE! This method doesn't actually insert the
Component
in the client DOM tree, using JavaScript.- Parameters:
component
- theComponent
that has theAjaxEventBehavior
we want to test. If theComponent
isnull
, the test will fail.event
- the event to simulate being fired. Ifevent
isnull
, the test will fail.
-
getTagByWicketId
Retrieves aTagTester
based on awicket:id
. If moreComponent
s exist with the samewicket:id
in the markup, only the first one is returned.- Parameters:
wicketId
- thewicket:id
to search for- Returns:
- the
TagTester
for the tag which has the givenwicket:id
-
getTagsByWicketId
Modified version of BaseWicketTester#getTagByWicketId(String) that returns all matching tags instead of just the first.- Parameters:
wicketId
-- Returns:
- List of Tags
-
getTagById
Retrieves aTagTester
based on an DOM id. If moreComponent
s 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
Retrieves the content type from the response header.- Returns:
- the content type from the response header
-
getContentLengthFromResponseHeader
Retrieves the content length from the response header.- Returns:
- the content length from the response header
-
getLastModifiedFromResponseHeader
Retrieves the last-modified value from the response header.- Returns:
- the last-modified value from the response header
-
getContentDispositionFromResponseHeader
Retrieves the content disposition from the response header.- Returns:
- the content disposition from the response header
-
applyRequest
RebuildsServletWebRequest
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
- Parameters:
expected
-actual
-- Returns:
- fail with message if not equal
-
checkUsability
Checks whether a component is visible and/or enabled before usage- Parameters:
component
-throwException
-- Returns:
- result
-
getRequestCycle
- Returns:
- request cycle
-
getResponse
- Returns:
- servlet response
-
getLastRequest
- Returns:
- last request
-
isExposeExceptions
- Returns:
- true, if exceptions are exposed
-
setExposeExceptions
- Parameters:
exposeExceptions
-
-
isUseRequestUrlAsBase
- Returns:
- useRequestUrlAsBase
-
setUseRequestUrlAsBase
- Parameters:
setBaseUrl
-
-
executeUrl
Starts a page, a shared resource or aIRequestListener
depending on what theIRequestMapper
s resolve for the passed url.- Parameters:
_url
- the url to resolve and execute
-