use of org.hibernate.validator.internal.engine.MessageInterpolatorContext 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.engine.MessageInterpolatorContext 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 org.hibernate.validator.internal.engine.MessageInterpolatorContext in project hibernate-validator by hibernate.
the class MessageInterpolatorContextTest method testGetPropertyPath.
@Test
@TestForIssue(jiraKey = "HV-1657")
public void testGetPropertyPath() {
Path pathMock = createMock(Path.class);
MessageInterpolator.Context context = new MessageInterpolatorContext(null, null, null, pathMock, Collections.<String, Object>emptyMap(), Collections.<String, Object>emptyMap(), ExpressionLanguageFeatureLevel.BEAN_METHODS, false);
assertSame(context.unwrap(HibernateMessageInterpolatorContext.class).getPropertyPath(), pathMock);
}
use of org.hibernate.validator.internal.engine.MessageInterpolatorContext in project hibernate-validator by hibernate.
the class ResourceBundleMessageInterpolatorTest method testUserResourceBundle.
@Test
public void testUserResourceBundle() {
interpolator = new ResourceBundleMessageInterpolator();
MessageInterpolatorContext messageInterpolatorContext = createMessageInterpolatorContext(notNullDescriptor);
String expected = "no puede ser null";
String actual = interpolator.interpolate(notNullDescriptor.getAnnotation().message(), messageInterpolatorContext, new Locale("es", "ES"));
assertEquals(actual, expected, "Wrong substitution");
}
use of org.hibernate.validator.internal.engine.MessageInterpolatorContext in project hibernate-validator by hibernate.
the class ResourceBundleMessageInterpolatorTest method testMessageLiterals.
@Test
public void testMessageLiterals() {
interpolator = new ResourceBundleMessageInterpolator(new TestResourceBundleLocator());
MessageInterpolatorContext messageInterpolatorContext = createMessageInterpolatorContext(notNullDescriptor);
String expected = "{";
String actual = interpolator.interpolate("\\{", messageInterpolatorContext);
assertEquals(actual, expected, "Wrong substitution");
expected = "}";
actual = interpolator.interpolate("\\}", messageInterpolatorContext);
assertEquals(actual, expected, "Wrong substitution");
expected = "\\";
actual = interpolator.interpolate("\\", messageInterpolatorContext);
assertEquals(actual, expected, "Wrong substitution");
}
Aggregations