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.ActionTest;
020: import org.apache.pluto.testsuite.TestResult;
021: import org.apache.pluto.testsuite.TestUtils;
022:
023: import java.util.Enumeration;
024: import java.util.Map;
025:
026: import javax.portlet.PortletRequest;
027:
028: /**
029: */
030: public class ActionParameterTest extends AbstractReflectivePortletTest
031: implements ActionTest {
032:
033: /** Parameter key encoded in the action URL. */
034: public static final String KEY = "org.apache.pluto.testsuite.PARAM_ACTION_KEY";
035:
036: /** Parameter value encoded in the action URL. */
037: public static final String VALUE = "org.apache.pluto.testsuite.ACTION_VALUE";
038:
039: // Test Methods ------------------------------------------------------------
040:
041: protected TestResult checkGetActionParameter(PortletRequest request) {
042: TestResult result = new TestResult();
043: result
044: .setDescription("Ensure parameters encoded in action URL are "
045: + "available in the action request.");
046:
047: String value = request.getParameter(KEY);
048: if (value != null && value.equals(VALUE)) {
049: result.setReturnCode(TestResult.PASSED);
050: } else {
051: TestUtils
052: .failOnAssertion("parameter", value, VALUE, result);
053: }
054: return result;
055: }
056:
057: protected TestResult checkGetActionParamerMap(PortletRequest request) {
058: TestResult result = new TestResult();
059: result
060: .setDescription("Ensure parameters encoded in action URL are "
061: + "available in the action request parameter map.");
062:
063: Map parameterMap = request.getParameterMap();
064: String[] values = (String[]) parameterMap.get(KEY);
065: if (values != null && values.length == 1
066: && VALUE.equals(values[0])) {
067: result.setReturnCode(TestResult.PASSED);
068: } else {
069: TestUtils.failOnAssertion("parameter values", values,
070: new String[] { VALUE }, result);
071: }
072: return result;
073: }
074:
075: protected TestResult checkParameterNames(PortletRequest request) {
076: TestResult result = new TestResult();
077: result
078: .setDescription("Ensure parameters encoded in action URL "
079: + "exists in the parameter name enumeration.");
080:
081: boolean hasParameterName = false;
082: for (Enumeration en = request.getParameterNames(); !hasParameterName
083: && en.hasMoreElements();) {
084: String name = (String) en.nextElement();
085: if (KEY.equals(name)) {
086: hasParameterName = true;
087: }
088: }
089:
090: if (hasParameterName) {
091: result.setReturnCode(TestResult.PASSED);
092: } else {
093: result.setReturnCode(TestResult.FAILED);
094: result.setResultMessage("Parameter name " + KEY
095: + " not found in parameter name enumeration.");
096: }
097: return result;
098: }
099:
100: }
|