Search in sources :

Example 26 with BeanDescriptor

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

the class BeanDescriptorTest method testIsTypeConstrainedForConstructorParameterConstrainedType.

@Test
public void testIsTypeConstrainedForConstructorParameterConstrainedType() {
    BeanDescriptor descriptor = getBeanDescriptor(ConstructorParameterConstrainedType.class);
    assertFalse(descriptor.isBeanConstrained(), "The entity should have no bean constraints");
    assertTrue(descriptor.getConstrainedMethods(MethodType.NON_GETTER, MethodType.GETTER).isEmpty(), "The entity should have no constrained methods");
    assertTrue(descriptor.getConstrainedConstructors().size() == 1, "The entity should have a constrained constructor");
}
Also used : ValidatorUtil.getBeanDescriptor(org.hibernate.validator.testutils.ValidatorUtil.getBeanDescriptor) BeanDescriptor(jakarta.validation.metadata.BeanDescriptor) Test(org.testng.annotations.Test)

Example 27 with BeanDescriptor

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

the class BeanDescriptorTest method testIsTypeConstrainedForReturnValueConstrainedType.

@Test
public void testIsTypeConstrainedForReturnValueConstrainedType() {
    BeanDescriptor descriptor = getBeanDescriptor(ReturnValueConstrainedType.class);
    assertFalse(descriptor.isBeanConstrained(), "The entity should have no bean constraints");
    assertFalse(descriptor.getConstrainedMethods(MethodType.NON_GETTER).isEmpty(), "The entity should have constrained methods");
}
Also used : ValidatorUtil.getBeanDescriptor(org.hibernate.validator.testutils.ValidatorUtil.getBeanDescriptor) BeanDescriptor(jakarta.validation.metadata.BeanDescriptor) Test(org.testng.annotations.Test)

Example 28 with BeanDescriptor

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

the class BeanDescriptorTest method testGetConstraintsForMethodFromBaseType.

// A method descriptor can be retrieved by specifying a method from a base
// type (qax() is not defined on CustomerRepositoryExt, but only on
// CustomerRepository).
@Test
public void testGetConstraintsForMethodFromBaseType() throws Exception {
    BeanDescriptor descriptor = getBeanDescriptor(CustomerRepositoryExt.class);
    MethodDescriptor methodDescriptor = descriptor.getConstraintsForMethod("qax", Integer.class);
    assertNotNull(methodDescriptor);
}
Also used : ValidatorUtil.getBeanDescriptor(org.hibernate.validator.testutils.ValidatorUtil.getBeanDescriptor) BeanDescriptor(jakarta.validation.metadata.BeanDescriptor) MethodDescriptor(jakarta.validation.metadata.MethodDescriptor) Test(org.testng.annotations.Test)

Example 29 with BeanDescriptor

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

the class BeanDescriptorTest method testIsTypeConstrainedForDerivedConstrainedType.

@Test
public void testIsTypeConstrainedForDerivedConstrainedType() {
    BeanDescriptor descriptor = getBeanDescriptor(DerivedConstrainedType.class);
    assertFalse(descriptor.isBeanConstrained(), "The entity should have no bean constraints");
    assertFalse(descriptor.getConstrainedMethods(MethodType.NON_GETTER).isEmpty(), "The entity should have constrained methods");
}
Also used : ValidatorUtil.getBeanDescriptor(org.hibernate.validator.testutils.ValidatorUtil.getBeanDescriptor) BeanDescriptor(jakarta.validation.metadata.BeanDescriptor) Test(org.testng.annotations.Test)

Example 30 with BeanDescriptor

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

the class DuplicateConfigurationTest method testXmlConfiguredConstraintExposesCorrespondingAnnotationViaMetadata.

@Test
@SpecAssertion(section = Sections.XML_MAPPING, id = "a")
public void testXmlConfiguredConstraintExposesCorrespondingAnnotationViaMetadata() {
    Configuration<?> config = TestUtil.getConfigurationUnderTest();
    config.addMapping(TestUtil.getInputStreamForPath(packageName + mappingFile1));
    Validator validator = config.buildValidatorFactory().getValidator();
    BeanDescriptor beanDescriptor = validator.getConstraintsForClass(User.class);
    Set<ConstraintDescriptor<?>> constraintDescriptors = beanDescriptor.getConstraintDescriptors();
    assertEquals(constraintDescriptors.size(), 1, "There should be one class level constraint defined in xml");
    ConstraintDescriptor<?> descriptor = constraintDescriptors.iterator().next();
    assertTrue(descriptor.getAnnotation() instanceof ConsistentUserInformation);
    constraintDescriptors = beanDescriptor.getConstraintsForProperty("lastname").getConstraintDescriptors();
    assertEquals(constraintDescriptors.size(), 1, "There should be one constraint defined in xml for 'lastname'");
    descriptor = constraintDescriptors.iterator().next();
    assertTrue(descriptor.getAnnotation() instanceof Pattern);
}
Also used : Pattern(jakarta.validation.constraints.Pattern) BeanDescriptor(jakarta.validation.metadata.BeanDescriptor) ConstraintDescriptor(jakarta.validation.metadata.ConstraintDescriptor) Validator(jakarta.validation.Validator) AbstractTCKTest(org.hibernate.beanvalidation.tck.tests.AbstractTCKTest) Test(org.testng.annotations.Test) SpecAssertion(org.jboss.test.audit.annotations.SpecAssertion)

Aggregations

BeanDescriptor (jakarta.validation.metadata.BeanDescriptor)116 Test (org.testng.annotations.Test)96 AbstractTCKTest (org.hibernate.beanvalidation.tck.tests.AbstractTCKTest)55 SpecAssertion (org.jboss.test.audit.annotations.SpecAssertion)40 PropertyDescriptor (jakarta.validation.metadata.PropertyDescriptor)39 Validator (jakarta.validation.Validator)35 ValidatorUtil.getBeanDescriptor (org.hibernate.validator.testutils.ValidatorUtil.getBeanDescriptor)31 ConstraintDescriptor (jakarta.validation.metadata.ConstraintDescriptor)24 MethodDescriptor (jakarta.validation.metadata.MethodDescriptor)19 SpecAssertions (org.jboss.test.audit.annotations.SpecAssertions)15 ConstructorDescriptor (jakarta.validation.metadata.ConstructorDescriptor)10 Test (org.junit.Test)10 CrossParameterDescriptor (jakarta.validation.metadata.CrossParameterDescriptor)7 TestForIssue (org.hibernate.validator.testutil.TestForIssue)7 NotNull (jakarta.validation.constraints.NotNull)6 Default (jakarta.validation.groups.Default)6 TestUtil.getValidatorUnderTest (org.hibernate.beanvalidation.tck.util.TestUtil.getValidatorUnderTest)6 ConstraintValidator (jakarta.validation.ConstraintValidator)4 ConstraintViolation (jakarta.validation.ConstraintViolation)4 Annotation (java.lang.annotation.Annotation)4