use of com.opensymphony.xwork2.validator.validators.ValidatorSupport in project struts by apache.
the class SimpleActionValidationTest method testMessageKeyIsReturnedIfNoOtherDefault.
public void testMessageKeyIsReturnedIfNoOtherDefault() throws ValidationException {
Validator validator = new ValidatorSupport() {
public void validate(Object object) throws ValidationException {
addActionError(object);
}
};
validator.setValueStack(ActionContext.getContext().getValueStack());
String messageKey = "does.not.exist";
validator.setMessageKey(messageKey);
SimpleAction action = new SimpleAction();
container.inject(action);
ValidatorContext validatorContext = new DelegatingValidatorContext(action, container.getInstance(TextProviderFactory.class));
validator.setValidatorContext(validatorContext);
validator.validate(this);
assertTrue(validatorContext.hasActionErrors());
Collection<String> errors = validatorContext.getActionErrors();
assertEquals(1, errors.size());
assertEquals(messageKey, errors.toArray()[0]);
}
use of com.opensymphony.xwork2.validator.validators.ValidatorSupport in project struts by apache.
the class ValidatorSupportTest method testConditionalParseExpression.
public void testConditionalParseExpression() {
OgnlValueStack stack = (OgnlValueStack) container.getInstance(ValueStackFactory.class).createValueStack();
stack.getContext().put("something", "somevalue");
ActionContext.of(stack.getContext()).withContainer(container).bind();
ValidatorSupport validator = new ValidatorSupport() {
public void validate(Object object) throws ValidationException {
}
};
validator.setValueStack(ActionContext.getContext().getValueStack());
String result1 = validator.parse("${#something}", String.class).toString();
assertEquals(result1, "somevalue");
}
Aggregations