use of com.opensymphony.xwork2.validator.DelegatingValidatorContext in project struts by apache.
the class DoubleRangeFieldValidatorTest method testRangeNotADoubleObjectValueInStack.
public void testRangeNotADoubleObjectValueInStack() throws Exception {
MyTestProduct prod = new MyTestProduct();
prod.setName("coca cola");
ValueStack stack = ActionContext.getContext().getValueStack();
stack.push(prod);
val.setMinInclusive(0d);
val.setMaxInclusive(10d);
val.setFieldName("name");
DelegatingValidatorContext context = new DelegatingValidatorContext(new ValidationAwareSupport(), tpf);
val.setValidatorContext(context);
val.validate(prod);
assertEquals(0d, val.getMinInclusive());
assertEquals(10d, val.getMaxInclusive());
}
use of com.opensymphony.xwork2.validator.DelegatingValidatorContext in project struts by apache.
the class DoubleRangeFieldValidatorTest method testEdgeOfMinRange.
public void testEdgeOfMinRange() throws Exception {
MyTestProduct prod = new MyTestProduct();
prod.setName("coca cola");
prod.setPrice(9.95);
ValueStack stack = ActionContext.getContext().getValueStack();
stack.push(prod);
val.setFieldName("price");
DelegatingValidatorContext context = new DelegatingValidatorContext(new ValidationAwareSupport(), tpf);
val.setValidatorContext(context);
val.setMinInclusive(9.95d);
// should pass
val.validate(prod);
assertFalse(context.hasErrors());
val.setMinExclusive(9.95d);
// should not pass
val.validate(prod);
assertTrue(context.hasErrors());
}
use of com.opensymphony.xwork2.validator.DelegatingValidatorContext in project struts by apache.
the class EmailValidatorTest method verifyEmailValidity.
protected boolean verifyEmailValidity(final String email) throws Exception {
ActionSupport action = new ActionSupport() {
public String getMyEmail() {
return email;
}
};
EmailValidator validator = new EmailValidator();
validator.setValidatorContext(new DelegatingValidatorContext(action, tpf));
validator.setFieldName("myEmail");
validator.setDefaultMessage("invalid email");
validator.setValueStack(ActionContext.getContext().getValueStack());
validator.validate(action);
return (action.getFieldErrors().size() == 0);
}
use of com.opensymphony.xwork2.validator.DelegatingValidatorContext in project struts by apache.
the class EmailValidatorTest method verifyEmailValidityWithExpression.
public boolean verifyEmailValidityWithExpression(final String email, final String expression) throws Exception {
ActionSupport action = new ActionSupport() {
public String getMyEmail() {
return email;
}
public String getEmailExpression() {
return expression;
}
};
EmailValidator validator = new EmailValidator();
ValueStack valueStack = ActionContext.getContext().getValueStack();
valueStack.push(action);
validator.setValueStack(valueStack);
validator.setValidatorContext(new DelegatingValidatorContext(action, tpf));
validator.setFieldName("myEmail");
validator.setDefaultMessage("invalid email");
validator.setRegexExpression("${emailExpression}");
validator.validate(action);
return (action.getFieldErrors().size() == 0);
}
use of com.opensymphony.xwork2.validator.DelegatingValidatorContext in project struts by apache.
the class ExpressionValidatorTest method testNoBooleanExpression.
public void testNoBooleanExpression() throws Exception {
Mock mock = new Mock(ValidationAware.class);
mock.expect("addActionError", C.ANY_ARGS);
ExpressionValidator ev = new ExpressionValidator();
ev.setValidatorContext(new DelegatingValidatorContext(mock.proxy(), tpf));
ev.setExpression("{top}");
ev.setValueStack(ActionContext.getContext().getValueStack());
// {top} will evaluate to Hello that is not a Boolean
ev.validate("Hello");
mock.verify();
}
Aggregations