use of com.opensymphony.xwork2.validator.Validator 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.Validator 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());
}
use of com.opensymphony.xwork2.validator.Validator 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());
}
use of com.opensymphony.xwork2.validator.Validator in project struts by apache.
the class SimpleActionValidationTest method testMessageKeyIsReturnedIfNoOtherDefault.
public void testMessageKeyIsReturnedIfNoOtherDefault() throws ValidationException {
Validator validator = new ValidatorSupport() {
public void validate(Object object) throws ValidationException {
addActionError(object);
}
};
validator.setValueStack(ActionContext.getContext().getValueStack());
String messageKey = "does.not.exist";
validator.setMessageKey(messageKey);
SimpleAction action = new SimpleAction();
container.inject(action);
ValidatorContext validatorContext = new DelegatingValidatorContext(action, container.getInstance(TextProviderFactory.class));
validator.setValidatorContext(validatorContext);
validator.validate(this);
assertTrue(validatorContext.hasActionErrors());
Collection<String> errors = validatorContext.getActionErrors();
assertEquals(1, errors.size());
assertEquals(messageKey, errors.toArray()[0]);
}
use of com.opensymphony.xwork2.validator.Validator in project struts by apache.
the class StringLengthFieldValidatorTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
action = new InternalActionSupport();
container.inject(action);
ValueStack valueStack = ActionContext.getContext().getValueStack();
valueStack.push(action);
validator = new StringLengthFieldValidator();
validator.setFieldName("myField");
validator.setMessageKey("error");
validator.setValidatorContext(new DelegatingValidatorContext(action, container.getInstance(TextProviderFactory.class)));
validator.setMaxLength(5);
validator.setMinLength(2);
validator.setValueStack(valueStack);
}
Aggregations