001package 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 024import java.util.Vector; 025 026import javax.servlet.http.HttpServletResponse; 027 028import org.apache.turbine.Turbine; 029import org.apache.turbine.TurbineConstants; 030import org.apache.turbine.om.security.User; 031import org.apache.turbine.test.BaseTestCase; 032import org.apache.turbine.test.EnhancedMockHttpServletRequest; 033import org.apache.turbine.test.EnhancedMockHttpSession; 034import org.apache.turbine.util.RunData; 035import org.apache.turbine.util.TurbineConfig; 036import org.apache.turbine.util.uri.URIConstants; 037import org.junit.AfterClass; 038import org.junit.Before; 039import org.junit.BeforeClass; 040import org.junit.Test; 041 042import com.mockobjects.servlet.MockHttpServletResponse; 043import com.mockobjects.servlet.MockServletConfig; 044 045import static org.junit.Assert.*; 046 047/** 048 * Tests TurbinePipeline. 049 * 050 * @author <a href="mailto:epugh@opensourceConnections.com">Eric Pugh</a> 051 * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a> 052 * @version $Id: DefaultSessionTimeoutValveTest.java 1606111 2014-06-27 14:46:47Z gk $ 053 */ 054public class DefaultSessionTimeoutValveTest extends BaseTestCase 055{ 056 private static TurbineConfig tc = null; 057 private MockServletConfig config = null; 058 private EnhancedMockHttpServletRequest request = null; 059 private EnhancedMockHttpSession session = null; 060 private HttpServletResponse response = null; 061 062 063 @BeforeClass 064 public static void init() { 065 tc = new TurbineConfig( 066 ".", 067 "/conf/test/CompleteTurbineResources.properties"); 068 tc.initialize(); 069 } 070 071 @Before 072 public void setUpBefore() throws Exception { 073 config = new MockServletConfig(); 074 config.setupNoParameters(); 075 request = new EnhancedMockHttpServletRequest(); 076 request.setupServerName("bob"); 077 request.setupGetProtocol("http"); 078 request.setupScheme("scheme"); 079 request.setupPathInfo("damn"); 080 request.setupGetServletPath("damn2"); 081 request.setupGetContextPath("wow"); 082 request.setupGetContentType("html/text"); 083 request.setupAddHeader("Content-type", "html/text"); 084 request.setupAddHeader("Accept-Language", "en-US"); 085 086 session = new EnhancedMockHttpSession(); 087 response = new MockHttpServletResponse(); 088 089 session.setupGetAttribute(User.SESSION_KEY, null); 090 091 request.setSession(session); 092 093 } 094 095 /** 096 * Tests the Valve. 097 */ 098 @Test public void testDefaults() throws Exception 099 { 100 // reset 101 Turbine.getConfiguration().setProperty(TurbineConstants.SESSION_TIMEOUT_KEY, 102 Integer.valueOf(TurbineConstants.SESSION_TIMEOUT_DEFAULT)); 103 Vector<String> v = new Vector<String>(); 104 v.add(URIConstants.CGI_ACTION_PARAM); 105 request.setupGetParameterNames(v.elements()); 106 request.setupAddParameter(URIConstants.CGI_ACTION_PARAM,"TestAction"); 107 108 PipelineData pipelineData = getPipelineData(request,response,config); 109 110 Pipeline pipeline = new TurbinePipeline(); 111 112 DefaultSessionTimeoutValve valve = new DefaultSessionTimeoutValve(); 113 pipeline.addValve(valve); 114 115 pipeline.invoke(pipelineData); 116 117 RunData runData = (RunData)pipelineData; 118 assertEquals(0,runData.getSession().getMaxInactiveInterval()); 119 120 121 } 122 123 /** 124 * Tests the Valve. 125 */ 126 @Test public void testTimeoutSet() throws Exception 127 { 128 129 Turbine.getConfiguration().setProperty(TurbineConstants.SESSION_TIMEOUT_KEY,"3600"); 130 PipelineData pipelineData = getPipelineData(request,response,config); 131 132 Pipeline pipeline = new TurbinePipeline(); 133 134 DefaultSessionTimeoutValve valve = new DefaultSessionTimeoutValve(); 135 pipeline.addValve(valve); 136 137 pipeline.invoke(pipelineData); 138 RunData runData = (RunData)pipelineData; 139 140 assertEquals(3600,runData.getSession().getMaxInactiveInterval()); 141 142 143 } 144 145 @AfterClass 146 public static void destroy() { 147 tc.dispose(); 148 } 149 150 151 152}