Search in sources :

Example 1 with ElementDescriptor

use of jakarta.validation.metadata.ElementDescriptor in project hibernate-validator by hibernate.

the class ElementDescriptorTest method testElementDescriptorForProperty.

@Test
@TestForIssue(jiraKey = "HV-95")
public void testElementDescriptorForProperty() {
    ElementDescriptor elementDescriptor = ValidatorUtil.getPropertyDescriptor(Order.class, "orderNumber");
    Set<ConstraintDescriptor<?>> constraintDescriptors = elementDescriptor.getConstraintDescriptors();
    assertTrue(constraintDescriptors.size() == 1, "There should be a descriptor");
}
Also used : ConstraintDescriptor(jakarta.validation.metadata.ConstraintDescriptor) ElementDescriptor(jakarta.validation.metadata.ElementDescriptor) Test(org.testng.annotations.Test) TestForIssue(org.hibernate.validator.testutil.TestForIssue)

Example 2 with ElementDescriptor

use of jakarta.validation.metadata.ElementDescriptor in project hibernate-validator by hibernate.

the class ElementDescriptorTest method testGetTypeForConstrainedProperty.

@Test
public void testGetTypeForConstrainedProperty() {
    ElementDescriptor elementDescriptor = ValidatorUtil.getPropertyDescriptor(Order.class, "orderNumber");
    assertEquals(elementDescriptor.getElementClass(), Integer.class, "Wrong type.");
}
Also used : ElementDescriptor(jakarta.validation.metadata.ElementDescriptor) Test(org.testng.annotations.Test)

Example 3 with ElementDescriptor

use of jakarta.validation.metadata.ElementDescriptor in project hibernate-validator by hibernate.

the class ElementDescriptorTest method testElementDescriptorImmutable.

@Test
@TestForIssue(jiraKey = "HV-95")
public void testElementDescriptorImmutable() {
    ElementDescriptor elementDescriptor = ValidatorUtil.getPropertyDescriptor(Order.class, "orderNumber");
    Set<ConstraintDescriptor<?>> constraintDescriptors = elementDescriptor.getConstraintDescriptors();
    try {
        constraintDescriptors.add(null);
        fail("Set should be immutable");
    } catch (UnsupportedOperationException e) {
    // success
    }
    try {
        constraintDescriptors.remove(constraintDescriptors.iterator().next());
        fail("Set should be immutable");
    } catch (UnsupportedOperationException e) {
    }
}
Also used : ConstraintDescriptor(jakarta.validation.metadata.ConstraintDescriptor) ElementDescriptor(jakarta.validation.metadata.ElementDescriptor) Test(org.testng.annotations.Test) TestForIssue(org.hibernate.validator.testutil.TestForIssue)

Aggregations

ElementDescriptor (jakarta.validation.metadata.ElementDescriptor)3 Test (org.testng.annotations.Test)3 ConstraintDescriptor (jakarta.validation.metadata.ConstraintDescriptor)2 TestForIssue (org.hibernate.validator.testutil.TestForIssue)2