Search in sources :

Example 11 with ConstructorDescriptor

use of jakarta.validation.metadata.ConstructorDescriptor in project beanvalidation-tck by eclipse-ee4j.

the class IgnoreAnnotationsInConstructorConfigurationTest method testIgnoreAnnotationsOnReturnValueParameterAndCrossParameter.

@Test
@SpecAssertion(section = Sections.XML_MAPPING_CONSTRAINTDECLARATIONINXML_CONSTRUCTORLEVELOVERRIDING, id = "k")
public void testIgnoreAnnotationsOnReturnValueParameterAndCrossParameter() {
    ConstructorDescriptor descriptor = TestUtil.getConstructorDescriptor(IgnoreAnnotations.class, String.class, String.class);
    CrossParameterDescriptor crossParameterDescriptor = descriptor.getCrossParameterDescriptor();
    assertFalse(crossParameterDescriptor.hasConstraints(), "Cross parameter constraints should be ignored.");
    ReturnValueDescriptor returnValueDescriptor = descriptor.getReturnValueDescriptor();
    assertFalse(returnValueDescriptor.hasConstraints(), "Return value constraints should be ignored.");
    ParameterDescriptor parameterDescriptor = descriptor.getParameterDescriptors().get(0);
    assertFalse(parameterDescriptor.hasConstraints(), "First parameter constraints should be ignored.");
    parameterDescriptor = descriptor.getParameterDescriptors().get(1);
    assertTrue(parameterDescriptor.hasConstraints(), "Second parameter constraints should be applied.");
}
Also used : ReturnValueDescriptor(jakarta.validation.metadata.ReturnValueDescriptor) ParameterDescriptor(jakarta.validation.metadata.ParameterDescriptor) CrossParameterDescriptor(jakarta.validation.metadata.CrossParameterDescriptor) ConstructorDescriptor(jakarta.validation.metadata.ConstructorDescriptor) CrossParameterDescriptor(jakarta.validation.metadata.CrossParameterDescriptor) AbstractTCKTest(org.hibernate.beanvalidation.tck.tests.AbstractTCKTest) Test(org.testng.annotations.Test) SpecAssertion(org.jboss.test.audit.annotations.SpecAssertion)

Example 12 with ConstructorDescriptor

use of jakarta.validation.metadata.ConstructorDescriptor in project beanvalidation-tck by eclipse-ee4j.

the class IgnoreAnnotationsOnConstructorTest method testIgnoreAnnotationsOnConstructorLevel.

@Test
@SpecAssertions({ @SpecAssertion(section = Sections.XML_MAPPING_CONSTRAINTDECLARATIONINXML_CONSTRUCTORLEVELOVERRIDING, id = "k"), @SpecAssertion(section = Sections.XML_MAPPING_CONSTRAINTDECLARATIONINXML_CONSTRUCTORLEVELOVERRIDING, id = "l"), @SpecAssertion(section = Sections.XML_MAPPING_CONSTRAINTDECLARATIONINXML_CONSTRUCTORLEVELOVERRIDING, id = "m"), @SpecAssertion(section = Sections.XML_MAPPING_CONSTRAINTDECLARATIONINXML_CONSTRUCTORLEVELOVERRIDING, id = "o") })
public void testIgnoreAnnotationsOnConstructorLevel() {
    ConstructorDescriptor descriptor = TestUtil.getConstructorDescriptor(IgnoreAnnotations.class, String.class, String.class);
    CrossParameterDescriptor crossParameterDescriptor = descriptor.getCrossParameterDescriptor();
    assertFalse(crossParameterDescriptor.hasConstraints(), "Cross parameter constraints should be ignored.");
    ReturnValueDescriptor returnValueDescriptor = descriptor.getReturnValueDescriptor();
    assertFalse(returnValueDescriptor.hasConstraints(), "Return value constraints should be ignored.");
    assertTrue(returnValueDescriptor.getGroupConversions().isEmpty(), "Group conversions should be ignored");
    ParameterDescriptor parameterDescriptor = descriptor.getParameterDescriptors().get(0);
    assertFalse(parameterDescriptor.hasConstraints(), "First parameter constraints should be ignored.");
    assertTrue(parameterDescriptor.getGroupConversions().isEmpty(), "Group conversions should be ignored");
    parameterDescriptor = descriptor.getParameterDescriptors().get(1);
    assertTrue(parameterDescriptor.hasConstraints(), "Second parameter constraints should be applied.");
    assertEquals(parameterDescriptor.getGroupConversions().size(), 2, "All group conversions should be combined");
}
Also used : ReturnValueDescriptor(jakarta.validation.metadata.ReturnValueDescriptor) ParameterDescriptor(jakarta.validation.metadata.ParameterDescriptor) CrossParameterDescriptor(jakarta.validation.metadata.CrossParameterDescriptor) ConstructorDescriptor(jakarta.validation.metadata.ConstructorDescriptor) CrossParameterDescriptor(jakarta.validation.metadata.CrossParameterDescriptor) SpecAssertions(org.jboss.test.audit.annotations.SpecAssertions) AbstractTCKTest(org.hibernate.beanvalidation.tck.tests.AbstractTCKTest) Test(org.testng.annotations.Test)

Example 13 with ConstructorDescriptor

use of jakarta.validation.metadata.ConstructorDescriptor in project beanvalidation-tck by eclipse-ee4j.

the class CascadedValidationTest method testValidaAnnotationIsApplied.

