public void testUpdateTitles() throws Throwable {
   String showletTypeCode = "test_showletType";
   assertNull(this._showletTypeManager.getShowletType(showletTypeCode));
   try {
     ShowletType type = this.createNewShowletType(showletTypeCode);
     this._showletTypeManager.addShowletType(type);
     String result = this.executeUpdate(showletTypeCode, "", "english title", "admin");
     assertEquals(Action.INPUT, result);
     ActionSupport action = this.getAction();
     assertEquals(1, action.getFieldErrors().size());
     result = this.executeUpdate(showletTypeCode, "Titolo modificato", "Modified title", "admin");
     assertEquals(Action.SUCCESS, result);
     ShowletType extracted = this._showletTypeManager.getShowletType(showletTypeCode);
     assertNotNull(extracted);
     assertEquals("Titolo modificato", extracted.getTitles().get("it"));
     assertEquals("Modified title", extracted.getTitles().get("en"));
   } catch (Throwable t) {
     throw t;
   } finally {
     if (null != this._showletTypeManager.getShowletType(showletTypeCode)) {
       this._showletTypeManager.deleteShowletType(showletTypeCode);
     }
     assertNull(this._showletTypeManager.getShowletType(showletTypeCode));
   }
 }
Пример #2
0
  /**
   * Checa se o usuário é administrador e em caso de erro configura action support
   *
   * @return true em caso de administrador, false caso contrário.
   */
  public static boolean checkAdministrador(ActionSupport as) {
    Usuario usuario = null;
    boolean error = false;
    request = ServletActionContext.getRequest();
    session = request.getSession();

    String login = (String) session.getAttribute("login");

    if (login == null) {
      if (as != null) as.addActionError("Você deve estar logado");
      error = true;
    } else {
      usuario = (Usuario) usuarioDao.selectByLogin(login);

      // Testa se o login foi digitado
      if (usuario == null) {
        if (as != null) as.addActionError("Erro ao identificar usuário");
        error = true;
      } else if (!usuario.getTipoUsuario().equals("ADMINISTRADOR")) {
        if (as != null) as.addActionError("Erro você deve estar logado como administrador");
        error = true;
      }
    }
    return !error;
  }
Пример #3
0
 @Override
 public String intercept(ActionInvocation invocation) throws Exception {
   logger.debug("intercept start");
   try {
     ActionSupport action = (ActionSupport) invocation.getAction();
     action.clearErrors();
     return invocation.invoke();
   } finally {
     logger.debug("intercept end");
   }
 }
  public void testFailureTrashType_1() throws Throwable {
    String result = this.executeTrash("content_viewer", "editorCustomers");
    assertEquals("userNotAllowed", result);

    result = this.executeTrash("content_viewer", "admin");
    assertEquals("inputShowletTypes", result);
    ActionSupport action = this.getAction();
    assertEquals(1, action.getActionErrors().size());

    result = this.executeUpdate("invalidShowletTitles", "italian title", "english title", "admin");
    assertEquals("inputShowletTypes", result);
    action = this.getAction();
    assertEquals(1, action.getActionErrors().size());
  }
Пример #5
0
 @Override
 public String intercept(ActionInvocation invocation) throws Exception {
   Object action = invocation.getAction();
   try {
     return invocation.invoke();
   } catch (XHRuntimeException xhe) {
     if (action instanceof ActionSupport) {
       ActionSupport as = (ActionSupport) action;
       String error = as.getText("error." + xhe.getCode());
       as.addActionError(error);
     }
     logger.error("Action XHRuntimeException.", xhe);
   }
   return "exception";
 }
