Search in sources :

Example 1 with MethodDescriptor

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

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

the class ConstraintMappingWithAnnotationProcessingOptionsTest method testIgnoreAnnotationsOnMethodAndReturnValue.

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

Example 3 with MethodDescriptor

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

the class ConstraintMappingWithAnnotationProcessingOptionsTest method testIgnoreAnnotationsOnMethodAndCrossParameter.

@Test
public void testIgnoreAnnotationsOnMethodAndCrossParameter() {
    ConstraintMapping mapping = config.createConstraintMapping();
    mapping = config.createConstraintMapping();
    mapping.type(Doer.class).method("doAnotherThing", String.class).ignoreAnnotations(true).crossParameter().ignoreAnnotations(false);
    config.addMapping(mapping);
    MethodDescriptor descriptor = config.buildValidatorFactory().getValidator().getConstraintsForClass(Doer.class).getConstraintsForMethod("doAnotherThing", String.class);
    assertTrue(descriptor.hasConstrainedParameters(), "Setting given for cross-parameter should take precedence");
}
Also used : ConstraintMapping(org.hibernate.validator.cfg.ConstraintMapping) MethodDescriptor(jakarta.validation.metadata.MethodDescriptor) Test(org.testng.annotations.Test)

Example 4 with MethodDescriptor

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

the class ConstraintMappingWithAnnotationProcessingOptionsTest method testIgnoreAnnotationsOnMethodReturnValue.

@Test
public void testIgnoreAnnotationsOnMethodReturnValue() {
    ConstraintMapping mapping = config.createConstraintMapping();
    mapping.type(Doer.class).method("doSomething", String.class).returnValue().ignoreAnnotations(true);
    config.addMapping(mapping);
    MethodDescriptor descriptor = config.buildValidatorFactory().getValidator().getConstraintsForClass(Doer.class).getConstraintsForMethod("doSomething", String.class);
    assertFalse(descriptor.hasConstrainedReturnValue());
}
Also used : ConstraintMapping(org.hibernate.validator.cfg.ConstraintMapping) MethodDescriptor(jakarta.validation.metadata.MethodDescriptor) Test(org.testng.annotations.Test)

Example 5 with MethodDescriptor

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

the class ConstraintMappingWithAnnotationProcessingOptionsTest method testIgnoreAnnotationsOnMethodParameter.

@Test
public void testIgnoreAnnotationsOnMethodParameter() {
    ConstraintMapping mapping = config.createConstraintMapping();
    mapping.type(Doer.class).method("doSomething", String.class).parameter(0).ignoreAnnotations(true);
    config.addMapping(mapping);
    MethodDescriptor descriptor = config.buildValidatorFactory().getValidator().getConstraintsForClass(Doer.class).getConstraintsForMethod("doSomething", String.class);
    assertFalse(descriptor.hasConstrainedParameters());
}
Also used : ConstraintMapping(org.hibernate.validator.cfg.ConstraintMapping) MethodDescriptor(jakarta.validation.metadata.MethodDescriptor) Test(org.testng.annotations.Test)

Aggregations

MethodDescriptor (jakarta.validation.metadata.MethodDescriptor)42 Test (org.testng.annotations.Test)37 ValidatorUtil.getMethodDescriptor (org.hibernate.validator.testutils.ValidatorUtil.getMethodDescriptor)18 BeanDescriptor (jakarta.validation.metadata.BeanDescriptor)14 ConstraintMapping (org.hibernate.validator.cfg.ConstraintMapping)8 ValidatorUtil.getBeanDescriptor (org.hibernate.validator.testutils.ValidatorUtil.getBeanDescriptor)7 CrossParameterDescriptor (jakarta.validation.metadata.CrossParameterDescriptor)6 ParameterDescriptor (jakarta.validation.metadata.ParameterDescriptor)5 ConstructorDescriptor (jakarta.validation.metadata.ConstructorDescriptor)4 ConstraintDescriptor (jakarta.validation.metadata.ConstraintDescriptor)3 ReturnValueDescriptor (jakarta.validation.metadata.ReturnValueDescriptor)3 TestForIssue (org.hibernate.validator.testutil.TestForIssue)3 Test (org.junit.Test)3 ConstraintValidator (jakarta.validation.ConstraintValidator)2 Validator (jakarta.validation.Validator)2 LocalDate (java.time.LocalDate)2 CustomerRepository (org.hibernate.validator.test.internal.metadata.CustomerRepository)2 ValidatorFactory (jakarta.validation.ValidatorFactory)1 MethodType (jakarta.validation.metadata.MethodType)1 Date (java.util.Date)1