    001    package org.apache.turbine.pipeline;
    002
    003
    004    /*
    005     * Licensed to the Apache Software Foundation (ASF) under one
    006     * or more contributor license agreements.  See the NOTICE file
    007     * distributed with this work for additional information
    008     * regarding copyright ownership.  The ASF licenses this file
    009     * to you under the Apache License, Version 2.0 (the
    010     * "License"); you may not use this file except in compliance
    011     * with the License.  You may obtain a copy of the License at
    012     *
    013     *   http://www.apache.org/licenses/LICENSE-2.0
    014     *
    015     * Unless required by applicable law or agreed to in writing,
    016     * software distributed under the License is distributed on an
    017     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    018     * KIND, either express or implied.  See the License for the
    019     * specific language governing permissions and limitations
    020     * under the License.
    021     */
    022
    023
    024    import java.util.Vector;
    025
    026    import javax.servlet.ServletConfig;
    027    import javax.servlet.http.HttpServletResponse;
    028
    029    import org.apache.turbine.Turbine;
    030    import org.apache.turbine.TurbineConstants;
    031    import org.apache.turbine.om.security.User;
    032    import org.apache.turbine.services.template.TemplateService;
    033    import org.apache.turbine.test.BaseTestCase;
    034    import org.apache.turbine.test.EnhancedMockHttpServletRequest;
    035    import org.apache.turbine.test.EnhancedMockHttpSession;
    036    import org.apache.turbine.util.RunData;
    037    import org.apache.turbine.util.TurbineConfig;
    038    import org.apache.turbine.util.uri.URIConstants;
    039
    040    import com.mockobjects.servlet.MockHttpServletResponse;
    041    import com.mockobjects.servlet.MockServletConfig;
    042
    043    /**
    044     * Tests TurbinePipeline.
    045     *
    046     * @author <a href="mailto:epugh@opensourceConnections.com">Eric Pugh</a>
    047     * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
    048     * @version $Id: DefaultSessionTimeoutValveTest.java 615328 2008-01-25 20:25:05Z tv $
    049     */
    050    public class DefaultSessionTimeoutValveTest extends BaseTestCase
    051    {
    052        private static TurbineConfig tc = null;
    053        private static TemplateService ts = null;
    054        private MockServletConfig config = null;
    055        private EnhancedMockHttpServletRequest request = null;
    056        private EnhancedMockHttpSession session = null;
    057        private HttpServletResponse response = null;
    058        private static ServletConfig sc = null;
    059        /**
    060         * Constructor
    061         */
    062        public DefaultSessionTimeoutValveTest(String testName) throws Exception
    063        {
    064            super(testName);
    065        }
    066
    067        protected void setUp() throws Exception {
    068            super.setUp();
    069            config = new MockServletConfig();
    070            config.setupNoParameters();
    071            request = new EnhancedMockHttpServletRequest();
    072            request.setupServerName("bob");
    073            request.setupGetProtocol("http");
    074            request.setupScheme("scheme");
    075            request.setupPathInfo("damn");
    076            request.setupGetServletPath("damn2");
    077            request.setupGetContextPath("wow");
    078            request.setupGetContentType("html/text");
    079            request.setupAddHeader("Content-type", "html/text");
    080            request.setupAddHeader("Accept-Language", "en-US");
    081
    082
    083
    084
    085
    086
    087            session = new EnhancedMockHttpSession();
    088            response = new MockHttpServletResponse();
    089
    090            session.setupGetAttribute(User.SESSION_KEY, null);
    091
    092            request.setSession(session);
    093
    094
    095
    096            sc = config;
    097            tc =
    098                new TurbineConfig(
    099                        ".",
    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    }