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