Search in sources :

Example 1 with ValidatorSupport

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]);
}
Also used : TextProviderFactory(com.opensymphony.xwork2.TextProviderFactory) SimpleAction(com.opensymphony.xwork2.SimpleAction) ValidatorSupport(com.opensymphony.xwork2.validator.validators.ValidatorSupport)

Example 2 with ValidatorSupport

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");
}
Also used : OgnlValueStack(com.opensymphony.xwork2.ognl.OgnlValueStack)

Aggregations

SimpleAction (com.opensymphony.xwork2.SimpleAction)1 TextProviderFactory (com.opensymphony.xwork2.TextProviderFactory)1 OgnlValueStack (com.opensymphony.xwork2.ognl.OgnlValueStack)1 ValidatorSupport (com.opensymphony.xwork2.validator.validators.ValidatorSupport)1