use of com.opensymphony.xwork2.validator.ValidatorContext in project struts by apache.
the class DateRangeFieldValidatorTest method testMaxValidation.
public void testMaxValidation() throws Exception {
// given
ValidationAction action = prepareAction(createDate(2014, Calendar.APRIL, 4));
ValidatorContext context = new DummyValidatorContext(action, tpf);
DateRangeFieldValidator validator = prepareValidator(action, context);
// when
validator.validate(action);
// then
assertEquals(1, context.getFieldErrors().size());
assertEquals("Max is 12.12.13, min is 01.01.13 but value is 04.04.14", context.getFieldErrors().get("dateRange").get(0));
}
use of com.opensymphony.xwork2.validator.ValidatorContext in project struts by apache.
the class DateRangeFieldValidatorTest method testMinValidation.
public void testMinValidation() throws Exception {
// given
ValidationAction action = prepareAction(createDate(2012, Calendar.MARCH, 3));
ValidatorContext context = new DummyValidatorContext(action, tpf);
DateRangeFieldValidator validator = prepareValidator(action, context);
System.out.println(ActionContext.getContext().getLocale());
// when
validator.validate(action);
// then
assertEquals(1, context.getFieldErrors().size());
assertEquals("Max is 12.12.13, min is 01.01.13 but value is 03.03.12", context.getFieldErrors().get("dateRange").get(0));
}
use of com.opensymphony.xwork2.validator.ValidatorContext in project struts by apache.
the class ConversionErrorFieldValidator method doValidate.
/**
* The validation implementation must guarantee that setValidatorContext will
* be called with a non-null ValidatorContext before validate is called.
*
* @param object the object to be validated
* @throws ValidationException in case of validation problems
*/
@Override
public void doValidate(Object object) throws ValidationException {
String fieldName = getFieldName();
String fullFieldName = getValidatorContext().getFullFieldName(fieldName);
ActionContext context = ActionContext.getContext();
Map<String, ConversionData> conversionErrors = context.getConversionErrors();
if (conversionErrors.containsKey(fullFieldName)) {
if (StringUtils.isBlank(defaultMessage)) {
defaultMessage = XWorkConverter.getConversionErrorMessage(fullFieldName, conversionErrors.get(fullFieldName).getToClass(), context.getValueStack());
}
addFieldError(fieldName, object);
}
}
use of com.opensymphony.xwork2.validator.ValidatorContext in project struts by apache.
the class LongRangeFieldValidatorTest method testPassValidation.
public void testPassValidation() throws Exception {
// given
ValidationAction action = prepareAction(100);
ValidatorContext context = new DummyValidatorContext(action, tpf);
LongRangeFieldValidator validator = prepareValidator(action, context);
// when
validator.validate(action);
// then
assertTrue(context.getFieldErrors().size() == 0);
}
use of com.opensymphony.xwork2.validator.ValidatorContext in project struts by apache.
the class RequiredStringValidatorTest method testRequiredStringPass.
public void testRequiredStringPass() throws Exception {
// given
ValueStack valueStack = ActionContext.getContext().getValueStack();
ValidationAction action = new ValidationAction();
action.setStringValue("a string");
valueStack.push(action);
ValidatorContext context = new DummyValidatorContext(action, tpf);
RequiredStringValidator validator = new RequiredStringValidator();
validator.setValidatorContext(context);
validator.setFieldName("stringValue");
validator.setValueStack(valueStack);
// when
validator.validate(action);
// then
assertTrue(context.getFieldErrors().size() == 0);
}
Aggregations