use of jakarta.validation.ConstraintViolationException 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 jakarta.validation.ConstraintViolationException 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 jakarta.validation.ConstraintViolationException 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"));
}
}
use of jakarta.validation.ConstraintViolationException in project hibernate-validator by hibernate.
the class ProgrammaticContainerElementConstraintsForReturnValueTest method canDeclareContainerElementConstraintsForReturnValueProgrammatically.
@Test
@TestForIssue(jiraKey = "HV-1239")
public void canDeclareContainerElementConstraintsForReturnValueProgrammatically() {
ConstraintMapping newMapping = config.createConstraintMapping();
newMapping.type(IFishTank.class).method("test1").returnValue().containerElementType(0).constraint(new SizeDef().min(3).max(10)).containerElementType(1).constraint(new MinDef().value(1));
config.addMapping(newMapping);
Validator validator = config.buildValidatorFactory().getValidator();
IFishTank fishTank = ValidatorUtil.getValidatingProxy(new FishTank(), validator);
try {
fishTank.test1();
fail("Expected exception wasn't raised");
} catch (ConstraintViolationException e) {
assertThat(e.getConstraintViolations()).containsOnlyViolations(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 jakarta.validation.ConstraintViolationException in project hibernate-validator by hibernate.
the class ProgrammaticContainerElementConstraintsForReturnValueTest method canDeclareContainerElementConstraintsForArrayTypedReturnValueProgrammatically.
// HV-1428 Container element support is disabled for arrays
@Test(expectedExceptions = ValidationException.class, expectedExceptionsMessageRegExp = "HV000226:.*")
@TestForIssue(jiraKey = "HV-1239")
public void canDeclareContainerElementConstraintsForArrayTypedReturnValueProgrammatically() {
ConstraintMapping newMapping = config.createConstraintMapping();
newMapping.type(IFishTank.class).method("test5").returnValue().containerElementType().constraint(new SizeDef().max(5));
config.addMapping(newMapping);
Validator validator = config.buildValidatorFactory().getValidator();
IFishTank fishTank = ValidatorUtil.getValidatingProxy(new FishTank(), validator);
try {
fishTank.test5();
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