use of com.opensymphony.xwork2.validator.Validator in project struts by apache.
the class EmailValidatorTest method testCaseSensitiveViaExpression.
public void testCaseSensitiveViaExpression() throws Exception {
EmailValidator validator = verifyCaseSensitive(true);
assertTrue(validator.isCaseSensitive());
validator = verifyCaseSensitive(false);
assertFalse(validator.isCaseSensitive());
}
use of com.opensymphony.xwork2.validator.Validator 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.Validator in project struts by apache.
the class EmailValidatorTest method verifyCaseSensitive.
private EmailValidator verifyCaseSensitive(final boolean caseSensitive) {
ActionSupport action = new ActionSupport() {
public boolean getEmailCaseSensitive() {
return caseSensitive;
}
};
EmailValidator validator = new EmailValidator();
ValueStack valueStack = ActionContext.getContext().getValueStack();
valueStack.push(action);
validator.setValueStack(valueStack);
validator.setCaseSensitiveExpression("${emailCaseSensitive}");
return validator;
}
use of com.opensymphony.xwork2.validator.Validator in project struts by apache.
the class EmailValidatorTest method testTrimViaExpression.
public void testTrimViaExpression() throws Exception {
EmailValidator validator = verifyTrim(true);
assertTrue(validator.isTrimed());
validator = verifyTrim(false);
assertFalse(validator.isTrimed());
}
use of com.opensymphony.xwork2.validator.Validator in project struts by apache.
the class URLValidatorTest method testCollectionOfUrlsSafness.
public void testCollectionOfUrlsSafness() throws Exception {
URLValidator validator = new URLValidator();
validator.setValidatorContext(new DummyValidatorContext(new Object(), tpf));
validator.setFieldName("urlSafeness");
validator.setValueStack(ActionContext.getContext().getValueStack());
validator.setDefaultMessage("Wrong URL provided: ${currentValue}");
validator.validate(new MyObject());
assertTrue(validator.getValidatorContext().hasErrors());
assertFalse(validator.getValidatorContext().hasActionErrors());
assertFalse(validator.getValidatorContext().hasActionMessages());
assertTrue(validator.getValidatorContext().hasFieldErrors());
assertEquals(2, validator.getValidatorContext().getFieldErrors().get("urlSafeness").size());
assertEquals("Wrong URL provided: ${1+2}", validator.getValidatorContext().getFieldErrors().get("urlSafeness").get(0));
assertEquals("Wrong URL provided: %{2+3}", validator.getValidatorContext().getFieldErrors().get("urlSafeness").get(1));
}
Aggregations