Search in sources :

Example 1 with Entity2

use of org.hibernate.validator.test.internal.engine.valueextraction.model.Entity2 in project hibernate-validator by hibernate.

the class MostSpecificValueExtractorTest method parallelValueExtractorDefinitionsCausesException.

@Test
@TestForIssue(jiraKey = "HV-1306")
public void parallelValueExtractorDefinitionsCausesException() throws Exception {
    Validator validator = Validation.byProvider(HibernateValidator.class).configure().addValueExtractor(new IWrapper21ValueExtractor()).addValueExtractor(new IWrapper211ValueExtractor()).addValueExtractor(new IWrapper212ValueExtractor()).addValueExtractor(new IWrapper22ValueExtractor()).addValueExtractor(new IWrapper221ValueExtractor()).buildValidatorFactory().getValidator();
    try {
        validator.validate(new Entity2(null));
        fail("An exception should have been thrown");
    } catch (ConstraintDeclarationException e) {
        String message = e.getMessage();
        assertThat(message).startsWith("HV000219");
        assertThat(message).contains(Wrapper2.class.getName());
        assertThat(message).contains(IWrapper21ValueExtractor.class.getName());
        assertThat(message).doesNotContain(IWrapper211ValueExtractor.class.getName());
        assertThat(message).doesNotContain(IWrapper212ValueExtractor.class.getName());
        assertThat(message).contains(IWrapper22ValueExtractor.class.getName());
        assertThat(message).doesNotContain(IWrapper221ValueExtractor.class.getName());
    }
}
Also used : ConstraintDeclarationException(jakarta.validation.ConstraintDeclarationException) Entity2(org.hibernate.validator.test.internal.engine.valueextraction.model.Entity2) Validator(jakarta.validation.Validator) HibernateValidator(org.hibernate.validator.HibernateValidator) Test(org.testng.annotations.Test) TestForIssue(org.hibernate.validator.testutil.TestForIssue)

Aggregations

ConstraintDeclarationException (jakarta.validation.ConstraintDeclarationException)1 Validator (jakarta.validation.Validator)1 HibernateValidator (org.hibernate.validator.HibernateValidator)1 Entity2 (org.hibernate.validator.test.internal.engine.valueextraction.model.Entity2)1 TestForIssue (org.hibernate.validator.testutil.TestForIssue)1 Test (org.testng.annotations.Test)1