Search in sources :

Example 1 with CrossParameterDescriptor

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

the class IgnoreCrossParameterConstraintTest method testCrossParameterConstraintsAreIgnored.

@Test
@TestForIssue(jiraKey = "HV-734")
public void testCrossParameterConstraintsAreIgnored() {
    Validator validator = getXmlConfiguredValidator("ignore-annotations-for-cross-parameter-constraints.xml");
    BeanDescriptor beanDescriptor = validator.getConstraintsForClass(this.getClass());
    // check that the test constructor has no cross parameter constraint
    ConstructorDescriptor constructorDescriptor = beanDescriptor.getConstraintsForConstructor(String.class, String.class);
    CrossParameterDescriptor crossParameterDescriptor = constructorDescriptor.getCrossParameterDescriptor();
    assertFalse(crossParameterDescriptor.hasConstraints(), "There should be no cross parameter constraints.");
    // check that the test method has no cross parameter constraint
    MethodDescriptor methodDescriptor = beanDescriptor.getConstraintsForMethod("snafu", String.class, String.class);
    crossParameterDescriptor = methodDescriptor.getCrossParameterDescriptor();
    assertFalse(crossParameterDescriptor.hasConstraints(), "There should be no cross parameter constraints.");
}
Also used : BeanDescriptor(jakarta.validation.metadata.BeanDescriptor) ConstructorDescriptor(jakarta.validation.metadata.ConstructorDescriptor) CrossParameterDescriptor(jakarta.validation.metadata.CrossParameterDescriptor) MethodDescriptor(jakarta.validation.metadata.MethodDescriptor) Validator(jakarta.validation.Validator) ConstraintValidator(jakarta.validation.ConstraintValidator) Test(org.testng.annotations.Test) TestForIssue(org.hibernate.validator.testutil.TestForIssue)

Example 2 with CrossParameterDescriptor

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

the class CrossParameterDescriptorTest method testHasConstraintsForConstructorDoesNotConsiderConstraintsFromSuperType.

@Test
public void testHasConstraintsForConstructorDoesNotConsiderConstraintsFromSuperType() {
    CrossParameterDescriptor descriptor = getConstructorDescriptor(CustomerRepositoryExt.class, LocalDate.class, LocalDate.class).getCrossParameterDescriptor();
    assertFalse(descriptor.hasConstraints(), "Constructor has no cross-parameter.");
}
Also used : CrossParameterDescriptor(jakarta.validation.metadata.CrossParameterDescriptor) CustomerRepositoryExt(org.hibernate.validator.test.internal.metadata.CustomerRepositoryExt) LocalDate(java.time.LocalDate) Test(org.testng.annotations.Test)

Example 3 with CrossParameterDescriptor

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

the class CrossParameterDescriptorTest method testGetConstraintDescriptorsForConstructorDoesNotConsiderConstraintsFromSuperType.

@Test
public void testGetConstraintDescriptorsForConstructorDoesNotConsiderConstraintsFromSuperType() {
    CrossParameterDescriptor descriptor = getConstructorDescriptor(CustomerRepositoryExt.class, LocalDate.class, LocalDate.class).getCrossParameterDescriptor();
    assertTrue(descriptor.getConstraintDescriptors().isEmpty());
}
Also used : CrossParameterDescriptor(jakarta.validation.metadata.CrossParameterDescriptor) CustomerRepositoryExt(org.hibernate.validator.test.internal.metadata.CustomerRepositoryExt) LocalDate(java.time.LocalDate) Test(org.testng.annotations.Test)

Example 4 with CrossParameterDescriptor

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

the class CrossParameterDescriptorTest method testHasConstraintsForConstructor.

@Test
public void testHasConstraintsForConstructor() {
    CrossParameterDescriptor descriptor = getConstructorDescriptor(CustomerRepository.class).getCrossParameterDescriptor();
    assertFalse(descriptor.hasConstraints(), "Constructor has no cross-parameter constraints.");
    descriptor = getConstructorDescriptor(CustomerRepository.class, LocalDate.class, LocalDate.class).getCrossParameterDescriptor();
    assertTrue(descriptor.hasConstraints(), "Constructor has one cross-parameter constraint.");
}
Also used : CustomerRepository(org.hibernate.validator.test.internal.metadata.CustomerRepository) CrossParameterDescriptor(jakarta.validation.metadata.CrossParameterDescriptor) Test(org.testng.annotations.Test)

Example 5 with CrossParameterDescriptor

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

the class CrossParameterDescriptorTest method testGetConstraintDescriptorsForMethodConsidersConstraintsFromSuperType.

@Test
public void testGetConstraintDescriptorsForMethodConsidersConstraintsFromSuperType() {
    CrossParameterDescriptor descriptor = getMethodDescriptor(CustomerRepositoryExt.class, "methodWithCrossParameterConstraint", LocalDate.class, LocalDate.class).getCrossParameterDescriptor();
    assertConstraintTypes(descriptor.getConstraintDescriptors(), ConsistentDateParameters.class);
}
Also used : CrossParameterDescriptor(jakarta.validation.metadata.CrossParameterDescriptor) CustomerRepositoryExt(org.hibernate.validator.test.internal.metadata.CustomerRepositoryExt) LocalDate(java.time.LocalDate) Test(org.testng.annotations.Test)

Aggregations

CrossParameterDescriptor (jakarta.validation.metadata.CrossParameterDescriptor)17 Test (org.testng.annotations.Test)15 LocalDate (java.time.LocalDate)9 CustomerRepositoryExt (org.hibernate.validator.test.internal.metadata.CustomerRepositoryExt)7 BeanDescriptor (jakarta.validation.metadata.BeanDescriptor)5 CustomerRepository (org.hibernate.validator.test.internal.metadata.CustomerRepository)5 MethodDescriptor (jakarta.validation.metadata.MethodDescriptor)4 ConstraintDescriptor (jakarta.validation.metadata.ConstraintDescriptor)3 ConstraintValidator (jakarta.validation.ConstraintValidator)2 Validator (jakarta.validation.Validator)2 ConstructorDescriptor (jakarta.validation.metadata.ConstructorDescriptor)2 TestForIssue (org.hibernate.validator.testutil.TestForIssue)2 Test (org.junit.Test)2 Default (jakarta.validation.groups.Default)1 PropertyDescriptor (jakarta.validation.metadata.PropertyDescriptor)1 ReturnValueDescriptor (jakarta.validation.metadata.ReturnValueDescriptor)1 List (java.util.List)1 ValidatorUtil.getBeanDescriptor (org.hibernate.validator.testutils.ValidatorUtil.getBeanDescriptor)1