Search in sources :

Example 21 with BeanDescriptor

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

the class BeanDescriptorTest method testGetConstrainedPropertiesForTypeWithClassLevelConstraint.

@Test
@TestForIssue(jiraKey = "HV-660")
public void testGetConstrainedPropertiesForTypeWithClassLevelConstraint() {
    BeanDescriptor descriptor = getBeanDescriptor(ClassLevelConstrainedType.class);
    Set<PropertyDescriptor> constrainedProperties = descriptor.getConstrainedProperties();
    assertThat(constrainedProperties).isEmpty();
}
Also used : PropertyDescriptor(jakarta.validation.metadata.PropertyDescriptor) ValidatorUtil.getBeanDescriptor(org.hibernate.validator.testutils.ValidatorUtil.getBeanDescriptor) BeanDescriptor(jakarta.validation.metadata.BeanDescriptor) Test(org.testng.annotations.Test) TestForIssue(org.hibernate.validator.testutil.TestForIssue)

Example 22 with BeanDescriptor

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

the class ConstraintDescriptorTest method testValidationAppliesTo.

@Test
public void testValidationAppliesTo() {
    BeanDescriptor beanDescriptor = getBeanDescriptor(Bar.class);
    Set<MethodDescriptor> methodDescriptors = beanDescriptor.getConstrainedMethods(MethodType.NON_GETTER);
    assertEquals(methodDescriptors.size(), 1);
    CrossParameterDescriptor crossParameterDescriptor = methodDescriptors.iterator().next().getCrossParameterDescriptor();
    Set<ConstraintDescriptor<?>> constraintDescriptors = crossParameterDescriptor.getConstraintDescriptors();
    assertEquals(constraintDescriptors.size(), 1);
    ConstraintDescriptor<?> constraintDescriptor = constraintDescriptors.iterator().next();
    assertEquals(constraintDescriptor.getValidationAppliesTo(), ConstraintTarget.PARAMETERS, "wrong constraint targets");
}
Also used : ValidatorUtil.getBeanDescriptor(org.hibernate.validator.testutils.ValidatorUtil.getBeanDescriptor) BeanDescriptor(jakarta.validation.metadata.BeanDescriptor) ConstraintDescriptor(jakarta.validation.metadata.ConstraintDescriptor) CrossParameterDescriptor(jakarta.validation.metadata.CrossParameterDescriptor) MethodDescriptor(jakarta.validation.metadata.MethodDescriptor) Test(org.testng.annotations.Test)

Example 23 with BeanDescriptor

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

the class ConstraintDescriptorTest method testBasicDescriptorAttributes.

@Test
public void testBasicDescriptorAttributes() {
    BeanDescriptor beanDescriptor = getBeanDescriptor(Foo.class);
    PropertyDescriptor propertyDescriptor = beanDescriptor.getConstraintsForProperty("fubar");
    Set<ConstraintDescriptor<?>> constraintDescriptors = propertyDescriptor.getConstraintDescriptors();
    assertEquals(constraintDescriptors.size(), 1);
    ConstraintDescriptor<?> constraintDescriptor = constraintDescriptors.iterator().next();
    assertEquals(constraintDescriptor.getMessageTemplate(), "bar", "Wrong message");
    Set<Class<?>> groups = newHashSet();
    groups.add(SnafuGroup.class);
    assertEquals(constraintDescriptor.getGroups(), groups, "Wrong groups");
    Set<Class<?>> payloads = newHashSet();
    payloads.add(Payload22.class);
    assertEquals(constraintDescriptor.getPayload(), payloads, "Wrong payload");
    assertNull(constraintDescriptor.getValidationAppliesTo(), "There is no validationAppliedTo attribute");
}
Also used : PropertyDescriptor(jakarta.validation.metadata.PropertyDescriptor) ValidatorUtil.getBeanDescriptor(org.hibernate.validator.testutils.ValidatorUtil.getBeanDescriptor) BeanDescriptor(jakarta.validation.metadata.BeanDescriptor) ConstraintDescriptor(jakarta.validation.metadata.ConstraintDescriptor) Test(org.testng.annotations.Test)

Example 24 with BeanDescriptor

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

the class BeanDescriptorTest method testGetElementClass.

@Test
public void testGetElementClass() {
    BeanDescriptor descriptor = getBeanDescriptor(CustomerRepository.class);
    assertEquals(descriptor.getElementClass(), CustomerRepository.class);
}
Also used : ValidatorUtil.getBeanDescriptor(org.hibernate.validator.testutils.ValidatorUtil.getBeanDescriptor) BeanDescriptor(jakarta.validation.metadata.BeanDescriptor) Test(org.testng.annotations.Test)

Example 25 with BeanDescriptor

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

the class BeanDescriptorTest method testIsTypeConstrainedForBeanConstrainedType.

@Test
public void testIsTypeConstrainedForBeanConstrainedType() {
    BeanDescriptor descriptor = getBeanDescriptor(CustomerRepository.class);
    assertTrue(descriptor.isBeanConstrained());
}
Also used : ValidatorUtil.getBeanDescriptor(org.hibernate.validator.testutils.ValidatorUtil.getBeanDescriptor) BeanDescriptor(jakarta.validation.metadata.BeanDescriptor) Test(org.testng.annotations.Test)

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