use of jakarta.validation.metadata.PropertyDescriptor in project minijax by minijax.
the class MinijaxValidator method validate.
@Override
public <T> Set<ConstraintViolation<T>> validate(final T object, final Class<?>... groups) {
final MinijaxConstraintValidatorContext<T> context = new MinijaxConstraintValidatorContext<>(object);
final BeanDescriptor descriptor = getConstraintsForClass(object.getClass());
for (final PropertyDescriptor propertyDescriptor : descriptor.getConstrainedProperties()) {
final Object value = ((MinijaxPropertyDescriptor) propertyDescriptor).getValue(object);
validateProperty(context, propertyDescriptor, value);
}
return context.getResult();
}
use of jakarta.validation.metadata.PropertyDescriptor in project hibernate-validator by hibernate.
the class MessageInterpolatorContextTest method testContextWithRightDescriptorAndValueAndRootBeanClassIsPassedToMessageInterpolator.
@Test
@TestForIssue(jiraKey = "HV-333")
public void testContextWithRightDescriptorAndValueAndRootBeanClassIsPassedToMessageInterpolator() {
// use a easy mock message interpolator for verifying that the right MessageInterpolatorContext
// will be passed
MessageInterpolator mock = createMock(MessageInterpolator.class);
Configuration<?> config = ValidatorUtil.getConfiguration().messageInterpolator(mock);
Validator validator = config.buildValidatorFactory().getValidator();
BeanDescriptor beanDescriptor = validator.getConstraintsForClass(TestBean.class);
PropertyDescriptor propertyDescriptor = beanDescriptor.getConstraintsForProperty("test");
Set<ConstraintDescriptor<?>> constraintDescriptors = propertyDescriptor.getConstraintDescriptors();
assertTrue(constraintDescriptors.size() == 1);
// prepare the mock interpolator to expect the right interpolate call
String validatedValue = "value";
expect(mock.interpolate(MESSAGE, new MessageInterpolatorContext(constraintDescriptors.iterator().next(), validatedValue, TestBean.class, null, Collections.<String, Object>emptyMap(), Collections.<String, Object>emptyMap(), ExpressionLanguageFeatureLevel.BEAN_METHODS, false))).andReturn("invalid");
replay(mock);
Set<ConstraintViolation<TestBean>> violations = validator.validate(new TestBean(validatedValue));
assertThat(violations).containsOnlyViolations(violationOf(Size.class).withMessage("invalid"));
// verify that the right context was passed
verify(mock);
}
use of jakarta.validation.metadata.PropertyDescriptor in project hibernate-validator by hibernate.
the class ConstraintValidatorManagerTest method getSingleConstraintDescriptorForProperty.
private ConstraintDescriptorImpl<?> getSingleConstraintDescriptorForProperty(Validator validator, Class<?> clazz, String propertyName) {
BeanDescriptor beanDescriptor = validator.getConstraintsForClass(clazz);
PropertyDescriptor propertyDescriptor = beanDescriptor.getConstraintsForProperty(propertyName);
Set<ConstraintDescriptor<?>> constraintDescriptorSet = propertyDescriptor.getConstraintDescriptors();
assertEquals(constraintDescriptorSet.size(), 1, "There should be only one constraint descriptor");
return (ConstraintDescriptorImpl<?>) constraintDescriptorSet.iterator().next();
}
use of jakarta.validation.metadata.PropertyDescriptor 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.PropertyDescriptor in project hibernate-validator by hibernate.
the class ElementDescriptorTest method testAtValidNotDefinedForPropertyDescriptor.
@Test
public void testAtValidNotDefinedForPropertyDescriptor() {
PropertyDescriptor propertyDescriptor = ValidatorUtil.getPropertyDescriptor(ChildWithoutAtValid2.class, "order");
assertFalse(propertyDescriptor.isCascaded(), "@Valid given neither locally nor in hierarchy should be reflected by PropertyDescriptor.");
}
Aggregations