Search in sources :

Example 6 with ParameterDescriptor

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

the class ParameterDescriptorTest method testFindConstraintLookingAtLocalElement.

@Test(enabled = false, description = "Temporarily disabled due to HV-443")
public void testFindConstraintLookingAtLocalElement() {
    Set<ConstraintDescriptor<?>> constraintDescriptors = createCustomerParameter2.findConstraints().lookingAt(Scope.LOCAL_ELEMENT).getConstraintDescriptors();
    assertEquals(constraintDescriptors.size(), 0, "No local constraint for CustomerRepositoryExt#createCustomer(), arg1, expected.");
    ParameterDescriptor createCustomerParameter2OnBaseType = getParameterDescriptor(CustomerRepository.class, "createCustomer", new Class<?>[] { CharSequence.class, String.class }, 1);
    constraintDescriptors = createCustomerParameter2OnBaseType.findConstraints().lookingAt(Scope.LOCAL_ELEMENT).getConstraintDescriptors();
    assertEquals(constraintDescriptors.size(), 1, "One local constraint for CustomerRepository#createCustomer(), arg1, expected.");
}
Also used : ConstraintDescriptor(jakarta.validation.metadata.ConstraintDescriptor) ParameterDescriptor(jakarta.validation.metadata.ParameterDescriptor) ValidatorUtil.getParameterDescriptor(org.hibernate.validator.testutils.ValidatorUtil.getParameterDescriptor) Test(org.testng.annotations.Test)

Example 7 with ParameterDescriptor

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

the class ParameterDescriptorTest method testIsCascaded.

@Test
public void testIsCascaded() {
    assertFalse(createCustomerParameter1.isCascaded());
    ParameterDescriptor saveCustomerParameter = getParameterDescriptor(CustomerRepositoryExt.class, "saveCustomer", new Class<?>[] { Customer.class }, 0);
    assertTrue(saveCustomerParameter.isCascaded());
}
Also used : ParameterDescriptor(jakarta.validation.metadata.ParameterDescriptor) ValidatorUtil.getParameterDescriptor(org.hibernate.validator.testutils.ValidatorUtil.getParameterDescriptor) Test(org.testng.annotations.Test)

Example 8 with ParameterDescriptor

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

the class ConstructorDescriptorTest method testGetParameterDescriptors.

@Test
public void testGetParameterDescriptors() {
    ConstructorDescriptor constructorDescriptor = getConstructorDescriptor(CustomerRepositoryExt.class, String.class, Customer.class);
    List<ParameterDescriptor> parameterDescriptors = constructorDescriptor.getParameterDescriptors();
    assertThat(parameterDescriptors).hasSize(2);
    ParameterDescriptor parameterDescriptor1 = parameterDescriptors.get(0);
    assertThat(parameterDescriptor1.getElementClass()).isEqualTo(String.class);
    assertThat(parameterDescriptor1.getIndex()).isEqualTo(0);
    assertThat(parameterDescriptor1.getName()).isEqualTo("foo");
    assertThat(parameterDescriptor1.hasConstraints()).isTrue();
    assertThat(parameterDescriptor1.isCascaded()).isFalse();
    ParameterDescriptor parameterDescriptor2 = parameterDescriptors.get(1);
    assertThat(parameterDescriptor2.getElementClass()).isEqualTo(Customer.class);
    assertThat(parameterDescriptor2.getIndex()).isEqualTo(1);
    assertThat(parameterDescriptor2.getName()).isEqualTo("customer");
    assertThat(parameterDescriptor2.hasConstraints()).isFalse();
    assertThat(parameterDescriptor2.isCascaded()).isTrue();
}
Also used : ParameterDescriptor(jakarta.validation.metadata.ParameterDescriptor) ConstructorDescriptor(jakarta.validation.metadata.ConstructorDescriptor) ValidatorUtil.getConstructorDescriptor(org.hibernate.validator.testutils.ValidatorUtil.getConstructorDescriptor) Test(org.testng.annotations.Test)

