KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > webwork > interceptor > WebWorkConversionErrorInterceptorTest


1 /*
2  * Copyright (c) 2002-2003 by OpenSymphony
3  * All rights reserved.
4  */

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 JavaDoc;
17 import java.util.Map JavaDoc;
18
19
20 /**
21  * WebWorkConversionErrorInterceptorTest
22  *
23  * @author Jason Carreira
24  * Date: Nov 27, 2003 10:11:42 PM
25  */

26 public class WebWorkConversionErrorInterceptorTest extends TestCase {
27     //~ Instance fields ////////////////////////////////////////////////////////
28

29     protected ActionContext context;
30     protected ActionInvocation invocation;
31     protected Map JavaDoc conversionErrors;
32     protected Mock mockInvocation;
33     protected OgnlValueStack stack;
34     protected WebWorkConversionErrorInterceptor interceptor;
35
36     //~ Methods ////////////////////////////////////////////////////////////////
37

38     public void testEmptyValuesDoNotSetFieldErrors() throws Exception JavaDoc {
39         conversionErrors.put("foo", new Long JavaDoc(123));
40         conversionErrors.put("bar", "");
41         conversionErrors.put("baz", new String JavaDoc[]{""});
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 JavaDoc {
56         conversionErrors.put("foo", new Long JavaDoc(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 JavaDoc {
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 JavaDoc();
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