Search in sources :

Example 11 with BeanDescriptor

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[]
}
Also used : ContainerElementTypeDescriptor(jakarta.validation.metadata.ContainerElementTypeDescriptor) PropertyDescriptor(jakarta.validation.metadata.PropertyDescriptor) BeanDescriptor(jakarta.validation.metadata.BeanDescriptor) ConstraintDescriptor(jakarta.validation.metadata.ConstraintDescriptor) Test(org.junit.Test)

Example 12 with BeanDescriptor

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));
}
Also used : ValidatorUtil.getBeanDescriptor(org.hibernate.validator.testutils.ValidatorUtil.getBeanDescriptor) BeanDescriptor(jakarta.validation.metadata.BeanDescriptor) Customer(org.hibernate.validator.test.internal.metadata.Customer) ConstructorDescriptor(jakarta.validation.metadata.ConstructorDescriptor) LocalDate(java.time.LocalDate) Test(org.testng.annotations.Test)

Example 13 with BeanDescriptor

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");
}
Also used : ValidatorUtil.getBeanDescriptor(org.hibernate.validator.testutils.ValidatorUtil.getBeanDescriptor) BeanDescriptor(jakarta.validation.metadata.BeanDescriptor) Test(org.testng.annotations.Test)

Example 14 with BeanDescriptor

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"));
}
Also used : ValidatorUtil.getBeanDescriptor(org.hibernate.validator.testutils.ValidatorUtil.getBeanDescriptor) BeanDescriptor(jakarta.validation.metadata.BeanDescriptor) Test(org.testng.annotations.Test)

Example 15 with BeanDescriptor

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);
}
Also used : ValidatorUtil.getBeanDescriptor(org.hibernate.validator.testutils.ValidatorUtil.getBeanDescriptor) BeanDescriptor(jakarta.validation.metadata.BeanDescriptor) MethodDescriptor(jakarta.validation.metadata.MethodDescriptor) Test(org.testng.annotations.Test)

Aggregations

BeanDescriptor (jakarta.validation.metadata.BeanDescriptor)116 Test (org.testng.annotations.Test)96 AbstractTCKTest (org.hibernate.beanvalidation.tck.tests.AbstractTCKTest)55 SpecAssertion (org.jboss.test.audit.annotations.SpecAssertion)40 PropertyDescriptor (jakarta.validation.metadata.PropertyDescriptor)39 Validator (jakarta.validation.Validator)35 ValidatorUtil.getBeanDescriptor (org.hibernate.validator.testutils.ValidatorUtil.getBeanDescriptor)31 ConstraintDescriptor (jakarta.validation.metadata.ConstraintDescriptor)24 MethodDescriptor (jakarta.validation.metadata.MethodDescriptor)19 SpecAssertions (org.jboss.test.audit.annotations.SpecAssertions)15 ConstructorDescriptor (jakarta.validation.metadata.ConstructorDescriptor)10 Test (org.junit.Test)10 CrossParameterDescriptor (jakarta.validation.metadata.CrossParameterDescriptor)7 TestForIssue (org.hibernate.validator.testutil.TestForIssue)7 NotNull (jakarta.validation.constraints.NotNull)6 Default (jakarta.validation.groups.Default)6 TestUtil.getValidatorUnderTest (org.hibernate.beanvalidation.tck.util.TestUtil.getValidatorUnderTest)6 ConstraintValidator (jakarta.validation.ConstraintValidator)4 ConstraintViolation (jakarta.validation.ConstraintViolation)4 Annotation (java.lang.annotation.Annotation)4