Package org.apache.wicket.util.tester
Class FormTester
- java.lang.Object
-
- org.apache.wicket.util.tester.FormTester
-
public class FormTester extends Object
A helper class for testing validation and submission ofFormComponent
s.- Since:
- 1.2.6
- Author:
- Ingram Chen, Frank Bille (frankbille)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
FormTester.ChoiceSelector
A selector template for selecting selectableFormComponent
s with an index of option -- supportsRadioGroup
,CheckGroup
, andAbstractChoice
family.
-
Constructor Summary
Constructors Modifier Constructor Description protected
FormTester(String path, Form<?> workingForm, BaseWicketTester wicketTester, boolean fillBlankString)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Form<?>
getForm()
Retrieves the currentForm
object.static String[]
getInputValue(FormComponent<?> formComponent)
Gets request parameter values for the form component that represents its current model valueString
getTextComponentValue(String id)
Gets the value for anAbstractTextComponent
with the provided id.boolean
isClearFeedbackMessagesBeforeSubmit()
FormTester
select(String formComponentId, int index)
Simulates selecting an option of aFormComponent
.FormTester
selectMultiple(String formComponentId, int[] indexes)
A convenience method to select multiple options for theFormComponent
.FormTester
selectMultiple(String formComponentId, int[] indexes, boolean replace)
A convenience method to select multiple options for theFormComponent
.FormTester
setClearFeedbackMessagesBeforeSubmit(boolean clearFeedbackMessagesBeforeSubmit)
FormTester
setFile(String formComponentId, File file, String contentType)
Sets theFile
on aFileUploadField
.FormTester
setValue(String checkBoxId, boolean value)
FormTester
setValue(String formComponentId, String value)
Simulates filling in a field on aForm
.FormTester
setValue(Component formComponent, String value)
Simulates filling in a field on aForm
.FormTester
submit()
Submits theForm
.FormTester
submit(String buttonComponentId)
A convenience method for submitting theForm
with an alternate button.FormTester
submit(Component buttonComponent)
A convenience method for submitting theForm
with an alternate button.FormTester
submitLink(String path, boolean pageRelative)
A convenience method to submit the Form via a SubmitLink which may inside or outside of the Form.
-
-
-
Constructor Detail
-
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:
BaseWicketTester.newFormTester(String)
-
-
Method Detail
-
getInputValue
public static String[] getInputValue(FormComponent<?> formComponent)
Gets request parameter values for the form component that represents its current model value- Parameters:
formComponent
-- Returns:
- array containing parameter values
-
getTextComponentValue
public String getTextComponentValue(String id)
Gets the value for anAbstractTextComponent
with the provided id.- Parameters:
id
-Component
id- Returns:
- the value of the text component
-
select
public FormTester select(String formComponentId, int index)
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
public FormTester selectMultiple(String formComponentId, int[] indexes)
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:
select(String, int)
-
selectMultiple
public FormTester selectMultiple(String formComponentId, int[] indexes, boolean replace)
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:
select(String, int)
-
setValue
public FormTester setValue(String formComponentId, String value)
Simulates filling in a field on aForm
.- Parameters:
formComponentId
- relative path (fromForm
) to the selectableFormComponent
orIFormSubmittingComponent
value
- the field value- Returns:
- This
-
setValue
public FormTester setValue(Component formComponent, String value)
Simulates filling in a field on aForm
.- Parameters:
formComponent
- relative path (fromForm
) to the selectableFormComponent
orIFormSubmittingComponent
value
- the field value- Returns:
- This
-
setValue
public FormTester setValue(String checkBoxId, boolean value)
- Parameters:
checkBoxId
-value
-- Returns:
- This
-
setFile
public FormTester setFile(String formComponentId, File file, String contentType)
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
public FormTester submit()
Submits theForm
. Note thatsubmit
can be executed only once.- Returns:
- This
-
isClearFeedbackMessagesBeforeSubmit
public boolean isClearFeedbackMessagesBeforeSubmit()
-
setClearFeedbackMessagesBeforeSubmit
public FormTester setClearFeedbackMessagesBeforeSubmit(boolean clearFeedbackMessagesBeforeSubmit)
-
submit
public FormTester submit(String buttonComponentId)
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
public FormTester submit(Component buttonComponent)
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
public FormTester submitLink(String path, boolean pageRelative)
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
-
-