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 org.apache.pluto.testsuite.TestResult;
020: import org.apache.pluto.testsuite.TestUtils;
021:
022: import javax.portlet.PortletContext;
023: import javax.portlet.PortletSession;
024: import java.util.Enumeration;
025:
026: /**
027: * @version 1.0
028: * @since Sep 15, 2004
029: */
030: public class ContextInitParameterTest extends
031: AbstractReflectivePortletTest {
032:
033: private static final String TEST_PARAM_NAME = "test-parameter-name";
034: private static final String TEST_PARAM_VALUE = "test-parameter-val";
035:
036: // Test Methods ------------------------------------------------------------
037:
038: protected TestResult checkEnumerationContainsNames(
039: PortletContext context) {
040: TestResult result = new TestResult();
041: result
042: .setDescription("Ensure that the expected init parameter name "
043: + "exists in the portlet context's init parameters.");
044: result.setSpecPLT("10.3.1");
045:
046: boolean found = false;
047: for (Enumeration en = context.getInitParameterNames(); !found
048: && en.hasMoreElements();) {
049: String name = (String) en.nextElement();
050: if (TEST_PARAM_NAME.equals(name)) {
051: found = true;
052: }
053: }
054:
055: if (found) {
056: result.setReturnCode(TestResult.PASSED);
057: } else {
058: result.setReturnCode(TestResult.FAILED);
059: result.setResultMessage("Expected init parameter '"
060: + TEST_PARAM_NAME
061: + "' not found in portlet context.");
062: }
063: return result;
064: }
065:
066: protected TestResult checkGetInitParameter(PortletContext context) {
067: TestResult result = new TestResult();
068: result
069: .setDescription("Ensure that init parameters are retrieveable.");
070: result.setSpecPLT("10.3.1");
071:
072: String value = context.getInitParameter(TEST_PARAM_NAME);
073: if (TEST_PARAM_VALUE.equals(value)) {
074: result.setReturnCode(TestResult.PASSED);
075: } else {
076: TestUtils.failOnAssertion("init parameter", value,
077: TEST_PARAM_VALUE, result);
078: }
079: return result;
080: }
081:
082: /**
083: * FIXME: should this test reside in this class? -- ZHENG Zhong
084: */
085: protected TestResult checkGetContextFromSession(
086: PortletSession session) {
087: TestResult result = new TestResult();
088: result
089: .setDescription("Ensure that the PortletContext can be retrieved "
090: + "from the portlet session.");
091:
092: PortletContext context = session.getPortletContext();
093: if (context != null) {
094: result.setReturnCode(TestResult.PASSED);
095: } else {
096: result.setReturnCode(TestResult.FAILED);
097: result
098: .setResultMessage("Fail to retrieve PortletContext from "
099: + "PortletSession: null returned.");
100: }
101: return result;
102: }
103: }
|