Search in sources :

Example 76 with ConstraintViolation

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

the class ChangeSecurityDetailsValidatorTest method allValuesPopulatedHappyPath.

@Test
public void allValuesPopulatedHappyPath() {
    ChangeSecurityQuestionForm form = new ChangeSecurityQuestionForm();
    form.setSecurityQuestionAnswer("My answer");
    form.setSecurityQuestionId(2);
    Set<ConstraintViolation<ChangeSecurityQuestionForm>> errors = validator.validate(form);
    assertEquals("Should be no errors", 0, errors.size());
}
Also used : ChangeSecurityQuestionForm(org.orcid.frontend.web.forms.ChangeSecurityQuestionForm) ConstraintViolation(javax.validation.ConstraintViolation) Test(org.junit.Test)

Example 77 with ConstraintViolation

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

the class ManagePasswordOptionsValidationFormTest method allValuesPopulatedHappyPath.

@Test
public void allValuesPopulatedHappyPath() {
    ManagePasswordOptionsForm form = new ManagePasswordOptionsForm();
    form.setPassword("passw0rd");
    form.setRetypedPassword("passw0rd");
    form.setSecurityQuestionId(1);
    form.setSecurityQuestionAnswer("stan");
    form.setVerificationNumber("9999");
    Set<ConstraintViolation<ManagePasswordOptionsForm>> errors = validator.validate(form);
    assertEquals("Should be no errors", 0, errors.size());
}
Also used : ManagePasswordOptionsForm(org.orcid.frontend.web.forms.ManagePasswordOptionsForm) ConstraintViolation(javax.validation.ConstraintViolation) Test(org.junit.Test)

Example 78 with ConstraintViolation

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

the class ManagePasswordOptionsValidationFormTest method testSpacesPermittted.

@Test
public void testSpacesPermittted() throws Exception {
    ManagePasswordOptionsForm form = new ManagePasswordOptionsForm();
    form.setPassword("Stellan Skasgård  is my no. 1 actor");
    form.setRetypedPassword("Stellan Skasgård  is my no. 1 actor");
    form.setSecurityQuestionId(1);
    form.setSecurityQuestionAnswer("stan");
    form.setVerificationNumber("9999");
    Set<ConstraintViolation<ManagePasswordOptionsForm>> errors = validator.validate(form);
    assertEquals("Should be no errors", 0, errors.size());
}
Also used : ManagePasswordOptionsForm(org.orcid.frontend.web.forms.ManagePasswordOptionsForm) ConstraintViolation(javax.validation.ConstraintViolation) Test(org.junit.Test)

Example 79 with ConstraintViolation

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

the class ManagePasswordOptionsValidationFormTest method testRegistrationFormInvalidData.

@Test
public void testRegistrationFormInvalidData() throws Exception {
    ManagePasswordOptionsForm form = new ManagePasswordOptionsForm();
    form.setSecurityQuestionId(0);
    form.setVerificationNumber("999");
    Set<ConstraintViolation<ManagePasswordOptionsForm>> violations = validator.validate(form);
    Map<String, String> allErrorValues = retrieveErrorKeyAndMessage(violations);
    String securityQuestion = allErrorValues.get("securityQuestionId");
    String digits = allErrorValues.get("verificationNumber");
    assertEquals("Please select a security question.", securityQuestion);
    assertEquals("Please enter a 4 digit verification number", digits);
    // also try a negative verification number just to make sure
    form.setVerificationNumber("-7299");
    violations = validator.validate(form);
    allErrorValues = retrieveErrorKeyAndMessage(violations);
    digits = allErrorValues.get("verificationNumber");
    assertEquals("Please enter a 4 digit verification number", digits);
}
Also used : ManagePasswordOptionsForm(org.orcid.frontend.web.forms.ManagePasswordOptionsForm) ConstraintViolation(javax.validation.ConstraintViolation) Test(org.junit.Test)

Example 80 with ConstraintViolation

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

the class ChangePasswordFormValidatorTest method testPasswordNumbersOnlyInvalid.

@Test
public void testPasswordNumbersOnlyInvalid() {
    ChangePasswordForm form = new ChangePasswordForm();
    form.setOldPassword("12345678");
    Set<ConstraintViolation<ChangePasswordForm>> violations = validator.validate(form);
    Map<String, String> allErrorValues = retrieveErrorKeyAndMessage(violations);
    String password = allErrorValues.get("oldPassword");
    assertEquals("Passwords must be 8 or more characters and contain at least 1 number and at least 1 alpha character or symbol", password);
    //add in a char
    form.setOldPassword("12345678b");
    violations = validator.validate(form);
    allErrorValues = retrieveErrorKeyAndMessage(violations);
    password = allErrorValues.get("oldPassword");
    assertNull(password);
}
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