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().getModel(); assertTrue(model.getObject() instanceof DemoRequest); DemoRequest req = (DemoRequest) model.getObject(); String requestUrl = req.getRequestUrl(); assertEquals(modifiedUrl, requestUrl); }
public void validate(Form<?> form) { // only validate on final submit if (form.findSubmittingButton() != form.get("submit")) { return; } // Getting pool components final Component maxPoolComponent = form.get("maxPoolSize"); final Component corePoolComponent = form.get("corePoolSize"); int maxPool; int corePool; // checking limits are properly set if (maxPoolComponent != null && maxPoolComponent instanceof TextField<?> && corePoolComponent != null && corePoolComponent instanceof TextField<?>) { final TextField maxPoolField = (TextField) maxPoolComponent; final TextField corePoolField = (TextField) corePoolComponent; final String mp = maxPoolField.getValue(); final String cp = corePoolField.getValue(); if (!(mp == null || cp == null || mp.trim().isEmpty() || cp.trim().isEmpty())) { try { maxPool = Integer.valueOf(mp); } catch (NumberFormatException nfe) { // The MinimumValidator(1) should already deal with that return; } try { corePool = Integer.valueOf(cp); } catch (NumberFormatException nfe) { // The MinimumValidator(1) should already deal with that return; } if (maxPool >= 1 && corePool >= 1 && maxPool < corePool) { form.error(new ParamResourceModel("poolSizeCheck", getPage()).getString()); } } } }