You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pluto-scm@portals.apache.org by cd...@apache.org on 2007/08/04 16:41:49 UTC
svn commit: r562725 [24/33] - in
/portals/pluto/branches/1.1-286-trunk-merge: ./ assembly/ assembly/src/
assembly/src/main/ assembly/src/main/assembly/ assembly/src/main/resources/
maven-pluto-plugin/ maven-pluto-plugin/src/ maven-pluto-plugin/src/main...
Added: portals/pluto/branches/1.1-286-trunk-merge/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/DispatcherRenderParameterTest.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/1.1-286-trunk-merge/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/DispatcherRenderParameterTest.java?view=auto&rev=562725
==============================================================================
--- portals/pluto/branches/1.1-286-trunk-merge/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/DispatcherRenderParameterTest.java (added)
+++ portals/pluto/branches/1.1-286-trunk-merge/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/DispatcherRenderParameterTest.java Sat Aug 4 07:41:23 2007
@@ -0,0 +1,344 @@
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pluto.testsuite.test;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.pluto.testsuite.TestResult;
+import org.apache.pluto.testsuite.TestUtils;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Map;
+
+import javax.portlet.PortletContext;
+import javax.portlet.PortletException;
+import javax.portlet.PortletRequest;
+import javax.portlet.PortletRequestDispatcher;
+import javax.portlet.PortletResponse;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.servlet.GenericServlet;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+/**
+ *
+ * @author <a href="mailto:ddewolf@apache.org">David H. DeWolf</a>
+ * @author <a href="mailto:zheng@apache.org">ZHENG Zhong</a>
+ * @version 1.0
+ * @since Mar 9, 2005
+ */
+public class DispatcherRenderParameterTest
+extends AbstractReflectivePortletTest {
+
+ /** Internal logger. */
+ private static final Log LOG = LogFactory.getLog(
+ DispatcherRenderParameterTest.class);
+
+ // Static Final Constants --------------------------------------------------
+
+ /** The path to the companion servlet. */
+ private static final String SERVLET_PATH = "/test/DispatcherRenderParameterTest_Servlet";
+
+ private static final String KEY_TARGET = "target";
+
+ private static final String TARGET_PARAMS = "testParams";
+ private static final String TARGET_SAME_NAME_PARAM = "testSameNameParam";
+ private static final String TARGET_ADDED_SAME_NAME_PARAM = "testAddedSameNameParam";
+ private static final String TARGET_INVALID_PARAMS = "testInvalidParams";
+
+ private static final String KEY_RENDER = "renderParamKey";
+ private static final String VALUE_RENDER = "renderParamValue";
+ private static final String VALUE_ADDED1 = "addedParamValue1";
+ private static final String VALUE_ADDED2 = "addedParamValue2";
+
+ private static final String KEY_A = "includedTestKeyA";
+ private static final String VALUE_A = "includedTestValueA";
+
+ private static final String KEY_B = "includedTestKeyB";
+ private static final String VALUE_B = "includedTestValueB";
+
+ private static final String KEY_C = "includedTestKeyC";
+ private static final String VALUE_C1 = "valueOneOfKeyC";
+ private static final String VALUE_C2 = "valueTwoOfKeyC";
+ private static final String VALUE_C3 = "valueThreeOfKeyC";
+
+ public static final String RESULT_KEY =
+ DispatcherRenderParameterTest.class.getName() + ".RESULT_KEY";
+
+
+ // AbstractReflectivePortletTest Impl --------------------------------------
+
+ /**
+ * Overwrites <code>super.getRenderParameters(..)</code> to set the
+ * test-specific render parameter in the render URL.
+ */
+ public Map getRenderParameters(PortletRequest request) {
+ Map parameterMap = super.getRenderParameters(request);
+ parameterMap.put(KEY_RENDER, new String[] { VALUE_RENDER });
+ return parameterMap;
+ }
+
+
+
+ // Test Methods ------------------------------------------------------------
+
+ protected TestResult checkParameters(PortletContext context,
+ PortletRequest request,
+ PortletResponse response)
+ throws IOException, PortletException {
+
+ // Dispatch to the companion servlet: call checkParameters().
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(SERVLET_PATH).append("?")
+ .append(KEY_TARGET).append("=").append(TARGET_PARAMS)
+ .append("&").append(KEY_A).append("=").append(VALUE_A)
+ .append("&").append(KEY_B).append("=").append(VALUE_B);
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Dispatching to: " + buffer.toString());
+ }
+ PortletRequestDispatcher dispatcher = context.getRequestDispatcher(
+ buffer.toString());
+ dispatcher.include((RenderRequest) request, (RenderResponse) response);
+
+ // Retrieve test result returned by the companion servlet.
+ TestResult result = (TestResult) request.getAttribute(RESULT_KEY);
+ request.removeAttribute(RESULT_KEY);
+ return result;
+ }
+
+
+ protected TestResult checkSameNameParameter(PortletContext context,
+ PortletRequest request,
+ PortletResponse response)
+ throws IOException, PortletException {
+
+ // Dispatch to the companion servlet: call checkSameNameParameter().
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(SERVLET_PATH).append("?")
+ .append(KEY_TARGET).append("=").append(TARGET_SAME_NAME_PARAM)
+ .append("&").append(KEY_C).append("=").append(VALUE_C1)
+ .append("&").append(KEY_C).append("=").append(VALUE_C2)
+ .append("&").append(KEY_C).append("=").append(VALUE_C3);
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Dispatching to: " + buffer.toString());
+ }
+ PortletRequestDispatcher dispatcher = context.getRequestDispatcher(
+ buffer.toString());
+ dispatcher.include((RenderRequest) request, (RenderResponse) response);
+
+ // Retrieve test result returned by the companion servlet.
+ TestResult result = (TestResult) request.getAttribute(RESULT_KEY);
+ request.removeAttribute(RESULT_KEY);
+ return result;
+ }
+
+ protected TestResult checkAddedSameNameParameter(PortletContext context,
+ PortletRequest request,
+ PortletResponse response)
+ throws IOException, PortletException {
+ // Dispatch to the companion servlet: call checkAddedSameNameParameter().
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(SERVLET_PATH).append("?")
+ .append(KEY_TARGET).append("=").append(TARGET_ADDED_SAME_NAME_PARAM)
+ .append("&").append(KEY_RENDER).append("=").append(VALUE_ADDED1)
+ .append("&").append(KEY_RENDER).append("=").append(VALUE_ADDED2);
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Dispatching to: " + buffer.toString());
+ }
+ PortletRequestDispatcher dispatcher = context.getRequestDispatcher(
+ buffer.toString());
+ dispatcher.include((RenderRequest) request, (RenderResponse) response);
+
+ // Retrieve test result returned by the companion servlet.
+ TestResult result = (TestResult) request.getAttribute(RESULT_KEY);
+ request.removeAttribute(RESULT_KEY);
+ return result;
+ }
+
+ protected TestResult checkInvalidParameters(PortletContext context,
+ PortletRequest request,
+ PortletResponse response)
+ throws IOException, PortletException {
+
+ // Dispatch to the companion servlet: call checkInvalidParameters().
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(SERVLET_PATH).append("?")
+ .append(KEY_TARGET).append("=").append(TARGET_INVALID_PARAMS)
+ .append("&").append(KEY_A)
+ .append("&").append(KEY_B).append("=").append(VALUE_B)
+ .append("&").append(KEY_C).append("=");
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Dispatching to: " + buffer.toString());
+ }
+ PortletRequestDispatcher dispatcher = context.getRequestDispatcher(
+ buffer.toString());
+ dispatcher.include((RenderRequest) request, (RenderResponse) response);
+
+ // Retrieve test result returned by the companion servlet.
+ TestResult result = (TestResult) request.getAttribute(RESULT_KEY);
+ request.removeAttribute(RESULT_KEY);
+ return result;
+ }
+
+
+ // Nested Companion Servlet Class ------------------------------------------
+
+ /**
+ * Nested static companion servlet class.
+ * @author <a href="mailto:ddewolf@apache.org">David H. DeWolf</a>
+ * @author <a href="mailto:zheng@apache.org">ZHENG Zhong</a>
+ */
+ public static class CompanionServlet extends GenericServlet {
+
+ // GenericServlet Impl -------------------------------------------------
+
+ public String getServletInfo() {
+ return getClass().getName();
+ }
+
+ /**
+ * Services the servlet request dispatched from the test portlet.
+ * This method checks the 'target' parameter to determine which test
+ * to run, and saves the test result in the request scope, which will
+ * be retrieved by the test portlet.
+ * @param request the incoming servlet request.
+ * @param response the incoming servlet response.
+ */
+ public void service(ServletRequest request, ServletResponse response)
+ throws ServletException, IOException {
+ TestResult result = null;
+ String target = request.getParameter(KEY_TARGET);
+ if (TARGET_PARAMS.equals(target)) {
+ result = checkParameters(request);
+ } else if (TARGET_SAME_NAME_PARAM.equals(target)) {
+ result = checkSameNameParameter(request);
+ } else if (TARGET_ADDED_SAME_NAME_PARAM.equals(target)) {
+ result = checkAddedSameNameParameter(request);
+ } else if (TARGET_INVALID_PARAMS.equals(target)) {
+ result = checkInvalidParameters(request);
+ } else {
+ result = failOnUnknownTarget(request);
+ }
+ request.setAttribute(RESULT_KEY, result);
+ }
+
+
+ // Private Methods -----------------------------------------------------
+
+ /**
+ * Check that parameters A and B are available in the dispatching
+ * request.
+ * @param request the servlet request.
+ */
+ private TestResult checkParameters(ServletRequest request) {
+ TestResult result = new TestResult();
+ result.setDescription("Ensure query parameters added during "
+ + "dispatching are attached to the request.");
+ String valueA = request.getParameter(KEY_A);
+ String valueB = request.getParameter(KEY_B);
+ if (VALUE_A.equals(valueA) && VALUE_B.equals(valueB)) {
+ result.setReturnCode(TestResult.PASSED);
+ } else if (!VALUE_A.equals(valueA)){
+ TestUtils.failOnAssertion("parameter", valueA, VALUE_A, result);
+ } else {
+ TestUtils.failOnAssertion("parameter", valueB, VALUE_B, result);
+ }
+ return result;
+ }
+
+ /**
+ * Check that parameter C has three values.
+ * @param request the servlet reqeust.
+ */
+ private TestResult checkSameNameParameter(ServletRequest request) {
+ TestResult result = new TestResult();
+ result.setDescription("Ensure query parameters with the same name "
+ + "added during dispatching are attached to the request.");
+ String[] values = request.getParameterValues(KEY_C);
+ String[] expected = new String[] {
+ VALUE_C1, VALUE_C2, VALUE_C3, };
+ if (Arrays.equals(values, expected)) {
+ result.setReturnCode(TestResult.PASSED);
+ } else {
+ TestUtils.failOnAssertion("parameter", values, expected, result);
+ }
+ return result;
+ }
+
+ /**
+ * Check that parameter RENDER has three values: one is the render
+ * parameter, while the other two are appended in the dispatch URI.
+ * @param request the servlet reqeust.
+ */
+ private TestResult checkAddedSameNameParameter(ServletRequest request) {
+ TestResult result = new TestResult();
+ result.setDescription("Ensure query parameters with the same name "
+ + "added during dispatching are attached to the request "
+ + "as well as render parameters.");
+ String[] values = request.getParameterValues(KEY_RENDER);
+ String[] expected = new String[] {
+ VALUE_ADDED1, VALUE_ADDED2, VALUE_RENDER, };
+ if (Arrays.equals(values, expected)) {
+ result.setReturnCode(TestResult.PASSED);
+ } else {
+ TestUtils.failOnAssertion("parameter", values, expected, result);
+ }
+ return result;
+ }
+
+ /**
+ * Check that invalid parameter A is ignored, parameter B is attached
+ * to the dispatching request with the correct value, and parameter C
+ * is attached to the dispatching request with an empty string.
+ * @param request the servlet request.
+ */
+ private TestResult checkInvalidParameters(ServletRequest request) {
+ TestResult result = new TestResult();
+ result.setDescription("Ensure invalid query parameters added "
+ + "during dispatching are ignored.");
+ String valueA = request.getParameter(KEY_A);
+ String valueB = request.getParameter(KEY_B);
+ String valueC = request.getParameter(KEY_C);
+ if (valueA == null && VALUE_B.equals(valueB) && "".equals(valueC)) {
+ result.setReturnCode(TestResult.PASSED);
+ } else if (valueA != null) {
+ TestUtils.failOnAssertion("parameter", valueA, null, result);
+ } else if (!VALUE_B.equals(valueB)) {
+ TestUtils.failOnAssertion("parameter", valueB, VALUE_B, result);
+ } else {
+ TestUtils.failOnAssertion("parameter", valueC, "", result);
+ }
+ return result;
+ }
+
+ private TestResult failOnUnknownTarget(ServletRequest request) {
+ TestResult result = new TestResult();
+ result.setReturnCode(TestResult.FAILED);
+ result.setResultMessage("Unable to perform test for parameter "
+ + KEY_TARGET + ": " + request.getParameter(KEY_TARGET));
+ return result;
+ }
+
+ }
+
+}
+
Added: portals/pluto/branches/1.1-286-trunk-merge/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/DispatcherRequestTest.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/1.1-286-trunk-merge/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/DispatcherRequestTest.java?view=auto&rev=562725
==============================================================================
--- portals/pluto/branches/1.1-286-trunk-merge/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/DispatcherRequestTest.java (added)
+++ portals/pluto/branches/1.1-286-trunk-merge/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/DispatcherRequestTest.java Sat Aug 4 07:41:23 2007
@@ -0,0 +1,405 @@
+/*
+ * Copyright 2003,2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pluto.testsuite.test;
+
+import java.io.IOException;
+
+import javax.portlet.PortletContext;
+import javax.portlet.PortletException;
+import javax.portlet.PortletRequest;
+import javax.portlet.PortletRequestDispatcher;
+import javax.portlet.PortletResponse;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.pluto.testsuite.TestResult;
+import org.apache.pluto.testsuite.TestUtils;
+
+public class DispatcherRequestTest extends AbstractReflectivePortletTest {
+
+ /** Logger. */
+ private static final Log LOG = LogFactory.getLog(DispatcherRequestTest.class);
+
+ /** The path to the companion servlet. */
+ private static final String SERVLET_PATH = "/test/DispatcherRequestTest_Servlet";
+
+ private static final String CHECK_PATH_INFO = "/checkPathInfo";
+ private static final String CHECK_REQUEST_URI = "/checkRequestURI";
+ private static final String CHECK_CONTEXT_PATH = "/checkContextPath";
+ private static final String CHECK_SERVLET_PATH = "/checkServletPath";
+ private static final String CHECK_QUERY_STRING = "/checkQueryString";
+
+ private static final String GET_REQUEST_URI = "/getRequestURI";
+ private static final String GET_CONTEXT_PATH = "/getContextPath";
+ private static final String GET_SERVLET_PATH = "/getServletPath";
+ private static final String GET_QUERY_STRING = "/getQueryString";
+
+ /** The query string appended to the dispatch URI. */
+ private static final String QUERY_STRING = "paramName=paramValue";
+
+ /** The request attribute key which associates the test result. */
+ private static final String RESULT_KEY =
+ DispatcherRequestTest.class.getName() + ".RESULT_KEY";
+
+ /** The key for the expected request URI. */
+ private static final String EXPECTED_REQUEST_URI =
+ DispatcherRequestTest.class.getName() + ".REQUEST_URI";
+
+ /** The key for the expected context path. */
+ private static final String EXPECTED_CONTEXT_PATH =
+ DispatcherRequestTest.class.getName() + ".CONTEXT_PATH";
+
+
+ // Test Methods ------------------------------------------------------------
+
+ protected TestResult checkPathInfo(PortletContext context,
+ PortletRequest request,
+ PortletResponse response)
+ throws IOException, PortletException {
+ return doCheckIncludedAttribute(context, request, response, CHECK_PATH_INFO);
+ }
+
+ protected TestResult checkRequestURI(PortletContext context,
+ PortletRequest request,
+ PortletResponse response)
+ throws IOException, PortletException {
+ return doCheckIncludedAttribute(context, request, response, CHECK_REQUEST_URI);
+ }
+
+ protected TestResult checkGetRequestURI(PortletContext context,
+ PortletRequest request,
+ PortletResponse response)
+ throws IOException, PortletException {
+ return doCheckIncludedAttribute(context, request, response, GET_REQUEST_URI);
+ }
+
+ protected TestResult checkContextPath(PortletContext context,
+ PortletRequest request,
+ PortletResponse response)
+ throws IOException, PortletException {
+ return doCheckIncludedAttribute(context, request, response, CHECK_CONTEXT_PATH);
+ }
+
+ protected TestResult checkGetContextPath(PortletContext context,
+ PortletRequest request,
+ PortletResponse response)
+ throws IOException, PortletException {
+ return doCheckIncludedAttribute(context, request, response, GET_CONTEXT_PATH);
+ }
+
+ protected TestResult checkServletPath(PortletContext context,
+ PortletRequest request,
+ PortletResponse response)
+ throws IOException, PortletException {
+ return doCheckIncludedAttribute(context, request, response, CHECK_SERVLET_PATH);
+ }
+
+ protected TestResult checkGetServletPath(PortletContext context,
+ PortletRequest request,
+ PortletResponse response)
+ throws IOException, PortletException {
+ return doCheckIncludedAttribute(context, request, response, GET_SERVLET_PATH);
+ }
+
+ protected TestResult checkQueryString(PortletContext context,
+ PortletRequest request,
+ PortletResponse response)
+ throws IOException, PortletException {
+ return doCheckIncludedAttribute(context, request, response, CHECK_QUERY_STRING);
+ }
+
+ protected TestResult checkGetQueryString(PortletContext context,
+ PortletRequest request,
+ PortletResponse response)
+ throws IOException, PortletException {
+ return doCheckIncludedAttribute(context, request, response, GET_QUERY_STRING);
+ }
+
+
+ // Private Methods ---------------------------------------------------------
+
+ private TestResult doCheckIncludedAttribute(PortletContext context,
+ PortletRequest request,
+ PortletResponse response,
+ String pathInfo)
+ throws IOException, PortletException {
+
+ // Save expected values as request attributes.
+ String contextPath = request.getContextPath();
+ String requestUri = contextPath + SERVLET_PATH + pathInfo;
+ request.setAttribute(EXPECTED_REQUEST_URI, requestUri);
+ request.setAttribute(EXPECTED_CONTEXT_PATH, contextPath);
+
+ // Dispatch to the companion servlet: call checkParameters().
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(SERVLET_PATH).append(pathInfo).append("?")
+ .append(QUERY_STRING);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Dispatching to: " + buffer.toString());
+ }
+ PortletRequestDispatcher dispatcher = context.getRequestDispatcher(
+ buffer.toString());
+ dispatcher.include((RenderRequest) request, (RenderResponse) response);
+
+ // Retrieve test result returned by the companion servlet.
+ TestResult result = (TestResult) request.getAttribute(RESULT_KEY);
+ request.removeAttribute(RESULT_KEY);
+ request.removeAttribute(EXPECTED_REQUEST_URI);
+ request.removeAttribute(EXPECTED_CONTEXT_PATH);
+ return result;
+ }
+
+
+ // Nested Companion Servlet Class ------------------------------------------
+
+ public static class CompanionServlet extends HttpServlet {
+
+ private static final String KEY_REQUEST_URI = "javax.servlet.include.request_uri";
+ private static final String KEY_CONTEXT_PATH = "javax.servlet.include.context_path";
+ private static final String KEY_SERVLET_PATH = "javax.servlet.include.servlet_path";
+ private static final String KEY_PATH_INFO = "javax.servlet.include.path_info";
+ private static final String KEY_QUERY_STRING = "javax.servlet.include.query_string";
+
+
+ // GenericServlet Impl -------------------------------------------------
+
+ public String getServletInfo() {
+ return getClass().getName();
+ }
+
+ /**
+ * This method uses <code>HttpServletRequest.getPathInfo</code> to
+ * retrieve the requested path info, and forwards to the corresponding
+ * check method to perform the test.
+ */
+ public void service(HttpServletRequest request,
+ HttpServletResponse response)
+ throws ServletException, IOException {
+ TestResult result = null;
+ String pathInfo = getPathInfo(request);
+ if (CHECK_PATH_INFO.equals(pathInfo)) {
+ result = checkPathInfo(request, pathInfo);
+ } else if (CHECK_REQUEST_URI.equals(pathInfo)) {
+ result = checkRequestURI(request);
+ } else if (CHECK_CONTEXT_PATH.equals(pathInfo)) {
+ result = checkContextPath(request);
+ } else if (CHECK_SERVLET_PATH.equals(pathInfo)) {
+ result = checkServletPath(request);
+ } else if (CHECK_QUERY_STRING.equals(pathInfo)) {
+ result = checkQueryString(request);
+ } else if (GET_REQUEST_URI.equals(pathInfo)) {
+ result = checkGetRequestURI(request);
+ } else if (GET_CONTEXT_PATH.equals(pathInfo)) {
+ result = checkGetContextPath(request);
+ } else if (GET_SERVLET_PATH.equals(pathInfo)) {
+ result = checkGetServletPath(request);
+ } else if (GET_QUERY_STRING.equals(pathInfo)) {
+ result = checkGetQueryString(request);
+ } else {
+ result = failOnPathInfo(pathInfo);
+ }
+ request.setAttribute(RESULT_KEY, result);
+ }
+
+
+ // Private Methods -----------------------------------------------------
+
+ /**
+ * Retrieves the path info from servlet request by invoking method
+ * <code>HttpServletRequest.getPathInfo()</code>.
+ * @param request the servlet request dispatched from test portlet.
+ * @return the path info retrieved from servlet request.
+ */
+ private String getPathInfo(HttpServletRequest request) {
+ return request.getPathInfo();
+ }
+
+ private TestResult checkPathInfo(HttpServletRequest request,
+ String expected) {
+ TestResult result = new TestResult();
+ result.setDescription("Ensure that included attribute '"
+ + KEY_PATH_INFO + "' is available in servlet request.");
+ result.setSpecPLT("16.3.1");
+
+ String pathInfo = (String) request.getAttribute(KEY_PATH_INFO);
+ if (pathInfo != null && pathInfo.equals(expected)) {
+ result.setReturnCode(TestResult.PASSED);
+ } else {
+ TestUtils.failOnAssertion(KEY_PATH_INFO,
+ pathInfo, expected, result);
+ }
+ return result;
+ }
+
+ private TestResult checkRequestURI(HttpServletRequest request) {
+ TestResult result = new TestResult();
+ result.setDescription("Ensure that included attribute '"
+ + KEY_REQUEST_URI + "' is available in servlet request.");
+ result.setSpecPLT("16.3.1");
+
+ String expected = (String) request.getAttribute(EXPECTED_REQUEST_URI);
+ String requestURI = (String) request.getAttribute(KEY_REQUEST_URI);
+ if (requestURI != null && requestURI.equals(expected)) {
+ result.setReturnCode(TestResult.PASSED);
+ } else {
+ TestUtils.failOnAssertion(KEY_REQUEST_URI,
+ requestURI, expected, result);
+ }
+ return result;
+ }
+
+ private TestResult checkGetRequestURI(HttpServletRequest request) {
+ TestResult result = new TestResult();
+ result.setDescription("Ensure that method request.getRequestURI() "
+ + "returns correct value.");
+ result.setSpecPLT("16.3.3");
+
+ String expected = (String) request.getAttribute(EXPECTED_REQUEST_URI);
+ String requestURI = request.getRequestURI();
+ if (requestURI != null && requestURI.equals(expected)) {
+ result.setReturnCode(TestResult.PASSED);
+ } else {
+ TestUtils.failOnAssertion("request.getRequestURI()",
+ requestURI, expected, result);
+ }
+ return result;
+ }
+
+ private TestResult checkContextPath(HttpServletRequest request) {
+ TestResult result = new TestResult();
+ result.setDescription("Ensure that included attribute '"
+ + KEY_CONTEXT_PATH + "' is available in servlet request.");
+ result.setSpecPLT("16.3.1");
+
+ String expected = (String) request.getAttribute(EXPECTED_CONTEXT_PATH);
+ String contextPath = (String) request.getAttribute(KEY_CONTEXT_PATH);
+ if (contextPath != null && contextPath.equals(expected)) {
+ result.setReturnCode(TestResult.PASSED);
+ } else {
+ TestUtils.failOnAssertion(KEY_CONTEXT_PATH,
+ contextPath, expected, result);
+ }
+ return result;
+ }
+
+ private TestResult checkGetContextPath(HttpServletRequest request) {
+ TestResult result = new TestResult();
+ result.setDescription("Ensure that method request.getContextPath() "
+ + "returns the correct value.");
+ result.setSpecPLT("16.3.3");
+
+ String expected = (String) request.getAttribute(EXPECTED_CONTEXT_PATH);
+ String contextPath = request.getContextPath();
+ if (contextPath != null && contextPath.equals(expected)) {
+ result.setReturnCode(TestResult.PASSED);
+ } else {
+ TestUtils.failOnAssertion("request.getContextPath()",
+ contextPath, expected, result);
+ }
+ return result;
+ }
+
+ private TestResult checkServletPath(HttpServletRequest request) {
+ TestResult result = new TestResult();
+ result.setDescription("Ensure that included attribute '"
+ + KEY_SERVLET_PATH + "' is available in servlet request.");
+ result.setSpecPLT("16.3.1");
+
+ String servletPath = (String) request.getAttribute(KEY_SERVLET_PATH);
+ if (SERVLET_PATH.equals(servletPath)) {
+ result.setReturnCode(TestResult.PASSED);
+ } else {
+ TestUtils.failOnAssertion(KEY_SERVLET_PATH,
+ servletPath, SERVLET_PATH, result);
+ }
+ return result;
+ }
+
+ private TestResult checkGetServletPath(HttpServletRequest request) {
+ TestResult result = new TestResult();
+ result.setDescription("Ensure that method request.getServletPath() "
+ + "returns the correct value.");
+ result.setSpecPLT("16.3.3");
+
+ String servletPath = request.getServletPath();
+ if (SERVLET_PATH.equals(servletPath)) {
+ result.setReturnCode(TestResult.PASSED);
+ } else {
+ TestUtils.failOnAssertion("request.getServletPath()",
+ servletPath, SERVLET_PATH, result);
+ }
+ return result;
+ }
+
+ private TestResult checkQueryString(HttpServletRequest request) {
+ TestResult result = new TestResult();
+ result.setDescription("Ensure that included attribute '"
+ + KEY_QUERY_STRING + "' is available in servlet request.");
+ result.setSpecPLT("16.3.1");
+
+ String queryString = (String) request.getAttribute(KEY_QUERY_STRING);
+ if (QUERY_STRING.equals(queryString)) {
+ result.setReturnCode(TestResult.PASSED);
+ } else {
+ TestUtils.failOnAssertion(KEY_QUERY_STRING,
+ queryString, QUERY_STRING, result);
+ }
+ return result;
+ }
+
+ private TestResult checkGetQueryString(HttpServletRequest request) {
+ TestResult result = new TestResult();
+ result.setDescription("Ensure that method request.getQueryString() "
+ + "returns the correct value.");
+ result.setSpecPLT("16.3.3");
+
+ String queryString = request.getQueryString();
+ if (QUERY_STRING.equals(queryString)) {
+ result.setReturnCode(TestResult.PASSED);
+ } else {
+ TestUtils.failOnAssertion("request.getQueryString()",
+ queryString, QUERY_STRING, result);
+ }
+ return result;
+ }
+
+ private TestResult failOnPathInfo(String pathInfo) {
+ TestResult result = new TestResult();
+ result.setDescription("Ensure that included attribute '"
+ + KEY_PATH_INFO + "' is available in servlet request.");
+ result.setSpecPLT("16.3.1");
+
+ String[] expectedPathInfos = new String[] {
+ CHECK_REQUEST_URI, CHECK_CONTEXT_PATH,
+ CHECK_SERVLET_PATH, CHECK_QUERY_STRING, };
+ TestUtils.failOnAssertion(KEY_PATH_INFO,
+ new String[] { pathInfo },
+ expectedPathInfos,
+ result);
+ return result;
+ }
+
+ }
+
+}
+
+
Added: portals/pluto/branches/1.1-286-trunk-merge/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/ExpectedResults.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/1.1-286-trunk-merge/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/ExpectedResults.java?view=auto&rev=562725
==============================================================================
--- portals/pluto/branches/1.1-286-trunk-merge/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/ExpectedResults.java (added)
+++ portals/pluto/branches/1.1-286-trunk-merge/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/ExpectedResults.java Sat Aug 4 07:41:23 2007
@@ -0,0 +1,111 @@
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.pluto.testsuite.test;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
+import org.apache.pluto.testsuite.InvalidConfigurationException;
+
+/**
+ * A Singleton which loads a properties file containing data expected by the
+ * tests in the testsuite.
+ * @author <a href="mailto:ddewolf@apache.org">David H. DeWolf</a>
+ * @author <a href="mailto:zheng@apache.org">ZHENG Zhong</a>
+ */
+public class ExpectedResults {
+
+ /** The file name of properties holding expected results. */
+ public static final String PROPERTY_FILENAME = "expectedResults.properties";
+
+ /** The static singleton instance. */
+ private static ExpectedResults instance = null;
+
+
+ // Private Member Variables ------------------------------------------------
+
+ /** The nested properties. */
+ private Properties properties = null;
+
+
+ // Constructor -------------------------------------------------------------
+
+ /**
+ * Private constructor that prevents external instantiation.
+ * @throws IOException if fail to load properties from file.
+ */
+ private ExpectedResults() throws IOException {
+ properties = new Properties();
+ InputStream in = Thread.currentThread().getContextClassLoader()
+ .getResourceAsStream(PROPERTY_FILENAME);
+ if (in != null) {
+ properties.load(in);
+ } else {
+ throw new IOException("Could not find " + PROPERTY_FILENAME);
+ }
+ }
+
+ /**
+ * Returns the singleton expected results instance.
+ * @return the singleton expected results instance.
+ * @throws InvalidConfigurationException if fail to read properties file.
+ */
+ public static ExpectedResults getInstance()
+ throws InvalidConfigurationException {
+ if (instance == null) {
+ try {
+ instance = new ExpectedResults();
+ } catch (IOException ex) {
+ throw new InvalidConfigurationException("Error reading file "
+ + PROPERTY_FILENAME + ": " + ex.getMessage());
+ }
+ }
+ return instance;
+ }
+
+
+ // Public Methods ----------------------------------------------------------
+
+ public String getMajorVersion() {
+ return properties.getProperty("expected.version.major");
+ }
+
+ public String getMinorVersion() {
+ return properties.getProperty("expected.version.minor");
+ }
+
+ public String getServerInfo() {
+ return properties.getProperty("expected.serverInfo");
+ }
+
+ public String getPortalInfo() {
+ return properties.getProperty("expected.portalInfo");
+ }
+
+ public String getMappedSecurityRole() {
+ return properties.getProperty("expected.security.role.mapped");
+ }
+
+ public String getUnmappedSecurityRole() {
+ return properties.getProperty("expected.security.role");
+ }
+
+}
+
+
Added: portals/pluto/branches/1.1-286-trunk-merge/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/ExternalAppScopedAttributeTest.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/1.1-286-trunk-merge/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/ExternalAppScopedAttributeTest.java?view=auto&rev=562725
==============================================================================
--- portals/pluto/branches/1.1-286-trunk-merge/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/ExternalAppScopedAttributeTest.java (added)
+++ portals/pluto/branches/1.1-286-trunk-merge/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/ExternalAppScopedAttributeTest.java Sat Aug 4 07:41:23 2007
@@ -0,0 +1,99 @@
+/*
+ * Copyright 2003,2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.pluto.testsuite.test;
+
+import java.io.IOException;
+
+import org.apache.pluto.testsuite.TestResult;
+
+import javax.portlet.PortletSession;
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+/**
+ * @author <a href="mailto:ddewolf@apache.org">David H. DeWolf</a>
+ * @author <a href="mailto:zheng@apache.org">ZHENG Zhong</a>
+ */
+public class ExternalAppScopedAttributeTest extends AbstractReflectivePortletTest {
+
+ public static final String INT_KEY = "org.apache.pluto.testsuite.INTERNALLY_SET_APP_SCOPED_SESSION_TEST_KEY";
+ public static final String EXT_KEY = "org.apache.pluto.testsuite.EXTERNALLY_SET_APP_SCOPED_SESSION_TEST_KEY";
+ public static final String VALUE = "Should be visible to all Portlets and Web Resources.";
+
+
+ // Test Methods ------------------------------------------------------------
+
+ protected TestResult checkSetAppScopedAttributeHereSeenElsewhere(
+ PortletSession session) {
+ TestResult result = new TestResult();
+ result.setDescription("Ensure application scoped attributes set here "
+ + "in portlet session can be seen elsewhere.");
+
+ session.setAttribute(INT_KEY, VALUE, PortletSession.APPLICATION_SCOPE);
+ result.setReturnCode(TestResult.WARNING);
+ result.setResultMessage("Click the provided link to validate test.");
+ return result;
+ }
+
+ protected TestResult checkSetAppScopedAttributeElsewhereSeenHere(
+ PortletSession session) {
+ TestResult result = new TestResult();
+ result.setDescription("Ensure application scoped attributes set "
+ + "elsewhere in portlet session can be seen here.");
+
+ Object value = session.getAttribute(EXT_KEY,
+ PortletSession.APPLICATION_SCOPE);
+ if (VALUE.equals(value)) {
+ result.setReturnCode(TestResult.PASSED);
+ } else {
+ result.setReturnCode(TestResult.WARNING);
+ result.setResultMessage("This test will not pass until you have "
+ + "opened the external resource using the link provided below.");
+ }
+ return result;
+ }
+
+
+ // Nested Servlet Class ----------------------------------------------------
+
+ /**
+ * The companion servlet that cooperates with this portlet test.
+ */
+ public static class CompanionServlet extends HttpServlet {
+
+ public void doGet(HttpServletRequest request,
+ HttpServletResponse response)
+ throws ServletException, IOException {
+ HttpSession session = request.getSession();
+ String value = (String) session.getAttribute(INT_KEY);
+ if (ExternalAppScopedAttributeTest.VALUE.equals(value)) {
+ request.setAttribute("passed", new Boolean(true));
+ session.setAttribute(EXT_KEY, VALUE);
+ }
+
+ RequestDispatcher dispatcher = request.getRequestDispatcher(
+ "/jsp/ExternalAppScopedAttributeTest_companion.jsp");
+ dispatcher.forward(request, response);
+ }
+
+ }
+
+}
Added: portals/pluto/branches/1.1-286-trunk-merge/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/MiscTest.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/1.1-286-trunk-merge/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/MiscTest.java?view=auto&rev=562725
==============================================================================
--- portals/pluto/branches/1.1-286-trunk-merge/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/MiscTest.java (added)
+++ portals/pluto/branches/1.1-286-trunk-merge/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/MiscTest.java Sat Aug 4 07:41:23 2007
@@ -0,0 +1,165 @@
+/*
+ * Copyright 2003,2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pluto.testsuite.test;
+
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.portlet.PortletContext;
+import javax.portlet.PortletMode;
+import javax.portlet.PortletRequest;
+import javax.portlet.WindowState;
+
+import org.apache.pluto.testsuite.TestResult;
+import org.apache.pluto.testsuite.TestUtils;
+
+/**
+ * @author <a href="mailto:ddewolf@apache.org">David H. DeWolf</a>
+ * @author <a href="mailto:zheng@apache.org">ZHENG Zhong</a>
+ */
+public class MiscTest extends AbstractReflectivePortletTest {
+
+ // Test Methods ------------------------------------------------------------
+
+ protected TestResult checkContextMajorVersion(PortletContext context) {
+ TestResult result = new TestResult();
+ result.setDescription("Ensure the expected major version number is returned.");
+
+ String majorVersion = String.valueOf(context.getMajorVersion());
+ ExpectedResults expectedResults = ExpectedResults.getInstance();
+ String expected = expectedResults.getMajorVersion();
+ if (majorVersion != null && majorVersion.equals(expected)) {
+ result.setReturnCode(TestResult.PASSED);
+ } else {
+ TestUtils.failOnAssertion("major version", majorVersion, expected, result);
+ }
+ return result;
+ }
+
+ protected TestResult checkContextMinorVersion(PortletContext context) {
+ TestResult result = new TestResult();
+ result.setDescription("Ensure the expected minor version number is returned.");
+
+ String minorVersion = String.valueOf(context.getMinorVersion());
+ ExpectedResults expectedResults = ExpectedResults.getInstance();
+ String expected = expectedResults.getMinorVersion();
+ if (minorVersion != null && minorVersion.equals(expected)) {
+ result.setReturnCode(TestResult.PASSED);
+ } else {
+ TestUtils.failOnAssertion("minor version", minorVersion, expected, result);
+ }
+ return result;
+ }
+
+ protected TestResult checkContextServerInfo(PortletContext context) {
+ TestResult result = new TestResult();
+ result.setDescription("Ensure the expected server info is returned.");
+
+ String serverInfo = context.getServerInfo();
+ ExpectedResults expectedResults = ExpectedResults.getInstance();
+ String expected = expectedResults.getServerInfo();
+ if (serverInfo != null && serverInfo.equals(expected)) {
+ result.setReturnCode(TestResult.PASSED);
+ } else {
+ TestUtils.failOnAssertion("server info", serverInfo, expected, result);
+ }
+ return result;
+ }
+
+ protected TestResult checkPortalInfo(PortletRequest request) {
+ TestResult result = new TestResult();
+ result.setDescription("Ensure the expected portal info is returned.");
+
+ String portalInfo = request.getPortalContext().getPortalInfo();
+ ExpectedResults expectedResults = ExpectedResults.getInstance();
+ String expected = expectedResults.getPortalInfo();
+ if (portalInfo != null && portalInfo.equals(expected)) {
+ result.setReturnCode(TestResult.PASSED);
+ } else {
+ TestUtils.failOnAssertion("portal info", portalInfo, expected, result);
+ }
+ return result;
+ }
+
+ /**
+ * Test to ensure that the basic modes are supported.
+ * @todo Enhance to check for custom modes.
+ * @param req
+ * @return
+ */
+ protected TestResult checkSupportedModes(PortletRequest request) {
+ TestResult result = new TestResult();
+ result.setDescription("Ensure the expected portlet modes are returned.");
+
+ List requiredPortletModes = new ArrayList();
+ requiredPortletModes.add(PortletMode.VIEW);
+ requiredPortletModes.add(PortletMode.EDIT);
+ requiredPortletModes.add(PortletMode.HELP);
+
+ for (Enumeration en = request.getPortalContext().getSupportedPortletModes();
+ en.hasMoreElements(); ) {
+ PortletMode portletMode = (PortletMode) en.nextElement();
+ requiredPortletModes.remove(portletMode);
+ }
+
+ if (requiredPortletModes.isEmpty()) {
+ result.setReturnCode(TestResult.PASSED);
+ } else {
+ result.setReturnCode(TestResult.FAILED);
+ StringBuffer buffer = new StringBuffer();
+ for (Iterator it = requiredPortletModes.iterator();
+ it.hasNext(); ) {
+ buffer.append(it.next()).append(", ");
+ }
+ result.setResultMessage("Required portlet modes ["
+ + buffer.toString() + "] are not supported.");
+ }
+ return result;
+ }
+
+ protected TestResult checkSupportedWindowSates(PortletRequest request) {
+ TestResult result = new TestResult();
+ result.setDescription("Ensure the expected window states are returned.");
+
+ List requiredWindowStates = new ArrayList();
+ requiredWindowStates.add(WindowState.MINIMIZED);
+ requiredWindowStates.add(WindowState.MAXIMIZED);
+ requiredWindowStates.add(WindowState.NORMAL);
+
+ for (Enumeration en = request.getPortalContext().getSupportedWindowStates();
+ en.hasMoreElements(); ) {
+ WindowState windowState = (WindowState) en.nextElement();
+ requiredWindowStates.remove(windowState);
+ }
+
+ if (requiredWindowStates.isEmpty()) {
+ result.setReturnCode(TestResult.PASSED);
+ } else {
+ result.setReturnCode(TestResult.FAILED);
+ StringBuffer buffer = new StringBuffer();
+ for (Iterator it = requiredWindowStates.iterator();
+ it.hasNext(); ) {
+ buffer.append(it.next()).append(", ");
+ }
+ result.setResultMessage("Required window states ["
+ + buffer.toString() + "] are not supported.");
+ }
+ return result;
+ }
+
+}
Added: portals/pluto/branches/1.1-286-trunk-merge/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/PreferenceCommonTest.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/1.1-286-trunk-merge/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/PreferenceCommonTest.java?view=auto&rev=562725
==============================================================================
--- portals/pluto/branches/1.1-286-trunk-merge/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/PreferenceCommonTest.java (added)
+++ portals/pluto/branches/1.1-286-trunk-merge/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/PreferenceCommonTest.java Sat Aug 4 07:41:23 2007
@@ -0,0 +1,483 @@
+/*
+ * Copyright 2003,2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pluto.testsuite.test;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.pluto.testsuite.TestResult;
+import org.apache.pluto.testsuite.TestUtils;
+
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.portlet.PortletPreferences;
+import javax.portlet.PortletRequest;
+import javax.portlet.ReadOnlyException;
+
+/**
+ * Common portlet preferences test.
+ * @author <a href="mailto:zheng@apache.org">ZHENG Zhong</a>
+ */
+public class PreferenceCommonTest extends AbstractReflectivePortletTest {
+
+ /** Logger. */
+ private static final Log LOG = LogFactory.getLog(PreferenceCommonTest.class);
+
+ protected static final String BOGUS_KEY = "org.apache.pluto.testsuite.BOGUS_KEY";
+
+ protected static final String READ_ONLY_PREF_NAME = "readonly";
+
+ protected static final String NO_VALUE_PREF_NAME = "nameWithNoValue";
+
+ protected static final String PREF_NAME = "dummyName";
+ protected static final String PREF_VALUE = "dummyValue";
+
+ protected static final String DEF_VALUE = "Default";
+ protected static final String NEW_VALUE = "notTheOriginal";
+
+
+ // Test Methods ------------------------------------------------------------
+
+ protected TestResult checkGetEmptyPreference(PortletRequest request) {
+ return doCheckDefaultPreference(request, "nonexistence!");
+ }
+
+ protected TestResult checkGetNoValuePreference(PortletRequest request) {
+ return doCheckDefaultPreference(request, NO_VALUE_PREF_NAME);
+ }
+
+ /**
+ * Private method that checks if a preference is not defined or has no
+ * value in <code>portlet.xml</code>, the default values are returned.
+ * @param request the portlet request.
+ * @param preferenceName the preference name which is not defined or has no
+ * value in <code>portlet.xml</code>.
+ * @return the test result.
+ */
+ private TestResult doCheckDefaultPreference(PortletRequest request,
+ String preferenceName) {
+ TestResult result = new TestResult();
+ result.setDescription("Ensure proper default is returned when "
+ + "a non-existing/value-undefined preference is requested.");
+ result.setSpecPLT("14.1");
+
+ PortletPreferences preferences = request.getPreferences();
+ String value = preferences.getValue(preferenceName, DEF_VALUE);
+ String[] values = preferences.getValues(preferenceName,
+ new String[] { DEF_VALUE });
+ if (DEF_VALUE.equals(value)
+ && values != null && values.length == 1
+ && DEF_VALUE.equals(values[0])) {
+ result.setReturnCode(TestResult.PASSED);
+ } else if (!DEF_VALUE.equals(value)) {
+ TestUtils.failOnAssertion("preference value", value, DEF_VALUE, result);
+ } else {
+ TestUtils.failOnAssertion("preference values",
+ values,
+ new String[] { DEF_VALUE },
+ result);
+ }
+ return result;
+ }
+
+
+ protected TestResult checkGetPreferences(PortletRequest request) {
+ TestResult result = new TestResult();
+ result.setDescription("Ensure that preferences defined "
+ + "in the deployment descriptor may be retrieved.");
+ result.setSpecPLT("14.1");
+
+ PortletPreferences preferences = request.getPreferences();
+ String value = preferences.getValue(PREF_NAME, DEF_VALUE);
+ if (value != null && value.equals(PREF_VALUE)) {
+ result.setReturnCode(TestResult.PASSED);
+ } else {
+ TestUtils.failOnAssertion("preference value", value, PREF_VALUE, result);
+ }
+ return result;
+ }
+
+ protected TestResult checkSetPreferenceSingleValue(PortletRequest request) {
+ TestResult result = new TestResult();
+ result.setDescription("Ensure a single preference value can be set.");
+ result.setSpecPLT("14.1");
+
+ PortletPreferences preferences = request.getPreferences();
+ try {
+ preferences.setValue("TEST", "TEST_VALUE");
+ } catch (ReadOnlyException ex) {
+ TestUtils.failOnException("Unable to set preference value.", ex, result);
+ return result;
+ }
+
+ String value = preferences.getValue("TEST", DEF_VALUE);
+ if (value != null && value.equals("TEST_VALUE")) {
+ result.setReturnCode(TestResult.PASSED);
+ } else {
+ TestUtils.failOnAssertion("preference value", value, "TEST_VALUE", result);
+ }
+ return result;
+ }
+
+ protected TestResult checkSetPreferenceMultiValues(PortletRequest request) {
+ TestResult result = new TestResult();
+ result.setDescription("Ensure multiple preference values can be set.");
+ result.setSpecPLT("14.1");
+
+ PortletPreferences preferences = request.getPreferences();
+ try {
+ preferences.setValues("TEST", new String[] {"ONE", "ANOTHER"});
+ } catch (ReadOnlyException ex) {
+ TestUtils.failOnException("Unable to set preference values.", ex, result);
+ return result;
+ }
+
+ String[] values = preferences.getValues("TEST", new String[] { DEF_VALUE });
+ if (values != null && values.length == 2
+ && values[0].equals("ONE") && values[1].equals("ANOTHER")) {
+ result.setReturnCode(TestResult.PASSED);
+ } else if (values == null) {
+ TestUtils.failOnAssertion("preference values",
+ values,
+ new String[] { "ONE", "ANOTHER" },
+ result);
+ } else if (values.length != 2) {
+ TestUtils.failOnAssertion("length of preference values",
+ String.valueOf(values.length),
+ String.valueOf(2),
+ result);
+ } else {
+ TestUtils.failOnAssertion("preference values",
+ values,
+ new String[] { "ONE", "ANOTHER" },
+ result);
+ }
+ return result;
+ }
+
+ protected TestResult checkSetPreferenceNull(PortletRequest request) {
+ TestResult result = new TestResult();
+ result.setDescription("Ensure a preference value can be set to null.");
+ result.setSpecPLT("14.1");
+
+ PortletPreferences preferences = request.getPreferences();
+ try {
+ preferences.setValue("TEST", null);
+ } catch (ReadOnlyException ex) {
+ TestUtils.failOnException("Unable to set preference value.", ex, result);
+ return result;
+ }
+
+ String value = preferences.getValue("TEST", DEF_VALUE);
+ if (DEF_VALUE.equals(value)) {
+ result.setReturnCode(TestResult.PASSED);
+ } else {
+ TestUtils.failOnAssertion("preference value", value, DEF_VALUE, result);
+ }
+ return result;
+ }
+
+ protected TestResult checkSetPreferencesReturnsFirst(PortletRequest request) {
+ TestResult result = new TestResult();
+ result.setDescription("Ensure the first value set to a given "
+ + "preference is returned first by PortletPreferences.getValue().");
+ result.setSpecPLT("14.1");
+
+ PortletPreferences preferences = request.getPreferences();
+ try {
+ preferences.setValues("TEST", new String[] { "FIRST", "SECOND" });
+ } catch (ReadOnlyException ex) {
+ TestUtils.failOnException("Unable to set preference values.", ex, result);
+ return result;
+ }
+
+ String value = preferences.getValue("TEST", DEF_VALUE);
+ if (value != null && value.equals("FIRST")) {
+ result.setReturnCode(TestResult.PASSED);
+ } else {
+ TestUtils.failOnAssertion("preference value", value, "FIRST", result);
+ }
+ return result;
+ }
+
+ protected TestResult checkResetPreferenceToDefault(PortletRequest request) {
+ TestResult result = new TestResult();
+ result.setDescription("Ensure preferences are properly reset.");
+ result.setSpecPLT("14.1");
+
+ PortletPreferences preferences = request.getPreferences();
+ boolean setOccured = false;
+ boolean resetOccured = false;
+
+ try {
+ // Set new value to overwrite the default value.
+ preferences.setValue(PREF_NAME, NEW_VALUE);
+ String value = preferences.getValue(PREF_NAME, DEF_VALUE);
+ if (NEW_VALUE.equals(value)) {
+ setOccured = true;
+ }
+ // Reset the preference so that default value is restored.
+ preferences.reset(PREF_NAME);
+ value = preferences.getValue(PREF_NAME, DEF_VALUE);
+ if (PREF_VALUE.equals(value)) {
+ resetOccured = true;
+ }
+ } catch (ReadOnlyException ex) {
+ TestUtils.failOnException("Unable to set preference value.", ex, result);
+ return result;
+ }
+
+ // Everything is OK.
+ if (setOccured && resetOccured) {
+ result.setReturnCode(TestResult.PASSED);
+ }
+ // Error occurred when setting or storing preferences.
+ else if (!setOccured) {
+ result.setReturnCode(TestResult.WARNING);
+ result.setResultMessage("A function upon which the reset test "
+ + "depends failed to execute as expected. "
+ + "Check the other test results in this test suite.");
+ }
+ // Error occurred when resetting preference.
+ else {
+ result.setReturnCode(TestResult.FAILED);
+ result.setResultMessage("Preferences value was not successfully reset after store");
+ }
+ return result;
+ }
+
+ protected TestResult checkResetPreferenceWithoutDefault(PortletRequest request) {
+ TestResult result = new TestResult();
+ result.setDescription("Ensure preferences are properly reset (removed) "
+ + "when the default value is not defined.");
+ result.setSpecPLT("14.1");
+
+ PortletPreferences preferences = request.getPreferences();
+ boolean setOccured = false;
+ boolean resetOccured = false;
+
+ try {
+ // Set preference value to overwrite the original (null).
+ preferences.setValue(BOGUS_KEY, NEW_VALUE);
+ String value = preferences.getValue(BOGUS_KEY, DEF_VALUE);
+ if (NEW_VALUE.equals(value)) {
+ setOccured = true;
+ }
+ // Reset preference value to null.
+ preferences.reset(BOGUS_KEY);
+ value = preferences.getValue(BOGUS_KEY, DEF_VALUE);
+ if (DEF_VALUE.equals(value)) {
+ resetOccured = true;
+ }
+ } catch (ReadOnlyException ex) {
+ TestUtils.failOnException("Unable to set preference value.", ex, result);
+ return result;
+ }
+
+ // Everything is OK.
+ if (setOccured && resetOccured) {
+ result.setReturnCode(TestResult.PASSED);
+ }
+ // Error occurred when setting or storing preferences.
+ else if (!setOccured) {
+ result.setReturnCode(TestResult.WARNING);
+ result.setResultMessage("A function upon which the reset test "
+ + "depends failed to execute as expected. "
+ + "Check the other test results in this test suite.");
+ }
+ // Error occurred when resetting preference value.
+ else {
+ result.setReturnCode(TestResult.FAILED);
+ result.setResultMessage("Preferences value was not successfully "
+ + "reset after store.");
+ }
+ return result;
+ }
+
+ protected TestResult checkModifyReadOnlyPreferences(PortletRequest request) {
+ TestResult result = new TestResult();
+ result.setDescription("Ensure that setValue() / setValues() / reset() "
+ + "methods throw ReadOnlyException when invoked "
+ + "on read-only preferences.");
+ result.setSpecPLT("14.1");
+
+ PortletPreferences preferences = request.getPreferences();
+ if (!preferences.isReadOnly(READ_ONLY_PREF_NAME)) {
+ result.setReturnCode(TestResult.WARNING);
+ result.setResultMessage("Preference " + READ_ONLY_PREF_NAME
+ + " is not a read-only preference. "
+ + "This may be due to misconfiuration.");
+ return result;
+ }
+
+ boolean setValueOK = false;
+ boolean setValuesOK = false;
+ boolean resetOK = false;
+
+ // Check setValue() method.
+ try {
+ preferences.setValue(READ_ONLY_PREF_NAME, "written");
+ } catch (ReadOnlyException ex) {
+ setValueOK = true;
+ }
+
+ // Check setValues() method.
+ try {
+ preferences.setValues(READ_ONLY_PREF_NAME, new String[] { "written" });
+ } catch (ReadOnlyException ex) {
+ setValuesOK = true;
+ }
+
+ // Check reset() method.
+ try {
+ preferences.reset(READ_ONLY_PREF_NAME);
+ } catch (ReadOnlyException ex) {
+ resetOK = true;
+ }
+
+ if (setValueOK && setValuesOK && resetOK) {
+ result.setReturnCode(TestResult.PASSED);
+ } else {
+ result.setReturnCode(TestResult.FAILED);
+ StringBuffer buffer = new StringBuffer();
+ if (!setValueOK) {
+ buffer.append("setValue(..), ");
+ }
+ if (!setValuesOK) {
+ buffer.append("setValues(..), ");
+ }
+ if (!resetOK) {
+ buffer.append("reset(..), ");
+ }
+ result.setResultMessage("Method(s) [" + buffer.toString()
+ + "] invoked on read-only preference (" + READ_ONLY_PREF_NAME
+ + ") without ReadOnlyException.");
+ }
+ return result;
+ }
+
+ protected TestResult checkGetPreferenceNames(PortletRequest request) {
+ TestResult result = new TestResult();
+ result.setDescription("Ensure returned enumeration is valid.");
+ result.setSpecPLT("14.1");
+
+ PortletPreferences preferences = request.getPreferences();
+ Map prefMap = preferences.getMap();
+ boolean hasAll = true;
+ for (Enumeration en = preferences.getNames(); en.hasMoreElements(); ) {
+ if (!prefMap.containsKey(en.nextElement())) {
+ hasAll = false;
+ break;
+ }
+ }
+
+ if (hasAll) {
+ result.setReturnCode(TestResult.PASSED);
+ } else {
+ result.setReturnCode(TestResult.FAILED);
+ result.setResultMessage("At least one name is not found "
+ + "in the preference map.");
+ }
+ return result;
+ }
+
+ /**
+ * FIXME:
+ */
+ protected TestResult checkGetPreferenceMap(PortletRequest request) {
+ TestResult result = checkGetPreferenceNames(request);
+ result.setDescription("Ensure returned map is valid.");
+ result.setSpecPLT("14.1");
+ return result;
+ }
+
+ /**
+ * Check (xci) SPEC 91, PLT 14.1: Preferences values are not modified
+ * if the values in the Map are altered.
+ */
+ protected TestResult checkPreferenceValueNotModified(PortletRequest request) {
+ TestResult result = new TestResult();
+ result.setDescription("Preferences values are not modified if "
+ + "the values in the returned preference Map are altered.");
+ result.setSpecPLT("14.1");
+
+ PortletPreferences preferences = request.getPreferences();
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Original Preferences:");
+ logPreferences(preferences);
+ }
+
+ // Modify the returned preference map.
+ Map prefMap = preferences.getMap();
+ String[] values = (String[]) prefMap.get(PREF_NAME);
+ String originalValue = null;
+ String modifiedValue = "Value modified in preferences map.";
+ if (values != null && values.length == 1) {
+ originalValue = values[0];
+ values[0] = modifiedValue;
+ }
+
+ // Check if the value held by portlet preferences is modified.
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Modified Preferences:");
+ logPreferences(preferences);
+ }
+ String newValue = preferences.getValue(PREF_NAME, DEF_VALUE);
+ if (newValue != null && newValue.equals(originalValue)) {
+ result.setReturnCode(TestResult.PASSED);
+ } else {
+ result.setReturnCode(TestResult.FAILED);
+ result.setResultMessage("Preference value modified according to "
+ + "the preference map.");
+ }
+ return result;
+ }
+
+
+ // Debug Methods -----------------------------------------------------------
+
+
+ /**
+ * Logs out the portlet preferences.
+ * @param preferences PortletPreferences to log.
+ */
+ protected void logPreferences(PortletPreferences preferences) {
+ StringBuffer buffer = new StringBuffer();
+ Map map = preferences.getMap();
+ for (Iterator it = map.keySet().iterator(); it.hasNext(); ) {
+ String key = (String) it.next();
+ String[] values = (String[]) map.get(key);
+ buffer.append(key).append("=");
+ if (values != null) {
+ buffer.append("{");
+ for (int i = 0; i < values.length; i++) {
+ buffer.append(values[i]);
+ if (i < values.length - 1) {
+ buffer.append(",");
+ }
+ }
+ buffer.append("}");
+ } else {
+ // Spec allows null values.
+ buffer.append("NULL");
+ }
+ buffer.append(";");
+ }
+ LOG.debug("PortletPreferences: " + buffer.toString());
+ }
+
+}
Added: portals/pluto/branches/1.1-286-trunk-merge/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/PreferenceInActionTest.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/1.1-286-trunk-merge/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/PreferenceInActionTest.java?view=auto&rev=562725
==============================================================================
--- portals/pluto/branches/1.1-286-trunk-merge/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/PreferenceInActionTest.java (added)
+++ portals/pluto/branches/1.1-286-trunk-merge/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/PreferenceInActionTest.java Sat Aug 4 07:41:23 2007
@@ -0,0 +1,194 @@
+/*
+ * Copyright 2003,2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pluto.testsuite.test;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.pluto.testsuite.ActionTest;
+import org.apache.pluto.testsuite.TestResult;
+import org.apache.pluto.testsuite.TestUtils;
+import org.apache.pluto.testsuite.validator.PreferencesValidatorImpl;
+
+import java.io.IOException;
+
+import javax.portlet.PortletPreferences;
+import javax.portlet.PortletRequest;
+import javax.portlet.ReadOnlyException;
+import javax.portlet.ValidatorException;
+
+/**
+ * @author <a href="mailto:ddewolf@apache.org">David H. DeWolf</a>
+ * @author <a href="mailto:zheng@apache.org">ZHENG Zhong</a>
+ */
+public class PreferenceInActionTest extends PreferenceCommonTest
+implements ActionTest {
+
+ /** Logger. */
+ private static final Log LOG = LogFactory.getLog(PreferenceInActionTest.class);
+
+
+ // Test Methods ------------------------------------------------------------
+
+ protected TestResult checkPreferenceValidator(PortletRequest request) {
+ TestResult result = new TestResult();
+ result.setDescription("Ensure the validator catches invalid preferences.");
+ result.setSpecPLT("14.4");
+
+ PortletPreferences preferences = request.getPreferences();
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Original preferences:");
+ logPreferences(preferences);
+ }
+ boolean exceptionThrown = false;
+ try {
+ preferences.setValue("TEST", " Spaces removed by trim ");
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Modified VALIDATION_TEST_KEY preference:");
+ logPreferences(preferences);
+ }
+ // Call store() method to invoke the validator.
+ preferences.store();
+
+ } catch (ReadOnlyException ex) {
+ TestUtils.failOnException("Unable to set preference value.", ex, result);
+ return result;
+
+ } catch (IOException ex) {
+ TestUtils.failOnException("Unable to store preference value.", ex, result);
+ return result;
+
+ } catch (ValidatorException ex) {
+ // We are expecting this exception!
+ exceptionThrown = true;
+ // FIXME: what is going on below?
+ try {
+ //get rid of spaces because it causes problems with reset() call.
+ preferences.setValue("TEST", "OK");
+ preferences.reset("TEST");
+ } catch (Throwable th) {
+ LOG.error(th);
+ }
+ }
+
+ if (exceptionThrown) {
+ result.setReturnCode(TestResult.PASSED);
+ } else {
+ result.setReturnCode(TestResult.FAILED);
+ result.setResultMessage("Illegal value not caught by validator.");
+ }
+ return result;
+ }
+
+ protected TestResult checkOnePreferenceValidatorPerPortletDefinition(
+ PortletRequest request) {
+ TestResult result = new TestResult();
+ result.setDescription("Ensure only one validator instance is created "
+ + "per portlet definition.");
+ result.setSpecPLT("14.4");
+
+ PortletPreferences preferences = request.getPreferences();
+ try {
+ preferences.setValue(
+ PreferencesValidatorImpl.CHECK_VALIDATOR_COUNT,
+ "true");
+ // Call store() method to invoke the validator.
+ preferences.store();
+ result.setReturnCode(TestResult.PASSED);
+ } catch (ReadOnlyException ex) {
+ TestUtils.failOnException("Unable to set preference value.", ex, result);
+ } catch (IOException ex) {
+ TestUtils.failOnException("Unable to store preference value.", ex, result);
+ } catch (ValidatorException ex) {
+ TestUtils.failOnException("Unable to store preference value.", ex, result);
+ } finally {
+ try {
+ preferences.reset(PreferencesValidatorImpl.CHECK_VALIDATOR_COUNT);
+ preferences.store();
+ } catch (Exception ex) {
+ TestUtils.failOnException("Unable to reset preference value for "
+ + PreferencesValidatorImpl.CHECK_VALIDATOR_COUNT,
+ ex, result);
+ }
+ }
+ return result;
+ }
+
+ protected TestResult checkStorePreferences(PortletRequest request) {
+ TestResult result = new TestResult();
+ result.setDescription("Ensure storage works for portlet preferences.");
+ result.setSpecPLT("14.1");
+
+ PortletPreferences preferences = request.getPreferences();
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Preferences to store: " + preferences);
+ }
+
+ boolean setOccured = false;
+ boolean storeOccured = false;
+
+ try {
+ // Set new value for preference "dummyName".
+ preferences.setValue(PREF_NAME, NEW_VALUE);
+ String value = preferences.getValue(PREF_NAME, DEF_VALUE);
+ if (NEW_VALUE.equals(value)) {
+ setOccured = true;
+ }
+ // Store the preference and get value.
+ preferences.store();
+ value = preferences.getValue(PREF_NAME, DEF_VALUE);
+ if (NEW_VALUE.equals(value)) {
+ storeOccured = true;
+ }
+ } catch (ReadOnlyException ex) {
+ TestUtils.failOnException("Unable to set preference value.", ex, result);
+ return result;
+ } catch (ValidatorException ex) {
+ TestUtils.failOnException("Unable to store preference value.", ex, result);
+ return result;
+ } catch(IOException ex) {
+ TestUtils.failOnException("Unable to store preference value.", ex, result);
+ return result;
+ } finally {
+ // Reset preference to default value, and store!
+ try {
+ preferences.reset(PREF_NAME);
+ preferences.store();
+ } catch (Exception ex) {
+ TestUtils.failOnException("Unable to set preference value.", ex, result);
+ return result;
+ }
+ }
+
+ // Everything is OK.
+ if (setOccured && storeOccured) {
+ result.setReturnCode(TestResult.PASSED);
+ }
+ // Error occurred when setting preference value.
+ else if (!setOccured) {
+ result.setReturnCode(TestResult.WARNING);
+ result.setResultMessage("A function upon which the reset test "
+ + "depends failed to execute as expected. "
+ + "Check the other test results in this test suite.");
+ }
+ // Error occurred when storing preference value.
+ else {
+ result.setReturnCode(TestResult.FAILED);
+ result.setResultMessage("Preferences not successfully stored.");
+ }
+ return result;
+ }
+
+}
Added: portals/pluto/branches/1.1-286-trunk-merge/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/PreferenceInRenderTest.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/1.1-286-trunk-merge/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/PreferenceInRenderTest.java?view=auto&rev=562725
==============================================================================
--- portals/pluto/branches/1.1-286-trunk-merge/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/PreferenceInRenderTest.java (added)
+++ portals/pluto/branches/1.1-286-trunk-merge/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/PreferenceInRenderTest.java Sat Aug 4 07:41:23 2007
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2003,2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pluto.testsuite.test;
+
+import java.io.IOException;
+
+import javax.portlet.PortletPreferences;
+import javax.portlet.PortletRequest;
+import javax.portlet.ValidatorException;
+
+import org.apache.pluto.testsuite.TestResult;
+import org.apache.pluto.testsuite.TestUtils;
+
+public class PreferenceInRenderTest extends PreferenceCommonTest {
+
+ // Test Methods ------------------------------------------------------------
+
+ protected TestResult checkStorePreferences(PortletRequest request) {
+ TestResult result = new TestResult();
+ result.setDescription("Ensure that if the store() method is invoked "
+ + "within render() method, an IllegalStateException will be "
+ + "thrown out.");
+ result.setSpecPLT("14.1");
+
+ PortletPreferences preferences = request.getPreferences();
+ boolean exceptionThrown = false;
+
+ // Store preferences and wait for IllegalStateException.
+ try {
+ preferences.store();
+ } catch (ValidatorException ex) {
+ TestUtils.failOnException("Unable to store preferences.", ex, result);
+ return result;
+ } catch (IOException ex) {
+ TestUtils.failOnException("Unable to store preferences.", ex, result);
+ return result;
+ } catch (IllegalStateException ex) {
+ exceptionThrown = true;
+ }
+
+ if (exceptionThrown) {
+ result.setReturnCode(TestResult.PASSED);
+ } else {
+ result.setReturnCode(TestResult.FAILED);
+ result.setResultMessage("IllegalStateException is not thrown out "
+ + "when store() method is invoked within render() method.");
+ }
+ return result;
+ }
+
+}