use of org.hibernate.validator.cfg.defs.NotNullDef in project hibernate-validator by hibernate.
the class MethodConstraintMappingTest method testParameterConstraint.
@Test
public void testParameterConstraint() {
ConstraintMapping mapping = config.createConstraintMapping();
mapping.type(GreetingService.class).method("greet", User.class).parameter(0).constraint(new NotNullDef());
config.addMapping(mapping);
try {
GreetingService service = getValidatingProxy(wrappedObject, config.buildValidatorFactory().getValidator());
service.greet((User) null);
fail("Expected exception wasn't thrown.");
} catch (ConstraintViolationException e) {
assertThat(e.getConstraintViolations()).containsOnlyViolations(violationOf(NotNull.class).withMessage("must not be null").withPropertyPath(pathWith().method("greet").parameter("user", 0)));
}
}
use of org.hibernate.validator.cfg.defs.NotNullDef in project hibernate-validator by hibernate.
the class MethodConstraintMappingTest method constraintConfiguredOnMethodIsEvaluatedByPropertyValidation.
@Test
public void constraintConfiguredOnMethodIsEvaluatedByPropertyValidation() {
ConstraintMapping mapping = config.createConstraintMapping();
mapping.type(GreetingService.class).method("getHello").returnValue().constraint(new NotNullDef());
config.addMapping(mapping);
Validator validator = config.buildValidatorFactory().getValidator();
Set<ConstraintViolation<GreetingServiceImpl>> violations = validator.validateProperty(new GreetingServiceImpl(), "hello");
assertThat(violations).containsOnlyViolations(violationOf(NotNull.class).withMessage("must not be null").withPropertyPath(pathWith().property("hello")));
}
use of org.hibernate.validator.cfg.defs.NotNullDef in project hibernate-validator by hibernate.
the class MultipleConstraintMappingsTest method testSamePropertyConfiguredSeveralTimesCausesException.
@Test(expectedExceptions = ValidationException.class, expectedExceptionsMessageRegExp = "HV000172.*")
public void testSamePropertyConfiguredSeveralTimesCausesException() {
ConstraintMapping marathonMapping = config.createConstraintMapping();
marathonMapping.type(Marathon.class).getter("name").constraint(new NotNullDef()).getter("name");
}
use of org.hibernate.validator.cfg.defs.NotNullDef in project hibernate-validator by hibernate.
the class MultipleConstraintMappingsTest method testSameParameterConfiguredSeveralTimesCausesException.
@Test(expectedExceptions = ValidationException.class, expectedExceptionsMessageRegExp = "HV000174.*")
public void testSameParameterConfiguredSeveralTimesCausesException() {
ConstraintMapping marathonMapping = config.createConstraintMapping();
marathonMapping.type(Marathon.class).method("setTournamentDate", Date.class).parameter(0).constraint(new NotNullDef()).parameter(0);
}
use of org.hibernate.validator.cfg.defs.NotNullDef in project hibernate-validator by hibernate.
the class MultipleConstraintMappingsTest method testSameMethodConfiguredSeveralTimesCausesException.
@Test(expectedExceptions = ValidationException.class, expectedExceptionsMessageRegExp = "HV000173.*")
public void testSameMethodConfiguredSeveralTimesCausesException() {
ConstraintMapping marathonMapping = config.createConstraintMapping();
marathonMapping.type(Marathon.class).method("setTournamentDate", Date.class).parameter(0).constraint(new NotNullDef()).method("setTournamentDate", Date.class);
}
Aggregations