java.lang.Object
org.apache.wicket.util.tester.FormTester
A helper class for testing validation and submission of
FormComponent
s.- Since:
- 1.2.6
- Author:
- Ingram Chen, Frank Bille (frankbille)
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected class
A selector template for selecting selectableFormComponent
s with an index of option -- supportsRadioGroup
,CheckGroup
, andAbstractChoice
family. -
Constructor Summary
ModifierConstructorDescriptionprotected
FormTester
(String path, Form<?> workingForm, BaseWicketTester wicketTester, boolean fillBlankString) -
Method Summary
Modifier and TypeMethodDescriptionForm<?>
getForm()
Retrieves the currentForm
object.static String[]
getInputValue
(FormComponent<?> formComponent) Gets request parameter values for the form component that represents its current model valueGets the value for anAbstractTextComponent
with the provided id.boolean
Simulates selecting an option of aFormComponent
.selectMultiple
(String formComponentId, int[] indexes) A convenience method to select multiple options for theFormComponent
.selectMultiple
(String formComponentId, int[] indexes, boolean replace) A convenience method to select multiple options for theFormComponent
.setClearFeedbackMessagesBeforeSubmit
(boolean clearFeedbackMessagesBeforeSubmit) Sets theFile
on aFileUploadField
.Simulates filling in a field on aForm
.Simulates filling in a field on aForm
.submit()
Submits theForm
.A convenience method for submitting theForm
with an alternate button.A convenience method for submitting theForm
with an alternate button.submitLink
(String path, boolean pageRelative) A convenience method to submit the Form via a SubmitLink which may inside or outside of the Form.
-
Constructor Details
-
FormTester
protected FormTester(String path, Form<?> workingForm, BaseWicketTester wicketTester, boolean fillBlankString) - Parameters:
path
- path toFormComponent
workingForm
-FormComponent
to be testedwicketTester
-WicketTester
that createsFormTester
fillBlankString
- specifies whether to fill childTextComponent
s with blankString
s- See Also:
-
-
Method Details
-
getInputValue
Gets request parameter values for the form component that represents its current model value- Parameters:
formComponent
-- Returns:
- array containing parameter values
-
getForm
Retrieves the currentForm
object.- Returns:
- the working
Form
-
getTextComponentValue
Gets the value for anAbstractTextComponent
with the provided id.- Parameters:
id
-Component
id- Returns:
- the value of the text component
-
select
Simulates selecting an option of aFormComponent
. SupportsRadioGroup
,CheckGroup
, andAbstractChoice
family currently. The behavior is similar to interacting on the browser: For a single choice, such asRadio
orDropDownList
, the selection will toggle each other. For multiple choice, such asCheckbox
orListMultipleChoice
, the selection will accumulate.- Parameters:
formComponentId
- relative path (fromForm
) to the selectableFormComponent
index
- index of the selectable option, starting from 0- Returns:
- This
-
selectMultiple
A convenience method to select multiple options for theFormComponent
. The method only support multiple selectableFormComponent
s.- Parameters:
formComponentId
- relative path (fromForm
) to the selectableFormComponent
indexes
- index of the selectable option, starting from 0- Returns:
- This
- See Also:
-
selectMultiple
A convenience method to select multiple options for theFormComponent
. The method only support multiple selectableFormComponent
s.- Parameters:
formComponentId
- relative path (fromForm
) to the selectableFormComponent
indexes
- index of the selectable option, starting from 0replace
- If true, than all previous selects are first reset, thus existing selects are replaced. If false, than the new indexes will be added.- Returns:
- This
- See Also:
-
setValue
Simulates filling in a field on aForm
.- Parameters:
formComponentId
- relative path (fromForm
) to the selectableFormComponent
orIFormSubmittingComponent
value
- the field value- Returns:
- This
-
setValue
Simulates filling in a field on aForm
.- Parameters:
formComponent
- relative path (fromForm
) to the selectableFormComponent
orIFormSubmittingComponent
value
- the field value- Returns:
- This
-
setValue
- Parameters:
checkBoxId
-value
-- Returns:
- This
-
setFile
Sets theFile
on aFileUploadField
.- Parameters:
formComponentId
- relative path (fromForm
) to the selectableFormComponent
. TheFormComponent
must be of a typeFileUploadField
.file
- theFile
to upload ornull
for an empty inputcontentType
- the content type of the file. Must be a valid mime type.- Returns:
- This
-
submit
Submits theForm
. Note thatsubmit
can be executed only once.- Returns:
- This
-
isClearFeedbackMessagesBeforeSubmit
-
setClearFeedbackMessagesBeforeSubmit
-
submit
A convenience method for submitting theForm
with an alternate button.Note that if the button is associated with a model, it's better to use the
setValue
method instead:formTester.setValue("to:my:button", "value on the button"); formTester.submit();
- Parameters:
buttonComponentId
- relative path (fromForm
) to the button- Returns:
- This
-
submit
A convenience method for submitting theForm
with an alternate button.Note that if the button is associated with a model, it's better to use the
setValue
method instead:formTester.setValue(myButton, "value on the button"); formTester.submit();
- Parameters:
buttonComponent
- relative path (fromForm
) to the button- Returns:
- This
-
submitLink
A convenience method to submit the Form via a SubmitLink which may inside or outside of the Form.- Parameters:
path
- The path to the SubmitLinkpageRelative
- if true, than the 'path' to the SubmitLink is relative to the page. Thus the link can be outside the form. If false, the path is relative to the form and thus the link is inside the form.- Returns:
- This
-