use of jakarta.validation.metadata.ConstraintDescriptor in project hibernate-validator by hibernate.
the class ConstraintDescriptorTest method testValidationAppliesTo.
@Test
public void testValidationAppliesTo() {
BeanDescriptor beanDescriptor = getBeanDescriptor(Bar.class);
Set<MethodDescriptor> methodDescriptors = beanDescriptor.getConstrainedMethods(MethodType.NON_GETTER);
assertEquals(methodDescriptors.size(), 1);
CrossParameterDescriptor crossParameterDescriptor = methodDescriptors.iterator().next().getCrossParameterDescriptor();
Set<ConstraintDescriptor<?>> constraintDescriptors = crossParameterDescriptor.getConstraintDescriptors();
assertEquals(constraintDescriptors.size(), 1);
ConstraintDescriptor<?> constraintDescriptor = constraintDescriptors.iterator().next();
assertEquals(constraintDescriptor.getValidationAppliesTo(), ConstraintTarget.PARAMETERS, "wrong constraint targets");
}
use of jakarta.validation.metadata.ConstraintDescriptor in project hibernate-validator by hibernate.
the class ConstraintDescriptorTest method testBasicDescriptorAttributes.
@Test
public void testBasicDescriptorAttributes() {
BeanDescriptor beanDescriptor = getBeanDescriptor(Foo.class);
PropertyDescriptor propertyDescriptor = beanDescriptor.getConstraintsForProperty("fubar");
Set<ConstraintDescriptor<?>> constraintDescriptors = propertyDescriptor.getConstraintDescriptors();
assertEquals(constraintDescriptors.size(), 1);
ConstraintDescriptor<?> constraintDescriptor = constraintDescriptors.iterator().next();
assertEquals(constraintDescriptor.getMessageTemplate(), "bar", "Wrong message");
Set<Class<?>> groups = newHashSet();
groups.add(SnafuGroup.class);
assertEquals(constraintDescriptor.getGroups(), groups, "Wrong groups");
Set<Class<?>> payloads = newHashSet();
payloads.add(Payload22.class);
assertEquals(constraintDescriptor.getPayload(), payloads, "Wrong payload");
assertNull(constraintDescriptor.getValidationAppliesTo(), "There is no validationAppliedTo attribute");
}
use of jakarta.validation.metadata.ConstraintDescriptor in project hibernate-validator by hibernate.
the class ConstructorDescriptorTest method testGetReturnValueDescriptor.
@Test
public void testGetReturnValueDescriptor() {
ConstructorDescriptor constructorDescriptor = getConstructorDescriptor(CustomerRepositoryExt.class, String.class);
ReturnValueDescriptor returnValueDescriptor = constructorDescriptor.getReturnValueDescriptor();
assertThat(returnValueDescriptor).isNotNull();
assertThat(returnValueDescriptor.getElementClass()).isEqualTo(CustomerRepositoryExt.class);
assertThat(returnValueDescriptor.hasConstraints()).isTrue();
assertThat(returnValueDescriptor.isCascaded()).isTrue();
Set<ConstraintDescriptor<?>> constraintDescriptors = returnValueDescriptor.getConstraintDescriptors();
assertThat(constraintDescriptors).hasSize(1);
ConstraintDescriptor<?> descriptor = constraintDescriptors.iterator().next();
assertThat(descriptor.getAnnotation().annotationType()).isEqualTo(ValidB2BRepository.class);
}
use of jakarta.validation.metadata.ConstraintDescriptor in project hibernate-validator by hibernate.
the class CrossParameterDescriptorTest method testFindConstraintsLookingAt.
@Test
public void testFindConstraintsLookingAt() {
CrossParameterDescriptor descriptor = getMethodDescriptor(CustomerRepositoryExt.class, "methodWithCrossParameterConstraint", LocalDate.class, LocalDate.class).getCrossParameterDescriptor();
Set<ConstraintDescriptor<?>> constraintDescriptors = descriptor.findConstraints().lookingAt(Scope.LOCAL_ELEMENT).getConstraintDescriptors();
assertEquals(constraintDescriptors.size(), 0);
constraintDescriptors = descriptor.findConstraints().lookingAt(Scope.HIERARCHY).getConstraintDescriptors();
assertEquals(constraintDescriptors.size(), 1);
assertEquals(constraintDescriptors.iterator().next().getAnnotation().annotationType(), ConsistentDateParameters.class);
}
use of jakarta.validation.metadata.ConstraintDescriptor in project minijax by minijax.
the class MinijaxContainerElementTypeDescriptor method build.
public static Set<ContainerElementTypeDescriptor> build(final Class<?> elementClass, final AnnotatedParameterizedType annotatedType) {
final Set<ContainerElementTypeDescriptor> result = new HashSet<>();
final Class<?> containerClass = ReflectionUtils.getRawType(annotatedType);
int argIndex = 0;
for (final AnnotatedType typeArg : annotatedType.getAnnotatedActualTypeArguments()) {
final Set<ConstraintDescriptor<?>> constraintDescriptors = new HashSet<>();
for (final Annotation annotation : typeArg.getAnnotations()) {
final MinijaxConstraintDescriptor<?> constraintDescriptor = MinijaxConstraintDescriptor.build(typeArg, annotation);
if (constraintDescriptor != null) {
constraintDescriptors.add(constraintDescriptor);
}
}
if (!constraintDescriptors.isEmpty()) {
result.add(new MinijaxContainerElementTypeDescriptor(elementClass, containerClass, argIndex, constraintDescriptors));
}
argIndex++;
}
return result;
}
Aggregations