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"));
}
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."));
}
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());
}
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);
}
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());
}
Aggregations