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);
}
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[]
}
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");
}
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");
}
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);
}
Aggregations