Search in sources :

Example 1 with ConstructorDescriptor

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

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

the class ConstraintMappingWithAnnotationProcessingOptionsTest method testIgnoreAnnotationsOnConstructorParameter.

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

Example 3 with ConstructorDescriptor

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

the class ConstraintMappingWithAnnotationProcessingOptionsTest method testIgnoreAnnotationsOnConstructorCrossParameter.

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

Example 4 with ConstructorDescriptor

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

the class ConstraintMappingWithAnnotationProcessingOptionsTest method testIgnoreAnnotationsOnConstructorAndReturnValue.

@Test
public void testIgnoreAnnotationsOnConstructorAndReturnValue() {
    ConstraintMapping mapping = config.createConstraintMapping();
    mapping.type(Doer.class).constructor(String.class).ignoreAnnotations(true).returnValue().ignoreAnnotations(false);
    config.addMapping(mapping);
    ConstructorDescriptor descriptor = config.buildValidatorFactory().getValidator().getConstraintsForClass(Doer.class).getConstraintsForConstructor(String.class);
    assertTrue(descriptor.hasConstrainedReturnValue(), "Setting given for return value should take precedence");
}
Also used : ConstraintMapping(org.hibernate.validator.cfg.ConstraintMapping) ConstructorDescriptor(jakarta.validation.metadata.ConstructorDescriptor) Test(org.testng.annotations.Test)

Example 5 with ConstructorDescriptor

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

the class ConstraintMappingWithAnnotationProcessingOptionsTest method testIgnoreAnnotationsOnTypeAndConstructor.

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

Aggregations

ConstructorDescriptor (jakarta.validation.metadata.ConstructorDescriptor)19 Test (org.testng.annotations.Test)16 ConstraintMapping (org.hibernate.validator.cfg.ConstraintMapping)8 BeanDescriptor (jakarta.validation.metadata.BeanDescriptor)7 CrossParameterDescriptor (jakarta.validation.metadata.CrossParameterDescriptor)4 MethodDescriptor (jakarta.validation.metadata.MethodDescriptor)4 ParameterDescriptor (jakarta.validation.metadata.ParameterDescriptor)4 ReturnValueDescriptor (jakarta.validation.metadata.ReturnValueDescriptor)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 ConstraintDescriptor (jakarta.validation.metadata.ConstraintDescriptor)2 TestForIssue (org.hibernate.validator.testutil.TestForIssue)2 Test (org.junit.Test)2 LocalDate (java.time.LocalDate)1 Date (java.util.Date)1 List (java.util.List)1 CollectionHelper.newArrayList (org.hibernate.validator.internal.util.CollectionHelper.newArrayList)1 Customer (org.hibernate.validator.test.internal.metadata.Customer)1