Search in sources :

Example 1 with GroupConversionDescriptor

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

the class PropertyDescriptorTest method testGetGroupConversionsDeclaredOnGetter.

@Test
public void testGetGroupConversionsDeclaredOnGetter() {
    PropertyDescriptor propertyDescriptor = getPropertyDescriptor(Customer.class, "lastOrder");
    Set<GroupConversionDescriptor> groupConversions = propertyDescriptor.getGroupConversions();
    assertThat(groupConversions).hasSize(2);
    assertThat(groupConversions).containsConversion(CustomerGetterBasic.class, OrderBasic.class);
    assertThat(groupConversions).containsConversion(CustomerGetterComplex.class, OrderComplex.class);
}
Also used : ValidatorUtil.getPropertyDescriptor(org.hibernate.validator.testutils.ValidatorUtil.getPropertyDescriptor) PropertyDescriptor(jakarta.validation.metadata.PropertyDescriptor) GroupConversionDescriptor(jakarta.validation.metadata.GroupConversionDescriptor) Test(org.testng.annotations.Test)

Example 2 with GroupConversionDescriptor

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

the class CarTest method testGroupConversionDescriptor.

@Test
public void testGroupConversionDescriptor() {
    BeanDescriptor carDescriptor = validator.getConstraintsForClass(Car.class);
    // tag::testGroupConversionDescriptor[]
    PropertyDescriptor driverDescriptor = carDescriptor.getConstraintsForProperty("driver");
    Set<GroupConversionDescriptor> groupConversions = driverDescriptor.getGroupConversions();
    assertEquals(1, groupConversions.size());
    GroupConversionDescriptor groupConversionDescriptor = groupConversions.iterator().next();
    assertEquals(Default.class, groupConversionDescriptor.getFrom());
    assertEquals(Person.Basic.class, groupConversionDescriptor.getTo());
// end::testGroupConversionDescriptor[]
}
Also used : PropertyDescriptor(jakarta.validation.metadata.PropertyDescriptor) BeanDescriptor(jakarta.validation.metadata.BeanDescriptor) GroupConversionDescriptor(jakarta.validation.metadata.GroupConversionDescriptor) Test(org.junit.Test)

Example 3 with GroupConversionDescriptor

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

the class MethodValidationTest method testGroupConversionOnReturnValueAndParameter.

@Test
@SpecAssertion(section = Sections.XML_MAPPING_CONSTRAINTDECLARATIONINXML_METHODLEVELOVERRIDING, id = "j")
public void testGroupConversionOnReturnValueAndParameter() throws Exception {
    MethodDescriptor descriptor = TestUtil.getMethodDescriptor(CustomerRepository.class, "findByExample", Customer.class);
    assertNotNull(descriptor, "the specified method should be configured in xml");
    ReturnValueDescriptor returnValueDescriptor = descriptor.getReturnValueDescriptor();
    Set<GroupConversionDescriptor> groupConversionDescriptors = returnValueDescriptor.getGroupConversions();
    assertTrue(groupConversionDescriptors.size() == 1);
    GroupConversionDescriptor groupConversionDescriptor = groupConversionDescriptors.iterator().next();
    assertEquals(groupConversionDescriptor.getFrom(), Default.class, "Wrong from class for group conversion");
    List<ParameterDescriptor> parameterDescriptors = descriptor.getParameterDescriptors();
    assertTrue(parameterDescriptors.size() == 1);
    ParameterDescriptor parameterDescriptor = parameterDescriptors.get(0);
    groupConversionDescriptors = parameterDescriptor.getGroupConversions();
    assertTrue(groupConversionDescriptors.size() == 1);
    groupConversionDescriptor = groupConversionDescriptors.iterator().next();
    assertEquals(groupConversionDescriptor.getFrom(), Default.class, "Wrong from class for group conversion");
}
Also used : ReturnValueDescriptor(jakarta.validation.metadata.ReturnValueDescriptor) ParameterDescriptor(jakarta.validation.metadata.ParameterDescriptor) CrossParameterDescriptor(jakarta.validation.metadata.CrossParameterDescriptor) GroupConversionDescriptor(jakarta.validation.metadata.GroupConversionDescriptor) MethodDescriptor(jakarta.validation.metadata.MethodDescriptor) AbstractTCKTest(org.hibernate.beanvalidation.tck.tests.AbstractTCKTest) Test(org.testng.annotations.Test) SpecAssertion(org.jboss.test.audit.annotations.SpecAssertion)

Example 4 with GroupConversionDescriptor

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

the class PropertyLevelOverridingTest method testGroupConversionsAreAdditive.

