use of org.hibernate.validator.cfg.defs.NotNullDef in project hibernate-validator by hibernate.
the class MethodConstraintMappingTest method constraintConfiguredOnFieldIsNotEvaluatedByMethodValidation.
@Test
public void constraintConfiguredOnFieldIsNotEvaluatedByMethodValidation() {
ConstraintMapping mapping = config.createConstraintMapping();
mapping.type(GreetingServiceImpl.class).field("hello").constraint(new NotNullDef());
config.addMapping(mapping);
GreetingService service = getValidatingProxy(wrappedObject, config.buildValidatorFactory().getValidator());
assertNull(service.getHello());
}
use of org.hibernate.validator.cfg.defs.NotNullDef in project hibernate-validator by hibernate.
the class MethodConstraintMappingTest method testCascadingMethodReturnDefinitionWithGroupConversion.
@Test
public void testCascadingMethodReturnDefinitionWithGroupConversion() {
ConstraintMapping mapping = config.createConstraintMapping();
mapping.type(GreetingService.class).method("greet", User.class).returnValue().valid().convertGroup(Default.class).to(TestGroup.class).type(Message.class).field("message").constraint(new NotNullDef().message("message must not be null").groups(TestGroup.class));
config.addMapping(mapping);
GreetingService service = getValidatingProxy(wrappedObject, config.buildValidatorFactory().getValidator());
try {
service.greet(new User("foo"));
fail("Expected exception wasn't thrown.");
} catch (ConstraintViolationException e) {
assertThat(e.getConstraintViolations()).containsOnlyViolations(violationOf(NotNull.class).withMessage("message must not be null").withPropertyPath(pathWith().method("greet").returnValue().property("message")));
}
}
Aggregations