/**
   * Validation de l'object m�tier User.<br>
   * Les r�gles sont les suivantes:
   *
   * <ul>
   *   <li>le login est obligatoire
   *   <li>le login est unique
   *   <li>le mot de passse est obligatoire
   *   <li>le nom est obligatoire
   *   <li>le pr�nom est obligatoire
   *   <li>l'email est obligatoire
   *   <li>Le login doit avoir entre 5 et 10 carat�res.
   *   <li>Le mot de passe doit avoir entre 5 et 10 caract�res.
   *   <li>Le format de l'adresse email doit �tre valide
   * </ul>
   *
   * @param object user � valider
   */
  public Errors validate(final Object object) {

    User user = (User) object;

    Errors errors = CoreObjectFactory.getErrors();

    if (user.getLogin() == null || user.getLogin().trim() == "") {

      errors.rejectValue("login", "user.loginMandatory");

    } else if (user.getLogin().length() < 5 || user.getLogin().length() > 10) {

      // le login doit avoir entre 5 et 10 caract�res
      errors.rejectValue("login", "user.loginIncorrectSize");

    } else if (user.getPersistanceId() == 0
        && userRepository.findUserByLogin(user.getLogin()) != null) {

      // le login doit �tre unique
      errors.rejectValue("login", "user.loginAlreadyExists");
    }

    if (user.getPassword() == null || user.getPassword().trim() == "") {

      errors.rejectValue("password", "user.passwordMandatory");

    } else if (user.getPassword().length() < 5 || user.getPassword().length() > 10) {

      // le password doit avoir entre 5 et 10 caract�res
      errors.rejectValue("password", "user.passwordIncorrectSize");
    }

    if (user.getLastName() == null || user.getLastName().trim() == "") {

      errors.rejectValue("lastName", "user.lastNameMandatory");
    }

    if (user.getFirstName() == null || user.getFirstName().trim() == "") {

      errors.rejectValue("firstName", "user.firstNameMandatory");
    }

    if (user.getEmail() == null || user.getEmail().trim() == "") {

      errors.rejectValue("email", "user.emailMandatory");

    } else if (!EmailValidator.getInstance().isValid(user.getEmail())) {

      // Le format de l'adresse email doit �tre valide

      errors.rejectValue("email", "user.incorrectEmail");
    }

    return errors;
  }
  public final void testValidateMandatoryProperties() {

    // In french
    Errors errors = companyValidator.validate(company);

    assertEquals("le nom est obligatoire", errors.getFieldError("name", Locale.FRENCH));

    // In English
    errors = companyValidator.validate(company);

    assertEquals("name is mandatory", errors.getFieldError("name", Locale.ENGLISH));
  }
  /** Max length = 100 */
  public final void testValidateNamePropertyLength() {

    company.setName(
        "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ");

    // In french
    Errors errors = companyValidator.validate(company);

    assertEquals("le nom est trop long", errors.getFieldError("name", Locale.FRENCH));

    // In English
    errors = companyValidator.validate(company);
    assertEquals("name is too long", errors.getFieldError("name", Locale.ENGLISH));

    // EveryThing OK
    company.setName(
        "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ");
    errors = companyValidator.validate(company);
    assertFalse(errors.hasFieldErrors("name"));
  }
  public final void testValidateWhenCompanyIsOK() {

    company.setName("World Company");
    Errors errors = companyValidator.validate(company);
    assertFalse(errors.hasErrors());
  }