use of org.hibernate.validator.cfg.defs.SizeDef in project hibernate-validator by hibernate.
the class ProgrammaticContainerElementConstraintsForParameterTest method canDeclareContainerElementConstraintsForMultiDimensionalArrayTypeParameterProgrammatically.
// HV-1428 Container element support is disabled for arrays
@Test(expectedExceptions = ValidationException.class, expectedExceptionsMessageRegExp = "HV000226:.*")
@TestForIssue(jiraKey = "HV-1239")
public void canDeclareContainerElementConstraintsForMultiDimensionalArrayTypeParameterProgrammatically() {
ConstraintMapping newMapping = config.createConstraintMapping();
newMapping.type(IFishTank.class).method("test7", String[][].class).parameter(0).containerElementType(0, 0).constraint(new SizeDef().max(5));
config.addMapping(newMapping);
Validator validator = config.buildValidatorFactory().getValidator();
IFishTank fishTank = ValidatorUtil.getValidatingProxy(new FishTank(), validator);
try {
String[][] fishNamesByMonthAsArray = new String[][] { new String[] { "Too Long" } };
fishTank.test7(fishNamesByMonthAsArray);
fail("Expected exception wasn't raised");
} catch (ConstraintViolationException e) {
assertThat(e.getConstraintViolations()).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 ConstraintMappingTest method testProgrammaticAndAnnotationPropertyConstraintsAddUp.
@Test
public void testProgrammaticAndAnnotationPropertyConstraintsAddUp() {
mapping.type(User.class).getter("lastName").constraint(new SizeDef().min(4).max(10));
config.addMapping(mapping);
Validator validator = config.buildValidatorFactory().getValidator();
Set<ConstraintViolation<User>> violations = validator.validateProperty(new User("", ""), "lastName");
assertThat(violations).containsOnlyViolations(violationOf(Size.class).withMessage("size must be between 3 and 10"), violationOf(Size.class).withMessage("size must be between 4 and 10"));
}
use of org.hibernate.validator.cfg.defs.SizeDef in project hibernate-validator by hibernate.
the class ProgrammaticContainerElementConstraintsForParameterTest method canDeclareContainerElementConstraintsForArrayTypedParameterProgrammatically.
// HV-1428 Container element support is disabled for arrays
@Test(expectedExceptions = ValidationException.class, expectedExceptionsMessageRegExp = "HV000226:.*")
@TestForIssue(jiraKey = "HV-1239")
public void canDeclareContainerElementConstraintsForArrayTypedParameterProgrammatically() {
ConstraintMapping newMapping = config.createConstraintMapping();
newMapping.type(IFishTank.class).method("test5", String[].class).parameter(0).containerElementType().constraint(new SizeDef().max(5));
config.addMapping(newMapping);
Validator validator = config.buildValidatorFactory().getValidator();
IFishTank fishTank = ValidatorUtil.getValidatingProxy(new FishTank(), validator);
try {
fishTank.test5(new String[] { "Too Long" });
fail("Expected exception wasn't raised");
} catch (ConstraintViolationException e) {
assertThat(e.getConstraintViolations()).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 ProgrammaticContainerElementConstraintsForReturnValueTest method canDeclareContainerElementConstraintsForListContainingArrayTypeReturnValueProgrammatically.
// HV-1428 Container element support is disabled for arrays
@Test(expectedExceptions = ValidationException.class, expectedExceptionsMessageRegExp = "HV000226:.*")
@TestForIssue(jiraKey = "HV-1239")
public void canDeclareContainerElementConstraintsForListContainingArrayTypeReturnValueProgrammatically() {
ConstraintMapping newMapping = config.createConstraintMapping();
newMapping.type(IFishTank.class).method("test6").returnValue().containerElementType(0, 0).constraint(new SizeDef().max(5));
config.addMapping(newMapping);
Validator validator = config.buildValidatorFactory().getValidator();
IFishTank fishTank = ValidatorUtil.getValidatingProxy(new FishTank(), validator);
try {
fishTank.test6();
fail("Expected exception wasn't raised");
} catch (ConstraintViolationException e) {
assertThat(e.getConstraintViolations()).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 ProgrammaticContainerElementConstraintsForReturnValueTest method canDeclareContainerElementConstraintsForMultiDimensionalArrayTypeReturnValueProgrammatically.
// HV-1428 Container element support is disabled for arrays
@Test(expectedExceptions = ValidationException.class, expectedExceptionsMessageRegExp = "HV000226:.*")
@TestForIssue(jiraKey = "HV-1239")
public void canDeclareContainerElementConstraintsForMultiDimensionalArrayTypeReturnValueProgrammatically() {
ConstraintMapping newMapping = config.createConstraintMapping();
newMapping.type(IFishTank.class).method("test7").returnValue().containerElementType(0, 0).constraint(new SizeDef().max(5));
config.addMapping(newMapping);
Validator validator = config.buildValidatorFactory().getValidator();
IFishTank fishTank = ValidatorUtil.getValidatingProxy(new FishTank(), validator);
try {
fishTank.test7();
fail("Expected exception wasn't raised");
} catch (ConstraintViolationException e) {
assertThat(e.getConstraintViolations()).containsOnlyViolations(violationOf(Size.class).withMessage("size must be between 0 and 5"));
}
}
Aggregations