use of com.opensymphony.xwork2.interceptor.ValidationAware in project struts by apache.
the class BeanValidationInterceptorTest method testModelDrivenAction.
public void testModelDrivenAction() throws Exception {
ActionProxy baseActionProxy = actionProxyFactory.createActionProxy("bean-validation", "modelDrivenAction", null, null);
ModelDrivenAction action = (ModelDrivenAction) baseActionProxy.getAction();
action.getModel().setName(null);
action.getModel().setEmail(null);
action.getModel().getAddress().setStreet(null);
baseActionProxy.execute();
Map<String, List<String>> fieldErrors = ((ValidationAware) baseActionProxy.getAction()).getFieldErrors();
assertNotNull(fieldErrors);
assertEquals(3, fieldErrors.size());
assertTrue(fieldErrors.get("name").size() > 0);
assertEquals(fieldErrors.get("name").get(0), "nameNotNull");
assertTrue(fieldErrors.get("email").size() > 0);
assertEquals(fieldErrors.get("email").get(0), "emailNotNull");
assertTrue(fieldErrors.get("address.street").size() > 0);
assertEquals(fieldErrors.get("address.street").get(0), "streetNotNull");
}
use of com.opensymphony.xwork2.interceptor.ValidationAware in project struts by apache.
the class BeanValidationInterceptorTest method testFieldMatchAction.
public void testFieldMatchAction() throws Exception {
ActionProxy baseActionProxy = actionProxyFactory.createActionProxy("bean-validation", "fieldMatchAction", null, null);
FieldMatchAction action = (FieldMatchAction) baseActionProxy.getAction();
action.setPassword("pass1");
action.setConfirmPassword("pass2");
action.setEmail("test1@mail.org");
action.setConfirmEmail("test2@mail.org");
baseActionProxy.execute();
Collection<String> actionErrors = ((ValidationAware) baseActionProxy.getAction()).getActionErrors();
System.out.println(actionErrors);
assertNotNull(actionErrors);
assertEquals(2, actionErrors.size());
}
use of com.opensymphony.xwork2.interceptor.ValidationAware in project struts by apache.
the class BeanValidationInterceptorTest method testModelDrivenActionSize.
public void testModelDrivenActionSize() throws Exception {
ActionProxy baseActionProxy = actionProxyFactory.createActionProxy("bean-validation", "modelDrivenAction", null, null);
ModelDrivenAction action = (ModelDrivenAction) baseActionProxy.getAction();
action.getModel().setName("j");
action.getModel().setEmail("jogep@apache.org");
action.getModel().getAddress().setStreet("st");
baseActionProxy.execute();
Map<String, List<String>> fieldErrors = ((ValidationAware) baseActionProxy.getAction()).getFieldErrors();
System.out.println(fieldErrors);
assertNotNull(fieldErrors);
assertEquals(2, fieldErrors.size());
assertTrue(fieldErrors.get("name").size() > 0);
assertEquals(fieldErrors.get("name").get(0), "nameSize");
assertTrue(fieldErrors.get("address.street").size() > 0);
assertEquals(fieldErrors.get("address.street").get(0), "streetSize");
}
use of com.opensymphony.xwork2.interceptor.ValidationAware in project struts by apache.
the class BeanValidationInterceptorTest method testValidationGroupActionStandard.
public void testValidationGroupActionStandard() throws Exception {
ActionProxy baseActionProxy = getValidateGroupAction("actionStandard");
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());
}
use of com.opensymphony.xwork2.interceptor.ValidationAware in project struts by apache.
the class JSONValidationInterceptor method doIntercept.
@Override
protected String doIntercept(ActionInvocation invocation) throws Exception {
HttpServletResponse response = ServletActionContext.getResponse();
HttpServletRequest request = ServletActionContext.getRequest();
Object action = invocation.getAction();
if (isJsonEnabled(request)) {
if (action instanceof ValidationAware) {
// generate json
ValidationAware validationAware = (ValidationAware) action;
if (validationAware.hasErrors()) {
return generateJSON(request, response, validationAware);
}
}
if (isValidateOnly(request)) {
// there were no errors
setupEncoding(response, request);
response.getWriter().print("{}");
response.setContentType("application/json");
return Action.NONE;
} else {
return invocation.invoke();
}
} else
return invocation.invoke();
}
Aggregations