geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jb...@apache.org
Subject svn commit: r559986 [3/7] - in /geronimo/sandbox/portals: pluto-portal/src/assemble/ pluto-portal/src/assemble/config/ pluto-portal/src/main/resources/ pluto-portal/src/main/webapp/ pluto-portal/src/main/webapp/WEB-INF/ pluto-portal/src/main/webapp/WEB...
Date Thu, 26 Jul 2007 21:22:14 GMT
Modified: geronimo/sandbox/portals/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/TestResults.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/portals/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/TestResults.java?view=diff&rev=559986&r1=559985&r2=559986
==============================================================================
--- geronimo/sandbox/portals/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/TestResults.java (original)
+++ geronimo/sandbox/portals/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/TestResults.java Thu Jul 26 14:22:10 2007
@@ -1,85 +1,85 @@
-/*
+/*
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
  * this work for additional information regarding copyright ownership.
  * The ASF licenses this file to You 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;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-
-/**
- * This class contains one or more test results.
- */
-public class TestResults implements Serializable {
-
-
-    private String name;
-
-    private ArrayList list = new ArrayList();
-
-    private boolean failed = false;
-    private boolean inQuestion = false;
-
-    public TestResults(String name) {
-        this.name = name;
-    }
-
-    public String getName() {
-        return name;
-    }
-
-    public void setName(String name) {
-        this.name = name;
-    }
-
-    public void add(TestResult result) {
-        if (result.getReturnCode() == TestResult.FAILED) {
-            failed = true;
-        } else if (result.getReturnCode() == TestResult.WARNING) {
-            inQuestion = true;
-        }
-        list.add(result);
-    }
-
-    public boolean isFailed() {
-        return failed;
-    }
-
-    public boolean isInQuestion() {
-        return inQuestion;
-    }
-
-    public Collection getCollection() {
-        return Collections.unmodifiableCollection(list);
-    }
-
-    /**
-     * Override of toString() that prints out variable
-     * names and values.
-     *
-     * @see java.lang.Object#toString()
-     */
-    public String toString(){
-    	StringBuffer buffer = new StringBuffer();
-    	buffer.append(getClass().getName());
-    	buffer.append("[name=").append(name);
-    	buffer.append(";failed=").append(failed);
-    	buffer.append(";inQuestion=").append(inQuestion);
-    	buffer.append(";results={").append(list).append("}]");
-    	return buffer.toString();
-    }
-}
+ * 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;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+
+/**
+ * This class contains one or more test results.
+ */
+public class TestResults implements Serializable {
+
+
+    private String name;
+
+    private ArrayList list = new ArrayList();
+
+    private boolean failed = false;
+    private boolean inQuestion = false;
+
+    public TestResults(String name) {
+        this.name = name;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public void add(TestResult result) {
+        if (result.getReturnCode() == TestResult.FAILED) {
+            failed = true;
+        } else if (result.getReturnCode() == TestResult.WARNING) {
+            inQuestion = true;
+        }
+        list.add(result);
+    }
+
+    public boolean isFailed() {
+        return failed;
+    }
+
+    public boolean isInQuestion() {
+        return inQuestion;
+    }
+
+    public Collection getCollection() {
+        return Collections.unmodifiableCollection(list);
+    }
+
+    /**
+     * Override of toString() that prints out variable
+     * names and values.
+     *
+     * @see java.lang.Object#toString()
+     */
+    public String toString(){
+    	StringBuffer buffer = new StringBuffer();
+    	buffer.append(getClass().getName());
+    	buffer.append("[name=").append(name);
+    	buffer.append(";failed=").append(failed);
+    	buffer.append(";inQuestion=").append(inQuestion);
+    	buffer.append(";results={").append(list).append("}]");
+    	return buffer.toString();
+    }
+}

Propchange: geronimo/sandbox/portals/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/TestResults.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: geronimo/sandbox/portals/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/TestUtils.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/portals/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/TestUtils.java?view=diff&rev=559986&r1=559985&r2=559986
==============================================================================
--- geronimo/sandbox/portals/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/TestUtils.java (original)
+++ geronimo/sandbox/portals/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/TestUtils.java Thu Jul 26 14:22:10 2007
@@ -1,138 +1,138 @@
-/*
+/*
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
  * this work for additional information regarding copyright ownership.
  * The ASF licenses this file to You 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;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * Static class that provides utility methods for Pluto testsuite.
- * @since 2006-02-13
- */
-public class TestUtils {
-
-	/** Logger. */
-	private static final Log LOG = LogFactory.getLog(TestUtils.class);
-
-
-	// Private Constructor -----------------------------------------------------
-
-	/**
-	 * Private method that prevents external instantiation.
-	 */
-	private TestUtils() {
-		// Do nothing.
-	}
-
-
-	// Public Static Methods ---------------------------------------------------
-
-	/**
-	 * Sets the test result return code to <code>FAILED</code>, and reports
-	 * assertion details by specifying values got and values expected.
-	 * @param valueName  the name of the values to assert.
-	 * @param valueGot  the values got.
-	 * @param valueExpected  the values expected.
-	 * @param result  the test result.
-	 */
-	public static void failOnAssertion(String valuesName,
-	                                   String[] valuesGot,
-	                                   String[] valuesExpected,
-	                                   TestResult result) {
-		failOnAssertion(valuesName,
-		                arrayToString(valuesGot),
-		                arrayToString(valuesExpected),
-		                result);
-	}
-
-	/**
-	 * Sets the test result return code to <code>FAILED</code>, and reports
-	 * assertion details by specifying value got and value expected.
-	 * @param valueName  the name of the value to assert.
-	 * @param valueGot  the value object got.
-	 * @param valueExpected  the value object expected.
-	 * @param result  the test result.
-	 */
-	public static void failOnAssertion(String valueName,
-	                                   Object valueGot,
-	                                   Object valueExpected,
-	                                   TestResult result) {
-		StringBuffer buffer = new StringBuffer();
-		buffer.append("Assertion failed: ");
-		buffer.append("got ").append(valueName).append(": ").append(valueGot);
-		buffer.append(", expected: ").append(valueExpected);
-    	result.setReturnCode(TestResult.FAILED);
-    	result.setResultMessage(buffer.toString());
-	}
-
-    /**
-     * Sets the test result return code to <code>FAILED</code>, and reports
-     * exception details.
-     * @param message  the error message.
-     * @param cause  the cause exception.
-     * @param result  the test result.
-     */
-    public static void failOnException(String message,
-                                       Throwable cause,
-                                       TestResult result) {
-    	// Construct error message.
-    	StringBuffer buffer = new StringBuffer();
-    	if (message != null) {
-    		buffer.append(message);
-    	} else {
-    		buffer.append("Exception occurred.");
-    	}
-    	buffer.append(" Cause (").append(cause.getClass().getName()).append("): ");
-    	buffer.append(cause.getMessage());
-
-    	// Log error message.
-    	if (LOG.isErrorEnabled()) {
-    		LOG.error(buffer.toString(), cause);
-    	}
-
-    	// Set error message to test result.
-    	result.setReturnCode(TestResult.FAILED);
-    	result.setResultMessage(buffer.toString());
-    }
-
-
-    // Private Static Methods --------------------------------------------------
-
-    /**
-     * Converts a string array to a string.
-     * @param values  the string array to convert.
-     * @return a string representing the values in the string array.
-     */
-    private static String arrayToString(String[] values) {
-		StringBuffer buffer = new StringBuffer();
-		if (values == null) {
-			buffer.append("null");
-		} else {
-			buffer.append("{");
-			for (int i = 0; i < values.length; i++) {
-				buffer.append(values[i]);
-				if (i < values.length - 1) {
-					buffer.append(",");
-				}
-			}
-			buffer.append("}");
-		}
-    	return buffer.toString();
-    }
-
-
-}
+ * 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;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Static class that provides utility methods for Pluto testsuite.
+ * @since 2006-02-13
+ */
+public class TestUtils {
+
+	/** Logger. */
+	private static final Log LOG = LogFactory.getLog(TestUtils.class);
+
+
+	// Private Constructor -----------------------------------------------------
+
+	/**
+	 * Private method that prevents external instantiation.
+	 */
+	private TestUtils() {
+		// Do nothing.
+	}
+
+
+	// Public Static Methods ---------------------------------------------------
+
+	/**
+	 * Sets the test result return code to <code>FAILED</code>, and reports
+	 * assertion details by specifying values got and values expected.
+	 * @param valueName  the name of the values to assert.
+	 * @param valueGot  the values got.
+	 * @param valueExpected  the values expected.
+	 * @param result  the test result.
+	 */
+	public static void failOnAssertion(String valuesName,
+	                                   String[] valuesGot,
+	                                   String[] valuesExpected,
+	                                   TestResult result) {
+		failOnAssertion(valuesName,
+		                arrayToString(valuesGot),
+		                arrayToString(valuesExpected),
+		                result);
+	}
+
+	/**
+	 * Sets the test result return code to <code>FAILED</code>, and reports
+	 * assertion details by specifying value got and value expected.
+	 * @param valueName  the name of the value to assert.
+	 * @param valueGot  the value object got.
+	 * @param valueExpected  the value object expected.
+	 * @param result  the test result.
+	 */
+	public static void failOnAssertion(String valueName,
+	                                   Object valueGot,
+	                                   Object valueExpected,
+	                                   TestResult result) {
+		StringBuffer buffer = new StringBuffer();
+		buffer.append("Assertion failed: ");
+		buffer.append("got ").append(valueName).append(": ").append(valueGot);
+		buffer.append(", expected: ").append(valueExpected);
+    	result.setReturnCode(TestResult.FAILED);
+    	result.setResultMessage(buffer.toString());
+	}
+
+    /**
+     * Sets the test result return code to <code>FAILED</code>, and reports
+     * exception details.
+     * @param message  the error message.
+     * @param cause  the cause exception.
+     * @param result  the test result.
+     */
+    public static void failOnException(String message,
+                                       Throwable cause,
+                                       TestResult result) {
+    	// Construct error message.
+    	StringBuffer buffer = new StringBuffer();
+    	if (message != null) {
+    		buffer.append(message);
+    	} else {
+    		buffer.append("Exception occurred.");
+    	}
+    	buffer.append(" Cause (").append(cause.getClass().getName()).append("): ");
+    	buffer.append(cause.getMessage());
+
+    	// Log error message.
+    	if (LOG.isErrorEnabled()) {
+    		LOG.error(buffer.toString(), cause);
+    	}
+
+    	// Set error message to test result.
+    	result.setReturnCode(TestResult.FAILED);
+    	result.setResultMessage(buffer.toString());
+    }
+
+
+    // Private Static Methods --------------------------------------------------
+
+    /**
+     * Converts a string array to a string.
+     * @param values  the string array to convert.
+     * @return a string representing the values in the string array.
+     */
+    private static String arrayToString(String[] values) {
+		StringBuffer buffer = new StringBuffer();
+		if (values == null) {
+			buffer.append("null");
+		} else {
+			buffer.append("{");
+			for (int i = 0; i < values.length; i++) {
+				buffer.append(values[i]);
+				if (i < values.length - 1) {
+					buffer.append(",");
+				}
+			}
+			buffer.append("}");
+		}
+    	return buffer.toString();
+    }
+
+
+}

Propchange: geronimo/sandbox/portals/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/TestUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: geronimo/sandbox/portals/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/AbstractReflectivePortletTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/portals/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/AbstractReflectivePortletTest.java?view=diff&rev=559986&r1=559985&r2=559986
==============================================================================
--- geronimo/sandbox/portals/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/AbstractReflectivePortletTest.java (original)
+++ geronimo/sandbox/portals/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/AbstractReflectivePortletTest.java Thu Jul 26 14:22:10 2007
@@ -1,235 +1,235 @@
-/*
+/*
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
  * this work for additional information regarding copyright ownership.
  * The ASF licenses this file to You 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.TestConfig;
-import org.apache.pluto.testsuite.PortletTest;
-import org.apache.pluto.testsuite.TestResult;
-import org.apache.pluto.testsuite.TestResults;
-
-import javax.portlet.PortletResponse;
-import javax.portlet.PortletRequest;
-import javax.portlet.PortletContext;
-import javax.portlet.PortletConfig;
-import javax.portlet.PortletSession;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.HashMap;
-
-/**
- */
-public abstract class AbstractReflectivePortletTest implements PortletTest {
-
-	/** Logger. */
-	private static final Log LOG = LogFactory.getLog(
-			AbstractReflectivePortletTest.class);
-
-    private Map initParameters;
-    private TestConfig config;
-
-
-    // PortletTest Impl --------------------------------------------------------
-
-    public void init(TestConfig config) {
-        this.config = config;
-        this.initParameters = config.getInitParameters();
-    }
-
-    /**
-     * Returns the render parameters that will be set into the render request.
-     * The default implementation just returns an empty Map object. This method
-     * may be overwritten by some concrete test to provide test-specific render
-     * parameters.
-     * @param request  the portlet request.
-     * @return an empty Map object.
-     */
-    public Map getRenderParameters(PortletRequest request) {
-        return new HashMap();
-    }
-
-    public TestConfig getConfig() {
-        return config;
-    }
-
-    /**
-     * Returns the test suite name. The test suite name is the portlet test
-     * class name without package name prefix.
-     * @return the test suite name.
-     */
-    public String getTestSuiteName() {
-    	String className = getClass().getName();
-    	int index = className.lastIndexOf(".");
-    	if (index >= 0 && index < className.length() - 1) {
-    		return className.substring(index + 1);
-    	} else {
-    		return className;
-    	}
-    }
-
-    /**
-     * Invoke test methods using java reflection. All 'check*' methods are
-     * invoked and test results are saved into <code>TestResults</code> object.
-     * @param config  the portlet config.
-     * @param context  the portlet context.
-     * @param request  the portlet request.
-     * @param response  the portlet response.
-     * @return the test results including several TestResult instances.
-     */
-    public TestResults doTest(PortletConfig config,
-                              PortletContext context,
-                              PortletRequest request,
-                              PortletResponse response) {
-        TestResults results = new TestResults(getTestSuiteName());
-
-        for (Iterator it = getCheckMethods().iterator(); it.hasNext(); ) {
-        	Method method = (Method) it.next();
-        	debugWithName("Invoking test method: " + method.getName());
-        	try {
-        		TestResult result = invoke(method, config, context, request, response);
-        		if (result.getName() == null) {
-        			result.setName(method.getName());
-        		}
-        		results.add(result);
-        		debugWithName("Result: " + result.getReturnCodeAsString());
-        	} catch (Throwable th) {
-        		String message = "Error invoking " + method.getName()
-        				+ " (" + th.getClass().getName() + "): "
-        				+ th.getMessage();
-        		errorWithName(message, th);
-        		TestResult result = new TestResult();
-        		result.setName(method.getName());
-        		result.setReturnCode(TestResult.FAILED);
-        		result.setResultMessage(message);
-        		results.add(result);
-            }
-        }
-
-        return results;
-    }
-
-
-    // Protected Methods -------------------------------------------------------
-
-    protected Map getInitParameters() {
-        return initParameters;
-    }
-
-
-    // Private Methods ---------------------------------------------------------
-
-    private void debugWithName(String message) {
-    	if (LOG.isDebugEnabled()) {
-    		LOG.debug("Test [" + getTestSuiteName() + "]: " + message);
-    	}
-    }
-
-    private void errorWithName(String message, Throwable cause) {
-    	if (LOG.isErrorEnabled()) {
-    		LOG.error("Test [" + getTestSuiteName() + "]: " + message, cause);
-    	}
-    }
-
-    /**
-     * Returns check methods to run as tests using java reflection.
-     * The following rules are applied to select check methods:
-     * <ul>
-     *   <li>methods declared in this class or inherited from super class</li>
-     *   <li>methods with modifier 'public' or 'protected', but not 'abstract'</li>
-     *   <li>methods that starts with <code>check</code></li>
-     * </ul>
-     * @return a list of check methods.
-     */
-    private List getCheckMethods() {
-    	List checkMethods = new ArrayList();
-    	for (Class clazz = getClass();
-    			clazz != null && AbstractReflectivePortletTest.class.isAssignableFrom(clazz);
-    			clazz = clazz.getSuperclass()) {
-    		// debugWithName("Checking class: " + clazz.getName());
-    		Method[] methods = clazz.getDeclaredMethods();
-    		for (int i = 0; i < methods.length; i++) {
-    			int mod = methods[i].getModifiers();
-    			if ((Modifier.isPublic(mod) || Modifier.isProtected(mod))
-    					&& !Modifier.isAbstract(mod)
-    					&& methods[i].getName().startsWith("check")) {
-    				// debugWithName(" - got check method: " + methods[i].getName());
-    				checkMethods.add(methods[i]);
-    			}
-    		}
-    	}
-        return checkMethods;
-    }
-
-    /**
-     * Invokes the test method ('<code>check*</code>') by preparing method
-     * parameters. A test method may accept the following types of parameters:
-     * <ul>
-     *   <li><code>javax.portlet.PortletConfig</code></li>
-     *   <li><code>javax.portlet.PortletContext</code></li>
-     *   <li><code>javax.portlet.PortletRequest</code></li>
-     *   <li><code>javax.portlet.PortletResponse</code></li>
-     *   <li><code>javax.portlet.PortletSession</code></li>
-     * </ul>
-     */
-    private TestResult invoke(Method method,
-                              PortletConfig config,
-                              PortletContext context,
-                              PortletRequest request,
-                              PortletResponse response)
-    throws IllegalAccessException, InvocationTargetException {
-
-        Class[] paramTypes = method.getParameterTypes();
-        Object[] paramValues = new Object[paramTypes.length];
-
-        for (int i = 0; i < paramTypes.length; i++) {
-            if (paramTypes[i].equals(PortletConfig.class)) {
-                paramValues[i] = config;
-            } else if (paramTypes[i].equals(PortletContext.class)) {
-                paramValues[i] = context;
-            } else if (paramTypes[i].equals(PortletRequest.class)) {
-                paramValues[i] = request;
-            } else if (paramTypes[i].equals(PortletResponse.class)) {
-                paramValues[i] = response;
-            } else if (paramTypes[i].equals(PortletSession.class)) {
-                paramValues[i] = request.getPortletSession();
-            }
-        }
-        TestResult result = (TestResult) method.invoke(this, paramValues);
-        return result;
-    }
-
-
-    // Object Methods ----------------------------------------------------------
-
-    /**
-     * Override of toString() that prints out names and values of variables.
-     * @see java.lang.Object#toString()
-     */
-    public String toString(){
-    	StringBuffer buffer = new StringBuffer();
-    	buffer.append(getClass().getName());
-    	buffer.append("[initParameters=").append(initParameters);
-    	buffer.append(";config=").append(config).append("]");
-    	return buffer.toString();
-    }
-}
+ * 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.TestConfig;
+import org.apache.pluto.testsuite.PortletTest;
+import org.apache.pluto.testsuite.TestResult;
+import org.apache.pluto.testsuite.TestResults;
+
+import javax.portlet.PortletResponse;
+import javax.portlet.PortletRequest;
+import javax.portlet.PortletContext;
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletSession;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ */
+public abstract class AbstractReflectivePortletTest implements PortletTest {
+
+	/** Logger. */
+	private static final Log LOG = LogFactory.getLog(
+			AbstractReflectivePortletTest.class);
+
+    private Map initParameters;
+    private TestConfig config;
+
+
+    // PortletTest Impl --------------------------------------------------------
+
+    public void init(TestConfig config) {
+        this.config = config;
+        this.initParameters = config.getInitParameters();
+    }
+
+    /**
+     * Returns the render parameters that will be set into the render request.
+     * The default implementation just returns an empty Map object. This method
+     * may be overwritten by some concrete test to provide test-specific render
+     * parameters.
+     * @param request  the portlet request.
+     * @return an empty Map object.
+     */
+    public Map getRenderParameters(PortletRequest request) {
+        return new HashMap();
+    }
+
+    public TestConfig getConfig() {
+        return config;
+    }
+
+    /**
+     * Returns the test suite name. The test suite name is the portlet test
+     * class name without package name prefix.
+     * @return the test suite name.
+     */
+    public String getTestSuiteName() {
+    	String className = getClass().getName();
+    	int index = className.lastIndexOf(".");
+    	if (index >= 0 && index < className.length() - 1) {
+    		return className.substring(index + 1);
+    	} else {
+    		return className;
+    	}
+    }
+
+    /**
+     * Invoke test methods using java reflection. All 'check*' methods are
+     * invoked and test results are saved into <code>TestResults</code> object.
+     * @param config  the portlet config.
+     * @param context  the portlet context.
+     * @param request  the portlet request.
+     * @param response  the portlet response.
+     * @return the test results including several TestResult instances.
+     */
+    public TestResults doTest(PortletConfig config,
+                              PortletContext context,
+                              PortletRequest request,
+                              PortletResponse response) {
+        TestResults results = new TestResults(getTestSuiteName());
+
+        for (Iterator it = getCheckMethods().iterator(); it.hasNext(); ) {
+        	Method method = (Method) it.next();
+        	debugWithName("Invoking test method: " + method.getName());
+        	try {
+        		TestResult result = invoke(method, config, context, request, response);
+        		if (result.getName() == null) {
+        			result.setName(method.getName());
+        		}
+        		results.add(result);
+        		debugWithName("Result: " + result.getReturnCodeAsString());
+        	} catch (Throwable th) {
+        		String message = "Error invoking " + method.getName()
+        				+ " (" + th.getClass().getName() + "): "
+        				+ th.getMessage();
+        		errorWithName(message, th);
+        		TestResult result = new TestResult();
+        		result.setName(method.getName());
+        		result.setReturnCode(TestResult.FAILED);
+        		result.setResultMessage(message);
+        		results.add(result);
+            }
+        }
+
+        return results;
+    }
+
+
+    // Protected Methods -------------------------------------------------------
+
+    protected Map getInitParameters() {
+        return initParameters;
+    }
+
+
+    // Private Methods ---------------------------------------------------------
+
+    private void debugWithName(String message) {
+    	if (LOG.isDebugEnabled()) {
+    		LOG.debug("Test [" + getTestSuiteName() + "]: " + message);
+    	}
+    }
+
+    private void errorWithName(String message, Throwable cause) {
+    	if (LOG.isErrorEnabled()) {
+    		LOG.error("Test [" + getTestSuiteName() + "]: " + message, cause);
+    	}
+    }
+
+    /**
+     * Returns check methods to run as tests using java reflection.
+     * The following rules are applied to select check methods:
+     * <ul>
+     *   <li>methods declared in this class or inherited from super class</li>
+     *   <li>methods with modifier 'public' or 'protected', but not 'abstract'</li>
+     *   <li>methods that starts with <code>check</code></li>
+     * </ul>
+     * @return a list of check methods.
+     */
+    private List getCheckMethods() {
+    	List checkMethods = new ArrayList();
+    	for (Class clazz = getClass();
+    			clazz != null && AbstractReflectivePortletTest.class.isAssignableFrom(clazz);
+    			clazz = clazz.getSuperclass()) {
+    		// debugWithName("Checking class: " + clazz.getName());
+    		Method[] methods = clazz.getDeclaredMethods();
+    		for (int i = 0; i < methods.length; i++) {
+    			int mod = methods[i].getModifiers();
+    			if ((Modifier.isPublic(mod) || Modifier.isProtected(mod))
+    					&& !Modifier.isAbstract(mod)
+    					&& methods[i].getName().startsWith("check")) {
+    				// debugWithName(" - got check method: " + methods[i].getName());
+    				checkMethods.add(methods[i]);
+    			}
+    		}
+    	}
+        return checkMethods;
+    }
+
+    /**
+     * Invokes the test method ('<code>check*</code>') by preparing method
+     * parameters. A test method may accept the following types of parameters:
+     * <ul>
+     *   <li><code>javax.portlet.PortletConfig</code></li>
+     *   <li><code>javax.portlet.PortletContext</code></li>
+     *   <li><code>javax.portlet.PortletRequest</code></li>
+     *   <li><code>javax.portlet.PortletResponse</code></li>
+     *   <li><code>javax.portlet.PortletSession</code></li>
+     * </ul>
+     */
+    private TestResult invoke(Method method,
+                              PortletConfig config,
+                              PortletContext context,
+                              PortletRequest request,
+                              PortletResponse response)
+    throws IllegalAccessException, InvocationTargetException {
+
+        Class[] paramTypes = method.getParameterTypes();
+        Object[] paramValues = new Object[paramTypes.length];
+
+        for (int i = 0; i < paramTypes.length; i++) {
+            if (paramTypes[i].equals(PortletConfig.class)) {
+                paramValues[i] = config;
+            } else if (paramTypes[i].equals(PortletContext.class)) {
+                paramValues[i] = context;
+            } else if (paramTypes[i].equals(PortletRequest.class)) {
+                paramValues[i] = request;
+            } else if (paramTypes[i].equals(PortletResponse.class)) {
+                paramValues[i] = response;
+            } else if (paramTypes[i].equals(PortletSession.class)) {
+                paramValues[i] = request.getPortletSession();
+            }
+        }
+        TestResult result = (TestResult) method.invoke(this, paramValues);
+        return result;
+    }
+
+
+    // Object Methods ----------------------------------------------------------
+
+    /**
+     * Override of toString() that prints out names and values of variables.
+     * @see java.lang.Object#toString()
+     */
+    public String toString(){
+    	StringBuffer buffer = new StringBuffer();
+    	buffer.append(getClass().getName());
+    	buffer.append("[initParameters=").append(initParameters);
+    	buffer.append(";config=").append(config).append("]");
+    	return buffer.toString();
+    }
+}

Propchange: geronimo/sandbox/portals/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/AbstractReflectivePortletTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: geronimo/sandbox/portals/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/ActionParameterTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/portals/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/ActionParameterTest.java?view=diff&rev=559986&r1=559985&r2=559986
==============================================================================
--- geronimo/sandbox/portals/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/ActionParameterTest.java (original)
+++ geronimo/sandbox/portals/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/ActionParameterTest.java Thu Jul 26 14:22:10 2007
@@ -1,96 +1,96 @@
-/*
+/*
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
  * this work for additional information regarding copyright ownership.
  * The ASF licenses this file to You 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.pluto.testsuite.ActionTest;
-import org.apache.pluto.testsuite.TestResult;
-import org.apache.pluto.testsuite.TestUtils;
-
-import java.util.Enumeration;
-import java.util.Map;
-
-import javax.portlet.PortletRequest;
-
-/**
- */
-public class ActionParameterTest extends AbstractReflectivePortletTest
-implements ActionTest {
-
-	/** Parameter key encoded in the action URL. */
-    public static final String KEY = "org.apache.pluto.testsuite.PARAM_ACTION_KEY";
-
-    /** Parameter value encoded in the action URL. */
-    public static final String VALUE = "org.apache.pluto.testsuite.ACTION_VALUE";
-
-
-    // Test Methods ------------------------------------------------------------
-
-    protected TestResult checkGetActionParameter(PortletRequest request) {
-        TestResult result = new TestResult();
-        result.setDescription("Ensure parameters encoded in action URL are "
-        		+ "available in the action request.");
-
-        String value = request.getParameter(KEY);
-        if (value != null && value.equals(VALUE)) {
-        	result.setReturnCode(TestResult.PASSED);
-        } else {
-        	TestUtils.failOnAssertion("parameter", value, VALUE, result);
-        }
-        return result;
-    }
-
-    protected TestResult checkGetActionParamerMap(PortletRequest request) {
-        TestResult result = new TestResult();
-        result.setDescription("Ensure parameters encoded in action URL are "
-        		+ "available in the action request parameter map.");
-
-        Map parameterMap = request.getParameterMap();
-        String[] values = (String[]) parameterMap.get(KEY);
-        if (values != null && values.length == 1 && VALUE.equals(values[0])) {
-        	result.setReturnCode(TestResult.PASSED);
-        } else {
-        	TestUtils.failOnAssertion("parameter values",
-        			values, new String[] { VALUE }, result);
-        }
-        return result;
-    }
-
-    protected TestResult checkParameterNames(PortletRequest request) {
-        TestResult result = new TestResult();
-        result.setDescription("Ensure parameters encoded in action URL "
-        		+ "exists in the parameter name enumeration.");
-
-        boolean hasParameterName = false;
-        for (Enumeration en = request.getParameterNames();
-        		!hasParameterName && en.hasMoreElements(); ) {
-        	String name = (String) en.nextElement();
-        	if (KEY.equals(name)) {
-        		hasParameterName = true;
-        	}
-        }
-
-        if (hasParameterName) {
-        	result.setReturnCode(TestResult.PASSED);
-        } else {
-        	result.setReturnCode(TestResult.FAILED);
-        	result.setResultMessage("Parameter name " + KEY
-        			+ " not found in parameter name enumeration.");
-        }
-        return result;
-    }
-
-}
+ * 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.pluto.testsuite.ActionTest;
+import org.apache.pluto.testsuite.TestResult;
+import org.apache.pluto.testsuite.TestUtils;
+
+import java.util.Enumeration;
+import java.util.Map;
+
+import javax.portlet.PortletRequest;
+
+/**
+ */
+public class ActionParameterTest extends AbstractReflectivePortletTest
+implements ActionTest {
+
+	/** Parameter key encoded in the action URL. */
+    public static final String KEY = "org.apache.pluto.testsuite.PARAM_ACTION_KEY";
+
+    /** Parameter value encoded in the action URL. */
+    public static final String VALUE = "org.apache.pluto.testsuite.ACTION_VALUE";
+
+
+    // Test Methods ------------------------------------------------------------
+
+    protected TestResult checkGetActionParameter(PortletRequest request) {
+        TestResult result = new TestResult();
+        result.setDescription("Ensure parameters encoded in action URL are "
+        		+ "available in the action request.");
+
+        String value = request.getParameter(KEY);
+        if (value != null && value.equals(VALUE)) {
+        	result.setReturnCode(TestResult.PASSED);
+        } else {
+        	TestUtils.failOnAssertion("parameter", value, VALUE, result);
+        }
+        return result;
+    }
+
+    protected TestResult checkGetActionParamerMap(PortletRequest request) {
+        TestResult result = new TestResult();
+        result.setDescription("Ensure parameters encoded in action URL are "
+        		+ "available in the action request parameter map.");
+
+        Map parameterMap = request.getParameterMap();
+        String[] values = (String[]) parameterMap.get(KEY);
+        if (values != null && values.length == 1 && VALUE.equals(values[0])) {
+        	result.setReturnCode(TestResult.PASSED);
+        } else {
+        	TestUtils.failOnAssertion("parameter values",
+        			values, new String[] { VALUE }, result);
+        }
+        return result;
+    }
+
+    protected TestResult checkParameterNames(PortletRequest request) {
+        TestResult result = new TestResult();
+        result.setDescription("Ensure parameters encoded in action URL "
+        		+ "exists in the parameter name enumeration.");
+
+        boolean hasParameterName = false;
+        for (Enumeration en = request.getParameterNames();
+        		!hasParameterName && en.hasMoreElements(); ) {
+        	String name = (String) en.nextElement();
+        	if (KEY.equals(name)) {
+        		hasParameterName = true;
+        	}
+        }
+
+        if (hasParameterName) {
+        	result.setReturnCode(TestResult.PASSED);
+        } else {
+        	result.setReturnCode(TestResult.FAILED);
+        	result.setResultMessage("Parameter name " + KEY
+        			+ " not found in parameter name enumeration.");
+        }
+        return result;
+    }
+
+}

Propchange: geronimo/sandbox/portals/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/ActionParameterTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: geronimo/sandbox/portals/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/AppScopedSessionAttributeTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/portals/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/AppScopedSessionAttributeTest.java?view=diff&rev=559986&r1=559985&r2=559986
==============================================================================
--- geronimo/sandbox/portals/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/AppScopedSessionAttributeTest.java (original)
+++ geronimo/sandbox/portals/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/AppScopedSessionAttributeTest.java Thu Jul 26 14:22:10 2007
@@ -1,86 +1,86 @@
-/*
+/*
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
  * this work for additional information regarding copyright ownership.
  * The ASF licenses this file to You 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.pluto.testsuite.TestResult;
-import org.apache.pluto.testsuite.TestUtils;
-
-import javax.portlet.PortletSession;
-
-/**
- */
-public class AppScopedSessionAttributeTest
-extends AbstractReflectivePortletTest {
-
-    private static final String BOGUS_KEY = "org.apache.pluto.testsuite.BOGUS_KEY";
-    private static final String KEY = "org.apache.pluto.testsuite.KEY";
-    private static final String VALUE = "VALUE";
-
-
-    // Test Methods ------------------------------------------------------------
-
-    protected TestResult checkGetEmptyAppScopedAttribute(PortletSession session) {
-        TestResult result = new TestResult();
-        result.setDescription("Retrieve an attribute that has not been set "
-        		+ "in the session's application scope "
-        		+ "and ensure it's value is null.");
-        result.setSpecPLT("15.3");
-
-        Object value = session.getAttribute(BOGUS_KEY, PortletSession.APPLICATION_SCOPE);
-        if (value == null) {
-        	result.setReturnCode(TestResult.PASSED);
-        } else {
-        	TestUtils.failOnAssertion("session attribute", value, null, result);
-        }
-        return result;
-    }
-
-    protected TestResult checkSetAppScopedAttribute(PortletSession session) {
-        TestResult result = new TestResult();
-        result.setDescription("Set an application scoped session attribute "
-        		+ "and ensure it's retrievable.");
-        result.setSpecPLT("15.3");
-
-        session.setAttribute(KEY, VALUE, PortletSession.APPLICATION_SCOPE);
-        Object value = session.getAttribute(KEY, PortletSession.APPLICATION_SCOPE);
-        if (VALUE.equals(value)) {
-        	result.setReturnCode(TestResult.PASSED);
-        } else {
-        	TestUtils.failOnAssertion("session attribute", value, VALUE, result);
-        }
-        return result;
-    }
-
-    protected TestResult checkRemoveAppScopedAttribute(PortletSession session) {
-        TestResult result = new TestResult();
-        result.setDescription("Remove an application scoped session attribute "
-        		+ "and ensure it's null.");
-        result.setSpecPLT("15.3");
-
-        session.setAttribute(KEY, VALUE, PortletSession.APPLICATION_SCOPE);
-        session.removeAttribute(KEY, PortletSession.APPLICATION_SCOPE);
-        Object value = session.getAttribute(KEY, PortletSession.APPLICATION_SCOPE);
-        if (value == null) {
-        	result.setReturnCode(TestResult.PASSED);
-        } else {
-        	TestUtils.failOnAssertion("session attribute", value, null, result);
-        }
-        return result;
-    }
-
-}
+ * 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.pluto.testsuite.TestResult;
+import org.apache.pluto.testsuite.TestUtils;
+
+import javax.portlet.PortletSession;
+
+/**
+ */
+public class AppScopedSessionAttributeTest
+extends AbstractReflectivePortletTest {
+
+    private static final String BOGUS_KEY = "org.apache.pluto.testsuite.BOGUS_KEY";
+    private static final String KEY = "org.apache.pluto.testsuite.KEY";
+    private static final String VALUE = "VALUE";
+
+
+    // Test Methods ------------------------------------------------------------
+
+    protected TestResult checkGetEmptyAppScopedAttribute(PortletSession session) {
+        TestResult result = new TestResult();
+        result.setDescription("Retrieve an attribute that has not been set "
+        		+ "in the session's application scope "
+        		+ "and ensure it's value is null.");
+        result.setSpecPLT("15.3");
+
+        Object value = session.getAttribute(BOGUS_KEY, PortletSession.APPLICATION_SCOPE);
+        if (value == null) {
+        	result.setReturnCode(TestResult.PASSED);
+        } else {
+        	TestUtils.failOnAssertion("session attribute", value, null, result);
+        }
+        return result;
+    }
+
+    protected TestResult checkSetAppScopedAttribute(PortletSession session) {
+        TestResult result = new TestResult();
+        result.setDescription("Set an application scoped session attribute "
+        		+ "and ensure it's retrievable.");
+        result.setSpecPLT("15.3");
+
+        session.setAttribute(KEY, VALUE, PortletSession.APPLICATION_SCOPE);
+        Object value = session.getAttribute(KEY, PortletSession.APPLICATION_SCOPE);
+        if (VALUE.equals(value)) {
+        	result.setReturnCode(TestResult.PASSED);
+        } else {
+        	TestUtils.failOnAssertion("session attribute", value, VALUE, result);
+        }
+        return result;
+    }
+
+    protected TestResult checkRemoveAppScopedAttribute(PortletSession session) {
+        TestResult result = new TestResult();
+        result.setDescription("Remove an application scoped session attribute "
+        		+ "and ensure it's null.");
+        result.setSpecPLT("15.3");
+
+        session.setAttribute(KEY, VALUE, PortletSession.APPLICATION_SCOPE);
+        session.removeAttribute(KEY, PortletSession.APPLICATION_SCOPE);
+        Object value = session.getAttribute(KEY, PortletSession.APPLICATION_SCOPE);
+        if (value == null) {
+        	result.setReturnCode(TestResult.PASSED);
+        } else {
+        	TestUtils.failOnAssertion("session attribute", value, null, result);
+        }
+        return result;
+    }
+
+}

Propchange: geronimo/sandbox/portals/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/AppScopedSessionAttributeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: geronimo/sandbox/portals/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/ContextInitParameterTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/portals/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/ContextInitParameterTest.java?view=diff&rev=559986&r1=559985&r2=559986
==============================================================================
--- geronimo/sandbox/portals/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/ContextInitParameterTest.java (original)
+++ geronimo/sandbox/portals/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/ContextInitParameterTest.java Thu Jul 26 14:22:10 2007
@@ -1,97 +1,97 @@
-/*
+/*
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
  * this work for additional information regarding copyright ownership.
  * The ASF licenses this file to You 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.pluto.testsuite.TestResult;
-import org.apache.pluto.testsuite.TestUtils;
-
-import javax.portlet.PortletContext;
-import javax.portlet.PortletSession;
-import java.util.Enumeration;
-
-/**
- * @version 1.0
- * @since Sep 15, 2004
- */
-public class ContextInitParameterTest extends AbstractReflectivePortletTest  {
-
-    private static final String TEST_PARAM_NAME = "test-parameter-name";
-    private static final String TEST_PARAM_VALUE = "test-parameter-val";
-
-
-    // Test Methods ------------------------------------------------------------
-
-    protected TestResult checkEnumerationContainsNames(
-    		PortletContext context) {
-        TestResult result = new TestResult();
-        result.setDescription("Ensure that the expected init parameter name "
-        		+ "exists in the portlet context's init parameters.");
-        result.setSpecPLT("10.3.1");
-
-        boolean found = false;
-        for (Enumeration en = context.getInitParameterNames();
-        		!found && en.hasMoreElements(); ) {
-            String name = (String) en.nextElement();
-            if (TEST_PARAM_NAME.equals(name)) {
-                found = true;
-            }
-        }
-
-        if (found) {
-        	result.setReturnCode(TestResult.PASSED);
-        } else {
-        	result.setReturnCode(TestResult.FAILED);
-        	result.setResultMessage("Expected init parameter '"
-        			+ TEST_PARAM_NAME + "' not found in portlet context.");
-        }
-        return result;
-    }
-
-    protected TestResult checkGetInitParameter(PortletContext context) {
-        TestResult result = new TestResult();
-        result.setDescription("Ensure that init parameters are retrieveable.");
-        result.setSpecPLT("10.3.1");
-
-        String value = context.getInitParameter(TEST_PARAM_NAME);
-        if (TEST_PARAM_VALUE.equals(value)) {
-        	result.setReturnCode(TestResult.PASSED);
-        } else {
-        	TestUtils.failOnAssertion("init parameter", value, TEST_PARAM_VALUE, result);
-        }
-        return result;
-    }
-
-    /**
-     * FIXME: should this test reside in this class?  -- ZHENG Zhong
-     */
-    protected TestResult checkGetContextFromSession(PortletSession session) {
-        TestResult result = new TestResult();
-        result.setDescription("Ensure that the PortletContext can be retrieved "
-        		+ "from the portlet session.");
-
-        PortletContext context = session.getPortletContext();
-        if (context != null) {
-        	result.setReturnCode(TestResult.PASSED);
-        } else {
-        	result.setReturnCode(TestResult.FAILED);
-        	result.setResultMessage("Fail to retrieve PortletContext from "
-        			+ "PortletSession: null returned.");
-        }
-        return result;
-    }
-}
-
+ * 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.pluto.testsuite.TestResult;
+import org.apache.pluto.testsuite.TestUtils;
+
+import javax.portlet.PortletContext;
+import javax.portlet.PortletSession;
+import java.util.Enumeration;
+
+/**
+ * @version 1.0
+ * @since Sep 15, 2004
+ */
+public class ContextInitParameterTest extends AbstractReflectivePortletTest  {
+
+    private static final String TEST_PARAM_NAME = "test-parameter-name";
+    private static final String TEST_PARAM_VALUE = "test-parameter-val";
+
+
+    // Test Methods ------------------------------------------------------------
+
+    protected TestResult checkEnumerationContainsNames(
+    		PortletContext context) {
+        TestResult result = new TestResult();
+        result.setDescription("Ensure that the expected init parameter name "
+        		+ "exists in the portlet context's init parameters.");
+        result.setSpecPLT("10.3.1");
+
+        boolean found = false;
+        for (Enumeration en = context.getInitParameterNames();
+        		!found && en.hasMoreElements(); ) {
+            String name = (String) en.nextElement();
+            if (TEST_PARAM_NAME.equals(name)) {
+                found = true;
+            }
+        }
+
+        if (found) {
+        	result.setReturnCode(TestResult.PASSED);
+        } else {
+        	result.setReturnCode(TestResult.FAILED);
+        	result.setResultMessage("Expected init parameter '"
+        			+ TEST_PARAM_NAME + "' not found in portlet context.");
+        }
+        return result;
+    }
+
+    protected TestResult checkGetInitParameter(PortletContext context) {
+        TestResult result = new TestResult();
+        result.setDescription("Ensure that init parameters are retrieveable.");
+        result.setSpecPLT("10.3.1");
+
+        String value = context.getInitParameter(TEST_PARAM_NAME);
+        if (TEST_PARAM_VALUE.equals(value)) {
+        	result.setReturnCode(TestResult.PASSED);
+        } else {
+        	TestUtils.failOnAssertion("init parameter", value, TEST_PARAM_VALUE, result);
+        }
+        return result;
+    }
+
+    /**
+     * FIXME: should this test reside in this class?  -- ZHENG Zhong
+     */
+    protected TestResult checkGetContextFromSession(PortletSession session) {
+        TestResult result = new TestResult();
+        result.setDescription("Ensure that the PortletContext can be retrieved "
+        		+ "from the portlet session.");
+
+        PortletContext context = session.getPortletContext();
+        if (context != null) {
+        	result.setReturnCode(TestResult.PASSED);
+        } else {
+        	result.setReturnCode(TestResult.FAILED);
+        	result.setResultMessage("Fail to retrieve PortletContext from "
+        			+ "PortletSession: null returned.");
+        }
+        return result;
+    }
+}
+

Propchange: geronimo/sandbox/portals/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/ContextInitParameterTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: geronimo/sandbox/portals/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/DispatcherRenderParameterTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/portals/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/DispatcherRenderParameterTest.java?view=diff&rev=559986&r1=559985&r2=559986
==============================================================================
--- geronimo/sandbox/portals/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/DispatcherRenderParameterTest.java (original)
+++ geronimo/sandbox/portals/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/DispatcherRenderParameterTest.java Thu Jul 26 14:22:10 2007
@@ -1,341 +1,341 @@
-/*
+/*
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
  * this work for additional information regarding copyright ownership.
  * The ASF licenses this file to You 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;
-
-/**
- *
- * @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.
-     */
-    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;
-        }
-
-    }
-
-}
-
+ * 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;
+
+/**
+ *
+ * @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.
+     */
+    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;
+        }
+
+    }
+
+}
+

Propchange: geronimo/sandbox/portals/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/DispatcherRenderParameterTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message