@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(); }
@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 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 testFalhaAutenticacao() { tester.startPage(Login.class); FormTester form = tester.newFormTester("loginForm"); form.setValue("userId", ""); form.setValue("password", ""); form.submit(); tester.assertRenderedPage(Login.class); }
@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 public void testUserMustNotBeSpambot() { tester.startPage(AddUser.class); FormTester formTester = tester.newFormTester("form"); formTester.setValue("email", "*****@*****.**"); formTester.setValue("firstName", "khaled"); formTester.setValue("lastName", "ayoubi"); formTester.setValue("password", "top-secret"); formTester.submit(); tester.assertErrorMessages("You must not be a spambot"); }
@Test public void testCanAddValidUser() { tester.startPage(AddUser.class); FormTester formTester = tester.newFormTester("form"); formTester.setValue("email", "*****@*****.**"); formTester.setValue("firstName", "khaled"); formTester.setValue("lastName", "ayoubi"); formTester.setValue("password", "top-secret"); formTester.setValue("notspambot", Boolean.TRUE); formTester.submit(); tester.assertNoErrorMessage(); }
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); }
protected void doTestFill() throws Exception { insertValues(); AbstractSecurityPage returnPage = initializeForUGServiceNamed(getUserGroupServiceName()); tester.startPage( page = (NewGroupPage) new NewGroupPage(getUserGroupServiceName()).setReturnPage(returnPage)); tester.assertRenderedPage(NewGroupPage.class); FormTester form = tester.newFormTester("form"); form.setValue("groupname", "testgroup"); assertTrue(((GeoServerUserGroup) page.get("form").getDefaultModelObject()).isEnabled()); form.setValue("enabled", false); assertTrue(page.rolePalette.isEnabled()); tester.assertComponent("form:roles:palette:recorder", Recorder.class); // add a role on the fly form.submit("roles:addRole"); tester.assertRenderedPage(NewRolePage.class); form = tester.newFormTester("form"); form.setValue("name", "ROLE_NEW"); form.submit("save"); // assign the new role to the new group form = tester.newFormTester("form"); tester.assertRenderedPage(NewGroupPage.class); form.setValue("roles:palette:recorder", gaService.getRoleByName("ROLE_NEW").getAuthority()); // reopen new role dialog again to ensure that the current state is not lost form.submit("roles:addRole"); tester.assertRenderedPage(NewRolePage.class); tester.clickLink("form:cancel"); tester.assertRenderedPage(NewGroupPage.class); // now save form = tester.newFormTester("form"); form.submit("save"); tester.assertRenderedPage(SecurityNamedServiceEditPage.class); tester.assertErrorMessages(new String[0]); GeoServerUserGroup group = ugService.getGroupByGroupname("testgroup"); assertNotNull(group); assertFalse(group.isEnabled()); SortedSet<GeoServerRole> roleList = gaService.getRolesForGroup("testgroup"); assertEquals(1, roleList.size()); assertEquals("ROLE_NEW", roleList.iterator().next().getAuthority()); }
@Test public void testCantAddExistingUser() { when(svc.isEmailTakenByAUser("*****@*****.**")).thenReturn(true); tester.startPage(AddUser.class); FormTester formTester = tester.newFormTester("form"); formTester.setValue("email", "*****@*****.**"); formTester.setValue("firstName", "khaled"); formTester.setValue("lastName", "ayoubi"); formTester.setValue("password", "top-secret"); formTester.setValue("notspambot", Boolean.TRUE); formTester.submit(); tester.assertErrorMessages("User already exist"); }
@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 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 testChange() { startPage(); FormTester formTester = tester.newFormTester("form"); formTester.setValue("panel:defaultValue", "testDefault"); formTester.setValue("panel:regex", "testRegex"); formTester.setValue("panel:normalize:case", "UPPER"); formTester.setValue("panel:normalize:locale", "en_CA"); formTester.submit(); assertThat(pf.getDefaultValue(), equalTo("testDefault")); assertThat(pf.getRegex(), equalTo("testRegex")); assertThat( pf.getNormalize(), both(hasProperty("case", is(Case.UPPER))).and(hasProperty("locale", is(Locale.CANADA)))); }
@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 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")); }
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(); }
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"}); }
@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"}); }
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 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())); }
@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 submittingForm_shouldCallDroolsServiceWithInstantiatedEvent() throws WorkflowException { formTester.setValue("fieldContainer:fields:3:row:field", "a"); submitForm(); ArgumentCaptor<Event> captor = ArgumentCaptor.forClass(Event.class); verify(eventService).processEvent(captor.capture()); assertThat(captor.getValue(), notNullValue()); assertThat(captor.getValue(), is(NullEvent2.class)); assertThat(((NullEvent2) captor.getValue()).getTestProperty(), is((Object) "a")); }
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()); }
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"); }
@Test public void testSaveInvalid() { wicketTester.startPage(RegistrationPage.class); FormTester formTester = wicketTester.newFormTester("registration"); formTester.setValue("firstname", "Max"); formTester.setValue("lastname", "Müller"); formTester.setValue("username", "Max.M"); formTester.setValue("email", "*****@*****.**"); formTester.setValue("password", "passsword123"); formTester.setValue("repeatPassword", "password123"); formTester.setValue("city", "München"); formTester.setValue("street", "Lindwurmstr. 33"); formTester.setValue("zip", "81369"); formTester.submit(); // verify(userService, times(0)); wicketTester.assertErrorMessages("The entered Passwords do not match"); }
public void testFill() throws Exception { Locale.setDefault(Locale.ENGLISH); // make sure the recorder is where we think it is, it contains the palette selection tester.assertComponent("userForm:roles:roles:recorder", Recorder.class); // try to add a new user FormTester form = tester.newFormTester("userForm"); form.setValue("username", "user"); form.setValue("password", "pwd"); form.setValue("confirmPassword", "pwd"); // note: use a known role, there is no way to add a new role using wickettester support form.setValue("roles:roles:recorder", dao.getRoles().get(0)); form.submit("save"); tester.assertErrorMessages(new String[0]); tester.assertRenderedPage(UserPage.class); dao.reload(); UserDetails user = dao.loadUserByUsername("user"); assertEquals("pwd", user.getPassword()); assertEquals(1, user.getAuthorities().length); }
@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(); }