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 java.util.ArrayList;
020: import java.util.Enumeration;
021: import java.util.Iterator;
022: import java.util.List;
023:
024: import javax.portlet.PortletContext;
025: import javax.portlet.PortletMode;
026: import javax.portlet.PortletRequest;
027: import javax.portlet.WindowState;
028:
029: import org.apache.pluto.testsuite.TestResult;
030: import org.apache.pluto.testsuite.TestUtils;
031:
032: /**
033: */
034: public class MiscTest extends AbstractReflectivePortletTest {
035:
036: // Test Methods ------------------------------------------------------------
037:
038: protected TestResult checkContextMajorVersion(PortletContext context) {
039: TestResult result = new TestResult();
040: result
041: .setDescription("Ensure the expected major version number is returned.");
042:
043: String majorVersion = String.valueOf(context.getMajorVersion());
044: ExpectedResults expectedResults = ExpectedResults.getInstance();
045: String expected = expectedResults.getMajorVersion();
046: if (majorVersion != null && majorVersion.equals(expected)) {
047: result.setReturnCode(TestResult.PASSED);
048: } else {
049: TestUtils.failOnAssertion("major version", majorVersion,
050: expected, result);
051: }
052: return result;
053: }
054:
055: protected TestResult checkContextMinorVersion(PortletContext context) {
056: TestResult result = new TestResult();
057: result
058: .setDescription("Ensure the expected minor version number is returned.");
059:
060: String minorVersion = String.valueOf(context.getMinorVersion());
061: ExpectedResults expectedResults = ExpectedResults.getInstance();
062: String expected = expectedResults.getMinorVersion();
063: if (minorVersion != null && minorVersion.equals(expected)) {
064: result.setReturnCode(TestResult.PASSED);
065: } else {
066: TestUtils.failOnAssertion("minor version", minorVersion,
067: expected, result);
068: }
069: return result;
070: }
071:
072: protected TestResult checkContextServerInfo(PortletContext context) {
073: TestResult result = new TestResult();
074: result
075: .setDescription("Ensure the expected server info is returned.");
076:
077: String serverInfo = context.getServerInfo();
078: ExpectedResults expectedResults = ExpectedResults.getInstance();
079: String expected = expectedResults.getServerInfo();
080: if (serverInfo != null && serverInfo.equals(expected)) {
081: result.setReturnCode(TestResult.PASSED);
082: } else {
083: TestUtils.failOnAssertion("server info", serverInfo,
084: expected, result);
085: }
086: return result;
087: }
088:
089: protected TestResult checkPortalInfo(PortletRequest request) {
090: TestResult result = new TestResult();
091: result
092: .setDescription("Ensure the expected portal info is returned.");
093:
094: String portalInfo = request.getPortalContext().getPortalInfo();
095: ExpectedResults expectedResults = ExpectedResults.getInstance();
096: String expected = expectedResults.getPortalInfo();
097: if (portalInfo != null && portalInfo.equals(expected)) {
098: result.setReturnCode(TestResult.PASSED);
099: } else {
100: TestUtils.failOnAssertion("portal info", portalInfo,
101: expected, result);
102: }
103: return result;
104: }
105:
106: /**
107: * Test to ensure that the basic modes are supported.
108: * @todo Enhance to check for custom modes.
109: * @param req
110: * @return
111: */
112: protected TestResult checkSupportedModes(PortletRequest request) {
113: TestResult result = new TestResult();
114: result
115: .setDescription("Ensure the expected portlet modes are returned.");
116:
117: List requiredPortletModes = new ArrayList();
118: requiredPortletModes.add(PortletMode.VIEW);
119: requiredPortletModes.add(PortletMode.EDIT);
120: requiredPortletModes.add(PortletMode.HELP);
121:
122: for (Enumeration en = request.getPortalContext()
123: .getSupportedPortletModes(); en.hasMoreElements();) {
124: PortletMode portletMode = (PortletMode) en.nextElement();
125: requiredPortletModes.remove(portletMode);
126: }
127:
128: if (requiredPortletModes.isEmpty()) {
129: result.setReturnCode(TestResult.PASSED);
130: } else {
131: result.setReturnCode(TestResult.FAILED);
132: StringBuffer buffer = new StringBuffer();
133: for (Iterator it = requiredPortletModes.iterator(); it
134: .hasNext();) {
135: buffer.append(it.next()).append(", ");
136: }
137: result.setResultMessage("Required portlet modes ["
138: + buffer.toString() + "] are not supported.");
139: }
140: return result;
141: }
142:
143: protected TestResult checkSupportedWindowSates(
144: PortletRequest request) {
145: TestResult result = new TestResult();
146: result
147: .setDescription("Ensure the expected window states are returned.");
148:
149: List requiredWindowStates = new ArrayList();
150: requiredWindowStates.add(WindowState.MINIMIZED);
151: requiredWindowStates.add(WindowState.MAXIMIZED);
152: requiredWindowStates.add(WindowState.NORMAL);
153:
154: for (Enumeration en = request.getPortalContext()
155: .getSupportedWindowStates(); en.hasMoreElements();) {
156: WindowState windowState = (WindowState) en.nextElement();
157: requiredWindowStates.remove(windowState);
158: }
159:
160: if (requiredWindowStates.isEmpty()) {
161: result.setReturnCode(TestResult.PASSED);
162: } else {
163: result.setReturnCode(TestResult.FAILED);
164: StringBuffer buffer = new StringBuffer();
165: for (Iterator it = requiredWindowStates.iterator(); it
166: .hasNext();) {
167: buffer.append(it.next()).append(", ");
168: }
169: result.setResultMessage("Required window states ["
170: + buffer.toString() + "] are not supported.");
171: }
172: return result;
173: }
174:
175: }
|