Пример #6
0
 /** @return registration status text. */
 public String getStatusText() {
   if (registration.getStatus() == RegistrationStatus.NOT_STARTED) {
     return registration.getStatus().getDisplay();
   }
   String[] args = {registration.getStatus().getDisplay(), getStatusDateDisplay()};
   return action.getText("registration.status.with.date", args);
 }
  public void testTrashType() throws Throwable {
    String pageCode = "pagina_1";
    int frame = 1;
    String showletTypeCode = "test_showletType";
    assertNull(this._showletTypeManager.getShowletType(showletTypeCode));
    try {
      ShowletType type = this.createNewShowletType(showletTypeCode);
      this._showletTypeManager.addShowletType(type);
      assertNotNull(this._showletTypeManager.getShowletType(showletTypeCode));

      IPage pagina_1 = this._pageManager.getPage(pageCode);
      assertNull(pagina_1.getShowlets()[frame]);
      String result = this.executeJoinShowlet(pageCode, frame, showletTypeCode, "admin");
      assertEquals(Action.SUCCESS, result);
      pagina_1 = this._pageManager.getPage(pageCode);
      assertNotNull(pagina_1.getShowlets()[frame]);

      result = this.executeTrash(showletTypeCode, "admin");
      assertEquals("inputShowletTypes", result);
      ActionSupport action = this.getAction();
      assertEquals(1, action.getActionErrors().size());

      result = this.executeDeleteShowletFromPage(pageCode, frame, "admin");
      assertEquals(Action.SUCCESS, result);

      result = this.executeTrash(showletTypeCode, "admin");
      assertEquals(Action.SUCCESS, result);

      result = this.executeDelete(showletTypeCode, "admin");
      assertEquals(Action.SUCCESS, result);

      assertNull(this._showletTypeManager.getShowletType(showletTypeCode));
    } catch (Throwable t) {
      IPage pagina_1 = this._pageManager.getPage(pageCode);
      pagina_1.getShowlets()[frame] = null;
      this._pageManager.updatePage(pagina_1);
      if (null != this._showletTypeManager.getShowletType(showletTypeCode)) {
        this._mockShowletTypeDAO.deleteShowletType(showletTypeCode);
      }
      ((IManager) this._showletTypeManager).refresh();
      assertNull(this._showletTypeManager.getShowletType(showletTypeCode));
      throw t;
    }
  }
 public void testFailureTrashType_2() throws Throwable {
   String showletTypeCode = "test_showletType";
   assertNull(this._showletTypeManager.getShowletType(showletTypeCode));
   try {
     ShowletType type = this.createNewShowletType(showletTypeCode);
     type.setLocked(true);
     this._showletTypeManager.addShowletType(type);
     assertNotNull(this._showletTypeManager.getShowletType(showletTypeCode));
     String result = this.executeTrash(showletTypeCode, "admin");
     assertEquals("inputShowletTypes", result);
     ActionSupport action = this.getAction();
     assertEquals(1, action.getActionErrors().size());
     assertNotNull(this._showletTypeManager.getShowletType(showletTypeCode));
   } catch (Throwable t) {
     throw t;
   } finally {
     if (null != this._showletTypeManager.getShowletType(showletTypeCode)) {
       this._mockShowletTypeDAO.deleteShowletType(showletTypeCode);
     }
     ((IManager) this._showletTypeManager).refresh();
     assertNull(this._showletTypeManager.getShowletType(showletTypeCode));
   }
 }
  public void testValidateProfile() throws Throwable {
    this.setUserOnSession(USERNAME_FOR_TEST);
    this.initAction("/do/jpuserprofile/MyProfile", "new");
    this.addParameter("profileTypeCode", "PFL");
    String result = this.executeAction();
    assertEquals(Action.SUCCESS, result);

    this.initAction("/do/jpuserprofile/MyProfile", "save");
    result = this.executeAction();
    assertEquals(Action.INPUT, result);

    ActionSupport action = this.getAction();
    assertEquals(5, action.getFieldErrors().size());

    this.initAction("/do/jpuserprofile/MyProfile", "save");
    this.addParameter("Name", "Eugenio");
    this.addParameter("Surname", "Santoboni");
    this.addParameter("email", "");
    this.addParameter("birthdate", "25/09/1972");
    this.addParameter("language", "it");
    result = this.executeAction();
    assertEquals(Action.INPUT, result);

    action = this.getAction();
    assertEquals(1, action.getFieldErrors().size());
    assertEquals(1, ((List<String>) action.getFieldErrors().get("email")).size());

    IUserProfile currentUserProfile =
        (IUserProfile)
            this.getRequest()
                .getSession()
                .getAttribute(ICurrentUserProfileAction.SESSION_PARAM_NAME_CURRENT_PROFILE);
    assertNotNull(currentUserProfile);
    assertEquals(USERNAME_FOR_TEST, currentUserProfile.getUsername());
    assertEquals("Eugenio", currentUserProfile.getValue("Name"));
    assertEquals("Santoboni", currentUserProfile.getValue("Surname"));
  }
  @Override
  public void validate() {

    if (carregaForm) {

      System.out.println("Validando campos do formulario");

      if (idGrupo == 0) {
        super.addFieldError("novoUsuario.idGrupo", "O grupo deve ser selecionado!");
      }

      if (perfil.equalsIgnoreCase("0")) {
        super.addFieldError("novoUsuario.perfil", "O perfil deve ser selecionado!");
      }

      if (novoUsuario.getNome() == null || novoUsuario.getNome().isEmpty()) {
        super.addFieldError("novoUsuario.nome", "O nome deve ser preenchido!");
      }

      if (novoUsuario.getSobrenome() == null || novoUsuario.getSobrenome().isEmpty()) {
        super.addFieldError("novoUsuario.sobrenome", "O sobrenome deve ser preenchido!");
      }

      if (novoUsuario.getEmail() == null || novoUsuario.getEmail().isEmpty()) {
        super.addFieldError("novoUsuario.email", "O e-mail deve ser preenchido!");
      }

      if (loginExistente(novoUsuario.getLogin())) {

        super.addFieldError("novoUsuario.login", "O login informado ja existe");
      }

      if (novoUsuario.getLogin() == null || novoUsuario.getLogin().isEmpty()) {

        super.addFieldError("novoUsuario.login", "O login deve ser preenchido");
      }

      if (novoUsuario.getSenha() == null || novoUsuario.getSenha().isEmpty()) {
        super.addFieldError("novoUsuario.senha", "A senha deve ser informada!");
      }
    }
  }
Пример #11
0
 /** @return invitation status text with date. */
 public String getInvitationStatusText() {
   String key = registration.getInvitation().getInvitationStatus().getKey() + ".with.date";
   String[] args = {dateFormat.format(registration.getInvitation().getInvitationChangeDate())};
   return action.getText(key, args);
 }
Пример #12
0
 /**
  * @param action action to help with formated strings
  * @param reg the registration for this row.
  */
 Row(ActionSupport action, AbstractProtocolRegistration reg) {
   this.registration = reg;
   this.action = action;
   dateFormat =
       new SimpleDateFormat(action.getText("date.format.timestamp"), Locale.getDefault());
 }
Пример #13
0
 @Override
 public void validate() {
   this.clearErrorsAndMessages();
   super.validate();
 }