@Test public void testEditCatalogMode() throws Exception { tester.startPage(DataSecurityPage.class); tester.assertRenderedPage(DataSecurityPage.class); // simple test assertFalse( ("CHALLENGE" .equals( tester .getComponentFromLastRenderedPage("catalogModeForm:catalogMode") .getDefaultModelObject()))); // edit catalogMode value final FormTester form = tester.newFormTester("catalogModeForm"); form.select("catalogMode", 1); form.getForm() .visitChildren( RadioChoice.class, (component, visit) -> { if (component.getId().equals("catalogMode")) { ((RadioChoice) component).onSelectionChanged(); } }); assertEquals( "MIXED", tester .getComponentFromLastRenderedPage("catalogModeForm:catalogMode") .getDefaultModelObject() .toString()); }
public void testUrlLinkUnmodified() { // 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 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(); assertEquals(demoDir, req.getDemoDir()); String requestFileName = req.getRequestFileName(); String requestUrl = req.getRequestUrl(); String requestBody = req.getRequestBody(); assertEquals(requestName, requestFileName); assertNotNull(requestUrl); assertNull(requestBody); }
@Test public void testFullSelection() throws Exception { tester.startPage( new FormTestPage( new ComponentBuilder() { public Component buildComponent(String id) { return new IntegerTable(id, true); } })); tester.assertComponent("form:panel", IntegerTable.class); IntegerTable table = (IntegerTable) tester.getComponentFromLastRenderedPage("form:panel"); // check the select all check and the row check are there String selectAllPath = "form:panel:listContainer:selectAllContainer:selectAll"; String selectFirstPath = "form:panel:listContainer:items:1:selectItemContainer:selectItem"; tester.assertComponent(selectAllPath, CheckBox.class); tester.assertComponent(selectFirstPath, CheckBox.class); // test full selection assertEquals(0, table.getSelection().size()); FormTester ft = tester.newFormTester("form"); ft.setValue("panel:listContainer:selectAllContainer:selectAll", "true"); tester.executeAjaxEvent(selectAllPath, "onclick"); assertEquals(10, table.getSelection().size()); assertEquals(new Integer(0), table.getSelection().get(0)); // reset selection table.setSelection(false); assertEquals(0, table.getSelection().size()); }
@Test public void submit() { FormTester formTester = tester.newFormTester( "printSelectionFrame:printSelectionFrame_body:blueBorder:blueBorder_body:selectionForm:criteriaForm"); formTester.selectMultiple("billableProjectGroup", new int[] {0, 2}); formTester.setValue("signOff", "true"); formTester.submit("store"); tester.assertNoErrorMessage(); assertEquals( Boolean.TRUE, reportCriteria .getUserSelectedCriteria() .getCustomParameters() .get(TimesheetExportParameter.INCL_SIGN_OFF.name())); assertEquals(2, reportCriteria.getUserSelectedCriteria().getProjects().size()); Integer id = reportCriteria.getUserSelectedCriteria().getProjects().get(1).getProjectId(); // order is unknown if (id != 0 && id != 2) { fail("id should be 0 or 2"); } verifyMocks(); }
@Test public void testRender() { tester.startPage(LoginPage.class); tester.assertRenderedPage(LoginPage.class); tester.assertNoErrorMessage(); tester.assertComponent("feedbackPanel", FeedbackPanel.class); tester.assertComponent("loginForm", LoginForm.class); tester.assertComponent("loginForm:user", TextField.class); tester.assertComponent("loginForm:password", PasswordTextField.class); // create the form tester object, mapping to its wicket:id FormTester form = tester.newFormTester("loginForm"); // set the parameters for each component in the form form.setValue("user", "admin"); form.setValue("password", "admin"); // all set, submit form.submit(); tester.assertNoErrorMessage(); // check if the page is correct: in this case, I'm expecting an error to take me back to the // same page tester.assertRenderedPage(AdminHomePage.class); // if you're not expecting an error (testing for submit unsuccessful) use // assertErrorMessage(String) instead tester.assertNoErrorMessage(); }
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); }
@Test public void checkCheckbox_shouldReturnTrueInModel() { startEditorPanel(attribBoolean); FormTester formTester = tester.newFormTester(editor.getId() + ":form"); formTester.setValue(buildFormComponentId(attribBoolean.getId()), true); formTester.submit(); assertThat(editor.getValues().get(attribBoolean.getId()), is("true")); }
@Test @Ignore("empty string in model gets replaced with null, why is this happening") public void submittingFormWithoutChange_shouldReturnInitialValues() throws Exception { startEditorPanel(attrib, attribNoDesc); FormTester formTester = tester.newFormTester(editor.getId() + ":form"); formTester.submit(); assertThat(editor.getValues(), is(defaultValues)); }
public void testNameRequired() { FormTester form = tester.newFormTester("rasterStoreForm"); form.setValue("namePanel:border:paramValue", null); form.submit(); tester.clickLink("rasterStoreForm:save"); tester.assertRenderedPage(CoverageStoreEditPage.class); tester.assertErrorMessages(new String[] {"Store name is required"}); }
private void testWithValidator(AttributeDefinition.Builder attributeDefinition) { AttributeDefinition a = attributeDefinition.validator(new FailValidator()).build(); startEditorPanel(a); FormTester formTester = tester.newFormTester(editor.getId() + ":form"); String buildFormComponentId = buildFormComponentId(a.getId()); formTester.setValue(buildFormComponentId, "1"); tester.executeAjaxEvent(editor.getId() + ":form:submitButton", "onclick"); tester.assertErrorMessages(new String[] {"Validation Error"}); }
/** * Convenience method to login to the application, mostly required as the whole is protected by * ACEGI and Swarm The test structure makes us of the ACEGI TestingAuthentication provider, * meaning that you can pass on any username (the password is the same). * * <p>The user 'medical' has an additional role 'ROLE_MEDICAL'. All other users have 'ROLE_USER' * * @param userName */ protected void loginToApp(String userName) { mock.startPage(MockLoginPage.class); mock.assertRenderedPage(MockLoginPage.class); FormTester form = mock.newFormTester("form"); form.setValue("username", userName); form.submit(); mock.assertRenderedPage(HomePage.class); mock.processRequestCycle(); }
@Test public void submittingFormWithChanges_shouldReflectChangesInValues() throws Exception { startEditorPanel(attrib); FormTester formTester = tester.newFormTester(editor.getId() + ":form"); tester.debugComponentTrees(); formTester.setValue(buildFormComponentId(attrib.getId()), "new_value_a"); formTester.submit(); assertThat(editor.getValues().get(attrib.getId()), is("new_value_a")); }
@Test public void testEnterLogin() throws Exception { tester.startPage(LoginPage.class); FormTester formTester = tester.newFormTester("form"); formTester.setValue("username", "test"); formTester.setValue("password", "password"); formTester.submit(); tester.assertNoErrorMessage(); tester.assertRenderedPage(Index.class); }
@Test public void testValidateOnlyAfterSubmit() throws Exception { startEditorPanel(numberAttrib); FormTester formTester = tester.newFormTester(editor.getId() + ":form"); String buildFormComponentId = buildFormComponentId(numberAttrib.getId()); formTester.setValue(buildFormComponentId, "A"); tester.executeAjaxEvent(editor.getId() + ":form:submitButton", "onclick"); // tester. }
@Test public void putLetterIntoNumberField_shouldResultInError() throws Exception { startEditorPanel(numberAttrib); FormTester formTester = tester.newFormTester(editor.getId() + ":form"); String buildFormComponentId = buildFormComponentId(numberAttrib.getId()); formTester.setValue(buildFormComponentId, "A"); tester.executeAjaxEvent(editor.getId() + ":form:submitButton", "onclick"); tester.assertErrorMessages(new String[] {"Number formating Error"}); }
@Test public void testDeleteNotExistingImport_shouldWork() throws Exception { FormTester formTester = tester.newFormTester("editForm"); formTester.setValue("importName", "test"); formTester.submit("deleteButton"); LinkTree tree = (LinkTree) tester.getComponentFromLastRenderedPage("tree"); assertEquals( imports.size(), tree.getModelObject().getChildCount(tree.getModelObject().getRoot())); }
public void testChangeName() { FormTester form = tester.newFormTester("rasterStoreForm"); form.setValue("namePanel:border:paramValue", "BlueMarbleModified"); form.submit(); tester.clickLink("rasterStoreForm:save"); tester.assertNoErrorMessage(); tester.assertRenderedPage(StorePage.class); assertNotNull(getCatalog().getStoreByName("BlueMarbleModified", CoverageStoreInfo.class)); }
@Test public void testAddNewImport_shouldAddImport() throws Exception { FormTester formTester = tester.newFormTester("editForm"); formTester.setValue("importName", "aaaa.bbbb.fff"); formTester.submit("submitButton"); LinkTree tree = (LinkTree) tester.getComponentFromLastRenderedPage("tree"); assertEquals( imports.size(), tree.getModelObject().getChildCount(tree.getModelObject().getRoot())); }
@Test public void testLogout() throws Exception { tester.startPage(LoginPage.class); FormTester formTester = tester.newFormTester("form"); formTester.setValue("username", "test"); formTester.setValue("password", "password"); formTester.submit(); tester.clickLink("logout"); tester.assertRenderedPage(LoginPage.class); }
@Test public void selectLabelInDropDownChoice_shouldSetRightValueInModel() { startEditorPanel(attribOption); FormTester formTester = tester.newFormTester(editor.getId() + ":form"); formTester.select(buildFormComponentId(attribOption.getId()), 1); formTester.submit(); assertThat( editor.getValues().get(attribOption.getId()), is(attribOption.getOptions().get(1).getValue())); }
@Test public void testInvalidLogin() throws Exception { tester.startPage(LoginPage.class); FormTester formTester = tester.newFormTester("form"); formTester.setValue("username", "test"); formTester.setValue("password", "wrongpassword"); formTester.submit(); tester.assertRenderedPage(LoginPage.class); List<Serializable> messages = tester.getMessages(FeedbackMessage.ERROR); assertFalse(messages.isEmpty()); }
@Test(enabled = true) public void testCreateNew() { tester.startPage(EditProductPage.class, new PageParameters()); FormTester formTester = tester.newFormTester("productPanel:productForm"); setMandatoryFormParameters(formTester); formTester.submitLink("submit", false); tester.assertRenderedPage(ProductPage.class); tester.assertNoErrorMessage(); }
private void login(String username, String password) { SecureWebSession session = (SecureWebSession) tester.getSession(); session.signOut(); tester.startPage(LoginPage.class); FormTester formTester = tester.newFormTester("loginForm"); formTester.setValue("username", username); formTester.setValue("password", password); formTester.submit(); tester.assertNoErrorMessage(); tester.assertRenderedPage(tester.getApplication().getHomePage()); }
@Test public void testFalhaAutenticacao() { tester.startPage(Login.class); FormTester form = tester.newFormTester("loginForm"); form.setValue("userId", ""); form.setValue("password", ""); form.submit(); tester.assertRenderedPage(Login.class); }
public void newAccountCanBeAdded() { checking( new Expectations() { { one(accountRepository).addAccount(new Account("1111-2222")); } }); FormTester form = wicket.newFormTester(form().getPageRelativePath()); form.setValue("accountNumber", "1111-2222"); wicket.executeAjaxEvent( selectFirst(Button.class, "addAccountButton").from(context).getPageRelativePath(), "onclick"); }
public void testPasswordsDontMatch() { Locale.setDefault(Locale.ENGLISH); FormTester form = tester.newFormTester("userForm"); form.setValue("username", "user"); form.setValue("password", "pwd1"); form.setValue("confirmPassword", "pwd2"); form.setValue("roles:roles:recorder", dao.getRoles().get(0)); form.submit("save"); tester.assertErrorMessages( new String[] {"'pwd1' from Password and 'pwd2' from Confirm password must be equal."}); tester.assertRenderedPage(NewUserPage.class); }
@Test public void testCreateNewXmlViewWithExistingProduct() { PageParameters pageParameters = new PageParameters(); pageParameters.set(VIEW.toString(), "xml"); tester.startPage(EditProductPage.class, pageParameters); FormTester formTester = tester.newFormTester("productPanel:productForm"); formTester.setValue("control.xml:xml", productMarshaller.marshal(shsProduct)); formTester.submitLink("submit", false); tester.assertRenderedPage(EditProductPage.class); tester.assertErrorMessages( "A product with the UUID " + shsProduct.getUuid() + " already exists"); }
@Test public void testCreateNewXmlView() { PageParameters pageParameters = new PageParameters(); pageParameters.set(VIEW.toString(), "xml"); tester.startPage(EditProductPage.class, pageParameters); FormTester formTester = tester.newFormTester("productPanel:productForm"); shsProduct.setUuid(UUID.randomUUID().toString()); formTester.setValue("control.xml:xml", productMarshaller.marshal(shsProduct)); formTester.submitLink("submit", false); tester.assertRenderedPage(ProductPage.class); tester.assertNoErrorMessage(); }
@Test public void testCreateNewWithExistingUuid() { tester.startPage(EditProductPage.class, new PageParameters()); FormTester formTester = tester.newFormTester("productPanel:productForm"); setMandatoryFormParameters(formTester); formTester.setValue("control.uuid:uuid", shsProduct.getUuid()); formTester.submitLink("submit", false); tester.assertRenderedPage(EditProductPage.class); tester.assertComponent("productPanel:feedback", FeedbackPanel.class); tester.assertErrorMessages( "A product with the UUID " + shsProduct.getUuid() + " already exists"); }
@SuppressWarnings({"unchecked"}) @Test public void addFailFieldValidator_ShouldNotCallFormValidator() { AttributeDefinition attrib1 = newAttribute("attrib1", "name1", "desc1").validator(new FailValidator()).build(); FormValidator mock = Mockito.mock(FormValidator.class); Mockito.when(mock.fieldsToValidate()).thenReturn(Arrays.asList(new String[] {"attrib1"})); startEditorPanel(mock, attrib1); FormTester formTester = tester.newFormTester(editor.getId() + ":form"); String component1Id = buildFormComponentId(attrib1.getId()); formTester.setValue(component1Id, "a"); tester.executeAjaxEvent(editor.getId() + ":form:submitButton", "onclick"); Mockito.verify(mock, Mockito.never()).validate(Mockito.anyMap()); }