checkClosed(); FormComponent component = (FormComponent)workingForm.get(formComponentId);
checkClosed(); FormComponent<?> component = (FormComponent<?>)workingForm.get(formComponentId);
/** * 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]); } }
/** * Simulates filling in a field on a <code>Form</code>. * * @param formComponentId * relative path (from <code>Form</code>) to the selectable * <code>FormComponent</code> or <code>IFormSubmittingComponent</code> * @param value * the field value */ public void setValue(final String formComponentId, final String value) { checkClosed(); Component component = workingForm.get(formComponentId); if (component instanceof IFormSubmittingComponent) { setFormSubmittingComponentValue((IFormSubmittingComponent)component, value); } else if (component instanceof FormComponent) { setFormComponentValue((FormComponent)component, value); } }
/** * Sets the <code>File</code> on a {@link FileUploadField}. * * @param formComponentId * relative path (from <code>Form</code>) to the selectable * <code>FormComponent</code>. The <code>FormComponent</code> must be of a type * <code>FileUploadField</code>. * @param file * the <code>File</code> to upload. * @param contentType * the content type of the file. Must be a valid mime type. */ public void setFile(final String formComponentId, final File file, final String contentType) { checkClosed(); FormComponent formComponent = (FormComponent)workingForm.get(formComponentId); if (formComponent instanceof FileUploadField == false) { throw new IllegalArgumentException("'" + formComponentId + "' is not " + "a FileUploadField. You can only attach a file to form " + "component of this type."); } MockHttpServletRequest servletRequest = baseWicketTester.getServletRequest(); servletRequest.addFile(formComponent.getInputName(), file, contentType); }
/** * Sets the <code>File</code> on a {@link FileUploadField}. * * @param formComponentId * relative path (from <code>Form</code>) to the selectable * <code>FormComponent</code>. The <code>FormComponent</code> must be of a type * <code>FileUploadField</code>. * @param file * the <code>File</code> to upload. * @param contentType * the content type of the file. Must be a valid mime type. */ public void setFile(final String formComponentId, final File file, final String contentType) { checkClosed(); FormComponent formComponent = (FormComponent)workingForm.get(formComponentId); if (formComponent instanceof FileUploadField == false) { throw new IllegalArgumentException("'" + formComponentId + "' is not " + "a FileUploadField. You can only attach a file to form " + "component of this type."); } MockHttpServletRequest servletRequest = baseWicketTester.getServletRequest(); servletRequest.addFile(formComponent.getInputName(), file, contentType); }
/** * Submits the <code>Form</code>. Note that <code>submit</code> can be executed only once. * * @return This */ public FormTester submit() { checkClosed(); try { if (clearFeedbackMessagesBeforeSubmit) { tester.clearFeedbackMessages(); } tester.getRequest().setUseMultiPartContentType(workingForm.isMultiPart()); tester.submitForm(path); } finally { closed = true; } 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 * @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); } }
/** * Submits the <code>Form</code>. Note that <code>submit</code> can be executed only once. * * @return This */ public FormTester submit() { checkClosed(); try { if (clearFeedbackMessagesBeforeSubmit) { tester.clearFeedbackMessages(); } tester.getRequest().setUseMultiPartContentType(workingForm.isMultiPart()); tester.submitForm(path); } finally { closed = true; } return this; }
/** * Simulates filling in a field on a <code>Form</code>. * * @param formComponent * relative path (from <code>Form</code>) to the selectable * <code>FormComponent</code> or <code>IFormSubmittingComponent</code> * @param value * the field value * @return This */ public FormTester setValue(final Component formComponent, final String value) { Args.notNull(formComponent, "formComponent"); checkClosed(); if (formComponent instanceof IFormSubmittingComponent) { setFormSubmittingComponentValue((IFormSubmittingComponent)formComponent, value); } else if (formComponent instanceof FormComponent) { setFormComponentValue((FormComponent<?>)formComponent, value); } else { fail("Component with id: " + formComponent.getId() + " is not a FormComponent"); } 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; }
/** * 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 filling in a field on a <code>Form</code>. * * @param formComponent * relative path (from <code>Form</code>) to the selectable * <code>FormComponent</code> or <code>IFormSubmittingComponent</code> * @param value * the field value * @return This */ public FormTester setValue(final Component formComponent, final String value) { Args.notNull(formComponent, "formComponent"); checkClosed(); if (formComponent instanceof IFormSubmittingComponent) { setFormSubmittingComponentValue((IFormSubmittingComponent)formComponent, value); } else if (formComponent instanceof FormComponent) { setFormComponentValue((FormComponent<?>)formComponent, value); } else { fail("Component with id: " + formComponent.getId() + " is not a FormComponent"); } return this; }
/** * Submits the <code>Form</code>. Note that <code>submit</code> can be executed only once. */ public void submit() { checkClosed(); try { MockHttpServletRequest servletRequest = baseWicketTester.getServletRequest(); WebRequestCycle requestCycle = baseWicketTester.createRequestCycle(); servletRequest.setRequestToComponent(workingForm); servletRequest.setUseMultiPartContentType(isMultiPart()); baseWicketTester.processRequestCycle(requestCycle); } finally { closed = true; } }
/** * Submits the <code>Form</code>. Note that <code>submit</code> can be executed only once. */ public void submit() { checkClosed(); try { baseWicketTester.getWicketSession().cleanupFeedbackMessages(); MockHttpServletRequest servletRequest = baseWicketTester.getServletRequest(); WebRequestCycle requestCycle = baseWicketTester.createRequestCycle(); servletRequest.setRequestToComponent(workingForm.getRootForm()); servletRequest.setUseMultiPartContentType(isMultiPart()); baseWicketTester.processRequestCycle(requestCycle); } finally { closed = true; } }
final String contentType) checkClosed();
final String contentType) checkClosed();