Search in sources :

Example 56 with Validator

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

Example 57 with Validator

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);
}
Also used : EmailValidator(com.opensymphony.xwork2.validator.validators.EmailValidator) ValueStack(com.opensymphony.xwork2.util.ValueStack) ActionSupport(com.opensymphony.xwork2.ActionSupport)

Example 58 with Validator

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;
}
Also used : EmailValidator(com.opensymphony.xwork2.validator.validators.EmailValidator) ValueStack(com.opensymphony.xwork2.util.ValueStack) ActionSupport(com.opensymphony.xwork2.ActionSupport)

Example 59 with 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());
}
Also used : EmailValidator(com.opensymphony.xwork2.validator.validators.EmailValidator)

Example 60 with Validator

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

Aggregations

ValueStack (com.opensymphony.xwork2.util.ValueStack)19 DummyValidatorContext (com.opensymphony.xwork2.validator.DummyValidatorContext)18 ValidatorContext (com.opensymphony.xwork2.validator.ValidatorContext)18 URLValidator (com.opensymphony.xwork2.validator.validators.URLValidator)16 RegexFieldValidator (com.opensymphony.xwork2.validator.validators.RegexFieldValidator)12 EmailValidator (com.opensymphony.xwork2.validator.validators.EmailValidator)9 ValueStackFactory (com.opensymphony.xwork2.util.ValueStackFactory)7 RequiredStringValidator (com.opensymphony.xwork2.validator.validators.RequiredStringValidator)6 HashMap (java.util.HashMap)6 ActionSupport (com.opensymphony.xwork2.ActionSupport)5 Validator (com.opensymphony.xwork2.validator.Validator)5 ExpressionValidator (com.opensymphony.xwork2.validator.validators.ExpressionValidator)5 VisitorFieldValidator (com.opensymphony.xwork2.validator.validators.VisitorFieldValidator)5 ConfigurationException (com.opensymphony.xwork2.config.ConfigurationException)4 RequiredFieldValidator (com.opensymphony.xwork2.validator.validators.RequiredFieldValidator)4 StringLengthFieldValidator (com.opensymphony.xwork2.validator.validators.StringLengthFieldValidator)4 TextProviderFactory (com.opensymphony.xwork2.TextProviderFactory)3 ConversionErrorFieldValidator (com.opensymphony.xwork2.validator.validators.ConversionErrorFieldValidator)3 DateRangeFieldValidator (com.opensymphony.xwork2.validator.validators.DateRangeFieldValidator)3 DoubleRangeFieldValidator (com.opensymphony.xwork2.validator.validators.DoubleRangeFieldValidator)3