KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > webwork > util > InvocationSessionStoreTest


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

5 package com.opensymphony.webwork.util;
6
7 import com.mockobjects.dynamic.Mock;
8 import com.opensymphony.xwork.ActionContext;
9 import com.opensymphony.xwork.ActionInvocation;
10 import com.opensymphony.xwork.ActionProxy;
11 import com.opensymphony.xwork.util.OgnlValueStack;
12 import junit.framework.TestCase;
13
14 import java.util.HashMap JavaDoc;
15 import java.util.Map JavaDoc;
16
17
18 /**
19  * InvocationSessionStoreTest
20  *
21  * @author Jason Carreira
22  * Created Apr 12, 2003 10:34:53 PM
23  */

24 public class InvocationSessionStoreTest extends TestCase {
25     //~ Static fields/initializers /////////////////////////////////////////////
26

27     private static final String JavaDoc INVOCATION_KEY = "com.opensymphony.webwork.util.InvocationSessionStoreTest.invocation";
28     private static final String JavaDoc TOKEN_VALUE = "com.opensymphony.webwork.util.InvocationSessionStoreTest.token";
29
30     //~ Instance fields ////////////////////////////////////////////////////////
31

32     private ActionInvocation invocation;
33     private Map JavaDoc session;
34     private Mock invocationMock;
35     private OgnlValueStack stack;
36
37     //~ Methods ////////////////////////////////////////////////////////////////
38

39     public void testStore() {
40         assertNull(InvocationSessionStore.loadInvocation(INVOCATION_KEY, TOKEN_VALUE));
41         InvocationSessionStore.storeInvocation(INVOCATION_KEY, TOKEN_VALUE, invocation);
42         assertNotNull(InvocationSessionStore.loadInvocation(INVOCATION_KEY, TOKEN_VALUE));
43         assertEquals(invocation, InvocationSessionStore.loadInvocation(INVOCATION_KEY, TOKEN_VALUE));
44     }
45
46     public void testValueStackReset() {
47         ActionContext actionContext = ActionContext.getContext();
48         assertEquals(stack, actionContext.getValueStack());
49         InvocationSessionStore.storeInvocation(INVOCATION_KEY, TOKEN_VALUE, invocation);
50         actionContext.setValueStack(null);
51         assertNull(actionContext.getValueStack());
52         InvocationSessionStore.loadInvocation(INVOCATION_KEY, TOKEN_VALUE);
53         assertEquals(stack, actionContext.getValueStack());
54     }
55
56     protected void setUp() throws Exception JavaDoc {
57         stack = new OgnlValueStack();
58
59         ActionContext actionContext = new ActionContext(stack.getContext());
60         ActionContext.setContext(actionContext);
61
62         session = new HashMap JavaDoc();
63         actionContext.setSession(session);
64
65         invocationMock = new Mock(ActionInvocation.class);
66         invocation = (ActionInvocation) invocationMock.proxy();
67
68         actionContext.setValueStack(stack);
69         invocationMock.matchAndReturn("getStack", stack);
70
71         Mock proxyMock = new Mock(ActionProxy.class);
72         proxyMock.matchAndReturn("getInvocation", invocation);
73
74         ActionProxy proxy = (ActionProxy) proxyMock.proxy();
75
76         invocationMock.matchAndReturn("getProxy", proxy);
77     }
78 }
79
Popular Tags