use of jakarta.validation.metadata.BeanDescriptor 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.BeanDescriptor in project hibernate-validator by hibernate.
the class BeanDescriptorTest method testGetConstrainedConstructors.
@Test
public void testGetConstrainedConstructors() {
BeanDescriptor descriptor = getBeanDescriptor(CustomerRepositoryExt.class);
Set<ConstructorDescriptor> constrainedConstructors = descriptor.getConstrainedConstructors();
assertThat(constrainedConstructors).isNotNull();
assertThat(getSignatures(constrainedConstructors)).containsOnly(Arrays.<Class<?>>asList(String.class), Arrays.<Class<?>>asList(String.class, Customer.class), Collections.<Class<?>>emptyList(), Arrays.<Class<?>>asList(LocalDate.class, LocalDate.class));
}
use of jakarta.validation.metadata.BeanDescriptor in project hibernate-validator by hibernate.
the class BeanDescriptorTest method testIsTypeConstrainedForCascadingParameterType.
@Test
public void testIsTypeConstrainedForCascadingParameterType() {
BeanDescriptor descriptor = getBeanDescriptor(CascadingParameterType.class);
assertFalse(descriptor.isBeanConstrained(), "The entity should have no bean constraints");
assertFalse(descriptor.getConstrainedMethods(MethodType.NON_GETTER).isEmpty(), "The entity should have constrained methods");
}
use of jakarta.validation.metadata.BeanDescriptor in project hibernate-validator by hibernate.
the class BeanDescriptorTest method testGetConstraintsForUnknownMethod.
@Test
public void testGetConstraintsForUnknownMethod() throws Exception {
BeanDescriptor descriptor = getBeanDescriptor(CustomerRepository.class);
assertNull(descriptor.getConstraintsForMethod("zap"));
}
use of jakarta.validation.metadata.BeanDescriptor in project hibernate-validator by hibernate.
the class BeanDescriptorTest method testGetConstraintsForMethod.
@Test
public void testGetConstraintsForMethod() throws Exception {
BeanDescriptor descriptor = getBeanDescriptor(CustomerRepository.class);
MethodDescriptor methodDescriptor = descriptor.getConstraintsForMethod("foo");
assertNotNull(methodDescriptor);
}
Aggregations