Example 9 with ParameterDescriptor

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

the class MethodDescriptorTest method testFindParameterConstraintLookingAt.

@Test
@TestForIssue(jiraKey = "HV-443")
public void testFindParameterConstraintLookingAt() {
    ParameterDescriptor parameterDescriptor = getMethodDescriptor(CustomerRepositoryExt.class, "createCustomer", CharSequence.class, String.class).getParameterDescriptors().get(1);
    Set<ConstraintDescriptor<?>> constraintDescriptors = parameterDescriptor.findConstraints().lookingAt(Scope.LOCAL_ELEMENT).getConstraintDescriptors();
    assertEquals(constraintDescriptors.size(), 0);
    constraintDescriptors = parameterDescriptor.findConstraints().lookingAt(Scope.HIERARCHY).getConstraintDescriptors();
    assertEquals(constraintDescriptors.size(), 1);
    assertEquals(constraintDescriptors.iterator().next().getAnnotation().annotationType(), NotNull.class);
}
Also used : ParameterDescriptor(jakarta.validation.metadata.ParameterDescriptor) ConstraintDescriptor(jakarta.validation.metadata.ConstraintDescriptor) Test(org.testng.annotations.Test) TestForIssue(org.hibernate.validator.testutil.TestForIssue)

Example 10 with ParameterDescriptor

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

the class MethodDescriptorTest method testGetParameterConstraints.

@Test
public void testGetParameterConstraints() {
    MethodDescriptor methodDescriptor = getMethodDescriptor(CustomerRepositoryExt.class, "createCustomer", CharSequence.class, String.class);
    List<ParameterDescriptor> parameterConstraints = methodDescriptor.getParameterDescriptors();
    assertNotNull(parameterConstraints);
    assertEquals(parameterConstraints.size(), 2);
    ParameterDescriptor parameterDescriptor1 = parameterConstraints.get(0);
    assertEquals(parameterDescriptor1.getElementClass(), CharSequence.class);
    assertFalse(parameterDescriptor1.hasConstraints());
    ParameterDescriptor parameterDescriptor2 = parameterConstraints.get(1);
    assertEquals(parameterDescriptor2.getElementClass(), String.class);
    assertTrue(parameterDescriptor2.hasConstraints());
}
Also used : ParameterDescriptor(jakarta.validation.metadata.ParameterDescriptor) MethodDescriptor(jakarta.validation.metadata.MethodDescriptor) ValidatorUtil.getMethodDescriptor(org.hibernate.validator.testutils.ValidatorUtil.getMethodDescriptor) Test(org.testng.annotations.Test)

Aggregations

ParameterDescriptor (jakarta.validation.metadata.ParameterDescriptor)10 Test (org.testng.annotations.Test)7 MethodDescriptor (jakarta.validation.metadata.MethodDescriptor)5 ConstructorDescriptor (jakarta.validation.metadata.ConstructorDescriptor)4 BeanDescriptor (jakarta.validation.metadata.BeanDescriptor)3 ConstraintDescriptor (jakarta.validation.metadata.ConstraintDescriptor)3 CrossParameterDescriptor (jakarta.validation.metadata.CrossParameterDescriptor)2 ReturnValueDescriptor (jakarta.validation.metadata.ReturnValueDescriptor)2 ValidatorUtil.getMethodDescriptor (org.hibernate.validator.testutils.ValidatorUtil.getMethodDescriptor)2 ValidatorUtil.getParameterDescriptor (org.hibernate.validator.testutils.ValidatorUtil.getParameterDescriptor)2 Test (org.junit.Test)2 ValidatorFactory (jakarta.validation.ValidatorFactory)1 Date (java.util.Date)1 List (java.util.List)1 CollectionHelper.newArrayList (org.hibernate.validator.internal.util.CollectionHelper.newArrayList)1 TestForIssue (org.hibernate.validator.testutil.TestForIssue)1 ValidatorUtil.getConstructorDescriptor (org.hibernate.validator.testutils.ValidatorUtil.getConstructorDescriptor)1