01: /*
02: * $Id: InvocationSessionStoreTest.java 471756 2006-11-06 15:01:43Z husted $
03: *
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "License"); you may not use this file except in compliance
10: * with the License. You may obtain a copy of the License at
11: *
12: * http://www.apache.org/licenses/LICENSE-2.0
13: *
14: * Unless required by applicable law or agreed to in writing,
15: * software distributed under the License is distributed on an
16: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17: * KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations
19: * under the License.
20: */
21: package org.apache.struts2.util;
22:
23: import java.util.HashMap;
24: import java.util.Map;
25:
26: import org.apache.struts2.StrutsTestCase;
27:
28: import com.mockobjects.dynamic.Mock;
29: import com.opensymphony.xwork2.ActionContext;
30: import com.opensymphony.xwork2.ActionInvocation;
31: import com.opensymphony.xwork2.ActionProxy;
32: import com.opensymphony.xwork2.util.ValueStack;
33: import com.opensymphony.xwork2.util.ValueStackFactory;
34:
35: /**
36: * InvocationSessionStoreTest
37: *
38: */
39: public class InvocationSessionStoreTest extends StrutsTestCase {
40:
41: private static final String INVOCATION_KEY = "org.apache.struts2.util.InvocationSessionStoreTest.invocation";
42: private static final String TOKEN_VALUE = "org.apache.struts2.util.InvocationSessionStoreTest.token";
43:
44: private ActionInvocation invocation;
45: private Map session;
46: private Mock invocationMock;
47: private ValueStack stack;
48:
49: public void testStore() {
50: assertNull(InvocationSessionStore.loadInvocation(
51: INVOCATION_KEY, TOKEN_VALUE));
52: InvocationSessionStore.storeInvocation(INVOCATION_KEY,
53: TOKEN_VALUE, invocation);
54: assertNotNull(InvocationSessionStore.loadInvocation(
55: INVOCATION_KEY, TOKEN_VALUE));
56: assertEquals(invocation, InvocationSessionStore.loadInvocation(
57: INVOCATION_KEY, TOKEN_VALUE));
58: }
59:
60: public void testValueStackReset() {
61: ActionContext actionContext = ActionContext.getContext();
62: assertEquals(stack, actionContext.getValueStack());
63: InvocationSessionStore.storeInvocation(INVOCATION_KEY,
64: TOKEN_VALUE, invocation);
65: actionContext.setValueStack(null);
66: assertNull(actionContext.getValueStack());
67: InvocationSessionStore.loadInvocation(INVOCATION_KEY,
68: TOKEN_VALUE);
69: assertEquals(stack, actionContext.getValueStack());
70: }
71:
72: protected void setUp() throws Exception {
73: stack = ValueStackFactory.getFactory().createValueStack();
74:
75: ActionContext actionContext = new ActionContext(stack
76: .getContext());
77: ActionContext.setContext(actionContext);
78:
79: session = new HashMap();
80: actionContext.setSession(session);
81:
82: invocationMock = new Mock(ActionInvocation.class);
83: invocation = (ActionInvocation) invocationMock.proxy();
84:
85: actionContext.setValueStack(stack);
86: invocationMock.matchAndReturn("getStack", stack);
87:
88: Mock proxyMock = new Mock(ActionProxy.class);
89: proxyMock.matchAndReturn("getInvocation", invocation);
90:
91: ActionProxy proxy = (ActionProxy) proxyMock.proxy();
92:
93: invocationMock.matchAndReturn("getProxy", proxy);
94: }
95: }
|