Search in sources :

Example 21 with MethodDescriptor

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

the class MethodValidationTest method testVarargsMethodParameter.

@Test
@SpecAssertions({ @SpecAssertion(section = Sections.XML_MAPPING_CONSTRAINTDECLARATIONINXML_METHODLEVELOVERRIDING, id = "a"), @SpecAssertion(section = Sections.XML_MAPPING_CONSTRAINTDECLARATIONINXML_METHODLEVELOVERRIDING, id = "b"), @SpecAssertion(section = Sections.XML_MAPPING_CONSTRAINTDECLARATIONINXML_METHODLEVELOVERRIDING, id = "c") })
public void testVarargsMethodParameter() throws Exception {
    MethodDescriptor descriptor = TestUtil.getMethodDescriptor(CustomerRepository.class, "addCustomers", Customer[].class);
    assertNotNull(descriptor, "the specified method should be configured in xml");
    assertTrue(descriptor.hasConstrainedParameters());
}
Also used : MethodDescriptor(jakarta.validation.metadata.MethodDescriptor) SpecAssertions(org.jboss.test.audit.annotations.SpecAssertions) AbstractTCKTest(org.hibernate.beanvalidation.tck.tests.AbstractTCKTest) Test(org.testng.annotations.Test)

Example 22 with MethodDescriptor

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

the class MethodValidationTest method testCascadingOnReturnValueAndParameter.

