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();
}
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.");
}
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);
}
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) {
}
}
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);
}
Aggregations