Search in sources :

Example 81 with ConstraintViolation

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

the class ChangePasswordFormValidatorTest method testSpacesPermittted.

@Test
public void testSpacesPermittted() throws Exception {
    ChangePasswordForm form = new ChangePasswordForm();
    form.setPassword("Ben Kingsley  is my no. 1 actor");
    form.setRetypedPassword("Ben Kingsley  is my no. 1 actor");
    form.setOldPassword("ååååååå1å");
    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 82 with ConstraintViolation

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

the class ChangePasswordFormValidatorTest method testPasswordMissingNumberInvalid.

@Test
public void testPasswordMissingNumberInvalid() {
    ChangePasswordForm form = new ChangePasswordForm();
    form.setOldPassword("£$$$$$$r");
    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 number
    form.setOldPassword("£$$$$$r1");
    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)

Example 83 with ConstraintViolation

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

the class ChangeSecurityDetailsValidatorTest method blankEntryPermittedWhenIndex0.

@Test
public void blankEntryPermittedWhenIndex0() {
    ChangeSecurityQuestionForm form = new ChangeSecurityQuestionForm();
    form.setSecurityQuestionAnswer("My answer");
    form.setSecurityQuestionId(0);
    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("");
    form.setSecurityQuestionId(0);
    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 84 with ConstraintViolation

use of javax.validation.ConstraintViolation in project opennms by OpenNMS.

the class FriendlyNameValidationTest method friendlyNameZero.

@Test
public void friendlyNameZero() {
    IdentityEntity identityEntity = new IdentityEntity();
    IPServiceEdgeEntity edge = new IPServiceEdgeEntity();
    edge.setFriendlyName(FRIENDLYNAME_EMPTY);
    edge.setMapFunction(identityEntity);
    Set<ConstraintViolation<IPServiceEdgeEntity>> constraintViolations = validator.validate(edge);
    Assert.assertEquals(0, constraintViolations.size());
}
Also used : IPServiceEdgeEntity(org.opennms.netmgt.bsm.persistence.api.IPServiceEdgeEntity) ConstraintViolation(javax.validation.ConstraintViolation) IdentityEntity(org.opennms.netmgt.bsm.persistence.api.functions.map.IdentityEntity) Test(org.junit.Test)

Example 85 with ConstraintViolation

use of javax.validation.ConstraintViolation in project wildfly by wildfly.

the class BootStrapValidationTestCase method testCustomConstraintValidatorFactory.

@Test
public void testCustomConstraintValidatorFactory() {
    HibernateValidatorConfiguration configuration = Validation.byProvider(HibernateValidator.class).configure();
    assertNotNull(configuration);
    ValidatorFactory factory = configuration.buildValidatorFactory();
    Validator validator = factory.getValidator();
    Employee emp = new Employee();
    // create employee
    emp.setEmpId("M1234");
    emp.setFirstName("MADHUMITA");
    emp.setLastName("SADHUKHAN");
    emp.setEmail("madhu@redhat.com");
    Set<ConstraintViolation<Employee>> constraintViolations = validator.validate(emp);
    assertEquals("Wrong number of constraints", constraintViolations.size(), 1);
    assertEquals("Created by default factory", constraintViolations.iterator().next().getMessage());
    // get a new factory using a custom configuration
    configuration.constraintValidatorFactory(new CustomConstraintValidatorFactory(configuration.getDefaultConstraintValidatorFactory()));
    factory = configuration.buildValidatorFactory();
    validator = factory.getValidator();
    constraintViolations = validator.validate(emp);
    assertEquals("Wrong number of constraints", constraintViolations.size(), 1);
    assertEquals("Created by custom factory", constraintViolations.iterator().next().getMessage());
}
Also used : HibernateValidator(org.hibernate.validator.HibernateValidator) ValidatorFactory(javax.validation.ValidatorFactory) ConstraintValidatorFactory(javax.validation.ConstraintValidatorFactory) HibernateValidatorFactory(org.hibernate.validator.HibernateValidatorFactory) ConstraintViolation(javax.validation.ConstraintViolation) HibernateValidatorConfiguration(org.hibernate.validator.HibernateValidatorConfiguration) ConstraintValidator(javax.validation.ConstraintValidator) Validator(javax.validation.Validator) HibernateValidator(org.hibernate.validator.HibernateValidator) 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