use of org.hibernate.validator.cfg.GenericConstraintDef in project hibernate-validator by hibernate.
the class ConstructorConstraintMappingTest method testMultipleReturnValueConstraints.
@Test
public void testMultipleReturnValueConstraints() throws Exception {
ConstraintMapping mapping = config.createConstraintMapping();
mapping.type(GreetingService.class).constructor(String.class).returnValue().constraint(new GenericConstraintDef<>(ValidGreetingService.class).message("invalid 1")).constraint(new GenericConstraintDef<>(ValidGreetingService.class).message("invalid 2"));
config.addMapping(mapping);
Constructor<GreetingService> constructor = GreetingService.class.getConstructor(String.class);
ExecutableValidator executableValidator = getConfiguredExecutableValidator();
Set<ConstraintViolation<GreetingService>> violations = executableValidator.validateConstructorReturnValue(constructor, new GreetingService(""));
assertThat(violations).containsOnlyViolations(violationOf(ValidGreetingService.class).withMessage("invalid 1").withPropertyPath(pathWith().constructor(GreetingService.class).returnValue()), violationOf(ValidGreetingService.class).withMessage("invalid 2").withPropertyPath(pathWith().constructor(GreetingService.class).returnValue()));
}
use of org.hibernate.validator.cfg.GenericConstraintDef in project hibernate-validator by hibernate.
the class ConstructorConstraintMappingTest method testReturnValueConstraint.
@Test
public void testReturnValueConstraint() throws Exception {
ConstraintMapping mapping = config.createConstraintMapping();
mapping.type(GreetingService.class).constructor(String.class).returnValue().constraint(new GenericConstraintDef<>(ValidGreetingService.class).message("invalid"));
config.addMapping(mapping);
Constructor<GreetingService> constructor = GreetingService.class.getConstructor(String.class);
ExecutableValidator executableValidator = getConfiguredExecutableValidator();
Set<ConstraintViolation<GreetingService>> violations = executableValidator.validateConstructorReturnValue(constructor, new GreetingService(""));
assertThat(violations).containsOnlyViolations(violationOf(ValidGreetingService.class).withMessage("invalid").withPropertyPath(pathWith().constructor(GreetingService.class).returnValue()));
}
Aggregations