use of jakarta.validation.metadata.ConstraintDescriptor in project hibernate-validator by hibernate.
the class ElementDescriptorTest method testThatMethodLevelConstraintsAreNotReflectedByBeanDescriptor.
@Test
public void testThatMethodLevelConstraintsAreNotReflectedByBeanDescriptor() {
BeanDescriptor beanDescriptor = getValidator().getConstraintsForClass(CustomerRepository.class);
Set<ConstraintDescriptor<?>> constraintDescriptors = beanDescriptor.getConstraintDescriptors();
assertEquals(constraintDescriptors.size(), 1, "Only the class-level @ScriptAssert is expected.");
constraintDescriptors = beanDescriptor.findConstraints().declaredOn(ElementType.PARAMETER).getConstraintDescriptors();
assertEquals(constraintDescriptors.size(), 0);
}
use of jakarta.validation.metadata.ConstraintDescriptor in project hibernate-validator by hibernate.
the class LibraryTest method testContainerElementTypeDescriptor.
@Test
public void testContainerElementTypeDescriptor() {
BeanDescriptor libraryDescriptor = validator.getConstraintsForClass(Library.class);
// tag::testContainerElementTypeDescriptor[]
PropertyDescriptor booksDescriptor = libraryDescriptor.getConstraintsForProperty("books");
Set<ContainerElementTypeDescriptor> booksContainerElementTypeDescriptors = booksDescriptor.getConstrainedContainerElementTypes();
ContainerElementTypeDescriptor booksContainerElementTypeDescriptor = booksContainerElementTypeDescriptors.iterator().next();
assertTrue(booksContainerElementTypeDescriptor.hasConstraints());
assertTrue(booksContainerElementTypeDescriptor.isCascaded());
assertEquals(0, booksContainerElementTypeDescriptor.getTypeArgumentIndex().intValue());
assertEquals(List.class, booksContainerElementTypeDescriptor.getContainerClass());
Set<ConstraintDescriptor<?>> constraintDescriptors = booksContainerElementTypeDescriptor.getConstraintDescriptors();
ConstraintDescriptor<?> constraintDescriptor = constraintDescriptors.iterator().next();
assertEquals(NotNull.class, constraintDescriptor.getAnnotation().annotationType());
// end::testContainerElementTypeDescriptor[]
}
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);
}
Aggregations