Search in sources :

Example 1 with ValidateGroupAction

use of org.apache.struts.beanvalidation.actions.ValidateGroupAction in project struts by apache.

the class BeanValidationInterceptorTest method testValidationGroupActionDefault.

public void testValidationGroupActionDefault() throws Exception {
    ActionProxy baseActionProxy = getValidateGroupAction("actionDefault");
    ValidateGroupAction action = (ValidateGroupAction) baseActionProxy.getAction();
    action.getModel().setName(null);
    action.getModel().setEmail(null);
    action.getModel().getAddress().setStreet(null);
    baseActionProxy.execute();
    assertEquals("every properties not valid", 3, ((ValidationAware) baseActionProxy.getAction()).getFieldErrors().size());
}
Also used : ActionProxy(com.opensymphony.xwork2.ActionProxy) ValidateGroupAction(org.apache.struts.beanvalidation.actions.ValidateGroupAction) ValidationAware(com.opensymphony.xwork2.interceptor.ValidationAware)

Example 2 with ValidateGroupAction

use of org.apache.struts.beanvalidation.actions.ValidateGroupAction in project struts by apache.

the class BeanValidationInterceptorTest method testValidationGroupActionNameChecks.

public void testValidationGroupActionNameChecks() throws Exception {
    ActionProxy baseActionProxy = getValidateGroupAction("actionNameChecks");
    baseActionProxy.execute();
    Map<String, List<String>> fieldErrors = ((ValidateGroupAction) baseActionProxy.getAction()).getFieldErrors();
    assertEquals(1, fieldErrors.size());
    assertEquals("check name-property @NotNull", "nameNotNull", fieldErrors.get("name").get(0));
    baseActionProxy = getValidateGroupAction("actionNameChecks");
    ((ValidateGroupAction) baseActionProxy.getAction()).getModel().setName("a");
    baseActionProxy.execute();
    fieldErrors = ((ValidateGroupAction) baseActionProxy.getAction()).getFieldErrors();
    assertEquals(1, fieldErrors.size());
    assertEquals("check name-property @Size", "nameSize", fieldErrors.get("name").get(0));
    baseActionProxy = getValidateGroupAction("actionNameChecks");
    ((ValidateGroupAction) baseActionProxy.getAction()).getModel().setName("aName");
    baseActionProxy.execute();
    assertTrue("name-property valid", ((ValidateGroupAction) baseActionProxy.getAction()).getFieldErrors().isEmpty());
}
Also used : ActionProxy(com.opensymphony.xwork2.ActionProxy) ValidateGroupAction(org.apache.struts.beanvalidation.actions.ValidateGroupAction) List(java.util.List)

Example 3 with ValidateGroupAction

use of org.apache.struts.beanvalidation.actions.ValidateGroupAction in project struts by apache.

the class BeanValidationInterceptorTest method getValidateGroupAction.

private ActionProxy getValidateGroupAction(String methodName) {
    ActionProxy baseActionProxy = actionProxyFactory.createActionProxy("bean-validation", "validateGroupActions", methodName, null);
    ValidateGroupAction action = (ValidateGroupAction) baseActionProxy.getAction();
    action.getModel().setName(null);
    action.getModel().setEmail(null);
    action.getModel().getAddress().setStreet(null);
    return baseActionProxy;
}
Also used : ActionProxy(com.opensymphony.xwork2.ActionProxy) ValidateGroupAction(org.apache.struts.beanvalidation.actions.ValidateGroupAction)

Example 4 with ValidateGroupAction

use of org.apache.struts.beanvalidation.actions.ValidateGroupAction in project struts by apache.

the class BeanValidationInterceptorTest method testValidationGroupActionLongNameChecks.

