Search in sources :

Example 21 with ConstraintDescriptor

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

the class XmlParsingTest method getSingleConstraintDescriptorForClass.

private ConstraintDescriptorImpl<?> getSingleConstraintDescriptorForClass(Validator validator, Class<?> clazz) {
    BeanDescriptor beanDescriptor = validator.getConstraintsForClass(clazz);
    Set<ConstraintDescriptor<?>> constraintDescriptorSet = beanDescriptor.getConstraintDescriptors();
    assertEquals(constraintDescriptorSet.size(), 1, "There should be only one constraint descriptor");
    return (ConstraintDescriptorImpl<?>) constraintDescriptorSet.iterator().next();
}
Also used : BeanDescriptor(jakarta.validation.metadata.BeanDescriptor) ConstraintDescriptor(jakarta.validation.metadata.ConstraintDescriptor) ConstraintDescriptorImpl(org.hibernate.validator.internal.metadata.descriptor.ConstraintDescriptorImpl)

Example 22 with ConstraintDescriptor

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

the class ParameterDescriptorTest method testFindConstraintLookingAtLocalElement.

@Test(enabled = false, description = "Temporarily disabled due to HV-443")
public void testFindConstraintLookingAtLocalElement() {
    Set<ConstraintDescriptor<?>> constraintDescriptors = createCustomerParameter2.findConstraints().lookingAt(Scope.LOCAL_ELEMENT).getConstraintDescriptors();
    assertEquals(constraintDescriptors.size(), 0, "No local constraint for CustomerRepositoryExt#createCustomer(), arg1, expected.");
    ParameterDescriptor createCustomerParameter2OnBaseType = getParameterDescriptor(CustomerRepository.class, "createCustomer", new Class<?>[] { CharSequence.class, String.class }, 1);
    constraintDescriptors = createCustomerParameter2OnBaseType.findConstraints().lookingAt(Scope.LOCAL_ELEMENT).getConstraintDescriptors();
    assertEquals(constraintDescriptors.size(), 1, "One local constraint for CustomerRepository#createCustomer(), arg1, expected.");
}
Also used : ConstraintDescriptor(jakarta.validation.metadata.ConstraintDescriptor) ParameterDescriptor(jakarta.validation.metadata.ParameterDescriptor) ValidatorUtil.getParameterDescriptor(org.hibernate.validator.testutils.ValidatorUtil.getParameterDescriptor) Test(org.testng.annotations.Test)

Example 23 with ConstraintDescriptor

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

the class BeanDescriptorTest method testGetConstraintDescriptors.

@Test
public void testGetConstraintDescriptors() {
    BeanDescriptor descriptor = getBeanDescriptor(CustomerRepository.class);
    Set<ConstraintDescriptor<?>> constraintDescriptors = descriptor.getConstraintDescriptors();
    assertEquals(constraintDescriptors.size(), 1);
    assertEquals(constraintDescriptors.iterator().next().getAnnotation().annotationType(), ScriptAssert.class);
}
Also used : ValidatorUtil.getBeanDescriptor(org.hibernate.validator.testutils.ValidatorUtil.getBeanDescriptor) BeanDescriptor(jakarta.validation.metadata.BeanDescriptor) ConstraintDescriptor(jakarta.validation.metadata.ConstraintDescriptor) Test(org.testng.annotations.Test)

Example 24 with ConstraintDescriptor

use of jakarta.validation.metadata.ConstraintDescriptor 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)

Example 25 with ConstraintDescriptor

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

the class MethodDescriptorTest method testFindParameterConstraintLookingAt.

@Test
@TestForIssue(jiraKey = "HV-443")
public void testFindParameterConstraintLookingAt() {
    ParameterDescriptor parameterDescriptor = getMethodDescriptor(CustomerRepositoryExt.class, "createCustomer", CharSequence.class, String.class).getParameterDescriptors().get(1);
    Set<ConstraintDescriptor<?>> constraintDescriptors = parameterDescriptor.findConstraints().lookingAt(Scope.LOCAL_ELEMENT).getConstraintDescriptors();
    assertEquals(constraintDescriptors.size(), 0);
    constraintDescriptors = parameterDescriptor.findConstraints().lookingAt(Scope.HIERARCHY).getConstraintDescriptors();
    assertEquals(constraintDescriptors.size(), 1);
    assertEquals(constraintDescriptors.iterator().next().getAnnotation().annotationType(), NotNull.class);
}
Also used : ParameterDescriptor(jakarta.validation.metadata.ParameterDescriptor) ConstraintDescriptor(jakarta.validation.metadata.ConstraintDescriptor) Test(org.testng.annotations.Test) TestForIssue(org.hibernate.validator.testutil.TestForIssue)

Aggregations

ConstraintDescriptor (jakarta.validation.metadata.ConstraintDescriptor)25 Test (org.testng.annotations.Test)11 BeanDescriptor (jakarta.validation.metadata.BeanDescriptor)10 CrossParameterDescriptor (jakarta.validation.metadata.CrossParameterDescriptor)4 PropertyDescriptor (jakarta.validation.metadata.PropertyDescriptor)4 Column (org.hibernate.mapping.Column)4 TestForIssue (org.hibernate.validator.testutil.TestForIssue)4 MethodDescriptor (jakarta.validation.metadata.MethodDescriptor)3 ParameterDescriptor (jakarta.validation.metadata.ParameterDescriptor)3 ReturnValueDescriptor (jakarta.validation.metadata.ReturnValueDescriptor)3 Selectable (org.hibernate.mapping.Selectable)3 ValidatorUtil.getBeanDescriptor (org.hibernate.validator.testutils.ValidatorUtil.getBeanDescriptor)3 Test (org.junit.Test)3 MessageInterpolator (jakarta.validation.MessageInterpolator)2 Validator (jakarta.validation.Validator)2 ConstructorDescriptor (jakarta.validation.metadata.ConstructorDescriptor)2 ContainerElementTypeDescriptor (jakarta.validation.metadata.ContainerElementTypeDescriptor)2 ElementDescriptor (jakarta.validation.metadata.ElementDescriptor)2 ConstraintDescriptorImpl (org.hibernate.validator.internal.metadata.descriptor.ConstraintDescriptorImpl)2 HibernateMessageInterpolatorContext (org.hibernate.validator.messageinterpolation.HibernateMessageInterpolatorContext)2