1 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 ; 15 import java.util.Map ; 16 17 18 24 public class InvocationSessionStoreTest extends TestCase { 25 27 private static final String INVOCATION_KEY = "com.opensymphony.webwork.util.InvocationSessionStoreTest.invocation"; 28 private static final String TOKEN_VALUE = "com.opensymphony.webwork.util.InvocationSessionStoreTest.token"; 29 30 32 private ActionInvocation invocation; 33 private Map session; 34 private Mock invocationMock; 35 private OgnlValueStack stack; 36 37 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 { 57 stack = new OgnlValueStack(); 58 59 ActionContext actionContext = new ActionContext(stack.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 } 79 | Popular Tags |