use of jakarta.validation.metadata.PropertyDescriptor 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.PropertyDescriptor in project hibernate-validator by hibernate.
the class LibraryTest method testContainerElementTypeDescriptor.
@Test
public void testContainerElementTypeDescriptor() {
BeanDescriptor libraryDescriptor = validator.getConstraintsForClass(Library.class);
// tag::testContainerElementTypeDescriptor[]
PropertyDescriptor booksDescriptor = libraryDescriptor.getConstraintsForProperty("books");
Set<ContainerElementTypeDescriptor> booksContainerElementTypeDescriptors = booksDescriptor.getConstrainedContainerElementTypes();
ContainerElementTypeDescriptor booksContainerElementTypeDescriptor = booksContainerElementTypeDescriptors.iterator().next();
assertTrue(booksContainerElementTypeDescriptor.hasConstraints());
assertTrue(booksContainerElementTypeDescriptor.isCascaded());
assertEquals(0, booksContainerElementTypeDescriptor.getTypeArgumentIndex().intValue());
assertEquals(List.class, booksContainerElementTypeDescriptor.getContainerClass());
Set<ConstraintDescriptor<?>> constraintDescriptors = booksContainerElementTypeDescriptor.getConstraintDescriptors();
ConstraintDescriptor<?> constraintDescriptor = constraintDescriptors.iterator().next();
assertEquals(NotNull.class, constraintDescriptor.getAnnotation().annotationType());
// end::testContainerElementTypeDescriptor[]
}
use of jakarta.validation.metadata.PropertyDescriptor 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();
}
use of jakarta.validation.metadata.PropertyDescriptor 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");
}
use of jakarta.validation.metadata.PropertyDescriptor in project beanvalidation-tck by eclipse-ee4j.
the class FieldLevelOverridingTest method testIncludeAnnotations.
@Test
@SpecAssertions({ @SpecAssertion(section = Sections.CONSTRAINTMETADATA_CONSTRAINTDESCRIPTOR, id = "a"), @SpecAssertion(section = Sections.XML_MAPPING_CONSTRAINTDECLARATIONINXML_FIELDLEVELOVERRIDING, id = "a"), @SpecAssertion(section = Sections.XML_MAPPING_CONSTRAINTDECLARATIONINXML_FIELDLEVELOVERRIDING, id = "d") })
public void testIncludeAnnotations() {
Validator validator = TestUtil.getValidatorUnderTest();
BeanDescriptor beanDescriptor = validator.getConstraintsForClass(User.class);
assertNotNull(beanDescriptor);
PropertyDescriptor propDescriptor = beanDescriptor.getConstraintsForProperty("lastname");
assertNotNull(propDescriptor);
Set<ConstraintDescriptor<?>> constraintDescriptors = propDescriptor.getConstraintDescriptors();
assertEquals(constraintDescriptors.size(), 2, "There should be two constraints");
boolean foundNotNullConstraint = false;
boolean foundPatternConstraint = false;
for (ConstraintDescriptor<?> descriptor : constraintDescriptors) {
if (descriptor.getAnnotation() instanceof NotNull) {
foundNotNullConstraint = true;
} else if (descriptor.getAnnotation() instanceof Pattern) {
foundPatternConstraint = true;
} else {
fail("Invalid constraint for property.");
}
}
if (!(foundNotNullConstraint && foundPatternConstraint)) {
fail("Not all configured constraints discovered.");
}
}
Aggregations