use of org.hibernate.validator.cfg.defs.NotNullDef in project hibernate-validator by hibernate.
the class ProgrammaticContainerElementConstraintsForFieldTest method canDeclareDeeplyNestedContainerElementConstraintsOnMultipleDifferentTypeArgumentsForFieldProgrammatically.
@Test
@TestForIssue(jiraKey = "HV-1614")
public void canDeclareDeeplyNestedContainerElementConstraintsOnMultipleDifferentTypeArgumentsForFieldProgrammatically() {
ConstraintMapping newMapping = config.createConstraintMapping();
newMapping.type(FishTank.class).field("tagsOfFishOfTheMonth").containerElementType(0, 0).constraint(new LengthDef().min(10).max(20)).containerElementType(0, 1, 0).constraint(new NotNullDef());
config.addMapping(newMapping);
Validator validator = config.buildValidatorFactory().getValidator();
Set<ConstraintViolation<FishTank>> violations = validator.validate(new FishTank());
assertThat(violations).containsOnlyViolations(violationOf(NotNull.class).withMessage("must not be null"), violationOf(Length.class).withMessage("length must be between 10 and 20"));
}
use of org.hibernate.validator.cfg.defs.NotNullDef in project hibernate-validator by hibernate.
the class ProgrammaticContainerElementConstraintsForFieldTest method canDeclareNestedContainerElementConstraintsForFieldProgrammatically.
@Test
@TestForIssue(jiraKey = "HV-1239")
public void canDeclareNestedContainerElementConstraintsForFieldProgrammatically() {
ConstraintMapping newMapping = config.createConstraintMapping();
newMapping.type(FishTank.class).field("fishOfTheMonth").containerElementType(1, 0).constraint(new NotNullDef());
config.addMapping(newMapping);
Validator validator = config.buildValidatorFactory().getValidator();
Set<ConstraintViolation<FishTank>> violations = validator.validate(new FishTank());
assertThat(violations).containsOnlyViolations(violationOf(NotNull.class).withMessage("must not be null"));
}
use of org.hibernate.validator.cfg.defs.NotNullDef in project hibernate-validator by hibernate.
the class ProgrammaticContainerElementConstraintsForFieldTest method canDeclareDeeplyNestedContainerElementConstraintsForFieldProgrammatically.
@Test
@TestForIssue(jiraKey = "HV-1239")
public void canDeclareDeeplyNestedContainerElementConstraintsForFieldProgrammatically() {
ConstraintMapping newMapping = config.createConstraintMapping();
newMapping.type(FishTank.class).field("tagsOfFishOfTheMonth").containerElementType(0, 1, 0).constraint(new NotNullDef());
config.addMapping(newMapping);
Validator validator = config.buildValidatorFactory().getValidator();
Set<ConstraintViolation<FishTank>> violations = validator.validate(new FishTank());
assertThat(violations).containsOnlyViolations(violationOf(NotNull.class).withMessage("must not be null"));
}
use of org.hibernate.validator.cfg.defs.NotNullDef in project hibernate-validator by hibernate.
the class ProgrammaticContainerElementConstraintsForGetterTest method canDeclareContainerElementCascadesForGetterProgrammatically.
@Test
@TestForIssue(jiraKey = "HV-1239")
public void canDeclareContainerElementCascadesForGetterProgrammatically() {
ConstraintMapping newMapping = config.createConstraintMapping();
newMapping.type(FishTank.class).getter("boss").containerElementType().valid().type(Fish.class).getter("name").constraint(new NotNullDef());
config.addMapping(newMapping);
Validator validator = config.buildValidatorFactory().getValidator();
Set<ConstraintViolation<FishTank>> violations = validator.validate(new FishTank());
assertThat(violations).containsOnlyViolations(violationOf(NotNull.class).withMessage("must not be null"));
}
use of org.hibernate.validator.cfg.defs.NotNullDef in project hibernate-validator by hibernate.
the class ProgrammaticContainerElementConstraintsForGetterTest method configuringSameContainerElementTwiceCausesException.
@Test(expectedExceptions = ValidationException.class, expectedExceptionsMessageRegExp = "HV000214.*")
@TestForIssue(jiraKey = "HV-1239")
public void configuringSameContainerElementTwiceCausesException() {
ConstraintMapping newMapping = config.createConstraintMapping();
newMapping.type(FishTank.class).getter("tagsOfFishOfTheMonth").containerElementType(0, 1, 0).constraint(new NotNullDef()).containerElementType(0, 1, 0);
}
Aggregations