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 java.util.Enumeration;
023: import java.util.HashMap;
024: import java.util.Map;
025:
026: import javax.portlet.PortletRequest;
027:
028: /**
029: */
030: public class RenderParameterTest extends AbstractReflectivePortletTest {
031:
032: private static final String ACTION_KEY = "org.apache.pluto.testsuite.PARAM_ACTION_KEY";
033:
034: private static final String RENDER_KEY = "org.apache.pluto.testsuite.PARAM_RENDER_KEY";
035: private static final String RENDER_VALUE = "org.apache.pluto.testsuite.RENDER_VALUE";
036:
037: public Map getRenderParameters(PortletRequest request) {
038: Map parameterMap = new HashMap();
039: parameterMap.put(RENDER_KEY, new String[] { RENDER_VALUE });
040: return parameterMap;
041: }
042:
043: // Test Methods ------------------------------------------------------------
044:
045: protected TestResult checkActionParametersNotHere(
046: PortletRequest request) {
047: TestResult result = new TestResult();
048: result
049: .setDescription("Ensure that action parameters are not available "
050: + "in the following render request.");
051:
052: String value = request.getParameter(ACTION_KEY);
053: if (value == null) {
054: result.setReturnCode(TestResult.PASSED);
055: } else {
056: TestUtils.failOnAssertion("parameter", value, null, result);
057: }
058: return result;
059: }
060:
061: protected TestResult checkRenderParameterValue(
062: PortletRequest request) {
063: TestResult result = new TestResult();
064: result
065: .setDescription("Ensure that render parameters set in action "
066: + "response are available in the following render request.");
067:
068: String value = request.getParameter(RENDER_KEY);
069: if (RENDER_VALUE.equals(value)) {
070: result.setReturnCode(TestResult.PASSED);
071: } else {
072: TestUtils.failOnAssertion("parameter", value, RENDER_VALUE,
073: result);
074: }
075: return result;
076: }
077:
078: protected TestResult checkRenderParameterValues(
079: PortletRequest request) {
080: TestResult result = new TestResult();
081: result
082: .setDescription("Ensure that render parameters set in action "
083: + "response are available in the following render request.");
084:
085: String[] values = request.getParameterValues(RENDER_KEY);
086: if (values != null && values.length == 1
087: && RENDER_VALUE.equals(values[0])) {
088: result.setReturnCode(TestResult.PASSED);
089: } else {
090: TestUtils.failOnAssertion("parameter values", values,
091: new String[] { RENDER_VALUE }, result);
092: }
093: return result;
094: }
095:
096: protected TestResult checkParameterMap(PortletRequest request) {
097: TestResult result = new TestResult();
098: result
099: .setDescription("Ensure that render request returns the correct "
100: + "parameter map.");
101:
102: Map parameterMap = request.getParameterMap();
103: String[] values = (String[]) parameterMap.get(RENDER_KEY);
104: if (values != null && values.length == 1
105: && RENDER_VALUE.equals(values[0])
106: && !parameterMap.containsKey(ACTION_KEY)) {
107: result.setReturnCode(TestResult.PASSED);
108: } else {
109: if (parameterMap.containsKey(ACTION_KEY)) {
110: result.setReturnCode(TestResult.FAILED);
111: result
112: .setResultMessage("Action parameter "
113: + ACTION_KEY
114: + " was found in render request with value(s): "
115: + parameterMap.get(ACTION_KEY));
116: } else {
117: TestUtils.failOnAssertion("parameter values", values,
118: new String[] { RENDER_VALUE }, result);
119: }
120: }
121: return result;
122: }
123:
124: protected TestResult checkParameterNames(PortletRequest request) {
125: TestResult result = new TestResult();
126: result
127: .setDescription("Ensure that render request returns the correct "
128: + "parameter names enumeration.");
129:
130: boolean hasActionParameter = false;
131: boolean hasRenderParameter = false;
132: for (Enumeration en = request.getParameterNames(); en
133: .hasMoreElements();) {
134: String name = (String) en.nextElement();
135: if (ACTION_KEY.equals(name)) {
136: hasActionParameter = true;
137: }
138: if (RENDER_KEY.equals(name)) {
139: hasRenderParameter = true;
140: }
141: }
142:
143: if (!hasActionParameter && hasRenderParameter) {
144: result.setReturnCode(TestResult.PASSED);
145: } else {
146: result.setReturnCode(TestResult.FAILED);
147: StringBuffer buffer = new StringBuffer();
148: if (!hasRenderParameter) {
149: buffer.append("Render parameter not found. ");
150: }
151: if (!hasActionParameter) {
152: buffer.append("Action parameter found. ");
153: }
154: result.setResultMessage(buffer.toString());
155: }
156: return result;
157: }
158: }
|