    1   package org.apache.turbine.pipeline;
    2
    3
    4   /*
    5    * Licensed to the Apache Software Foundation (ASF) under one
    6    * or more contributor license agreements.  See the NOTICE file
    7    * distributed with this work for additional information
    8    * regarding copyright ownership.  The ASF licenses this file
    9    * to you under the Apache License, Version 2.0 (the
    10   * "License"); you may not use this file except in compliance
    11   * with the License.  You may obtain a copy of the License at
    12   *
    13   *   http://www.apache.org/licenses/LICENSE-2.0
    14   *
    15   * Unless required by applicable law or agreed to in writing,
    16   * software distributed under the License is distributed on an
    17   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    18   * KIND, either express or implied.  See the License for the
    19   * specific language governing permissions and limitations
    20   * under the License.
    21   */
    22
    23
    24  import java.util.Vector;
    25
    26  import javax.servlet.ServletConfig;
    27  import javax.servlet.http.HttpServletResponse;
    28
    29  import org.apache.turbine.Turbine;
    30  import org.apache.turbine.TurbineConstants;
    31  import org.apache.turbine.om.security.User;
    32  import org.apache.turbine.services.template.TemplateService;
    33  import org.apache.turbine.test.BaseTestCase;
    34  import org.apache.turbine.test.EnhancedMockHttpServletRequest;
    35  import org.apache.turbine.test.EnhancedMockHttpSession;
    36  import org.apache.turbine.util.RunData;
    37  import org.apache.turbine.util.TurbineConfig;
    38  import org.apache.turbine.util.uri.URIConstants;
    39
    40  import com.mockobjects.servlet.MockHttpServletResponse;
    41  import com.mockobjects.servlet.MockServletConfig;
    42
    43  /**
    44   * Tests TurbinePipeline.
    45   *
    46   * @author <a href="mailto:epugh@opensourceConnections.com">Eric Pugh</a>
    47   * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
    48   * @version $Id: DefaultSessionTimeoutValveTest.java 615328 2008-01-25 20:25:05Z tv $
    49   */
    50  public class DefaultSessionTimeoutValveTest extends BaseTestCase
    51  {
    52      private static TurbineConfig tc = null;
    53      private static TemplateService ts = null;
    54      private MockServletConfig config = null;
    55      private EnhancedMockHttpServletRequest request = null;
    56      private EnhancedMockHttpSession session = null;
    57      private HttpServletResponse response = null;
    58      private static ServletConfig sc = null;
    59      /**
    60       * Constructor
    61       */
    62      public DefaultSessionTimeoutValveTest(String testName) throws Exception
    63      {
    64          super(testName);
    65      }
    66
    67      protected void setUp() throws Exception {
    68          super.setUp();
    69          config = new MockServletConfig();
    70          config.setupNoParameters();
    71          request = new EnhancedMockHttpServletRequest();
    72          request.setupServerName("bob");
    73          request.setupGetProtocol("http");
    74          request.setupScheme("scheme");
    75          request.setupPathInfo("damn");
    76          request.setupGetServletPath("damn2");
    77          request.setupGetContextPath("wow");
    78          request.setupGetContentType("html/text");
    79          request.setupAddHeader("Content-type", "html/text");
    80          request.setupAddHeader("Accept-Language", "en-US");
    81
    82
    83
    84
    85
    86
    87          session = new EnhancedMockHttpSession();
    88          response = new MockHttpServletResponse();
    89
    90          session.setupGetAttribute(User.SESSION_KEY, null);
    91
    92          request.setSession(session);
    93
    94
    95
    96          sc = config;
    97          tc =
    98              new TurbineConfig(
    99                      ".",
    100             "/conf/test/CompleteTurbineResources.properties");
    101         tc.initialize();
    102     }
    103
    104     /**
    105      * Tests the Valve.
    106      */
    107     public void testDefaults() throws Exception
    108     {
    109         Vector v = new Vector();
    110         v.add(URIConstants.CGI_ACTION_PARAM);
    111         request.setupGetParameterNames(v.elements());
    112
    113         request.setupAddParameter(URIConstants.CGI_ACTION_PARAM,"TestAction");
    114
    115
    116         PipelineData pipelineData = getPipelineData(request,response,config);
    117
    118         Pipeline pipeline = new TurbinePipeline();
    119
    120         DefaultSessionTimeoutValve valve = new DefaultSessionTimeoutValve();
    121         pipeline.addValve(valve);
    122
    123         pipeline.invoke(pipelineData);
    124
    125         RunData runData = (RunData)pipelineData;
    126         assertEquals(0,runData.getSession().getMaxInactiveInterval());
    127
    128
    129     }
    130
    131     /**
    132      * Tests the Valve.
    133      */
    134     public void testTimeoutSet() throws Exception
    135     {
    136
    137         Turbine.getConfiguration().setProperty(TurbineConstants.SESSION_TIMEOUT_KEY,"3600");
    138         PipelineData pipelineData = getPipelineData(request,response,config);
    139
    140         Pipeline pipeline = new TurbinePipeline();
    141
    142         DefaultSessionTimeoutValve valve = new DefaultSessionTimeoutValve();
    143         pipeline.addValve(valve);
    144
    145         pipeline.invoke(pipelineData);
    146         RunData runData = (RunData)pipelineData;
    147
    148         assertEquals(3600,runData.getSession().getMaxInactiveInterval());
    149
    150
    151     }
    152
    153
    154
    155 }