Search in sources :

Example 6 with RegexFieldValidator

use of com.opensymphony.xwork2.validator.validators.RegexFieldValidator in project struts by apache.

the class RegexFieldValidatorTest method testIsTrimmed.

public void testIsTrimmed() {
    RegexFieldValidator validator = new RegexFieldValidator();
    assertTrue(validator.isTrimed());
    validator.setTrim(false);
    assertFalse(validator.isTrimed());
}
Also used : RegexFieldValidator(com.opensymphony.xwork2.validator.validators.RegexFieldValidator)

Example 7 with RegexFieldValidator

use of com.opensymphony.xwork2.validator.validators.RegexFieldValidator in project struts by apache.

the class RegexFieldValidatorTest method testMatch.

public void testMatch() throws Exception {
    MyTestPerson testPerson = new MyTestPerson();
    testPerson.setUsername("Secret");
    RegexFieldValidator validator = new RegexFieldValidator();
    validator.setRegex("^Sec.*");
    validator.setValidatorContext(new DummyValidatorContext(new Object(), tpf));
    validator.setFieldName("username");
    validator.setValueStack(ActionContext.getContext().getValueStack());
    validator.validate(testPerson);
    assertFalse(validator.getValidatorContext().hasErrors());
    assertFalse(validator.getValidatorContext().hasActionErrors());
    assertFalse(validator.getValidatorContext().hasActionMessages());
    assertFalse(validator.getValidatorContext().hasFieldErrors());
}
Also used : RegexFieldValidator(com.opensymphony.xwork2.validator.validators.RegexFieldValidator)

Example 8 with RegexFieldValidator

use of com.opensymphony.xwork2.validator.validators.RegexFieldValidator in project struts by apache.

the class RegexFieldValidatorTest method testMatchNoTrim.

public void testMatchNoTrim() throws Exception {
    MyTestPerson testPerson = new MyTestPerson();
    // must end with one whitespace
    testPerson.setUsername("Secret ");
    RegexFieldValidator validator = new RegexFieldValidator();
    validator.setTrim(false);
    validator.setRegex("^Sec.*\\s");
    validator.setValidatorContext(new DummyValidatorContext(new Object(), tpf));
    validator.setFieldName("username");
    validator.setValueStack(ActionContext.getContext().getValueStack());
    validator.validate(testPerson);
    assertFalse(validator.getValidatorContext().hasErrors());
    assertFalse(validator.getValidatorContext().hasActionErrors());
    assertFalse(validator.getValidatorContext().hasActionMessages());
    assertFalse(validator.getValidatorContext().hasFieldErrors());
}
Also used : RegexFieldValidator(com.opensymphony.xwork2.validator.validators.RegexFieldValidator)

Example 9 with RegexFieldValidator

use of com.opensymphony.xwork2.validator.validators.RegexFieldValidator in project struts by apache.

the class RegexFieldValidatorTest method testFail.

public void testFail() throws Exception {
    MyTestPerson testPerson = new MyTestPerson();
    testPerson.setUsername("Superman");
    RegexFieldValidator validator = new RegexFieldValidator();
    validator.setRegex("^Sec.*");
    validator.setValidatorContext(new DummyValidatorContext(new Object(), tpf));
    validator.setFieldName("username");
    validator.setValueStack(ActionContext.getContext().getValueStack());
    validator.validate(testPerson);
    assertTrue(validator.getValidatorContext().hasErrors());
    assertTrue(validator.getValidatorContext().hasFieldErrors());
    List<String> msgs = validator.getValidatorContext().getFieldErrors().get("username");
    assertNotNull(msgs);
    // should contain 1 error message
    assertEquals(1, msgs.size());
    // when failing the validator will not add action errors/msg
    assertFalse(validator.getValidatorContext().hasActionErrors());
    assertFalse(validator.getValidatorContext().hasActionMessages());
}
Also used : RegexFieldValidator(com.opensymphony.xwork2.validator.validators.RegexFieldValidator)

Example 10 with RegexFieldValidator

use of com.opensymphony.xwork2.validator.validators.RegexFieldValidator in project struts by apache.

the class RegexFieldValidatorTest method testNoStringField.

public void testNoStringField() throws Exception {
    MyTestPerson testPerson = new MyTestPerson();
    testPerson.setAge(33);
    RegexFieldValidator validator = new RegexFieldValidator();
    validator.setRegex("[0-9][0-9]");
    validator.setValidatorContext(new DummyValidatorContext(new Object(), tpf));
    validator.setFieldName("age");
    validator.setValueStack(ActionContext.getContext().getValueStack());
    validator.validate(testPerson);
    assertFalse(validator.getValidatorContext().hasErrors());
    assertFalse(validator.getValidatorContext().hasActionErrors());
    assertFalse(validator.getValidatorContext().hasActionMessages());
    assertFalse(validator.getValidatorContext().hasFieldErrors());
}
Also used : RegexFieldValidator(com.opensymphony.xwork2.validator.validators.RegexFieldValidator)

Aggregations

RegexFieldValidator (com.opensymphony.xwork2.validator.validators.RegexFieldValidator)10