Search in sources :

Example 1 with ValidationAwareSupport

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());
}
Also used : ValidationAwareSupport(com.opensymphony.xwork2.ValidationAwareSupport) Equidae(com.opensymphony.xwork2.test.Equidae)

Example 2 with ValidationAwareSupport

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());
}
Also used : TextProviderFactory(com.opensymphony.xwork2.TextProviderFactory) ValidationAwareSupport(com.opensymphony.xwork2.ValidationAwareSupport) ValueStack(com.opensymphony.xwork2.util.ValueStack) HashMap(java.util.HashMap) ConversionData(com.opensymphony.xwork2.conversion.impl.ConversionData) ConversionErrorFieldValidator(com.opensymphony.xwork2.validator.validators.ConversionErrorFieldValidator)

Example 3 with ValidationAwareSupport

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());
}
Also used : ValidationAwareSupport(com.opensymphony.xwork2.ValidationAwareSupport)

Example 4 with ValidationAwareSupport

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);
}
Also used : ValidationAwareSupport(com.opensymphony.xwork2.ValidationAwareSupport) List(java.util.List)

Example 5 with ValidationAwareSupport

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());
}
Also used : ValidationAwareSupport(com.opensymphony.xwork2.ValidationAwareSupport)

Aggregations

ValidationAwareSupport (com.opensymphony.xwork2.ValidationAwareSupport)15 ValueStack (com.opensymphony.xwork2.util.ValueStack)4 List (java.util.List)4 Equidae (com.opensymphony.xwork2.test.Equidae)3 Map (java.util.Map)2 ActionProxy (com.opensymphony.xwork2.ActionProxy)1 ActionProxyFactory (com.opensymphony.xwork2.ActionProxyFactory)1 TextProviderFactory (com.opensymphony.xwork2.TextProviderFactory)1 ConversionData (com.opensymphony.xwork2.conversion.impl.ConversionData)1 ValidationAware (com.opensymphony.xwork2.interceptor.ValidationAware)1 ConversionErrorFieldValidator (com.opensymphony.xwork2.validator.validators.ConversionErrorFieldValidator)1 File (java.io.File)1 URI (java.net.URI)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 ServletContext (javax.servlet.ServletContext)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 ApplicationMap (org.apache.struts2.dispatcher.ApplicationMap)1 Dispatcher (org.apache.struts2.dispatcher.Dispatcher)1