use of org.hibernate.validator.cfg.defs.SizeDef in project hibernate-validator by hibernate.
the class ProgrammaticContainerElementConstraintsForFieldTest method canDeclareContainerElementConstraintsForMultiDimensionalArrayTypeFieldProgrammatically.
// HV-1428 Container element support is disabled for arrays
@Test(expectedExceptions = ValidationException.class, expectedExceptionsMessageRegExp = "HV000226:.*")
@TestForIssue(jiraKey = "HV-1239")
public void canDeclareContainerElementConstraintsForMultiDimensionalArrayTypeFieldProgrammatically() {
ConstraintMapping newMapping = config.createConstraintMapping();
newMapping.type(FishTank.class).field("fishNamesByMonthAsArray").containerElementType(0, 0).constraint(new SizeDef().max(5));
config.addMapping(newMapping);
Validator validator = config.buildValidatorFactory().getValidator();
Set<ConstraintViolation<FishTank>> violations = validator.validate(new FishTank());
assertThat(violations).containsOnlyViolations(violationOf(Size.class).withMessage("size must be between 0 and 5"));
}
use of org.hibernate.validator.cfg.defs.SizeDef in project hibernate-validator by hibernate.
the class ProgrammaticContainerElementConstraintsForFieldTest method canDeclareContainerElementConstraintsForListContainingArrayTypeFieldProgrammatically.
// HV-1428 Container element support is disabled for arrays
@Test(expectedExceptions = ValidationException.class, expectedExceptionsMessageRegExp = "HV000226:.*")
@TestForIssue(jiraKey = "HV-1239")
public void canDeclareContainerElementConstraintsForListContainingArrayTypeFieldProgrammatically() {
ConstraintMapping newMapping = config.createConstraintMapping();
newMapping.type(FishTank.class).field("fishNamesByMonth").containerElementType(0, 0).constraint(new SizeDef().max(5));
config.addMapping(newMapping);
Validator validator = config.buildValidatorFactory().getValidator();
Set<ConstraintViolation<FishTank>> violations = validator.validate(new FishTank());
assertThat(violations).containsOnlyViolations(violationOf(Size.class).withMessage("size must be between 0 and 5"));
}
use of org.hibernate.validator.cfg.defs.SizeDef in project hibernate-validator by hibernate.
the class ProgrammaticContainerElementConstraintsForGetterTest method canDeclareContainerElementConstraintsForGetterProgrammatically.
@Test
@TestForIssue(jiraKey = "HV-1239")
public void canDeclareContainerElementConstraintsForGetterProgrammatically() {
ConstraintMapping newMapping = config.createConstraintMapping();
newMapping.type(FishTank.class).getter("model").containerElementType().constraint(new SizeDef().max(5)).getter("fishCountByType").containerElementType(0).constraint(new SizeDef().min(3).max(10)).containerElementType(1).constraint(new MinDef().value(1));
config.addMapping(newMapping);
Validator validator = config.buildValidatorFactory().getValidator();
Set<ConstraintViolation<FishTank>> violations = validator.validate(new FishTank());
assertThat(violations).containsOnlyViolations(violationOf(Size.class).withMessage("size must be between 0 and 5"), violationOf(Size.class).withMessage("size must be between 3 and 10"), violationOf(Size.class).withMessage("size must be between 3 and 10"), violationOf(Min.class).withMessage("must be greater than or equal to 1"), violationOf(Min.class).withMessage("must be greater than or equal to 1"));
}
use of org.hibernate.validator.cfg.defs.SizeDef in project hibernate-validator by hibernate.
the class ProgrammaticContainerElementConstraintsForGetterTest method canDeclareContainerElementConstraintsForListContainingArrayTypeGetterProgrammatically.
// HV-1428 Container element support is disabled for arrays
@Test(expectedExceptions = ValidationException.class, expectedExceptionsMessageRegExp = "HV000226:.*")
@TestForIssue(jiraKey = "HV-1239")
public void canDeclareContainerElementConstraintsForListContainingArrayTypeGetterProgrammatically() {
ConstraintMapping newMapping = config.createConstraintMapping();
newMapping.type(FishTank.class).getter("fishNamesByMonth").containerElementType(0, 0).constraint(new SizeDef().max(5));
config.addMapping(newMapping);
Validator validator = config.buildValidatorFactory().getValidator();
Set<ConstraintViolation<FishTank>> violations = validator.validate(new FishTank());
assertThat(violations).containsOnlyViolations(violationOf(Size.class).withMessage("size must be between 0 and 5"));
}
use of org.hibernate.validator.cfg.defs.SizeDef in project hibernate-validator by hibernate.
the class ProgrammaticContainerElementConstraintsForParameterTest method configuringConstraintsOnGenericTypeArgumentOfArrayThrowsException.
// HV-1428 Container element support is disabled for arrays
@Test(expectedExceptions = ValidationException.class, expectedExceptionsMessageRegExp = "HV000226:.*")
// @Test(expectedExceptions = UnexpectedTypeException.class, expectedExceptionsMessageRegExp = "HV000030:.*")
@TestForIssue(jiraKey = "HV-1279")
public void configuringConstraintsOnGenericTypeArgumentOfArrayThrowsException() {
ConstraintMapping newMapping = config.createConstraintMapping();
newMapping.type(IFishTank.class).method("test9", Object[].class).parameter(0).containerElementType(0).constraint(new SizeDef().max(5));
config.addMapping(newMapping);
Validator validator = config.buildValidatorFactory().getValidator();
IFishTank fishTank = ValidatorUtil.getValidatingProxy(new FishTank(), validator);
fishTank.test9(new String[] { "Too long" });
}
Aggregations