1 5 package com.opensymphony.webwork.interceptor; 6 7 import com.mockobjects.dynamic.C; 8 import com.mockobjects.dynamic.Mock; 9 import com.opensymphony.xwork.Action; 10 import com.opensymphony.xwork.ActionContext; 11 import com.opensymphony.xwork.ActionInvocation; 12 import com.opensymphony.xwork.ActionSupport; 13 import com.opensymphony.xwork.util.OgnlValueStack; 14 import junit.framework.TestCase; 15 16 import java.util.HashMap ; 17 import java.util.Map ; 18 19 20 26 public class WebWorkConversionErrorInterceptorTest extends TestCase { 27 29 protected ActionContext context; 30 protected ActionInvocation invocation; 31 protected Map conversionErrors; 32 protected Mock mockInvocation; 33 protected OgnlValueStack stack; 34 protected WebWorkConversionErrorInterceptor interceptor; 35 36 38 public void testEmptyValuesDoNotSetFieldErrors() throws Exception { 39 conversionErrors.put("foo", new Long (123)); 40 conversionErrors.put("bar", ""); 41 conversionErrors.put("baz", new String []{""}); 42 43 ActionSupport action = new ActionSupport(); 44 stack.push(action); 45 assertNull(action.getFieldErrors().get("foo")); 46 assertNull(action.getFieldErrors().get("bar")); 47 assertNull(action.getFieldErrors().get("baz")); 48 interceptor.intercept(invocation); 49 assertTrue(action.hasFieldErrors()); 50 assertNotNull(action.getFieldErrors().get("foo")); 51 assertNull(action.getFieldErrors().get("bar")); 52 assertNull(action.getFieldErrors().get("baz")); 53 } 54 55 public void testFieldErrorAdded() throws Exception { 56 conversionErrors.put("foo", new Long (123)); 57 58 ActionSupport action = new ActionSupport(); 59 stack.push(action); 60 assertNull(action.getFieldErrors().get("foo")); 61 interceptor.intercept(invocation); 62 assertTrue(action.hasFieldErrors()); 63 assertNotNull(action.getFieldErrors().get("foo")); 64 } 65 66 protected void setUp() throws Exception { 67 super.setUp(); 68 interceptor = new WebWorkConversionErrorInterceptor(); 69 mockInvocation = new Mock(ActionInvocation.class); 70 invocation = (ActionInvocation) mockInvocation.proxy(); 71 stack = new OgnlValueStack(); 72 context = new ActionContext(stack.getContext()); 73 conversionErrors = new HashMap (); 74 context.setConversionErrors(conversionErrors); 75 mockInvocation.matchAndReturn("getInvocationContext", context); 76 mockInvocation.expectAndReturn("invoke", Action.SUCCESS); 77 mockInvocation.expectAndReturn("getStack", stack); 78 mockInvocation.expect("addPreResultListener", C.ANY_ARGS); 79 } 80 } 81 | Popular Tags |