use of com.opensymphony.xwork2.validator.DummyValidatorContext in project struts by apache.
the class RegexFieldValidatorTest method testNoFieldName.
public void testNoFieldName() throws Exception {
MyTestPerson testPerson = new MyTestPerson();
testPerson.setUsername("NoExpression");
RegexFieldValidator validator = new RegexFieldValidator();
validator.setRegex("^Sec.*");
validator.setValidatorContext(new DummyValidatorContext(new Object(), tpf));
validator.setFieldName(null);
validator.setValueStack(ActionContext.getContext().getValueStack());
validator.validate(testPerson);
assertFalse(validator.getValidatorContext().hasErrors());
assertFalse(validator.getValidatorContext().hasActionErrors());
assertFalse(validator.getValidatorContext().hasActionMessages());
assertFalse(validator.getValidatorContext().hasFieldErrors());
}
use of com.opensymphony.xwork2.validator.DummyValidatorContext in project struts by apache.
the class RegexFieldValidatorTest method testArrayOfStringField.
public void testArrayOfStringField() throws Exception {
MyTestPerson testPerson = new MyTestPerson();
testPerson.setFriends(new String[] { "Alice", "Matt" });
RegexFieldValidator validator = new RegexFieldValidator();
validator.setRegex("A([a-zA-Z]*)");
validator.setValidatorContext(new DummyValidatorContext(new Object(), tpf));
validator.setFieldName("friends");
validator.setValueStack(ActionContext.getContext().getValueStack());
validator.setDefaultMessage("Only names starting with A are allowed!");
validator.validate(testPerson);
assertTrue(validator.getValidatorContext().hasErrors());
assertFalse(validator.getValidatorContext().hasActionErrors());
assertFalse(validator.getValidatorContext().hasActionMessages());
assertTrue(validator.getValidatorContext().hasFieldErrors());
assertEquals(1, validator.getValidatorContext().getFieldErrors().size());
assertEquals(1, validator.getValidatorContext().getFieldErrors().get("friends").size());
assertEquals("Only names starting with A are allowed!", validator.getValidatorContext().getFieldErrors().get("friends").get(0));
}
use of com.opensymphony.xwork2.validator.DummyValidatorContext in project struts by apache.
the class RegexFieldValidatorTest method testListOfStringField.
public void testListOfStringField() throws Exception {
MyTestPerson testPerson = new MyTestPerson();
testPerson.setCars(Arrays.asList("Audi", "BMW"));
RegexFieldValidator validator = new RegexFieldValidator();
validator.setRegex("A([a-zA-Z]*)");
validator.setValidatorContext(new DummyValidatorContext(new Object(), tpf));
validator.setFieldName("cars");
validator.setValueStack(ActionContext.getContext().getValueStack());
validator.setDefaultMessage("Only cars starting with A are allowed!");
validator.validate(testPerson);
assertTrue(validator.getValidatorContext().hasErrors());
assertFalse(validator.getValidatorContext().hasActionErrors());
assertFalse(validator.getValidatorContext().hasActionMessages());
assertTrue(validator.getValidatorContext().hasFieldErrors());
assertEquals(1, validator.getValidatorContext().getFieldErrors().size());
assertEquals(1, validator.getValidatorContext().getFieldErrors().get("cars").size());
assertEquals("Only cars starting with A are allowed!", validator.getValidatorContext().getFieldErrors().get("cars").get(0));
}
use of com.opensymphony.xwork2.validator.DummyValidatorContext in project struts by apache.
the class RegexFieldValidatorTest method testEmptyName.
public void testEmptyName() throws Exception {
MyTestPerson testPerson = new MyTestPerson();
testPerson.setUsername("");
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());
}
use of com.opensymphony.xwork2.validator.DummyValidatorContext 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());
}
Aggregations