View Javadoc

    1   /*
    2    * $Id: InvocationSessionStoreTest.java 471756 2006-11-06 15:01:43Z husted $
    3    *
    4    * Licensed to the Apache Software Foundation (ASF) under one
    5    * or more contributor license agreements.  See the NOTICE file
    6    * distributed with this work for additional information
    7    * regarding copyright ownership.  The ASF licenses this file
    8    * to you under the Apache License, Version 2.0 (the
    9    * "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  /***
    37   * InvocationSessionStoreTest
    38   *
    39   */
    40  public class InvocationSessionStoreTest extends StrutsTestCase {
    41
    42      private static final String INVOCATION_KEY = "org.apache.struts2.util.InvocationSessionStoreTest.invocation";
    43      private static final String TOKEN_VALUE = "org.apache.struts2.util.InvocationSessionStoreTest.token";
    44
    45
    46      private ActionInvocation invocation;
    47      private Map session;
    48      private Mock invocationMock;
    49      private ValueStack stack;
    50
    51
    52      public void testStore() {
    53          assertNull(InvocationSessionStore.loadInvocation(INVOCATION_KEY, TOKEN_VALUE));
    54          InvocationSessionStore.storeInvocation(INVOCATION_KEY, TOKEN_VALUE, invocation);
    55          assertNotNull(InvocationSessionStore.loadInvocation(INVOCATION_KEY, TOKEN_VALUE));
    56          assertEquals(invocation, InvocationSessionStore.loadInvocation(INVOCATION_KEY, TOKEN_VALUE));
    57      }
    58
    59      public void testValueStackReset() {
    60          ActionContext actionContext = ActionContext.getContext();
    61          assertEquals(stack, actionContext.getValueStack());
    62          InvocationSessionStore.storeInvocation(INVOCATION_KEY, TOKEN_VALUE, invocation);
    63          actionContext.setValueStack(null);
    64          assertNull(actionContext.getValueStack());
    65          InvocationSessionStore.loadInvocation(INVOCATION_KEY, TOKEN_VALUE);
    66          assertEquals(stack, actionContext.getValueStack());
    67      }
    68
    69      protected void setUp() throws Exception {
    70          stack = ValueStackFactory.getFactory().createValueStack();
    71
    72          ActionContext actionContext = new ActionContext(stack.getContext());
    73          ActionContext.setContext(actionContext);
    74
    75          session = new HashMap();
    76          actionContext.setSession(session);
    77
    78          invocationMock = new Mock(ActionInvocation.class);
    79          invocation = (ActionInvocation) invocationMock.proxy();
    80
    81          actionContext.setValueStack(stack);
    82          invocationMock.matchAndReturn("getStack", stack);
    83
    84          Mock proxyMock = new Mock(ActionProxy.class);
    85          proxyMock.matchAndReturn("getInvocation", invocation);
    86
    87          ActionProxy proxy = (ActionProxy) proxyMock.proxy();
    88
    89          invocationMock.matchAndReturn("getProxy", proxy);
    90      }
    91  }