Exemplo n.º 1
0
  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());
  }
Exemplo n.º 2
0
  @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();
  }
Exemplo n.º 3
0
  @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();
  }
Exemplo n.º 4
0
 @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));
 }
Exemplo n.º 5
0
 @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"));
 }
  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"});
  }
 /**
  * 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();
 }
Exemplo n.º 8
0
 @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"));
 }
Exemplo n.º 9
0
 @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()));
 }
Exemplo n.º 10
0
  @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()));
  }
Exemplo n.º 11
0
 @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);
 }
Exemplo n.º 12
0
 @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);
 }
  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));
  }
Exemplo n.º 14
0
  @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()));
  }
Exemplo n.º 15
0
 @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());
 }
Exemplo n.º 16
0
  @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);
  }
 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());
 }
Exemplo n.º 18
0
  @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");
  }
Exemplo n.º 19
0
  @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);
  }
Exemplo n.º 21
0
  @Test
  public void ボタンの確認() {
    // 大文字開始
    tester.assertLabel("form:label", "FIELD");
    tester.assertModelValue("form:upperButton", "FIELD");
    tester.assertLabel("form:lowerButton:label", "FIELD");

    // ボタンを押すよ
    FormTester form1 = tester.newFormTester("form");
    form1.submit("lowerButton");

    tester.assertLabel("form:label", "field");
    tester.assertModelValue("form:upperButton", "field");
    tester.assertLabel("form:lowerButton:label", "field");

    // ボタンを押すよ
    FormTester form2 = tester.newFormTester("form");
    form2.submit("upperButton");

    tester.assertLabel("form:label", "FIELD");
    tester.assertModelValue("form:upperButton", "FIELD");
    tester.assertLabel("form:lowerButton:label", "FIELD");
  }
Exemplo n.º 22
0
  @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");
  }
Exemplo n.º 23
0
  @Test
  public void testGroupNameConflict() throws Exception {
    insertValues();
    AbstractSecurityPage returnPage = initializeForUGServiceNamed(getUserGroupServiceName());
    tester.startPage(
        page =
            (NewGroupPage) new NewGroupPage(getUserGroupServiceName()).setReturnPage(returnPage));

    FormTester form = tester.newFormTester("form");
    form.setValue("groupname", "group1");
    form.submit("save");

    assertTrue(testErrorMessagesWithRegExp(".*group1.*"));
    tester.getMessages(FeedbackMessage.ERROR);
    tester.assertRenderedPage(NewGroupPage.class);
  }
  @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))));
  }
Exemplo n.º 25
0
  @Ignore("Wicket1.5.xだと動かない")
  @Test
  public void AJAXボタンの確認() {
    // ボタンを押すよ
    FormTester form2 = tester.newFormTester("ajaxForm");
    form2.submit("rightButton");
    tester.assertComponentOnAjaxResponse("ajaxForm:p2");
    tester.assertLabel("ajaxForm:p2:rightLabel", "fugaa");

    // clickイベントを直接叩いてもOK
    tester.executeAjaxEvent("ajaxForm:leftButton", "click");
    tester.assertComponentOnAjaxResponse("ajaxForm:p1");
    tester.assertLabel("ajaxForm:p1:leftLabel", "hogee");

    // ajaxのtarget外でも WicketTester#assertLabel で見ると変わるので、
    // 「ajaxで内部は変わってるけど裏は変わらない」とかの検証はしづらい。
    // する必要もないだろうけどなー。
  }
Exemplo n.º 26
0
  @Test
  public void testReadOnlyRoleService() throws Exception {
    activateRORoleService();
    AbstractSecurityPage returnPage = initializeForUGServiceNamed(getUserGroupServiceName());
    tester.startPage(
        page =
            (NewGroupPage) new NewGroupPage(getUserGroupServiceName()).setReturnPage(returnPage));
    assertFalse(page.rolePalette.isEnabled());

    FormTester form = tester.newFormTester("form");
    form.setValue("groupname", "testgroup");
    form.submit("save");

    GeoServerUserGroup group = ugService.getGroupByGroupname("testgroup");
    assertNotNull(group);
    assertTrue(group.isEnabled());
    SortedSet<GeoServerRole> roleList = gaService.getRolesForGroup("testgroup");
    assertEquals(0, roleList.size());
  }
  @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");
  }
  @Test
  public void testErrorSearch() {
    tester.startPage(ListCategoryPage.class);
    tester.assertRenderedPage(ListCategoryPage.class);
    tester.assertNoErrorMessage();

    // create the form tester object, mapping to its wicket:id
    FormTester form = tester.newFormTester("categoryForm");
    // set the parameters for each component in the form
    form.setValue("name", "test");
    // all set, submit
    form.submit();
    // check if the page is correct: in this case, I'm expecting an error to take me back to the
    // same page
    tester.assertRenderedPage(ListCategoryPage.class);
    // if you're not expecting an error (testing for submit unsuccessful) use
    // assertErrorMessage(String) instead
    tester.assertErrorMessages(new String[] {ERROR_MESSAGE});
  }
  /**
   * Test that changing a datastore's workspace updates the datastore's "namespace" parameter as
   * well as the namespace of its previously configured resources
   */
  public void testWorkspaceSyncsUpWithNamespace() {
    final Catalog catalog = getCatalog();

    final FormTester formTester = tester.newFormTester("rasterStoreForm");

    final String wsDropdownPath = "rasterStoreForm:workspacePanel:border:paramValue";

    tester.assertModelValue(wsDropdownPath, catalog.getWorkspaceByName(MockData.WCS_PREFIX));

    // select the fifth item in the drop down, which is the cdf workspace
    formTester.select("workspacePanel:border:paramValue", 2);

    // weird on this test I need to both call form.submit() and also simulate clicking on the
    // ajax "save" link for the model to be updated. On a running geoserver instance it works ok
    // though
    formTester.submit();

    final boolean isAjax = true;
    tester.clickLink("rasterStoreForm:save", isAjax);

    // did the save finish normally?
    tester.assertRenderedPage(StorePage.class);

    CoverageStoreInfo store = catalog.getCoverageStore(coverageStore.getId());
    WorkspaceInfo workspace = store.getWorkspace();
    assertFalse(MockData.WCS_PREFIX.equals(workspace.getName()));

    // was the namespace for the datastore resources updated?
    List<CoverageInfo> resourcesByStore;
    resourcesByStore = catalog.getResourcesByStore(store, CoverageInfo.class);

    assertTrue(resourcesByStore.size() > 0);

    for (CoverageInfo cv : resourcesByStore) {
      assertEquals(
          "Namespace for " + cv.getName() + " was not updated",
          workspace.getName(),
          cv.getNamespace().getPrefix());
    }
  }
Exemplo n.º 30
0
  /** Test creation with regular expression. */
  @Test
  public void testCreation_withExpression() {
    String expression = "[^b]at"; // $NON-NLS-1$
    descriptor.setExpression(expression);
    tester.startPage(getTestPage());

    @SuppressWarnings("unchecked")
    TextArea<String> tf = (TextArea<String>) getTestSubject();

    tf.setDefaultModelObject("bat"); // $NON-NLS-1$

    FormTester ft = tester.newFormTester(TestPage.FORM_ID);
    ft.submit();

    Assert.assertTrue(getFeedbackPanel().anyErrorMessage());
    List<FeedbackMessage> messages = getFeedbackPanel().getFeedbackMessagesModel().getObject();
    Assert.assertEquals(1, messages.size());
    String msg = messages.get(0).toString();
    Assert.assertTrue(msg.contains(expression));

    Assert.assertFalse(tester.getLastResponse().getDocument().contains(MarkupConstants.READONLY));
  }