@Test
@SpecAssertion(section = Sections.XML_MAPPING_CONSTRAINTDECLARATIONINXML_CONSTRUCTORLEVELOVERRIDING, id = "n")
public void testValidaAnnotationIsApplied() throws Exception {
    ConstructorDescriptor descriptor = TestUtil.getConstructorDescriptor(Cascaded.class, String.class);
    assertNotNull(descriptor, "the specified constructor should be configured in xml");
    ReturnValueDescriptor returnValueDescriptor = descriptor.getReturnValueDescriptor();
    assertTrue(returnValueDescriptor.isCascaded(), "Cascaded validation should be applied");
    ParameterDescriptor parameterDescriptor = descriptor.getParameterDescriptors().get(0);
    assertTrue(parameterDescriptor.isCascaded(), "Cascaded validation should be applied");
}
Also used : ReturnValueDescriptor(jakarta.validation.metadata.ReturnValueDescriptor) ParameterDescriptor(jakarta.validation.metadata.ParameterDescriptor) ConstructorDescriptor(jakarta.validation.metadata.ConstructorDescriptor) AbstractTCKTest(org.hibernate.beanvalidation.tck.tests.AbstractTCKTest) Test(org.testng.annotations.Test) SpecAssertion(org.jboss.test.audit.annotations.SpecAssertion)

Example 14 with ConstructorDescriptor

use of jakarta.validation.metadata.ConstructorDescriptor in project beanvalidation-tck by eclipse-ee4j.

the class ConstructorValidationTest method testConstraintOnConstructorReturnValueAndParameter.

@Test
@SpecAssertions({ @SpecAssertion(section = Sections.CONSTRAINTMETADATA_CONSTRAINTDESCRIPTOR, id = "a"), @SpecAssertion(section = Sections.XML_MAPPING_CONSTRAINTDECLARATIONINXML_CONSTRUCTORLEVELOVERRIDING, id = "g") })
public void testConstraintOnConstructorReturnValueAndParameter() throws Exception {
    ConstructorDescriptor descriptor = TestUtil.getConstructorDescriptor(CustomerRepository.class, String.class);
    assertNotNull(descriptor, "the specified constructor should be configured in xml");
    ReturnValueDescriptor returnValueDescriptor = descriptor.getReturnValueDescriptor();
    Set<ConstraintDescriptor<?>> constraintDescriptors = returnValueDescriptor.getConstraintDescriptors();
    assertTrue(constraintDescriptors.size() == 1);
    ConstraintDescriptor<?> constraintDescriptor = constraintDescriptors.iterator().next();
    assertEquals(constraintDescriptor.getAnnotation().annotationType(), NotNull.class, "Unexpected constraint type");
    List<ParameterDescriptor> parameterDescriptors = descriptor.getParameterDescriptors();
    assertTrue(parameterDescriptors.size() == 1);
    ParameterDescriptor parameterDescriptor = parameterDescriptors.get(0);
    constraintDescriptors = parameterDescriptor.getConstraintDescriptors();
    assertTrue(constraintDescriptors.size() == 1);
    constraintDescriptor = constraintDescriptors.iterator().next();
    assertEquals(constraintDescriptor.getAnnotation().annotationType(), NotNull.class, "Unexpected constraint type");
}
Also used : ReturnValueDescriptor(jakarta.validation.metadata.ReturnValueDescriptor) ConstraintDescriptor(jakarta.validation.metadata.ConstraintDescriptor) ParameterDescriptor(jakarta.validation.metadata.ParameterDescriptor) CrossParameterDescriptor(jakarta.validation.metadata.CrossParameterDescriptor) ConstructorDescriptor(jakarta.validation.metadata.ConstructorDescriptor) SpecAssertions(org.jboss.test.audit.annotations.SpecAssertions) AbstractTCKTest(org.hibernate.beanvalidation.tck.tests.AbstractTCKTest) Test(org.testng.annotations.Test)

Example 15 with ConstructorDescriptor

use of jakarta.validation.metadata.ConstructorDescriptor in project beanvalidation-tck by eclipse-ee4j.

the class ConstructorValidationTest method testCascadingOnReturnValueAndParameter.

@Test
@SpecAssertion(section = Sections.XML_MAPPING_CONSTRAINTDECLARATIONINXML_CONSTRUCTORLEVELOVERRIDING, id = "h")
public void testCascadingOnReturnValueAndParameter() throws Exception {
    ConstructorDescriptor descriptor = TestUtil.getConstructorDescriptor(CustomerRepository.class, CustomerRepository.class);
    assertNotNull(descriptor, "the specified constructor should be configured in xml");
    ReturnValueDescriptor returnValueDescriptor = descriptor.getReturnValueDescriptor();
    assertTrue(returnValueDescriptor.isCascaded(), "<valid/> is used to configure cascading");
    List<ParameterDescriptor> parameterDescriptors = descriptor.getParameterDescriptors();
    assertTrue(parameterDescriptors.size() == 1);
    ParameterDescriptor parameterDescriptor = parameterDescriptors.get(0);
    assertTrue(parameterDescriptor.isCascaded(), "<valid/> is used to configure cascading");
}
Also used : ReturnValueDescriptor(jakarta.validation.metadata.ReturnValueDescriptor) ParameterDescriptor(jakarta.validation.metadata.ParameterDescriptor) CrossParameterDescriptor(jakarta.validation.metadata.CrossParameterDescriptor) ConstructorDescriptor(jakarta.validation.metadata.ConstructorDescriptor) AbstractTCKTest(org.hibernate.beanvalidation.tck.tests.AbstractTCKTest) Test(org.testng.annotations.Test) SpecAssertion(org.jboss.test.audit.annotations.SpecAssertion)

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