FormComponent component = (FormComponent)workingForm.get(formComponentId); ChoiceSelector choiceSelector = choiceSelectorFactory.create(component); choiceSelector.doSelect(index); if (component instanceof DropDownChoice)
FormComponent<?> component = (FormComponent<?>)workingForm.get(formComponentId); ChoiceSelector choiceSelector = choiceSelectorFactory.create(component); choiceSelector.doSelect(index); if (component instanceof DropDownChoice)
/** * Creates a <code>ChoiceSelector</code>. * * @param formComponent * a <code>FormComponent</code> * @return ChoiceSelector a <code>ChoiceSelector</code> */ protected ChoiceSelector create(FormComponent formComponent) { if (formComponent == null) { fail("Trying to select on null component."); } if (formComponent instanceof RadioGroup || formComponent instanceof DropDownChoice || formComponent instanceof RadioChoice) { return new SingleChoiceSelector(formComponent); } else if (allowMultipleChoice(formComponent)) { return new MultipleChoiceSelector(formComponent); } else { fail("Selecting on the component:'" + formComponent.getPath() + "' is not supported."); return null; } }
/** * Creates a <code>ChoiceSelector</code>. * * @param formComponent * a <code>FormComponent</code> * @return ChoiceSelector a <code>ChoiceSelector</code> */ protected ChoiceSelector create(FormComponent<?> formComponent) { if (formComponent == null) { fail("Trying to select on null component."); } if (formComponent instanceof RadioGroup || formComponent instanceof DropDownChoice || formComponent instanceof RadioChoice) { return new SingleChoiceSelector(formComponent); } else if (allowMultipleChoice(formComponent)) { return new MultipleChoiceSelector(formComponent); } else { fail("Selecting on the component:'" + formComponent.getPath() + "' is not supported."); return null; } }
/** * A convenience method to select multiple options for the <code>FormComponent</code>. The * method only support multiple selectable <code>FormComponent</code>s. * * @see #select(String, int) * * @param formComponentId * relative path (from <code>Form</code>) to the selectable * <code>FormComponent</code> * @param indexes * index of the selectable option, starting from 0 * @param replace * If true, than all previous selects are first reset, thus existing selects are * replaced. If false, than the new indexes will be added. */ public void selectMultiple(String formComponentId, int[] indexes, final boolean replace) { checkClosed(); if (replace == true) { // Reset first setValue(formComponentId, ""); } ChoiceSelector choiceSelector = choiceSelectorFactory.createForMultiple((FormComponent<?>)workingForm.get(formComponentId)); for (int index : indexes) { choiceSelector.doSelect(index); } }
ChoiceSelector choiceSelector = choiceSelectorFactory.createForMultiple((FormComponent<?>)workingForm.get(formComponentId));
ChoiceSelector choiceSelector = choiceSelectorFactory.createForMultiple((FormComponent<?>)workingForm.get(formComponentId));
/** * Creates a <code>ChoiceSelector</code>. * * @param formComponent * a <code>FormComponent</code> * @return ChoiceSelector a <code>ChoiceSelector</code> */ protected ChoiceSelector create(FormComponent<?> formComponent) { if (formComponent == null) { fail("Trying to select on null component."); return null; } else if (formComponent instanceof RadioGroup || formComponent instanceof AbstractSingleSelectChoice) { return new SingleChoiceSelector(formComponent); } else if (allowMultipleChoice(formComponent)) { return new MultipleChoiceSelector(formComponent); } else { fail("Selecting on the component:'" + formComponent.getPath() + "' is not supported."); return null; } }
/** * Creates a <code>ChoiceSelector</code>. * * @param formComponent * a <code>FormComponent</code> * @return ChoiceSelector a <code>ChoiceSelector</code> */ protected ChoiceSelector create(FormComponent<?> formComponent) { if (formComponent == null) { fail("Trying to select on null component."); return null; } else if (formComponent instanceof RadioGroup || formComponent instanceof AbstractSingleSelectChoice) { return new SingleChoiceSelector(formComponent); } else if (allowMultipleChoice(formComponent)) { return new MultipleChoiceSelector(formComponent); } else { fail("Selecting on the component:'" + formComponent.getPath() + "' is not supported."); return null; } }
/** * Simulates selecting an option of a <code>FormComponent</code>. Supports * <code>RadioGroup</code>, <code>CheckGroup</code>, and <code>AbstractChoice</code> family * currently. The behavior is similar to interacting on the browser: For a single choice, such * as <code>Radio</code> or <code>DropDownList</code>, the selection will toggle each other. For * multiple choice, such as <code>Checkbox</code> or <code>ListMultipleChoice</code>, the * selection will accumulate. * * @param formComponentId * relative path (from <code>Form</code>) to the selectable * <code>FormComponent</code> * @param index * index of the selectable option, starting from 0 * @return This */ public FormTester select(final String formComponentId, int index) { checkClosed(); FormComponent<?> component = (FormComponent<?>)workingForm.get(formComponentId); ChoiceSelector choiceSelector = choiceSelectorFactory.create(component); choiceSelector.doSelect(index); for (FormComponentUpdatingBehavior updater : component.getBehaviors(FormComponentUpdatingBehavior.class)) { tester.invokeListener(component, updater); } return this; }
/** * Simulates selecting an option of a <code>FormComponent</code>. Supports * <code>RadioGroup</code>, <code>CheckGroup</code>, and <code>AbstractChoice</code> family * currently. The behavior is similar to interacting on the browser: For a single choice, such * as <code>Radio</code> or <code>DropDownList</code>, the selection will toggle each other. For * multiple choice, such as <code>Checkbox</code> or <code>ListMultipleChoice</code>, the * selection will accumulate. * * @param formComponentId * relative path (from <code>Form</code>) to the selectable * <code>FormComponent</code> * @param index * index of the selectable option, starting from 0 * @return This */ public FormTester select(final String formComponentId, int index) { checkClosed(); FormComponent<?> component = (FormComponent<?>)workingForm.get(formComponentId); ChoiceSelector choiceSelector = choiceSelectorFactory.create(component); choiceSelector.doSelect(index); for (FormComponentUpdatingBehavior updater : component.getBehaviors(FormComponentUpdatingBehavior.class)) { tester.invokeListener(component, updater); } return this; }
/** * A convenience method to select multiple options for the <code>FormComponent</code>. The * method only support multiple selectable <code>FormComponent</code>s. * * @see #select(String, int) * * @param formComponentId * relative path (from <code>Form</code>) to the selectable * <code>FormComponent</code> * @param indexes * index of the selectable option, starting from 0 */ public void selectMultiple(String formComponentId, int[] indexes) { checkClosed(); ChoiceSelector choiceSelector = choiceSelectorFactory.createForMultiple((FormComponent)workingForm.get(formComponentId)); for (int i = 0; i < indexes.length; i++) { choiceSelector.doSelect(indexes[i]); } }
/** * Constructor. * * @param formComponent * a <code>FormComponent</code> */ protected MultipleChoiceSelector(FormComponent<?> formComponent) { super(formComponent); if (!allowMultipleChoice(formComponent)) { fail("Component:'" + formComponent.getPath() + "' Does not support multiple selection."); } }