public void testEditBasic() { // print(tester.getLastRenderedPage(), true, true); FormTester ft = tester.newFormTester("form"); ft.select("panel:language", 0); ft.setValue("panel:metadataURL", "http://www.geoserver.org/test"); ft.select("panel:metadataURLType", 0); ft.submit(); // print(tester.getLastRenderedPage(), true, true); tester.assertModelValue("form:panel:language", "bul"); tester.assertModelValue("form:panel:metadataURL", "http://www.geoserver.org/test"); tester.assertModelValue("form:panel:metadataURLType", "application/vnd.ogc.csw.GetRecordByIdResponse_xml"); }
/** * A convenience method for submitting the <code>Form</code> with an alternate button. * <p> * Note that if the button is associated with a model, it's better to use the * <code>setValue</code> method instead: * * <pre> * formTester.setValue("to:my:button", "value on the button"); * formTester.submit(); * </pre> * * @param buttonComponentId * relative path (from <code>Form</code>) to the button * @return This */ public FormTester submit(final String buttonComponentId) { Component submitter = getForm().get(buttonComponentId); if (submitter == null) { fail("Cannot submit the form because there is no submitting component with id: " + buttonComponentId); } return submit(submitter); }
<pre><code>//simulate insert new value FormTester formTester = tester.newFormTester(PANEL_ID + FORM); formTester.setValue("selectBox", "newValue"); //Find onchange behaviour AjaxFormComponentUpdatingBehavior behavior = (AjaxFormComponentUpdatingBehavior) WicketTesterHelper.findBehavior( tester.getComponentFromLastRenderedPage(PANEL_ID + FORM + ":" + "selectBox"), ajaxFormComponentUpdatingBehavior.class); //execute onchange tester.executeBehavior(behavior); </code></pre>
@Override public FormTester submit(String buttonComponentId) { String formRelativeComponentId = getFormRelativeComponentId(buttonComponentId); return super.submit(formRelativeComponentId); }
public void testExisting() { final LayerInfo layer = getCatalog().getLayerByName(MockData.PONDS.getLocalPart()); FormTestPage page = new FormTestPage(new ComponentBuilder() { public Component buildComponent(String id) { return new WMSLayerConfig(id, new Model(layer)); } } ); tester.startPage(page); tester.assertRenderedPage(FormTestPage.class); tester.assertComponent("form", Form.class); tester.assertComponent("form:panel:styles:defaultStyle", DropDownChoice.class); // check selecting something else works StyleInfo target = ((List<StyleInfo>) new StylesModel().getObject()).get(0); FormTester ft = tester.newFormTester("form"); ft.select("panel:styles:defaultStyle", 0); ft.submit(); tester.assertModelValue("form:panel:styles:defaultStyle", target); }
form.setValue(WicketPath.IMPORT_DIRECTORY.path, this.dataRoot.getAbsolutePath() + "/../../src/test/data/geotiff/rotated.tiff"); form.setValue(WicketPath.IMPORT_OUTDIRECTORY.path, "/tmp"); this.checkFormStateWhenCopyIsUnchecked(form.getForm()); form.setValue(WicketPath.IMPORT_COPY.path, true); this.executeWidgetUpdate(); this.checkFormStateWhenCopyIsChecked(form.getForm()); this.checkFormStateWhenTileIsUnchecked(form.getForm()); this.checkFormStateWhenOverviewIsUnchecked(form.getForm()); form.setValue(WicketPath.GEOTIFF_TILE.path, true); this.executeWidgetUpdate(); this.checkFormStateWhenCopyIsChecked(form.getForm()); this.checkFormStateWhenTileIsChecked(form.getForm()); this.checkFormStateWhenOverviewIsUnchecked(form.getForm()); form.setValue(WicketPath.GEOTIFF_OVERVIEW.path, true); this.executeWidgetUpdate(); this.checkFormStateWhenCopyIsChecked(form.getForm()); this.checkFormStateWhenTileIsChecked(form.getForm()); this.checkFormStateWhenOverviewIsChecked(form.getForm()); form.setValue(WicketPath.GEOTIFF_OVERVIEW.path, false); this.executeWidgetUpdate(); this.checkFormStateWhenCopyIsChecked(form.getForm()); this.checkFormStateWhenTileIsChecked(form.getForm()); this.checkFormStateWhenOverviewIsUnchecked(form.getForm());
public void testImportShapefileCopyGUI() { tester.clickLink(WicketPath.IMPORT_LINK.path); tester.clickLink(WicketPath.IMPORT_SHAPEFILELINK.path); // Checks that, by default, the output directory cannot be set FormTester form = tester.newFormTester(WicketPath.IMPORT_FORM.path); this.assertDisabled(form.getForm(), WicketPath.IMPORT_OUTDIRECTORY.path); // Checks that, the output directory is enabled when "copy" is set form.setValue(WicketPath.IMPORT_COPY.path, true); this.executeWidgetUpdate(); this.assertEnabled(form.getForm(), WicketPath.IMPORT_OUTDIRECTORY.path); }
public void testUpload() throws Exception { FormTester upload = tester.newFormTester("uploadForm"); File styleFile = new File(new java.io.File(getClass().getResource("default_point.sld").toURI())); String sld = IOUtils.toString(new FileReader(styleFile)).replaceAll("\r\n", "\n").replaceAll("\r", "\n"); upload.setFile("filename", styleFile, "application/xml"); upload.submit(); tester.assertRenderedPage(StyleNewPage.class); tester.assertModelValue("form:SLD", sld); }
public FormTester select(String formComponentId, int index) { String formRelativeComponentId = getFormRelativeComponentId(formComponentId); return super.select(formRelativeComponentId, index); }
protected Stream<FormComponent> findFormComponentsByType(SType type) { return findFormComponentsByType(form.getForm(), type); }
/** * Creates a {@link FormTester} for the <code>Form</code> at a given path. * * @param path * path to <code>FormComponent</code> * @param fillBlankString * specifies whether to fill all child <code>FormComponent</code>s with blank * <code>String</code>s * @return a <code>FormTester</code> instance for testing the <code>Form</code> * @see FormTester */ public FormTester newFormTester(final String path, final boolean fillBlankString) { return new FormTester(path, (Form<?>)getComponentFromLastRenderedPage(path), this, fillBlankString); }
FormTester formTester = tester.newFormTester("form"); formTester.setValue("myformfield", "Hello Sailor");
/** @FIXME This test fails in 2.6 */ @Test public void testCancel() throws URISyntaxException, IOException { GeofenceTestUtils.emptyFile("test-config.properties"); // GeofenceTestUtils.emptyFile("test-cache-config.properties"); FormTester ft = tester.newFormTester("form"); ft.submit("cancel"); tester.assertRenderedPage(GeoServerHomePage.class); assertTrue(GeofenceTestUtils.readConfig("test-config.properties").length() == 0); // assertTrue(GeofenceTestUtils.readConfig("test-cache-config.properties").length() == 0); }
@Test public void testActionEditLayer() { Task task3 = tutil.initTask(FileRemotePublicationTaskTypeImpl.NAME, "task3"); util.addTaskToConfiguration(config, task3); config = dao.save(config); ConfigurationPage page = new ConfigurationPage(config); tester.startPage(page); tester.assertRenderedPage(ConfigurationPage.class); tester.assertComponent( "configurationForm:attributesPanel:listContainer:items:10:itemProperties:2:component", PanelListPanel.class); tester.assertComponent( "configurationForm:attributesPanel:listContainer:items:10:itemProperties:2:component:listview:0:panel", ButtonPanel.class); tester.assertModelValue( "configurationForm:attributesPanel:listContainer:items:10:itemProperties:2:component:listview:0:panel:button", "Edit Layer.."); FormTester formTester = tester.newFormTester("configurationForm"); formTester.submit( "attributesPanel:listContainer:items:10:itemProperties:2:component:listview:0:panel:button"); assertFeedback("topFeedback", "You cannot execute this action with this value."); formTester.select( "attributesPanel:listContainer:items:10:itemProperties:1:component:dropdown", 1); formTester.submit( "attributesPanel:listContainer:items:10:itemProperties:2:component:listview:0:panel:button"); tester.assertNoErrorMessage(); tester.assertRenderedPage(ResourceConfigurationPage.class); tester.clickLink("publishedinfo:cancel"); tester.assertRenderedPage(ConfigurationPage.class); }
public void testUrlLinkModified() { // print(tester.getLastRenderedPage(), true, true); final FormTester requestFormTester = tester.newFormTester("demoRequestsForm"); final String requestName = "WMS_describeLayer.url"; requestFormTester.select("demoRequestsList", 1); /* * There's an AjaxFormSubmitBehavior attached to onchange so force it */ tester.executeAjaxEvent("demoRequestsForm:demoRequestsList", "onchange"); tester.assertModelValue("demoRequestsForm:demoRequestsList", requestName); final String modifiedUrl = "http://modified/url"; TextField url = (TextField) tester.getComponentFromLastRenderedPage("demoRequestsForm:url"); url.setModelValue(new String[] { modifiedUrl }); assertEquals(modifiedUrl, url.getValue()); final boolean isAjax = true; tester.clickLink("demoRequestsForm:submit", isAjax); tester.assertVisible("responseWindow"); IModel model = tester.getLastRenderedPage().getDefaultModel(); assertTrue(model.getObject() instanceof DemoRequest); DemoRequest req = (DemoRequest) model.getObject(); String requestUrl = req.getRequestUrl(); assertEquals(modifiedUrl, requestUrl); }
protected static String formField(FormTester form, String leafName) { return "form:" + TestFinders.findId(form.getForm(), leafName).orElse(null); }
/** * Creates a {@link FormTester} for the <code>Form</code> at a given path. * * @param path * path to <code>FormComponent</code> * @param fillBlankString * specifies whether to fill all child <code>FormComponent</code>s with blank * <code>String</code>s * @return a <code>FormTester</code> instance for testing the <code>Form</code> * @see FormTester */ public FormTester newFormTester(final String path, final boolean fillBlankString) { return new FormTester(path, (Form<?>)getComponentFromLastRenderedPage(path), this, fillBlankString); }
public void testImportShapefileCorruptedDirectory() { // Go to the page for importing a directory containing corrupted shapefiles tester.clickLink(WicketPath.IMPORT_LINK.path); tester.clickLink(WicketPath.IMPORT_SHAPEFILELINK.path); // Fills the form with a directory containing no Shapefiles FormTester form = tester.newFormTester(WicketPath.IMPORT_FORM.path); form.setValue(WicketPath.IMPORT_NAME.path, "testshp"); form.setValue(WicketPath.IMPORT_DESCRIPTION.path, "Shapefile test"); form.setValue(WicketPath.IMPORT_DIRECTORY.path, this.dataRoot.getAbsolutePath() + "/../../src/test/data/corruptedshp"); form.submit(WicketPath.IMPORT_NEXT.path); this.assertNoException(); }