org.apache.wicket.util.tester
Class FormTester

java.lang.Object
  extended by org.apache.wicket.util.tester.FormTester

public class FormTester
extends java.lang.Object

A helper class for testing validation and submission of FormComponents.

Since:
1.2.6
Author:
Ingram Chen, Frank Bille (frankbille)

Nested Class Summary
protected  class FormTester.ChoiceSelector
          A selector template for selecting selectable FormComponents with an index of option -- supports RadioGroup, CheckGroup, and AbstractChoice family.
 
Constructor Summary
protected FormTester(java.lang.String path, Form<?> workingForm, BaseWicketTester wicketTester, boolean fillBlankString)
           
 
Method Summary
 Form<?> getForm()
          Retrieves the current Form object.
 java.lang.String getTextComponentValue(java.lang.String id)
          Gets the value for an AbstractTextComponent with the provided id.
 FormTester select(java.lang.String formComponentId, int index)
          Simulates selecting an option of a FormComponent.
 FormTester selectMultiple(java.lang.String formComponentId, int[] indexes)
          A convenience method to select multiple options for the FormComponent.
 FormTester selectMultiple(java.lang.String formComponentId, int[] indexes, boolean replace)
          A convenience method to select multiple options for the FormComponent.
 FormTester setFile(java.lang.String formComponentId, File file, java.lang.String contentType)
          Sets the File on a FileUploadField.
 FormTester setValue(Component formComponent, java.lang.String value)
          Simulates filling in a field on a Form.
 FormTester setValue(java.lang.String checkBoxId, boolean value)
           
 FormTester setValue(java.lang.String formComponentId, java.lang.String value)
          Simulates filling in a field on a Form.
 FormTester submit()
          Submits the Form.
 FormTester submit(Component buttonComponent)
          A convenience method for submitting the Form with an alternate button.
 FormTester submit(java.lang.String buttonComponentId)
          A convenience method for submitting the Form with an alternate button.
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FormTester

protected FormTester(java.lang.String path,
                     Form<?> workingForm,
                     BaseWicketTester wicketTester,
                     boolean fillBlankString)
Parameters:
path - path to FormComponent
workingForm - FormComponent to be tested
wicketTester - WicketTester that creates FormTester
fillBlankString - specifies whether to fill child TextComponents with blank Strings
See Also:
BaseWicketTester.newFormTester(String)
Method Detail

getForm

public Form<?> getForm()
Retrieves the current Form object.

Returns:
the working Form

getTextComponentValue

public java.lang.String getTextComponentValue(java.lang.String id)
Gets the value for an AbstractTextComponent with the provided id.

Parameters:
id - Component id
Returns:
the value of the text component

select

public FormTester select(java.lang.String formComponentId,
                         int index)
Simulates selecting an option of a FormComponent. Supports RadioGroup, CheckGroup, and AbstractChoice family currently. The behavior is similar to interacting on the browser: For a single choice, such as Radio or DropDownList, the selection will toggle each other. For multiple choice, such as Checkbox or ListMultipleChoice, the selection will accumulate.

Parameters:
formComponentId - relative path (from Form) to the selectable FormComponent
index - 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 the FormComponent. The method only support multiple selectable FormComponents.

Parameters:
formComponentId - relative path (from Form) to the selectable FormComponent
indexes - 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 the FormComponent. The method only support multiple selectable FormComponents.

Parameters:
formComponentId - relative path (from Form) to the selectable FormComponent
indexes - index of the selectable option, starting from 0
replace - 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 a Form.

Parameters:
formComponentId - relative path (from Form) to the selectable FormComponent or IFormSubmittingComponent
value - the field value
Returns:
This

setValue

public FormTester setValue(Component formComponent,
                           java.lang.String value)
Simulates filling in a field on a Form.

Parameters:
formComponent - relative path (from Form) to the selectable FormComponent or IFormSubmittingComponent
value - 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,
                          File file,
                          java.lang.String contentType)
Sets the File on a FileUploadField.

Parameters:
formComponentId - relative path (from Form) to the selectable FormComponent. The FormComponent must be of a type FileUploadField.
file - the File to upload.
contentType - the content type of the file. Must be a valid mime type.
Returns:
This

submit

public FormTester submit()
Submits the Form. Note that submit can be executed only once.

Returns:
This

submit

public FormTester submit(java.lang.String buttonComponentId)
A convenience method for submitting the Form 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 (from Form) to the button
Returns:
This

submit

public FormTester submit(Component buttonComponent)
A convenience method for submitting the Form 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 (from Form) 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 SubmitLink
pageRelative - 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


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