Search in sources :

Example 31 with ConstraintViolation

use of javax.validation.ConstraintViolation in project ORCID-Source by ORCID.

the class ChangePasswordFormValidatorTest method testPasswordsMatchValidation.

@Test
public void testPasswordsMatchValidation() throws Exception {
    String eightMixedCharactersDigitsAndSymbol = "p4s]sW[rd";
    String incorrectRetype = "p4s]sT]rd";
    ChangePasswordForm form = new ChangePasswordForm();
    form.setPassword(eightMixedCharactersDigitsAndSymbol);
    form.setRetypedPassword(incorrectRetype);
    Set<ConstraintViolation<ChangePasswordForm>> violations = validator.validate(form);
    Map<String, String> allErrorValues = retrieveErrorKeyAndMessage(violations);
    String passwordFormatError = allErrorValues.get("password");
    String retypedPasswordFormatError = allErrorValues.get("retypedPassword");
    allErrorValues = retrieveErrorKeyAndMessage(violations);
    // the passwords themselves should be ok as they conform to the format,
    // problem is they don't match
    assertNull(passwordFormatError);
    assertNull(retypedPasswordFormatError);
    Set<String> fieldLevelErrors = retrieveErrorValuesOnly(violations);
    assertTrue(fieldLevelErrors.contains("New password values don’t match. Please try again"));
    // now match them
    form.setRetypedPassword("p4s]sW[rd");
    violations = validator.validate(form);
    allErrorValues = retrieveErrorKeyAndMessage(violations);
    passwordFormatError = allErrorValues.get("password");
    retypedPasswordFormatError = allErrorValues.get("retypedPassword");
    allErrorValues = retrieveErrorKeyAndMessage(violations);
    assertNull(passwordFormatError);
    assertNull(retypedPasswordFormatError);
    fieldLevelErrors = retrieveErrorValuesOnly(violations);
    assertFalse(fieldLevelErrors.contains("The password and confirmed password must match"));
}
Also used : ChangePasswordForm(org.orcid.frontend.web.forms.ChangePasswordForm) ConstraintViolation(javax.validation.ConstraintViolation) Test(org.junit.Test)

Example 32 with ConstraintViolation

use of javax.validation.ConstraintViolation in project ORCID-Source by ORCID.

the class ChangeSecurityDetailsValidatorTest method blankEntryNotPermittedWhenIndexNot0.

@Test
public void blankEntryNotPermittedWhenIndexNot0() {
    ChangeSecurityQuestionForm form = new ChangeSecurityQuestionForm();
    form.setSecurityQuestionAnswer("");
    form.setSecurityQuestionId(3);
    Set<ConstraintViolation<ChangeSecurityQuestionForm>> violations = validator.validate(form);
    Set<String> fieldLevelErrors = retrieveErrorValuesOnly(violations);
    assertTrue(fieldLevelErrors.contains("Please provide an answer to your challenge question."));
    form.setSecurityQuestionAnswer("An answer");
    form.setSecurityQuestionId(3);
    violations = validator.validate(form);
    fieldLevelErrors = retrieveErrorValuesOnly(violations);
    assertFalse(fieldLevelErrors.contains("Please provide an answer to your challenge question."));
}
Also used : ChangeSecurityQuestionForm(org.orcid.frontend.web.forms.ChangeSecurityQuestionForm) ConstraintViolation(javax.validation.ConstraintViolation) Test(org.junit.Test)

Example 33 with ConstraintViolation

use of javax.validation.ConstraintViolation in project ORCID-Source by ORCID.

the class ChangePasswordFormValidatorTest method allValuesPopulatedHappyPath.

@Test
public void allValuesPopulatedHappyPath() {
    ChangePasswordForm form = new ChangePasswordForm();
    form.setOldPassword("0ldPassw$rd");
    form.setPassword("passw0rd");
    form.setRetypedPassword("passw0rd");
    Set<ConstraintViolation<ChangePasswordForm>> errors = validator.validate(form);
    assertEquals("Should be no errors", 0, errors.size());
}
Also used : ChangePasswordForm(org.orcid.frontend.web.forms.ChangePasswordForm) ConstraintViolation(javax.validation.ConstraintViolation) Test(org.junit.Test)

Example 34 with ConstraintViolation

use of javax.validation.ConstraintViolation in project ORCID-Source by ORCID.

the class ChangePasswordFormValidatorTest method testPasswordWithSymbolButNotCharacterValid.

@Test
public void testPasswordWithSymbolButNotCharacterValid() {
    ChangePasswordForm form = new ChangePasswordForm();
    form.setPassword("£$$$$$$$");
    Set<ConstraintViolation<ChangePasswordForm>> violations = validator.validate(form);
    Map<String, String> allErrorValues = retrieveErrorKeyAndMessage(violations);
    String password = allErrorValues.get("password");
    assertEquals("Passwords must be 8 or more characters and contain at least 1 number and at least 1 alpha character or symbol", password);
    form.setPassword("£$$$$$$7");
    violations = validator.validate(form);
    allErrorValues = retrieveErrorKeyAndMessage(violations);
    password = allErrorValues.get("password");
    assertNull(password);
}
Also used : ChangePasswordForm(org.orcid.frontend.web.forms.ChangePasswordForm) ConstraintViolation(javax.validation.ConstraintViolation) Test(org.junit.Test)

Example 35 with ConstraintViolation

use of javax.validation.ConstraintViolation in project ORCID-Source by ORCID.

the class ChangePasswordFormValidatorTest method testSymbolsPermitttedButNotRequired.

@Test
public void testSymbolsPermitttedButNotRequired() throws Exception {
    ChangePasswordForm form = new ChangePasswordForm();
    form.setOldPassword("Ben Kingsley  is my no. 1 actor");
    form.setPassword("passw0rd");
    form.setRetypedPassword("passw0rd");
    Set<ConstraintViolation<ChangePasswordForm>> errors = validator.validate(form);
    assertEquals("Should be no errors", 0, errors.size());
    //check that the test doesn't break when symbols introduced
    form.setPassword("p$ssw0rd");
    form.setRetypedPassword("p$ssw0rd");
    errors = validator.validate(form);
    assertEquals("Should be no errors", 0, errors.size());
}
Also used : ChangePasswordForm(org.orcid.frontend.web.forms.ChangePasswordForm) ConstraintViolation(javax.validation.ConstraintViolation) Test(org.junit.Test)

Aggregations

ConstraintViolation (javax.validation.ConstraintViolation)95 Test (org.junit.Test)78 Validator (javax.validation.Validator)19 ConstraintViolationException (javax.validation.ConstraintViolationException)12 SMSMessage (org.apache.camel.component.cm.client.SMSMessage)12 ChangePasswordForm (org.orcid.frontend.web.forms.ChangePasswordForm)11 CmsDocumentBlobSegment (gov.ca.cwds.data.persistence.cms.CmsDocumentBlobSegment)10 ValidatorFactory (javax.validation.ValidatorFactory)9 ManagePasswordOptionsForm (org.orcid.frontend.web.forms.ManagePasswordOptionsForm)8 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)6 CMConfiguration (org.apache.camel.component.cm.CMConfiguration)6 Set (java.util.Set)5 InitialContext (javax.naming.InitialContext)5 Session (org.hibernate.Session)5 Transaction (org.hibernate.Transaction)5 Method (java.lang.reflect.Method)4 ExecutableValidator (javax.validation.executable.ExecutableValidator)4 CamelExecutionException (org.apache.camel.CamelExecutionException)4 Exchange (org.apache.camel.Exchange)4