FileDocCategorySizeDatePackage
StrutsConversionErrorInterceptorTest.javaAPI DocExample3978Mon Jul 23 13:26:18 BST 2007org.apache.struts2.interceptor

StrutsConversionErrorInterceptorTest

public 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
Constructors Summary
Methods Summary
protected voidsetUp()

        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 voidtestEmptyValuesDoNotSetFieldErrors()

        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 voidtestFieldErrorAdded()

        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"));