Search in sources :

Example 26 with TestForIssue

use of org.hibernate.validator.testutil.TestForIssue in project hibernate-validator by hibernate.

the class ProgrammaticContainerElementConstraintsForParameterTest method declaringContainerElementConstraintOnNonGenericParameterCausesException.

@Test(expectedExceptions = ValidationException.class, expectedExceptionsMessageRegExp = "HV000211.*")
@TestForIssue(jiraKey = "HV-1239")
public void declaringContainerElementConstraintOnNonGenericParameterCausesException() {
    ConstraintMapping newMapping = config.createConstraintMapping();
    newMapping.type(IFishTank.class).method("setSize", int.class).parameter(0).containerElementType(1);
}
Also used : ConstraintMapping(org.hibernate.validator.cfg.ConstraintMapping) Test(org.testng.annotations.Test) TestForIssue(org.hibernate.validator.testutil.TestForIssue)

Example 27 with TestForIssue

use of org.hibernate.validator.testutil.TestForIssue in project hibernate-validator by hibernate.

the class ProgrammaticContainerElementConstraintsForParameterTest method omittingTypeArgumentForMultiTypeArgumentTypeOnParameterCausesException.

@Test(expectedExceptions = ValidationException.class, expectedExceptionsMessageRegExp = "HV000213.*")
@TestForIssue(jiraKey = "HV-1239")
public void omittingTypeArgumentForMultiTypeArgumentTypeOnParameterCausesException() {
    ConstraintMapping newMapping = config.createConstraintMapping();
    newMapping.type(FishTank.class).method("test1", Optional.class, Map.class).parameter(1).containerElementType();
}
Also used : ConstraintMapping(org.hibernate.validator.cfg.ConstraintMapping) Test(org.testng.annotations.Test) TestForIssue(org.hibernate.validator.testutil.TestForIssue)

Example 28 with TestForIssue

use of org.hibernate.validator.testutil.TestForIssue in project hibernate-validator by hibernate.

the class ProgrammaticContainerElementConstraintsForReturnValueTest method canDeclareDeeplyNestedContainerElementConstraintsForReturnValueProgrammatically.

@Test
@TestForIssue(jiraKey = "HV-1239")
public void canDeclareDeeplyNestedContainerElementConstraintsForReturnValueProgrammatically() {
    ConstraintMapping newMapping = config.createConstraintMapping();
    newMapping.type(IFishTank.class).method("test3").returnValue().containerElementType(0, 1, 0).constraint(new NotNullDef());
    config.addMapping(newMapping);
    Validator validator = config.buildValidatorFactory().getValidator();
    IFishTank fishTank = ValidatorUtil.getValidatingProxy(new FishTank(), validator);
    try {
        fishTank.test3();
        fail("Expected exception wasn't raised");
    } catch (ConstraintViolationException e) {
        assertThat(e.getConstraintViolations()).containsOnlyViolations(violationOf(NotNull.class).withMessage("must not be null"));
    }
}
Also used : ConstraintMapping(org.hibernate.validator.cfg.ConstraintMapping) ConstraintViolationException(jakarta.validation.ConstraintViolationException) NotNullDef(org.hibernate.validator.cfg.defs.NotNullDef) NotNull(jakarta.validation.constraints.NotNull) Validator(jakarta.validation.Validator) HibernateValidator(org.hibernate.validator.HibernateValidator) Test(org.testng.annotations.Test) TestForIssue(org.hibernate.validator.testutil.TestForIssue)

Example 29 with TestForIssue

use of org.hibernate.validator.testutil.TestForIssue in project hibernate-validator by hibernate.

the class ProgrammaticContainerElementConstraintsForReturnValueTest method canDeclareContainerElementCascadesForReturnValueProgrammatically.

@Test
@TestForIssue(jiraKey = "HV-1239")
public void canDeclareContainerElementCascadesForReturnValueProgrammatically() {
    ConstraintMapping newMapping = config.createConstraintMapping();
    newMapping.type(IFishTank.class).method("test4").returnValue().containerElementType().valid().type(Fish.class).field("name").constraint(new NotNullDef());
    config.addMapping(newMapping);
    Validator validator = config.buildValidatorFactory().getValidator();
    IFishTank fishTank = ValidatorUtil.getValidatingProxy(new FishTank(), validator);
    try {
        fishTank.test4();
        fail("Expected exception wasn't raised");
    } catch (ConstraintViolationException e) {
        assertThat(e.getConstraintViolations()).containsOnlyViolations(violationOf(NotNull.class).withMessage("must not be null"));
    }
}
Also used : ConstraintMapping(org.hibernate.validator.cfg.ConstraintMapping) ConstraintViolationException(jakarta.validation.ConstraintViolationException) NotNullDef(org.hibernate.validator.cfg.defs.NotNullDef) NotNull(jakarta.validation.constraints.NotNull) Validator(jakarta.validation.Validator) HibernateValidator(org.hibernate.validator.HibernateValidator) Test(org.testng.annotations.Test) TestForIssue(org.hibernate.validator.testutil.TestForIssue)

Example 30 with TestForIssue

use of org.hibernate.validator.testutil.TestForIssue in project hibernate-validator by hibernate.

the class ProgrammaticContainerElementConstraintsForReturnValueTest method declaringContainerElementConstraintForNonExistingTypeArgumentIndexOnReturnValueCausesException.

@Test(expectedExceptions = ValidationException.class, expectedExceptionsMessageRegExp = "HV000212.*")
@TestForIssue(jiraKey = "HV-1239")
public void declaringContainerElementConstraintForNonExistingTypeArgumentIndexOnReturnValueCausesException() {
    ConstraintMapping newMapping = config.createConstraintMapping();
    newMapping.type(FishTank.class).method("test1").returnValue().containerElementType(2);
}
Also used : ConstraintMapping(org.hibernate.validator.cfg.ConstraintMapping) Test(org.testng.annotations.Test) TestForIssue(org.hibernate.validator.testutil.TestForIssue)

Aggregations

TestForIssue (org.hibernate.validator.testutil.TestForIssue)286 Test (org.testng.annotations.Test)286 Validator (jakarta.validation.Validator)180 ConstraintViolation (jakarta.validation.ConstraintViolation)134 HibernateValidator (org.hibernate.validator.HibernateValidator)80 ConstraintMapping (org.hibernate.validator.cfg.ConstraintMapping)80 ConstraintValidator (jakarta.validation.ConstraintValidator)64 ValidatorUtil.getValidator (org.hibernate.validator.testutils.ValidatorUtil.getValidator)55 HibernateValidatorConfiguration (org.hibernate.validator.HibernateValidatorConfiguration)33 ValidatorFactory (jakarta.validation.ValidatorFactory)29 ConstraintViolationException (jakarta.validation.ConstraintViolationException)26 NotNullDef (org.hibernate.validator.cfg.defs.NotNullDef)22 ExecutableValidator (jakarta.validation.executable.ExecutableValidator)21 SizeDef (org.hibernate.validator.cfg.defs.SizeDef)21 NotNull (jakarta.validation.constraints.NotNull)17 Method (java.lang.reflect.Method)17 Size (jakarta.validation.constraints.Size)15 CountValidationCallsValidator (org.hibernate.validator.testutil.CountValidationCallsValidator)13 File (java.io.File)12 HibernateConstraintViolation (org.hibernate.validator.engine.HibernateConstraintViolation)12