01: /*
02: * Copyright (c) 2002-2003 by OpenSymphony
03: * All rights reserved.
04: */
05: package com.opensymphony.webwork.util;
06:
07: import com.mockobjects.dynamic.Mock;
08: import com.opensymphony.webwork.WebWorkTestCase;
09: import com.opensymphony.xwork.ActionContext;
10: import com.opensymphony.xwork.ActionInvocation;
11: import com.opensymphony.xwork.ActionProxy;
12: import com.opensymphony.xwork.util.OgnlValueStack;
13:
14: import java.util.HashMap;
15: import java.util.Map;
16:
17: /**
18: * InvocationSessionStoreTest
19: *
20: * @author Jason Carreira Created Apr 12, 2003 10:34:53 PM
21: */
22: public class InvocationSessionStoreTest extends WebWorkTestCase {
23:
24: private static final String INVOCATION_KEY = "com.opensymphony.webwork.util.InvocationSessionStoreTest.invocation";
25: private static final String TOKEN_VALUE = "com.opensymphony.webwork.util.InvocationSessionStoreTest.token";
26:
27: private ActionInvocation invocation;
28: private Map session;
29: private Mock invocationMock;
30: private OgnlValueStack stack;
31:
32: public void testStore() {
33: assertNull(InvocationSessionStore.loadInvocation(
34: INVOCATION_KEY, TOKEN_VALUE));
35: InvocationSessionStore.storeInvocation(INVOCATION_KEY,
36: TOKEN_VALUE, invocation);
37: assertNotNull(InvocationSessionStore.loadInvocation(
38: INVOCATION_KEY, TOKEN_VALUE));
39: assertEquals(invocation, InvocationSessionStore.loadInvocation(
40: INVOCATION_KEY, TOKEN_VALUE));
41: }
42:
43: public void testValueStackReset() {
44: ActionContext actionContext = ActionContext.getContext();
45: assertEquals(stack, actionContext.getValueStack());
46: InvocationSessionStore.storeInvocation(INVOCATION_KEY,
47: TOKEN_VALUE, invocation);
48: actionContext.setValueStack(null);
49: assertNull(actionContext.getValueStack());
50: InvocationSessionStore.loadInvocation(INVOCATION_KEY,
51: TOKEN_VALUE);
52: assertEquals(stack, actionContext.getValueStack());
53: }
54:
55: protected void setUp() throws Exception {
56: stack = new OgnlValueStack();
57:
58: ActionContext actionContext = new ActionContext(stack
59: .getContext());
60: ActionContext.setContext(actionContext);
61:
62: session = new HashMap();
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: }
|