@Test
@SpecAssertions({ @SpecAssertion(section = Sections.XML_MAPPING_CONSTRAINTDECLARATIONINXML_PROPERTYLEVELOVERRIDING, id = "f") })
public void testGroupConversionsAreAdditive() {
    Validator validator = TestUtil.getValidatorUnderTest();
    BeanDescriptor beanDescriptor = validator.getConstraintsForClass(User.class);
    assertNotNull(beanDescriptor);
    PropertyDescriptor propDescriptor = beanDescriptor.getConstraintsForProperty("firstCreditCard");
    assertNotNull(propDescriptor);
    assertTrue(propDescriptor.isCascaded(), "Cascaded validation is configured via xml.");
    Set<GroupConversionDescriptor> groupConversionDescriptorSet = propDescriptor.getGroupConversions();
    assertTrue(groupConversionDescriptorSet.size() == 2, "There should be two group conversions. One configured via annotations and one via XML");
    boolean foundDefaultToRatingA = false;
    boolean foundDefaultToRatingAA = false;
    for (GroupConversionDescriptor groupConversionDescriptor : groupConversionDescriptorSet) {
        if (groupConversionDescriptor.getFrom().equals(Default.class) && groupConversionDescriptor.getTo().equals(User.CreditRatingA.class)) {
            foundDefaultToRatingA = true;
        } else if (groupConversionDescriptor.getFrom().equals(User.CreditRatingA.class) && groupConversionDescriptor.getTo().equals(User.CreditRatingAA.class)) {
            foundDefaultToRatingAA = true;
        } else {
            fail("Unexpected group conversion");
        }
    }
    assertTrue(foundDefaultToRatingA && foundDefaultToRatingAA, "Group conversions defined via XML and Annotation are additive");
}
Also used : PropertyDescriptor(jakarta.validation.metadata.PropertyDescriptor) BeanDescriptor(jakarta.validation.metadata.BeanDescriptor) GroupConversionDescriptor(jakarta.validation.metadata.GroupConversionDescriptor) Default(jakarta.validation.groups.Default) Validator(jakarta.validation.Validator) SpecAssertions(org.jboss.test.audit.annotations.SpecAssertions) AbstractTCKTest(org.hibernate.beanvalidation.tck.tests.AbstractTCKTest) Test(org.testng.annotations.Test)

Example 5 with GroupConversionDescriptor

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

the class GroupConversionTest method testGroupConversionsAppliedOnGetter.

@Test
@SpecAssertion(section = Sections.XML_MAPPING_CONSTRAINTDECLARATIONINXML_GROUPCONVERSIONS, id = "a")
@SpecAssertion(section = Sections.XML_MAPPING_CONSTRAINTDECLARATIONINXML_GROUPCONVERSIONS, id = "b")
@SpecAssertion(section = Sections.CONSTRAINTDECLARATIONVALIDATIONPROCESS_GROUPSEQUENCE_GROUPCONVERSION, id = "d")
public void testGroupConversionsAppliedOnGetter() throws Exception {
    PropertyDescriptor propertyDescriptor = TestUtil.getPropertyDescriptor(Groups.class, "snafu");
    assertNotNull(propertyDescriptor, "the specified property should be configured in xml");
    Set<GroupConversionDescriptor> groupConversionDescriptors = propertyDescriptor.getGroupConversions();
    assertTrue(groupConversionDescriptors.size() == 3);
    GroupConversionDescriptor groupConversionDescriptor = getGroupConversionDescriptorByFrom(groupConversionDescriptors, Default.class);
    assertEquals(groupConversionDescriptor.getTo(), ConvertA.class);
    groupConversionDescriptor = getGroupConversionDescriptorByFrom(groupConversionDescriptors, ConvertA.class);
    assertEquals(groupConversionDescriptor.getTo(), ConvertB.class);
    groupConversionDescriptor = getGroupConversionDescriptorByFrom(groupConversionDescriptors, ConvertB.class);
    assertEquals(groupConversionDescriptor.getTo(), ConvertC.class);
}
Also used : PropertyDescriptor(jakarta.validation.metadata.PropertyDescriptor) GroupConversionDescriptor(jakarta.validation.metadata.GroupConversionDescriptor) AbstractTCKTest(org.hibernate.beanvalidation.tck.tests.AbstractTCKTest) Test(org.testng.annotations.Test) SpecAssertion(org.jboss.test.audit.annotations.SpecAssertion)

Aggregations

GroupConversionDescriptor (jakarta.validation.metadata.GroupConversionDescriptor)30 Test (org.testng.annotations.Test)28 AbstractTCKTest (org.hibernate.beanvalidation.tck.tests.AbstractTCKTest)25 SpecAssertion (org.jboss.test.audit.annotations.SpecAssertion)22 PropertyDescriptor (jakarta.validation.metadata.PropertyDescriptor)12 ReturnValueDescriptor (jakarta.validation.metadata.ReturnValueDescriptor)11 ParameterDescriptor (jakarta.validation.metadata.ParameterDescriptor)9 TestUtil.getPropertyDescriptor (org.hibernate.beanvalidation.tck.util.TestUtil.getPropertyDescriptor)5 StrictChecks (org.hibernate.beanvalidation.tck.tests.metadata.CustomerService.StrictChecks)4 StrictCustomerServiceChecks (org.hibernate.beanvalidation.tck.tests.metadata.CustomerService.StrictCustomerServiceChecks)4 BeanDescriptor (jakarta.validation.metadata.BeanDescriptor)3 ContainerElementTypeDescriptor (jakarta.validation.metadata.ContainerElementTypeDescriptor)3 SpecAssertions (org.jboss.test.audit.annotations.SpecAssertions)3 Validator (jakarta.validation.Validator)2 Default (jakarta.validation.groups.Default)2 ConstructorDescriptor (jakarta.validation.metadata.ConstructorDescriptor)2 CrossParameterDescriptor (jakarta.validation.metadata.CrossParameterDescriptor)2 MethodDescriptor (jakarta.validation.metadata.MethodDescriptor)2 StrictChecks (org.hibernate.beanvalidation.tck.tests.metadata.Customer.StrictChecks)2 StrictCustomerChecks (org.hibernate.beanvalidation.tck.tests.metadata.Customer.StrictCustomerChecks)2