public void testValidationGroupActionLongNameChecks() throws Exception {
    ActionProxy baseActionProxy = getValidateGroupAction("actionLongNameChecks");
    baseActionProxy.execute();
    Map<String, List<String>> fieldErrors = ((ValidateGroupAction) baseActionProxy.getAction()).getFieldErrors();
    assertEquals(3, fieldErrors.size());
    assertTrue("name-property @NotNull", fieldErrors.containsKey("name"));
    assertTrue("email-property @NotNull", fieldErrors.containsKey("email"));
    assertTrue("street-property @NotNull", fieldErrors.containsKey("address.street"));
    baseActionProxy = getValidateGroupAction("actionLongNameChecks");
    ((ValidateGroupAction) baseActionProxy.getAction()).getModel().setName("toShortName");
    ((ValidateGroupAction) baseActionProxy.getAction()).getModel().setEmail("actionLongNameChecks@mail.org");
    ((ValidateGroupAction) baseActionProxy.getAction()).getModel().getAddress().setStreet("aStreet");
    baseActionProxy.execute();
    fieldErrors = ((ValidateGroupAction) baseActionProxy.getAction()).getFieldErrors();
    assertEquals(1, fieldErrors.size());
    assertEquals("name-property @Size", "nameSize20", fieldErrors.get("name").get(0));
    baseActionProxy = getValidateGroupAction("actionLongNameChecks");
    ((ValidateGroupAction) baseActionProxy.getAction()).getModel().setName("this_is_a_really_long_Name");
    ((ValidateGroupAction) baseActionProxy.getAction()).getModel().setEmail("actionLongNameChecks@mail.org");
    ((ValidateGroupAction) baseActionProxy.getAction()).getModel().getAddress().setStreet("aStreet");
    baseActionProxy.execute();
    assertTrue("every properties not valid", ((ValidateGroupAction) baseActionProxy.getAction()).getFieldErrors().isEmpty());
}
Also used : ActionProxy(com.opensymphony.xwork2.ActionProxy) ValidateGroupAction(org.apache.struts.beanvalidation.actions.ValidateGroupAction) List(java.util.List)

Example 5 with ValidateGroupAction

use of org.apache.struts.beanvalidation.actions.ValidateGroupAction in project struts by apache.

the class BeanValidationInterceptorTest method testValidationGroupActionStreetChecks.

public void testValidationGroupActionStreetChecks() throws Exception {
    ActionProxy baseActionProxy = getValidateGroupAction("actionStreetChecks");
    baseActionProxy.execute();
    Map<String, List<String>> fieldErrors = ((ValidateGroupAction) baseActionProxy.getAction()).getFieldErrors();
    assertEquals(1, fieldErrors.size());
    assertEquals("street-property @NotNull", "streetNotNull", fieldErrors.get("address.street").get(0));
    baseActionProxy = getValidateGroupAction("actionStreetChecks");
    ((ValidateGroupAction) baseActionProxy.getAction()).getModel().getAddress().setStreet("a");
    baseActionProxy.execute();
    fieldErrors = ((ValidateGroupAction) baseActionProxy.getAction()).getFieldErrors();
    assertEquals(1, fieldErrors.size());
    assertEquals("street-property @Size", "streetSize", fieldErrors.get("address.street").get(0));
    baseActionProxy = getValidateGroupAction("actionStreetChecks");
    ((ValidateGroupAction) baseActionProxy.getAction()).getModel().getAddress().setStreet("aStreet");
    baseActionProxy.execute();
    assertTrue("street-property valid", ((ValidateGroupAction) baseActionProxy.getAction()).getFieldErrors().isEmpty());
}
Also used : ActionProxy(com.opensymphony.xwork2.ActionProxy) ValidateGroupAction(org.apache.struts.beanvalidation.actions.ValidateGroupAction) List(java.util.List)

Aggregations

ActionProxy (com.opensymphony.xwork2.ActionProxy)8 ValidateGroupAction (org.apache.struts.beanvalidation.actions.ValidateGroupAction)8 List (java.util.List)5 ValidationAware (com.opensymphony.xwork2.interceptor.ValidationAware)2