001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.pluto.testsuite.test;
018:
019: import javax.portlet.PortletRequest;
020: import javax.portlet.PortletSession;
021:
022: import org.apache.commons.logging.Log;
023: import org.apache.commons.logging.LogFactory;
024: import org.apache.pluto.testsuite.TestResult;
025:
026: public class SessionTimeoutTest extends AbstractReflectivePortletTest {
027:
028: /** Logger. */
029: private static final Log LOG = LogFactory
030: .getLog(SessionTimeoutTest.class);
031:
032: /**
033: * Render parameter name indicating if the max inactive interval is set to
034: * the portlet session or not.
035: */
036: private static final String MAX_INACTIVE_INTERVAL_SET = "maxInactiveIntervalSet";
037:
038: // Test Methods ------------------------------------------------------------
039:
040: protected TestResult checkSessionInvalidated(PortletRequest request) {
041: TestResult result = new TestResult();
042: result
043: .setDescription("Ensure portlet session is invalidated after "
044: + "the max inactive interval.");
045: result.setSpecPLT("15.6");
046:
047: // Check if max inactive interval is set to the portlet session.
048: String maxInactiveIntervalSet = request
049: .getParameter(MAX_INACTIVE_INTERVAL_SET);
050: if (LOG.isDebugEnabled()) {
051: LOG.debug("Retrieved render parameter: "
052: + MAX_INACTIVE_INTERVAL_SET + " = "
053: + maxInactiveIntervalSet);
054: }
055:
056: // If the max inactive interval is set to portlet session, the portlet
057: // session should have been invalidated by the container.
058: if (Boolean.TRUE.toString().equals(maxInactiveIntervalSet)) {
059: if (LOG.isDebugEnabled()) {
060: LOG
061: .debug("Max inactive interval is set to portlet session: "
062: + "portlet session should have expired "
063: + "(current time millis: "
064: + System.currentTimeMillis() + ")...");
065: }
066: PortletSession session = request.getPortletSession(false);
067: if (session == null) {
068: result.setReturnCode(TestResult.PASSED);
069: } else {
070: result.setReturnCode(TestResult.FAILED);
071: result
072: .setResultMessage("PortletSession should have expired "
073: + "and have been invalidated, but is still available. "
074: + "Make sure that other portlets did not create a new "
075: + "portlet session.");
076: }
077: }
078:
079: // If the max inactive interval is not set to portlet session, set its
080: // value to 5 (seconds). In this way, next time the test portlet is
081: // rendered, the portlet session should have been invalidated.
082: else {
083: if (LOG.isDebugEnabled()) {
084: LOG
085: .debug("Max inactive interval is not set to portlet session: "
086: + "setting to 5 seconds (current time millis: "
087: + System.currentTimeMillis() + ")...");
088: }
089: PortletSession session = request.getPortletSession(true);
090: session.setMaxInactiveInterval(5);
091: result.setReturnCode(TestResult.WARNING);
092: result
093: .setResultMessage("Click the provided link to validate test.");
094: }
095:
096: // Return the test result:
097: // PASSED - the test is passed.
098: // FAILED - the test is failed.
099: // WARNING - the test requires manual intervention.
100: return result;
101: }
102:
103: }
|