use of org.hibernate.validator.internal.util.annotation.ConstraintAnnotationDescriptor 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.util.annotation.ConstraintAnnotationDescriptor 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.util.annotation.ConstraintAnnotationDescriptor in project hibernate-validator by hibernate.
the class ResourceBundleMessageInterpolatorTest method testRecursiveMessageInterpolation.
@Test
@TestForIssue(jiraKey = "HV-102")
public void testRecursiveMessageInterpolation() {
ConstraintAnnotationDescriptor.Builder<Max> descriptorBuilder = new ConstraintAnnotationDescriptor.Builder<>(Max.class);
descriptorBuilder.setMessage("{replace.in.user.bundle1}");
descriptorBuilder.setAttribute("value", 10L);
ConstraintAnnotationDescriptor<Max> descriptor = descriptorBuilder.build();
ConstraintDescriptorImpl<Max> constraintDescriptor = new ConstraintDescriptorImpl<Max>(ConstraintHelper.forAllBuiltinConstraints(), null, descriptorBuilder.build(), ConstraintLocationKind.FIELD);
interpolator = new ResourceBundleMessageInterpolator(new TestResourceBundleLocator());
MessageInterpolator.Context messageInterpolatorContext = createMessageInterpolatorContext(constraintDescriptor);
String expected = "{replace.in.default.bundle2}";
String actual = interpolator.interpolate(descriptor.getAnnotation().message(), messageInterpolatorContext);
assertEquals(actual, expected, "Within default bundle replacement parameter evaluation should not be recursive!");
}
Aggregations