Search in sources :

Example 1 with HibernateConstraintViolation

use of org.hibernate.validator.engine.HibernateConstraintViolation in project hibernate-validator by hibernate.

the class HibernateConstraintValidatorContextTest method testNullIsReturnedForNonExistingPayloadType.

@Test
@TestForIssue(jiraKey = "HV-1020")
public void testNullIsReturnedForNonExistingPayloadType() {
    Validator validator = getValidator();
    Set<ConstraintViolation<ExpressionVariableFoo>> constraintViolations = validator.validate(new ExpressionVariableFoo(QUESTION_4));
    assertThat(constraintViolations).containsOnlyViolations(violationOf(ExpressionVariableOracleConstraint.class));
    ConstraintViolation<ExpressionVariableFoo> constraintViolation = constraintViolations.iterator().next();
    @SuppressWarnings("unchecked") HibernateConstraintViolation<ExpressionVariableFoo> hibernateConstraintViolation = constraintViolation.unwrap(HibernateConstraintViolation.class);
    Assert.assertNull(hibernateConstraintViolation.getDynamicPayload(String.class));
}
Also used : ConstraintViolation(jakarta.validation.ConstraintViolation) HibernateConstraintViolation(org.hibernate.validator.engine.HibernateConstraintViolation) Validator(jakarta.validation.Validator) ConstraintValidator(jakarta.validation.ConstraintValidator) ValidatorUtil.getValidator(org.hibernate.validator.testutils.ValidatorUtil.getValidator) Test(org.testng.annotations.Test) TestForIssue(org.hibernate.validator.testutil.TestForIssue)

Example 2 with HibernateConstraintViolation

use of org.hibernate.validator.engine.HibernateConstraintViolation in project hibernate-validator by hibernate.

the class HibernateConstraintValidatorContextTest method testDynamicPayloadExposedInHibernateConstraintViolation.

// Dynamic payload
@Test
@TestForIssue(jiraKey = "HV-1020")
public void testDynamicPayloadExposedInHibernateConstraintViolation() {
    Validator validator = getValidator();
    Set<ConstraintViolation<ExpressionVariableFoo>> constraintViolations = validator.validate(new ExpressionVariableFoo(QUESTION_4));
    assertThat(constraintViolations).containsOnlyViolations(violationOf(ExpressionVariableOracleConstraint.class));
    ConstraintViolation<ExpressionVariableFoo> constraintViolation = constraintViolations.iterator().next();
    @SuppressWarnings("unchecked") HibernateConstraintViolation<ExpressionVariableFoo> hibernateConstraintViolation = constraintViolation.unwrap(HibernateConstraintViolation.class);
    Assert.assertEquals(hibernateConstraintViolation.getDynamicPayload(List.class), INVALID_KEYWORDS);
}
Also used : ConstraintViolation(jakarta.validation.ConstraintViolation) HibernateConstraintViolation(org.hibernate.validator.engine.HibernateConstraintViolation) List(java.util.List) Validator(jakarta.validation.Validator) ConstraintValidator(jakarta.validation.ConstraintValidator) ValidatorUtil.getValidator(org.hibernate.validator.testutils.ValidatorUtil.getValidator) Test(org.testng.annotations.Test) TestForIssue(org.hibernate.validator.testutil.TestForIssue)

Example 3 with HibernateConstraintViolation

use of org.hibernate.validator.engine.HibernateConstraintViolation in project hibernate-validator by hibernate.

the class HibernateConstraintValidatorContextTest method testNullIsReturnedIfPayloadIsNull.

@Test
@TestForIssue(jiraKey = "HV-1164")
public void testNullIsReturnedIfPayloadIsNull() {
    Validator validator = getValidator();
    Set<ConstraintViolation<ExpressionVariableFoo>> constraintViolations = validator.validate(new ExpressionVariableFoo(QUESTION_1));
    assertThat(constraintViolations).containsOnlyViolations(violationOf(ExpressionVariableOracleConstraint.class));
    ConstraintViolation<ExpressionVariableFoo> constraintViolation = constraintViolations.iterator().next();
    @SuppressWarnings("unchecked") HibernateConstraintViolation<ExpressionVariableFoo> hibernateConstraintViolation = constraintViolation.unwrap(HibernateConstraintViolation.class);
    Assert.assertNull(hibernateConstraintViolation.getDynamicPayload(Object.class));
}
Also used : ConstraintViolation(jakarta.validation.ConstraintViolation) HibernateConstraintViolation(org.hibernate.validator.engine.HibernateConstraintViolation) Validator(jakarta.validation.Validator) ConstraintValidator(jakarta.validation.ConstraintValidator) ValidatorUtil.getValidator(org.hibernate.validator.testutils.ValidatorUtil.getValidator) Test(org.testng.annotations.Test) TestForIssue(org.hibernate.validator.testutil.TestForIssue)

Aggregations

ConstraintValidator (jakarta.validation.ConstraintValidator)3 ConstraintViolation (jakarta.validation.ConstraintViolation)3 Validator (jakarta.validation.Validator)3 HibernateConstraintViolation (org.hibernate.validator.engine.HibernateConstraintViolation)3 TestForIssue (org.hibernate.validator.testutil.TestForIssue)3 ValidatorUtil.getValidator (org.hibernate.validator.testutils.ValidatorUtil.getValidator)3 Test (org.testng.annotations.Test)3 List (java.util.List)1