StrutsConversionErrorInterceptorTestpublic class StrutsConversionErrorInterceptorTest extends org.apache.struts2.StrutsTestCase StrutsConversionErrorInterceptorTest |
Fields Summary |
---|
protected com.opensymphony.xwork2.ActionContext | context | protected com.opensymphony.xwork2.ActionInvocation | invocation | protected Map | conversionErrors | protected com.mockobjects.dynamic.Mock | mockInvocation | protected com.opensymphony.xwork2.util.ValueStack | stack | protected StrutsConversionErrorInterceptor | interceptor |
Methods Summary |
---|
protected void | setUp()
super.setUp();
interceptor = new StrutsConversionErrorInterceptor();
mockInvocation = new Mock(ActionInvocation.class);
invocation = (ActionInvocation) mockInvocation.proxy();
stack = ValueStackFactory.getFactory().createValueStack();
context = new ActionContext(stack.getContext());
conversionErrors = new HashMap();
context.setConversionErrors(conversionErrors);
mockInvocation.matchAndReturn("getInvocationContext", context);
mockInvocation.expectAndReturn("invoke", Action.SUCCESS);
mockInvocation.expectAndReturn("getStack", stack);
mockInvocation.expect("addPreResultListener", C.ANY_ARGS);
| public void | testEmptyValuesDoNotSetFieldErrors()
conversionErrors.put("foo", new Long(123));
conversionErrors.put("bar", "");
conversionErrors.put("baz", new String[]{""});
ActionSupport action = new ActionSupport();
mockInvocation.expectAndReturn("getAction", action);
stack.push(action);
mockInvocation.matchAndReturn("getAction",action);
assertNull(action.getFieldErrors().get("foo"));
assertNull(action.getFieldErrors().get("bar"));
assertNull(action.getFieldErrors().get("baz"));
interceptor.intercept(invocation);
assertTrue(action.hasFieldErrors());
assertNotNull(action.getFieldErrors().get("foo"));
assertNull(action.getFieldErrors().get("bar"));
assertNull(action.getFieldErrors().get("baz"));
| public void | testFieldErrorAdded()
conversionErrors.put("foo", new Long(123));
ActionSupport action = new ActionSupport();
mockInvocation.expectAndReturn("getAction", action);
stack.push(action);
mockInvocation.matchAndReturn("getAction",action);
assertNull(action.getFieldErrors().get("foo"));
interceptor.intercept(invocation);
assertTrue(action.hasFieldErrors());
assertNotNull(action.getFieldErrors().get("foo"));
|
|