Package org.apache.wicket.util.tester
Class FormTester
- java.lang.Object
-
- org.apache.wicket.util.tester.FormTester
-
public class FormTester extends java.lang.ObjectA helper class for testing validation and submission ofFormComponents.- Since:
- 1.2.6
- Author:
- Ingram Chen, Frank Bille (frankbille)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classFormTester.ChoiceSelectorA selector template for selecting selectableFormComponents with an index of option -- supportsRadioGroup,CheckGroup, andAbstractChoicefamily.
-
Constructor Summary
Constructors Modifier Constructor Description protectedFormTester(java.lang.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 currentFormobject.static java.lang.String[]getInputValue(FormComponent<?> formComponent)Gets request parameter values for the form component that represents its current model valuejava.lang.StringgetTextComponentValue(java.lang.String id)Gets the value for anAbstractTextComponentwith the provided id.booleanisClearFeedbackMessagesBeforeSubmit()FormTesterselect(java.lang.String formComponentId, int index)Simulates selecting an option of aFormComponent.FormTesterselectMultiple(java.lang.String formComponentId, int[] indexes)A convenience method to select multiple options for theFormComponent.FormTesterselectMultiple(java.lang.String formComponentId, int[] indexes, boolean replace)A convenience method to select multiple options for theFormComponent.FormTestersetClearFeedbackMessagesBeforeSubmit(boolean clearFeedbackMessagesBeforeSubmit)FormTestersetFile(java.lang.String formComponentId, org.apache.wicket.util.file.File file, java.lang.String contentType)Sets theFileon aFileUploadField.FormTestersetValue(java.lang.String checkBoxId, boolean value)FormTestersetValue(java.lang.String formComponentId, java.lang.String value)Simulates filling in a field on aForm.FormTestersetValue(Component formComponent, java.lang.String value)Simulates filling in a field on aForm.FormTestersubmit()Submits theForm.FormTestersubmit(java.lang.String buttonComponentId)A convenience method for submitting theFormwith an alternate button.FormTestersubmit(Component buttonComponent)A convenience method for submitting theFormwith an alternate button.FormTestersubmitLink(java.lang.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(java.lang.String path, Form<?> workingForm, BaseWicketTester wicketTester, boolean fillBlankString)- Parameters:
path- path toFormComponentworkingForm-FormComponentto be testedwicketTester-WicketTesterthat createsFormTesterfillBlankString- specifies whether to fill childTextComponents with blankStrings- See Also:
BaseWicketTester.newFormTester(String)
-
-
Method Detail
-
getInputValue
public static java.lang.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
-
getForm
public Form<?> getForm()
Retrieves the currentFormobject.- Returns:
- the working
Form
-
getTextComponentValue
public java.lang.String getTextComponentValue(java.lang.String id)
Gets the value for anAbstractTextComponentwith the provided id.- Parameters:
id-Componentid- Returns:
- the value of the text component
-
select
public FormTester select(java.lang.String formComponentId, int index)
Simulates selecting an option of aFormComponent. SupportsRadioGroup,CheckGroup, andAbstractChoicefamily currently. The behavior is similar to interacting on the browser: For a single choice, such asRadioorDropDownList, the selection will toggle each other. For multiple choice, such asCheckboxorListMultipleChoice, the selection will accumulate.- Parameters:
formComponentId- relative path (fromForm) to the selectableFormComponentindex- index of the selectable option, starting from 0- Returns:
- This
-
selectMultiple
public FormTester selectMultiple(java.lang.String formComponentId, int[] indexes)
A convenience method to select multiple options for theFormComponent. The method only support multiple selectableFormComponents.- Parameters:
formComponentId- relative path (fromForm) to the selectableFormComponentindexes- index of the selectable option, starting from 0- Returns:
- This
- See Also:
select(String, int)
-
selectMultiple
public FormTester selectMultiple(java.lang.String formComponentId, int[] indexes, boolean replace)
A convenience method to select multiple options for theFormComponent. The method only support multiple selectableFormComponents.- Parameters:
formComponentId- relative path (fromForm) to the selectableFormComponentindexes- 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(java.lang.String formComponentId, java.lang.String value)
Simulates filling in a field on aForm.- Parameters:
formComponentId- relative path (fromForm) to the selectableFormComponentorIFormSubmittingComponentvalue- the field value- Returns:
- This
-
setValue
public FormTester setValue(Component formComponent, java.lang.String value)
Simulates filling in a field on aForm.- Parameters:
formComponent- relative path (fromForm) to the selectableFormComponentorIFormSubmittingComponentvalue- the field value- Returns:
- This
-
setValue
public FormTester setValue(java.lang.String checkBoxId, boolean value)
- Parameters:
checkBoxId-value-- Returns:
- This
-
setFile
public FormTester setFile(java.lang.String formComponentId, org.apache.wicket.util.file.File file, java.lang.String contentType)
Sets theFileon aFileUploadField.- Parameters:
formComponentId- relative path (fromForm) to the selectableFormComponent. TheFormComponentmust be of a typeFileUploadField.file- theFileto upload ornullfor an empty inputcontentType- the content type of the file. Must be a valid mime type.- Returns:
- This
-
submit
public FormTester submit()
Submits theForm. Note thatsubmitcan be executed only once.- Returns:
- This
-
isClearFeedbackMessagesBeforeSubmit
public boolean isClearFeedbackMessagesBeforeSubmit()
-
setClearFeedbackMessagesBeforeSubmit
public FormTester setClearFeedbackMessagesBeforeSubmit(boolean clearFeedbackMessagesBeforeSubmit)
-
submit
public FormTester submit(java.lang.String buttonComponentId)
A convenience method for submitting theFormwith an alternate button.Note that if the button is associated with a model, it's better to use the
setValuemethod 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 theFormwith an alternate button.Note that if the button is associated with a model, it's better to use the
setValuemethod instead:formTester.setValue(myButton, "value on the button"); formTester.submit();
- Parameters:
buttonComponent- relative path (fromForm) to the button- Returns:
- This
-
submitLink
public FormTester submitLink(java.lang.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
-
-