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:
018: package org.apache.pluto.testsuite.test;
019:
020: import java.io.IOException;
021:
022: import org.apache.pluto.testsuite.TestResult;
023:
024: import javax.portlet.PortletSession;
025: import javax.servlet.RequestDispatcher;
026: import javax.servlet.ServletException;
027: import javax.servlet.http.HttpServlet;
028: import javax.servlet.http.HttpServletRequest;
029: import javax.servlet.http.HttpServletResponse;
030: import javax.servlet.http.HttpSession;
031:
032: /**
033: */
034: public class ExternalAppScopedAttributeTest extends
035: AbstractReflectivePortletTest {
036:
037: public static final String INT_KEY = "org.apache.pluto.testsuite.INTERNALLY_SET_APP_SCOPED_SESSION_TEST_KEY";
038: public static final String EXT_KEY = "org.apache.pluto.testsuite.EXTERNALLY_SET_APP_SCOPED_SESSION_TEST_KEY";
039: public static final String VALUE = "Should be visible to all Portlets and Web Resources.";
040:
041: // Test Methods ------------------------------------------------------------
042:
043: protected TestResult checkSetAppScopedAttributeHereSeenElsewhere(
044: PortletSession session) {
045: TestResult result = new TestResult();
046: result
047: .setDescription("Ensure application scoped attributes set here "
048: + "in portlet session can be seen elsewhere.");
049:
050: session.setAttribute(INT_KEY, VALUE,
051: PortletSession.APPLICATION_SCOPE);
052: result.setReturnCode(TestResult.WARNING);
053: result
054: .setResultMessage("Click the provided link to validate test.");
055: return result;
056: }
057:
058: protected TestResult checkSetAppScopedAttributeElsewhereSeenHere(
059: PortletSession session) {
060: TestResult result = new TestResult();
061: result
062: .setDescription("Ensure application scoped attributes set "
063: + "elsewhere in portlet session can be seen here.");
064:
065: Object value = session.getAttribute(EXT_KEY,
066: PortletSession.APPLICATION_SCOPE);
067: if (VALUE.equals(value)) {
068: result.setReturnCode(TestResult.PASSED);
069: } else {
070: result.setReturnCode(TestResult.WARNING);
071: result
072: .setResultMessage("This test will not pass until you have "
073: + "opened the external resource using the link provided below.");
074: }
075: return result;
076: }
077:
078: // Nested Servlet Class ----------------------------------------------------
079:
080: /**
081: * The companion servlet that cooperates with this portlet test.
082: */
083: public static class CompanionServlet extends HttpServlet {
084:
085: public void doGet(HttpServletRequest request,
086: HttpServletResponse response) throws ServletException,
087: IOException {
088: HttpSession session = request.getSession();
089: String value = (String) session.getAttribute(INT_KEY);
090: if (ExternalAppScopedAttributeTest.VALUE.equals(value)) {
091: request.setAttribute("passed", new Boolean(true));
092: session.setAttribute(EXT_KEY, VALUE);
093: }
094:
095: RequestDispatcher dispatcher = request
096: .getRequestDispatcher("/jsp/ExternalAppScopedAttributeTest_companion.jsp");
097: dispatcher.forward(request, response);
098: }
099:
100: }
101:
102: }
|