@Test
@SpecAssertion(section = Sections.XML_MAPPING_CONSTRAINTDECLARATIONINXML_METHODLEVELOVERRIDING, id = "i")
public void testCascadingOnReturnValueAndParameter() throws Exception {
    MethodDescriptor descriptor = TestUtil.getMethodDescriptor(CustomerRepository.class, "findByExample", Customer.class);
    assertNotNull(descriptor, "the specified method 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) MethodDescriptor(jakarta.validation.metadata.MethodDescriptor) AbstractTCKTest(org.hibernate.beanvalidation.tck.tests.AbstractTCKTest) Test(org.testng.annotations.Test) SpecAssertion(org.jboss.test.audit.annotations.SpecAssertion)

Example 23 with MethodDescriptor

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

the class MethodValidationTest method testMethodCrossParameterConstraint.

@Test
@SpecAssertions({ @SpecAssertion(section = Sections.XML_MAPPING_CONSTRAINTDECLARATIONINXML_METHODLEVELOVERRIDING, id = "c"), @SpecAssertion(section = Sections.XML_MAPPING_CONSTRAINTDECLARATIONINXML_METHODLEVELOVERRIDING, id = "g"), @SpecAssertion(section = Sections.XML_MAPPING_CONSTRAINTDECLARATIONINXML_METHODLEVELOVERRIDING, id = "k") })
public void testMethodCrossParameterConstraint() throws Exception {
    MethodDescriptor descriptor = TestUtil.getMethodDescriptor(CustomerRepository.class, "notifyCustomer", Customer.class, String.class);
    assertNotNull(descriptor, "the specified method should be configured in xml");
    CrossParameterDescriptor crossParameterDescriptor = descriptor.getCrossParameterDescriptor();
    assertTrue(crossParameterDescriptor.hasConstraints());
    Set<ConstraintDescriptor<?>> constraintDescriptors = crossParameterDescriptor.getConstraintDescriptors();
    assertTrue(constraintDescriptors.size() == 1);
    ConstraintDescriptor<?> constraintDescriptor = constraintDescriptors.iterator().next();
    assertEquals(constraintDescriptor.getAnnotation().annotationType(), CrossRepositoryConstraint.class, "Unexpected constraint type");
}
Also used : ConstraintDescriptor(jakarta.validation.metadata.ConstraintDescriptor) CrossParameterDescriptor(jakarta.validation.metadata.CrossParameterDescriptor) MethodDescriptor(jakarta.validation.metadata.MethodDescriptor) SpecAssertions(org.jboss.test.audit.annotations.SpecAssertions) AbstractTCKTest(org.hibernate.beanvalidation.tck.tests.AbstractTCKTest) Test(org.testng.annotations.Test)

Example 24 with MethodDescriptor

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

the class CascadedValidationTest method testValidaAnnotationIsApplied.

@Test
@SpecAssertion(section = Sections.XML_MAPPING_CONSTRAINTDECLARATIONINXML_METHODLEVELOVERRIDING, id = "o")
public void testValidaAnnotationIsApplied() throws Exception {
    MethodDescriptor descriptor = TestUtil.getMethodDescriptor(Cascaded.class, "cascade", String.class);
    assertNotNull(descriptor, "the specified method 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) MethodDescriptor(jakarta.validation.metadata.MethodDescriptor) AbstractTCKTest(org.hibernate.beanvalidation.tck.tests.AbstractTCKTest) Test(org.testng.annotations.Test) SpecAssertion(org.jboss.test.audit.annotations.SpecAssertion)

Example 25 with MethodDescriptor

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

the class ExecutableDescriptorIgnoresValidatedExecutableXmlSettingsTest method testMethodDescriptorCanBeRetrievedAlsoIfValidateExecutableIsSetToNONEInXml.

@Test
@SpecAssertion(section = Sections.CONSTRAINTMETADATA_EXECUTABLEDESCRIPTOR, id = "h")
public void testMethodDescriptorCanBeRetrievedAlsoIfValidateExecutableIsSetToNONEInXml() {
    assertEquals(Validation.byDefaultProvider().configure().getBootstrapConfiguration().getDefaultValidatedExecutableTypes(), Collections.emptySet());
    MethodDescriptor descriptor = getMethodDescriptor(StockItem.class, "setName", String.class);
    assertNotNull(descriptor);
    assertEquals(descriptor.getName(), "setName");
    assertEquals(descriptor.getParameterDescriptors().get(0).getConstraintDescriptors().size(), 1);
}
Also used : MethodDescriptor(jakarta.validation.metadata.MethodDescriptor) TestUtil.getMethodDescriptor(org.hibernate.beanvalidation.tck.util.TestUtil.getMethodDescriptor) AbstractTCKTest(org.hibernate.beanvalidation.tck.tests.AbstractTCKTest) Test(org.testng.annotations.Test) SpecAssertion(org.jboss.test.audit.annotations.SpecAssertion)

Aggregations

MethodDescriptor (jakarta.validation.metadata.MethodDescriptor)93 Test (org.testng.annotations.Test)86 AbstractTCKTest (org.hibernate.beanvalidation.tck.tests.AbstractTCKTest)49 SpecAssertion (org.jboss.test.audit.annotations.SpecAssertion)44 BeanDescriptor (jakarta.validation.metadata.BeanDescriptor)19 ValidatorUtil.getMethodDescriptor (org.hibernate.validator.testutils.ValidatorUtil.getMethodDescriptor)18 ParameterDescriptor (jakarta.validation.metadata.ParameterDescriptor)13 CrossParameterDescriptor (jakarta.validation.metadata.CrossParameterDescriptor)12 ReturnValueDescriptor (jakarta.validation.metadata.ReturnValueDescriptor)11 ConstraintMapping (org.hibernate.validator.cfg.ConstraintMapping)8 ValidatorUtil.getBeanDescriptor (org.hibernate.validator.testutils.ValidatorUtil.getBeanDescriptor)7 ConstraintDescriptor (jakarta.validation.metadata.ConstraintDescriptor)5 ConstructorDescriptor (jakarta.validation.metadata.ConstructorDescriptor)4 SpecAssertions (org.jboss.test.audit.annotations.SpecAssertions)4 Validator (jakarta.validation.Validator)3 TestUtil.getMethodDescriptor (org.hibernate.beanvalidation.tck.util.TestUtil.getMethodDescriptor)3 TestForIssue (org.hibernate.validator.testutil.TestForIssue)3 Test (org.junit.Test)3 ConstraintValidator (jakarta.validation.ConstraintValidator)2 ValidatorFactory (jakarta.validation.ValidatorFactory)2