use of org.hibernate.validator.internal.metadata.descriptor.ConstraintDescriptorImpl in project graphql-java-extended-validation by graphql-java.
the class ResourceBundleMessageInterpolator method buildHibernateContext.
@SuppressWarnings("ConstantConditions")
private MessageInterpolatorContext buildHibernateContext(Map<String, Object> messageParams, ValidationEnvironment validationEnvironment) {
Object validatedValue = validationEnvironment.getValidatedValue();
ConstraintAnnotationDescriptor<BridgeAnnotation> annotationDescriptor = new ConstraintAnnotationDescriptor.Builder<>(BridgeAnnotation.class).build();
ConstraintDescriptorImpl<BridgeAnnotation> constraintDescriptor = new ConstraintDescriptorImpl<>(ConstraintHelper.forAllBuiltinConstraints(), null, annotationDescriptor, ConstraintLocationKind.FIELD, ConstraintType.GENERIC);
Map<String, Object> expressionVariables = StandardELVariables.standardELVars(validationEnvironment);
Class<?> rootBeanType = null;
Path propertyPath = null;
return new MessageInterpolatorContext(constraintDescriptor, validatedValue, rootBeanType, propertyPath, messageParams, expressionVariables, ExpressionLanguageFeatureLevel.BEAN_PROPERTIES, true);
}
use of org.hibernate.validator.internal.metadata.descriptor.ConstraintDescriptorImpl in project hibernate-validator by hibernate.
the class ResourceBundleMessageInterpolatorTest method testCorrectMessageInterpolationIfParameterCannotBeReplaced.
@Test
@TestForIssue(jiraKey = "HV-182")
public void testCorrectMessageInterpolationIfParameterCannotBeReplaced() {
ConstraintAnnotationDescriptor.Builder<Max> descriptorBuilder = new ConstraintAnnotationDescriptor.Builder<>(Max.class);
String message = "Message should stay unchanged since {fubar} is not replaceable";
descriptorBuilder.setMessage(message);
descriptorBuilder.setAttribute("value", 10L);
ConstraintAnnotationDescriptor<Max> maxDescriptor = descriptorBuilder.build();
ConstraintDescriptorImpl<Max> constraintDescriptor = new ConstraintDescriptorImpl<Max>(ConstraintHelper.forAllBuiltinConstraints(), null, maxDescriptor, ConstraintLocationKind.FIELD);
interpolator = new ResourceBundleMessageInterpolator(new TestResourceBundleLocator());
MessageInterpolator.Context messageInterpolatorContext = createMessageInterpolatorContext(constraintDescriptor);
String actual = interpolator.interpolate(maxDescriptor.getMessage(), messageInterpolatorContext);
assertEquals(actual, message, "The message should not have changed.");
}
use of org.hibernate.validator.internal.metadata.descriptor.ConstraintDescriptorImpl 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 org.hibernate.validator.internal.metadata.descriptor.ConstraintDescriptorImpl in project hibernate-validator by hibernate.
the class AnnotationMetaDataProvider method findTypeUseConstraints.
/**
* Finds type use annotation constraints defined on the type argument.
*/
private Set<MetaConstraint<?>> findTypeUseConstraints(Constrainable constrainable, AnnotatedType typeArgument, TypeVariable<?> typeVariable, TypeArgumentLocation location, Type type) {
List<ConstraintDescriptorImpl<?>> constraintDescriptors = findConstraints(constrainable, typeArgument.getAnnotations(), ConstraintLocationKind.TYPE_USE);
if (constraintDescriptors.isEmpty()) {
return Collections.emptySet();
}
Set<MetaConstraint<?>> constraints = newHashSet(constraintDescriptors.size());
ConstraintLocation constraintLocation = ConstraintLocation.forTypeArgument(location.toConstraintLocation(), typeVariable, type);
for (ConstraintDescriptorImpl<?> constraintDescriptor : constraintDescriptors) {
constraints.add(MetaConstraints.create(constraintCreationContext.getTypeResolutionHelper(), constraintCreationContext.getValueExtractorManager(), constraintCreationContext.getConstraintValidatorManager(), constraintDescriptor, constraintLocation));
}
return constraints;
}
use of org.hibernate.validator.internal.metadata.descriptor.ConstraintDescriptorImpl in project graphql-java-extended-validation by graphql-java.
the class ELDiscover method main.
public static void main(String[] args) throws Exception {
elDirect();
Map<String, Object> attributes = new HashMap<>();
ConstraintAnnotationDescriptor.Builder<NotNull> constraintBuilder = new ConstraintAnnotationDescriptor.Builder<>(NotNull.class, attributes);
ConstraintDescriptorImpl<NotNull> constraintDescriptor = new ConstraintDescriptorImpl<>(ConstraintHelper.forAllBuiltinConstraints(), null, constraintBuilder.build(), ConstraintLocationKind.FIELD, ConstraintType.GENERIC);
User user = new User();
user.setAge(18);
ResourceBundleMessageInterpolator messageInterpolator = new ResourceBundleMessageInterpolator();
PathImpl rootPath = PathImpl.createRootPath();
ExpressionLanguageFeatureLevel level = ExpressionLanguageFeatureLevel.BEAN_METHODS;
MessageInterpolator.Context context = new MessageInterpolatorContext(constraintDescriptor, user, null, rootPath, Collections.emptyMap(), Collections.emptyMap(), level, true);
print("${validatedValue.age}", messageInterpolator, context);
print("${validatedValue}", messageInterpolator, context);
print("[1,2,3,4].stream().sum()", messageInterpolator, context);
print("${4.0>= 3}", messageInterpolator, context);
print("${! empty validatedValue}", messageInterpolator, context);
print("#{cube=(x->x*x*x);cube(2)}", messageInterpolator, context);
}
Aggregations