Search in sources :

Example 6 with ConstructorDescriptor

use of jakarta.validation.metadata.ConstructorDescriptor in project hibernate-validator by hibernate.

the class ConstraintMappingWithAnnotationProcessingOptionsTest method testIgnoreAnnotationsOnConstructor.

@Test
public void testIgnoreAnnotationsOnConstructor() {
    ConstraintMapping mapping = config.createConstraintMapping();
    mapping.type(Doer.class).constructor(String.class).ignoreAnnotations(true);
    config.addMapping(mapping);
    ConstructorDescriptor descriptor = config.buildValidatorFactory().getValidator().getConstraintsForClass(Doer.class).getConstraintsForConstructor(String.class);
    assertNull(descriptor);
}
Also used : ConstraintMapping(org.hibernate.validator.cfg.ConstraintMapping) ConstructorDescriptor(jakarta.validation.metadata.ConstructorDescriptor) Test(org.testng.annotations.Test)

Example 7 with ConstructorDescriptor

use of jakarta.validation.metadata.ConstructorDescriptor 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 8 with ConstructorDescriptor

use of jakarta.validation.metadata.ConstructorDescriptor in project hibernate-validator by hibernate.

the class BeanDescriptorTest method getSignatures.

private Set<List<Class<?>>> getSignatures(Set<ConstructorDescriptor> descriptors) {
    Set<List<Class<?>>> signatures = newHashSet();
    for (ConstructorDescriptor methodDescriptor : descriptors) {
        List<Class<?>> parameterTypes = newArrayList();
        for (ParameterDescriptor oneParameter : methodDescriptor.getParameterDescriptors()) {
            parameterTypes.add(oneParameter.getElementClass());
        }
        signatures.add(parameterTypes);
    }
    return signatures;
}
Also used : ParameterDescriptor(jakarta.validation.metadata.ParameterDescriptor) ConstructorDescriptor(jakarta.validation.metadata.ConstructorDescriptor) CollectionHelper.newArrayList(org.hibernate.validator.internal.util.CollectionHelper.newArrayList) List(java.util.List)

Example 9 with ConstructorDescriptor

use of jakarta.validation.metadata.ConstructorDescriptor in project hibernate-validator by hibernate.

the class BeanDescriptorTest method testGetConstraintsForConstructor.

@Test
public void testGetConstraintsForConstructor() {
    BeanDescriptor descriptor = getBeanDescriptor(CustomerRepositoryExt.class);
    ConstructorDescriptor constructorDescriptor = descriptor.getConstraintsForConstructor(String.class, Customer.class);
    assertThat(constructorDescriptor).isNotNull();
}
Also used : ValidatorUtil.getBeanDescriptor(org.hibernate.validator.testutils.ValidatorUtil.getBeanDescriptor) BeanDescriptor(jakarta.validation.metadata.BeanDescriptor) ConstructorDescriptor(jakarta.validation.metadata.ConstructorDescriptor) Test(org.testng.annotations.Test)

Example 10 with ConstructorDescriptor

use of jakarta.validation.metadata.ConstructorDescriptor 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);
}
Also used : ReturnValueDescriptor(jakarta.validation.metadata.ReturnValueDescriptor) ConstraintDescriptor(jakarta.validation.metadata.ConstraintDescriptor) ConstructorDescriptor(jakarta.validation.metadata.ConstructorDescriptor) ValidatorUtil.getConstructorDescriptor(org.hibernate.validator.testutils.ValidatorUtil.getConstructorDescriptor) Test(org.testng.annotations.Test)

Aggregations

ConstructorDescriptor (jakarta.validation.metadata.ConstructorDescriptor)64 Test (org.testng.annotations.Test)59 AbstractTCKTest (org.hibernate.beanvalidation.tck.tests.AbstractTCKTest)43 SpecAssertion (org.jboss.test.audit.annotations.SpecAssertion)38 ParameterDescriptor (jakarta.validation.metadata.ParameterDescriptor)12 ReturnValueDescriptor (jakarta.validation.metadata.ReturnValueDescriptor)11 BeanDescriptor (jakarta.validation.metadata.BeanDescriptor)10 CrossParameterDescriptor (jakarta.validation.metadata.CrossParameterDescriptor)10 ConstraintMapping (org.hibernate.validator.cfg.ConstraintMapping)8 SpecAssertions (org.jboss.test.audit.annotations.SpecAssertions)5 ConstraintDescriptor (jakarta.validation.metadata.ConstraintDescriptor)4 MethodDescriptor (jakarta.validation.metadata.MethodDescriptor)4 List (java.util.List)3 TestUtil.getConstructorDescriptor (org.hibernate.beanvalidation.tck.util.TestUtil.getConstructorDescriptor)3 ValidatorUtil.getBeanDescriptor (org.hibernate.validator.testutils.ValidatorUtil.getBeanDescriptor)3 ValidatorUtil.getConstructorDescriptor (org.hibernate.validator.testutils.ValidatorUtil.getConstructorDescriptor)3 ConstraintValidator (jakarta.validation.ConstraintValidator)2 Validator (jakarta.validation.Validator)2 GroupConversionDescriptor (jakarta.validation.metadata.GroupConversionDescriptor)2 ArrayList (java.util.ArrayList)2