use of org.hibernate.validator.internal.engine.MessageInterpolatorContext in project hibernate-validator by hibernate.
the class ResourceBundleMessageInterpolatorTest method testDefaultInterpolation.
@Test
public void testDefaultInterpolation() {
interpolator = new ResourceBundleMessageInterpolator(new TestResourceBundleLocator());
MessageInterpolatorContext messageInterpolatorContext = createMessageInterpolatorContext(notNullDescriptor);
String expected = "must not be null";
String actual = interpolator.interpolate(notNullDescriptor.getAnnotation().message(), messageInterpolatorContext);
assertEquals(actual, expected, "Wrong substitution");
// unknown token {}
expected = "size must be between 0 and 2147483647";
messageInterpolatorContext = createMessageInterpolatorContext(sizeDescriptor);
actual = interpolator.interpolate(sizeDescriptor.getAnnotation().message(), messageInterpolatorContext);
assertEquals(actual, expected, "Wrong substitution");
}
use of org.hibernate.validator.internal.engine.MessageInterpolatorContext in project hibernate-validator by hibernate.
the class ResourceBundleMessageInterpolatorTest method testUnknownTokenInterpolation.
@Test
public void testUnknownTokenInterpolation() {
interpolator = new ResourceBundleMessageInterpolator(new TestResourceBundleLocator());
MessageInterpolatorContext messageInterpolatorContext = createMessageInterpolatorContext(notNullDescriptor);
// unknown token {}
String expected = "{bar}";
String actual = interpolator.interpolate("{bar}", messageInterpolatorContext);
assertEquals(actual, expected, "Wrong substitution");
}
use of org.hibernate.validator.internal.engine.MessageInterpolatorContext 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);
}
use of org.hibernate.validator.internal.engine.MessageInterpolatorContext in project graphql-java-extended-validation by graphql-java.
the class ResourceBundleMessageInterpolator method interpolateMessageImpl.
private String interpolateMessageImpl(String messageTemplate, Map<String, Object> messageParams, ValidationEnvironment validationEnvironment) {
Locale locale = validationEnvironment.getLocale() == null ? defaultLocale : validationEnvironment.getLocale();
messageTemplate = loadMessageResource(messageTemplate, locale);
MessageInterpolatorContext context = buildHibernateContext(messageParams, validationEnvironment);
if (locale == null) {
// let hibernate code do the local defaulting
return hibernateInterpolator().interpolate(messageTemplate, context);
} else {
return hibernateInterpolator().interpolate(messageTemplate, context, locale);
}
}
use of org.hibernate.validator.internal.engine.MessageInterpolatorContext in project hibernate-validator by hibernate.
the class MessageInterpolatorContextTest method testUnwrapToInterfaceTypesSucceeds.
@Test
public void testUnwrapToInterfaceTypesSucceeds() {
Context context = new MessageInterpolatorContext(null, null, null, null, Collections.<String, Object>emptyMap(), Collections.<String, Object>emptyMap(), ExpressionLanguageFeatureLevel.BEAN_METHODS, false);
MessageInterpolator.Context asMessageInterpolatorContext = context.unwrap(MessageInterpolator.Context.class);
assertSame(asMessageInterpolatorContext, context);
HibernateMessageInterpolatorContext asHibernateMessageInterpolatorContext = context.unwrap(HibernateMessageInterpolatorContext.class);
assertSame(asHibernateMessageInterpolatorContext, context);
Object asObject = context.unwrap(Object.class);
assertSame(asObject, context);
}
Aggregations