use of com.opensymphony.xwork2.ValidationAwareSupport in project struts by apache.
the class StringValidatorTest method testRequiredStringWithNullValue.
public void testRequiredStringWithNullValue() throws Exception {
Equidae equidae = new Equidae();
equidae.setHorse(null);
DelegatingValidatorContext context = new DelegatingValidatorContext(new ValidationAwareSupport(), tpf);
container.getInstance(ActionValidatorManager.class).validate(equidae, null, context);
assertTrue(context.hasFieldErrors());
}
use of com.opensymphony.xwork2.ValidationAwareSupport in project struts by apache.
the class ConversionErrorFieldValidatorTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
ValueStack stack = ActionContext.getContext().getValueStack();
Map<String, ConversionData> conversionErrors = new HashMap<>();
conversionErrors.put("foo", new ConversionData("bar", Integer.class));
ActionContext.of(stack.getContext()).withConversionErrors(conversionErrors).bind();
validator = new ConversionErrorFieldValidator();
validationAware = new ValidationAwareSupport();
DelegatingValidatorContext validatorContext = new DelegatingValidatorContext(validationAware, container.getInstance(TextProviderFactory.class));
stack.push(validatorContext);
validator.setValidatorContext(validatorContext);
validator.setFieldName("foo");
validator.setValueStack(ActionContext.getContext().getValueStack());
assertEquals(0, validationAware.getFieldErrors().size());
}
use of com.opensymphony.xwork2.ValidationAwareSupport in project struts by apache.
the class DoubleRangeFieldValidatorTest method testNoValue.
public void testNoValue() throws Exception {
val.setFieldName("price");
DelegatingValidatorContext context = new DelegatingValidatorContext(new ValidationAwareSupport(), tpf);
val.setValidatorContext(context);
val.setMinInclusive(9.95d);
val.validate(null);
// should pass as null value passed in
assertFalse(context.hasErrors());
}
use of com.opensymphony.xwork2.ValidationAwareSupport in project struts by apache.
the class FileUploadInterceptorTest method testAcceptFileWithNoFile.
public void testAcceptFileWithNoFile() throws Exception {
FileUploadInterceptor interceptor = new FileUploadInterceptor();
interceptor.setAllowedTypes("text/plain");
// when file is not of allowed types
ValidationAwareSupport validation = new ValidationAwareSupport();
boolean notOk = interceptor.acceptFile(action, null, "filename.html", "text/html", "inputName", validation);
assertFalse(notOk);
assertFalse(validation.getFieldErrors().isEmpty());
assertTrue(validation.hasErrors());
List errors = (List) validation.getFieldErrors().get("inputName");
assertEquals(1, errors.size());
String msg = (String) errors.get(0);
assertTrue(msg.startsWith("Error uploading:"));
assertTrue(msg.indexOf("inputName") > 0);
}
use of com.opensymphony.xwork2.ValidationAwareSupport in project struts by apache.
the class FileUploadInterceptorTest method testAcceptFileWithEmptyAllowedTypesAndExtensions.
public void testAcceptFileWithEmptyAllowedTypesAndExtensions() throws Exception {
// when allowed type is empty
ValidationAwareSupport validation = new ValidationAwareSupport();
boolean ok = interceptor.acceptFile(action, EMPTY_FILE, "filename", "text/plain", "inputName", validation);
assertTrue(ok);
assertTrue(validation.getFieldErrors().isEmpty());
assertFalse(validation.hasErrors());
}
Aggregations