use of com.opensymphony.xwork2.validator.validators.RequiredStringValidator in project struts by apache.
the class StringValidatorTest method testGetSetTrim.
public void testGetSetTrim() {
RequiredStringValidator val = new RequiredStringValidator();
val.setTrim(true);
assertEquals(true, val.isTrim());
val.setTrim(false);
assertEquals(false, val.isTrim());
}
use of com.opensymphony.xwork2.validator.validators.RequiredStringValidator in project struts by apache.
the class RequiredStringValidatorTest method testTrimAsExpression.
public void testTrimAsExpression() throws Exception {
// given
ValueStack valueStack = ActionContext.getContext().getValueStack();
ActionSupport action = new ActionSupport() {
public boolean getTrimValue() {
return false;
}
};
valueStack.push(action);
RequiredStringValidator validator = new RequiredStringValidator();
validator.setValueStack(valueStack);
assertTrue(validator.isTrim());
// when
validator.setTrimExpression("${trimValue}");
// then
assertFalse(validator.isTrim());
}
use of com.opensymphony.xwork2.validator.validators.RequiredStringValidator in project struts by apache.
the class RequiredStringValidatorTest method testRequiredArrayOfStringsPass.
public void testRequiredArrayOfStringsPass() throws Exception {
// given
ValueStack valueStack = ActionContext.getContext().getValueStack();
ValidationAction action = new ValidationAction();
action.setStrings(new String[] { "", "12334", null });
valueStack.push(action);
ValidatorContext context = new DummyValidatorContext(action, tpf);
RequiredStringValidator validator = new RequiredStringValidator();
validator.setValidatorContext(context);
validator.setFieldName("strings");
validator.setValueStack(valueStack);
// when
validator.validate(action);
// then
assertTrue(context.hasFieldErrors());
assertEquals(1, context.getFieldErrors().size());
assertEquals(2, context.getFieldErrors().get("strings").size());
}
use of com.opensymphony.xwork2.validator.validators.RequiredStringValidator in project struts by apache.
the class RequiredStringValidatorTest method testRequiredStringFails.
public void testRequiredStringFails() throws Exception {
// given
ValueStack valueStack = ActionContext.getContext().getValueStack();
ValidationAction action = new ValidationAction();
valueStack.push(action);
ValidatorContext context = new DummyValidatorContext(action, tpf);
RequiredStringValidator validator = new RequiredStringValidator();
validator.setValidatorContext(context);
validator.setFieldName("stringValue");
validator.setValueStack(valueStack);
validator.setDefaultMessage("Field ${fieldName} is required");
// when
validator.validate(action);
// then
assertTrue(context.getFieldErrors().size() == 1);
assertEquals(context.getFieldErrors().get("stringValue").get(0), "Field stringValue is required");
}
use of com.opensymphony.xwork2.validator.validators.RequiredStringValidator in project struts by apache.
the class RequiredStringValidatorTest method testRequiredCollectionOfStringsPass.
public void testRequiredCollectionOfStringsPass() throws Exception {
// given
ValueStack valueStack = ActionContext.getContext().getValueStack();
ValidationAction action = new ValidationAction();
action.setStringCollection(Arrays.asList("", "123456", null));
valueStack.push(action);
ValidatorContext context = new DummyValidatorContext(action, tpf);
RequiredStringValidator validator = new RequiredStringValidator();
validator.setValidatorContext(context);
validator.setFieldName("stringCollection");
validator.setValueStack(valueStack);
// when
validator.validate(action);
// then
assertTrue(context.hasFieldErrors());
assertEquals(1, context.getFieldErrors().size());
assertEquals(2, context.getFieldErrors().get("stringCollection").size());
}
Aggregations