geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jb...@apache.org
Subject svn commit: r559986 [5/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/test/PreferenceCommonTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/portals/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/PreferenceCommonTest.java?view=diff&rev=559986&r1=559985&r2=559986
==============================================================================
--- geronimo/sandbox/portals/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/PreferenceCommonTest.java (original)
+++ geronimo/sandbox/portals/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/PreferenceCommonTest.java Thu Jul 26 14:22:10 2007
@@ -1,483 +1,483 @@
-/*
+/*
  * 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.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.
- */
-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());
-    }
-
-}
+ * 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.
+ */
+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());
+    }
+
+}

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

Modified: geronimo/sandbox/portals/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/PreferenceInActionTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/portals/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/PreferenceInActionTest.java?view=diff&rev=559986&r1=559985&r2=559986
==============================================================================
--- geronimo/sandbox/portals/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/PreferenceInActionTest.java (original)
+++ geronimo/sandbox/portals/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/PreferenceInActionTest.java Thu Jul 26 14:22:10 2007
@@ -1,193 +1,193 @@
-/*
+/*
  * 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.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;
-
-/**
- */
-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;
-    }
-
-}
+ * 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;
+
+/**
+ */
+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;
+    }
+
+}

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

Modified: geronimo/sandbox/portals/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/PreferenceInRenderTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/portals/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/PreferenceInRenderTest.java?view=diff&rev=559986&r1=559985&r2=559986
==============================================================================
--- geronimo/sandbox/portals/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/PreferenceInRenderTest.java (original)
+++ geronimo/sandbox/portals/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/PreferenceInRenderTest.java Thu Jul 26 14:22:10 2007
@@ -1,65 +1,65 @@
-/*
+/*
  * 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 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;
-	}
-	
-}
+ * 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;
+	}
+	
+}

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

Modified: geronimo/sandbox/portals/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/RenderParameterTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/portals/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/RenderParameterTest.java?view=diff&rev=559986&r1=559985&r2=559986
==============================================================================
--- geronimo/sandbox/portals/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/RenderParameterTest.java (original)
+++ geronimo/sandbox/portals/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/RenderParameterTest.java Thu Jul 26 14:22:10 2007
@@ -1,150 +1,150 @@
-/*
+/*
  * 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 java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.portlet.PortletRequest;
-
-/**
- */
-public class RenderParameterTest extends AbstractReflectivePortletTest {
-
-    private static final String ACTION_KEY = "org.apache.pluto.testsuite.PARAM_ACTION_KEY";
-
-    private static final String RENDER_KEY = "org.apache.pluto.testsuite.PARAM_RENDER_KEY";
-    private static final String RENDER_VALUE = "org.apache.pluto.testsuite.RENDER_VALUE";
-
-
-    public Map getRenderParameters(PortletRequest request) {
-        Map parameterMap = new HashMap();
-        parameterMap.put(RENDER_KEY, new String[] { RENDER_VALUE });
-        return parameterMap;
-    }
-
-
-    // Test Methods ------------------------------------------------------------
-
-    protected TestResult checkActionParametersNotHere(PortletRequest request) {
-        TestResult result = new TestResult();
-        result.setDescription("Ensure that action parameters are not available "
-        		+ "in the following render request.");
-
-        String value = request.getParameter(ACTION_KEY);
-        if (value == null) {
-        	result.setReturnCode(TestResult.PASSED);
-        } else {
-        	TestUtils.failOnAssertion("parameter", value, null, result);
-        }
-        return result;
-    }
-
-
-    protected TestResult checkRenderParameterValue(PortletRequest request) {
-        TestResult result = new TestResult();
-        result.setDescription("Ensure that render parameters set in action "
-        		+ "response are available in the following render request.");
-
-        String value = request.getParameter(RENDER_KEY);
-        if (RENDER_VALUE.equals(value)) {
-        	result.setReturnCode(TestResult.PASSED);
-        } else {
-        	TestUtils.failOnAssertion("parameter", value, RENDER_VALUE, result);
-        }
-        return result;
-    }
-
-    protected TestResult checkRenderParameterValues(PortletRequest request) {
-        TestResult result = new TestResult();
-        result.setDescription("Ensure that render parameters set in action "
-        		+ "response are available in the following render request.");
-
-        String[] values = request.getParameterValues(RENDER_KEY);
-        if (values != null && values.length == 1
-        		&& RENDER_VALUE.equals(values[0])) {
-        	result.setReturnCode(TestResult.PASSED);
-        } else {
-        	TestUtils.failOnAssertion("parameter values",
-        			values, new String[] { RENDER_VALUE }, result);
-        }
-        return result;
-    }
-
-    protected TestResult checkParameterMap(PortletRequest request) {
-        TestResult result = new TestResult();
-        result.setDescription("Ensure that render request returns the correct "
-        		+ "parameter map.");
-
-        Map parameterMap = request.getParameterMap();
-        String[] values = (String[]) parameterMap.get(RENDER_KEY);
-        if (values != null && values.length == 1
-        		&& RENDER_VALUE.equals(values[0])
-        		&& !parameterMap.containsKey(ACTION_KEY)) {
-        	result.setReturnCode(TestResult.PASSED);
-        } else {
-        	if (parameterMap.containsKey(ACTION_KEY)) {
-            	result.setReturnCode(TestResult.FAILED);
-        		result.setResultMessage("Action parameter " + ACTION_KEY
-        				+ " was found in render request with value(s): "
-        				+ parameterMap.get(ACTION_KEY));
-        	} else {
-        		TestUtils.failOnAssertion("parameter values",
-        				values, new String[] { RENDER_VALUE }, result);
-        	}
-        }
-        return result;
-    }
-
-    protected TestResult checkParameterNames(PortletRequest request) {
-        TestResult result = new TestResult();
-        result.setDescription("Ensure that render request returns the correct "
-        		+ "parameter names enumeration.");
-
-        boolean hasActionParameter = false;
-        boolean hasRenderParameter = false;
-        for (Enumeration en = request.getParameterNames();
-        		en.hasMoreElements(); ) {
-            String name = (String) en.nextElement();
-            if (ACTION_KEY.equals(name)) {
-            	hasActionParameter = true;
-            }
-            if (RENDER_KEY.equals(name)) {
-            	hasRenderParameter = true;
-            }
-        }
-
-        if (!hasActionParameter && hasRenderParameter) {
-        	result.setReturnCode(TestResult.PASSED);
-        } else {
-        	result.setReturnCode(TestResult.FAILED);
-            StringBuffer buffer = new StringBuffer();
-            if (!hasRenderParameter) {
-            	buffer.append("Render parameter not found. ");
-            }
-            if (!hasActionParameter) {
-            	buffer.append("Action parameter found. ");
-            }
-            result.setResultMessage(buffer.toString());
-        }
-        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 java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.portlet.PortletRequest;
+
+/**
+ */
+public class RenderParameterTest extends AbstractReflectivePortletTest {
+
+    private static final String ACTION_KEY = "org.apache.pluto.testsuite.PARAM_ACTION_KEY";
+
+    private static final String RENDER_KEY = "org.apache.pluto.testsuite.PARAM_RENDER_KEY";
+    private static final String RENDER_VALUE = "org.apache.pluto.testsuite.RENDER_VALUE";
+
+
+    public Map getRenderParameters(PortletRequest request) {
+        Map parameterMap = new HashMap();
+        parameterMap.put(RENDER_KEY, new String[] { RENDER_VALUE });
+        return parameterMap;
+    }
+
+
+    // Test Methods ------------------------------------------------------------
+
+    protected TestResult checkActionParametersNotHere(PortletRequest request) {
+        TestResult result = new TestResult();
+        result.setDescription("Ensure that action parameters are not available "
+        		+ "in the following render request.");
+
+        String value = request.getParameter(ACTION_KEY);
+        if (value == null) {
+        	result.setReturnCode(TestResult.PASSED);
+        } else {
+        	TestUtils.failOnAssertion("parameter", value, null, result);
+        }
+        return result;
+    }
+
+
+    protected TestResult checkRenderParameterValue(PortletRequest request) {
+        TestResult result = new TestResult();
+        result.setDescription("Ensure that render parameters set in action "
+        		+ "response are available in the following render request.");
+
+        String value = request.getParameter(RENDER_KEY);
+        if (RENDER_VALUE.equals(value)) {
+        	result.setReturnCode(TestResult.PASSED);
+        } else {
+        	TestUtils.failOnAssertion("parameter", value, RENDER_VALUE, result);
+        }
+        return result;
+    }
+
+    protected TestResult checkRenderParameterValues(PortletRequest request) {
+        TestResult result = new TestResult();
+        result.setDescription("Ensure that render parameters set in action "
+        		+ "response are available in the following render request.");
+
+        String[] values = request.getParameterValues(RENDER_KEY);
+        if (values != null && values.length == 1
+        		&& RENDER_VALUE.equals(values[0])) {
+        	result.setReturnCode(TestResult.PASSED);
+        } else {
+        	TestUtils.failOnAssertion("parameter values",
+        			values, new String[] { RENDER_VALUE }, result);
+        }
+        return result;
+    }
+
+    protected TestResult checkParameterMap(PortletRequest request) {
+        TestResult result = new TestResult();
+        result.setDescription("Ensure that render request returns the correct "
+        		+ "parameter map.");
+
+        Map parameterMap = request.getParameterMap();
+        String[] values = (String[]) parameterMap.get(RENDER_KEY);
+        if (values != null && values.length == 1
+        		&& RENDER_VALUE.equals(values[0])
+        		&& !parameterMap.containsKey(ACTION_KEY)) {
+        	result.setReturnCode(TestResult.PASSED);
+        } else {
+        	if (parameterMap.containsKey(ACTION_KEY)) {
+            	result.setReturnCode(TestResult.FAILED);
+        		result.setResultMessage("Action parameter " + ACTION_KEY
+        				+ " was found in render request with value(s): "
+        				+ parameterMap.get(ACTION_KEY));
+        	} else {
+        		TestUtils.failOnAssertion("parameter values",
+        				values, new String[] { RENDER_VALUE }, result);
+        	}
+        }
+        return result;
+    }
+
+    protected TestResult checkParameterNames(PortletRequest request) {
+        TestResult result = new TestResult();
+        result.setDescription("Ensure that render request returns the correct "
+        		+ "parameter names enumeration.");
+
+        boolean hasActionParameter = false;
+        boolean hasRenderParameter = false;
+        for (Enumeration en = request.getParameterNames();
+        		en.hasMoreElements(); ) {
+            String name = (String) en.nextElement();
+            if (ACTION_KEY.equals(name)) {
+            	hasActionParameter = true;
+            }
+            if (RENDER_KEY.equals(name)) {
+            	hasRenderParameter = true;
+            }
+        }
+
+        if (!hasActionParameter && hasRenderParameter) {
+        	result.setReturnCode(TestResult.PASSED);
+        } else {
+        	result.setReturnCode(TestResult.FAILED);
+            StringBuffer buffer = new StringBuffer();
+            if (!hasRenderParameter) {
+            	buffer.append("Render parameter not found. ");
+            }
+            if (!hasActionParameter) {
+            	buffer.append("Action parameter found. ");
+            }
+            result.setResultMessage(buffer.toString());
+        }
+        return result;
+    }
+}

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

Modified: geronimo/sandbox/portals/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/RenderResponseNoContentTypeTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/portals/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/RenderResponseNoContentTypeTest.java?view=diff&rev=559986&r1=559985&r2=559986
==============================================================================
--- geronimo/sandbox/portals/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/RenderResponseNoContentTypeTest.java (original)
+++ geronimo/sandbox/portals/pluto-testsuite/src/main/java/org/apache/pluto/testsuite/test/RenderResponseNoContentTypeTest.java Thu Jul 26 14:22:10 2007
@@ -1,131 +1,131 @@
-/*
+/*
  * 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 java.io.IOException;
-
-import javax.portlet.PortletResponse;
-import javax.portlet.RenderResponse;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.pluto.testsuite.TestResult;
-import org.apache.pluto.testsuite.TestUtils;
-
-/**
- * FIXME: separate the two check methods to two classes.
- *
- */
-public class RenderResponseNoContentTypeTest
-extends AbstractReflectivePortletTest {
-
-	private static final Log LOG = LogFactory.getLog(RenderResponseNoContentTypeTest.class);
-
-	/**
-	 * Overwrite super implementation to return null. This test requires that
-	 * content type of the render response is not set.
-	 * @return <code>null</code>.
-	 */
-	public String getRenderResponseContentType() {
-		return null;
-	}
-
-	// Test Methods ------------------------------------------------------------
-
-	protected TestResult checkGetPortletOutputStream(PortletResponse response) {
-		TestResult result = new TestResult();
-		result.setDescription("Ensure If the getPortletOutputStream() method "
-				+ "is called before the setContentType() method, it will throw "
-				+ "an IllegalStateException.");
-		result.setSpecPLT("12.3.1");
-
-		RenderResponse renderResponse = (RenderResponse) response;
-		ensureContentTypeNotSet(renderResponse, result);
-		if (result.getReturnCode() == TestResult.WARNING) {
-			return result;
-		}
-
-		try {
-			renderResponse.getPortletOutputStream();
-			result.setReturnCode(TestResult.FAILED);
-			result.setResultMessage("Method getPortletOutputStream() didn't "
-					+ "throw an IllegalStateException when content type is "
-					+ "not set before.");
-		} catch (IllegalStateException ex) {
-			// We are expecting this exception!
-			result.setReturnCode(TestResult.PASSED);
-		} catch (IOException ex) {
-			TestUtils.failOnException("Method getPortletOutputStream() throws "
-					+ "an unexpected IOException", ex, result);
-		}
-		return result;
-	}
-
-	protected TestResult checkGetWriter(PortletResponse response) {
-		TestResult result = new TestResult();
-		result.setDescription("Ensure If the getWriter() method "
-				+ "is called before the setContentType() method, it will throw "
-				+ "an IllegalStateException.");
-		result.setSpecPLT("12.3.1");
-
-		RenderResponse renderResponse = (RenderResponse) response;
-		ensureContentTypeNotSet(renderResponse, result);
-		if (result.getReturnCode() == TestResult.WARNING) {
-			return result;
-		}
-
-		try {
-			renderResponse.getWriter();
-			result.setReturnCode(TestResult.FAILED);
-			result.setResultMessage("Method getWriter() didn't "
-					+ "throw an IllegalStateException when content type is "
-					+ "not set before.");
-		} catch (IllegalStateException ex) {
-			// We are expecting this exception!
-			result.setReturnCode(TestResult.PASSED);
-		} catch (IOException ex) {
-			TestUtils.failOnException("Method getWriter() throws "
-					+ "an unexpected IOException", ex, result);
-		}
-		return result;
-	}
-
-
-	// Private Methods ---------------------------------------------------------
-
-	/**
-	 * Ensures that the content type of the current render response is not set.
-	 * If the content type is already set, this method sets the test result to
-	 * WARNING with a warning message. Otherwise, this method does nothing.
-	 * @param response  the render response to check.
-	 * @param result  the test result.
-	 */
-	private void ensureContentTypeNotSet(RenderResponse response,
-	                                     TestResult result) {
-		String contentType = response.getContentType();
-		if (contentType != null) {
-			if (LOG.isWarnEnabled()) {
-				LOG.warn("Unable to run test: content type is already set ("
-						+ contentType + ").");
-			}
-        	result.setReturnCode(TestResult.WARNING);
-        	result.setResultMessage("The content type of the render response "
-        			+ "is not as expected (" + contentType + " != null).");
-		}
-	}
-
-}
+ * 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.PortletResponse;
+import javax.portlet.RenderResponse;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.pluto.testsuite.TestResult;
+import org.apache.pluto.testsuite.TestUtils;
+
+/**
+ * FIXME: separate the two check methods to two classes.
+ *
+ */
+public class RenderResponseNoContentTypeTest
+extends AbstractReflectivePortletTest {
+
+	private static final Log LOG = LogFactory.getLog(RenderResponseNoContentTypeTest.class);
+
+	/**
+	 * Overwrite super implementation to return null. This test requires that
+	 * content type of the render response is not set.
+	 * @return <code>null</code>.
+	 */
+	public String getRenderResponseContentType() {
+		return null;
+	}
+
+	// Test Methods ------------------------------------------------------------
+
+	protected TestResult checkGetPortletOutputStream(PortletResponse response) {
+		TestResult result = new TestResult();
+		result.setDescription("Ensure If the getPortletOutputStream() method "
+				+ "is called before the setContentType() method, it will throw "
+				+ "an IllegalStateException.");
+		result.setSpecPLT("12.3.1");
+
+		RenderResponse renderResponse = (RenderResponse) response;
+		ensureContentTypeNotSet(renderResponse, result);
+		if (result.getReturnCode() == TestResult.WARNING) {
+			return result;
+		}
+
+		try {
+			renderResponse.getPortletOutputStream();
+			result.setReturnCode(TestResult.FAILED);
+			result.setResultMessage("Method getPortletOutputStream() didn't "
+					+ "throw an IllegalStateException when content type is "
+					+ "not set before.");
+		} catch (IllegalStateException ex) {
+			// We are expecting this exception!
+			result.setReturnCode(TestResult.PASSED);
+		} catch (IOException ex) {
+			TestUtils.failOnException("Method getPortletOutputStream() throws "
+					+ "an unexpected IOException", ex, result);
+		}
+		return result;
+	}
+
+	protected TestResult checkGetWriter(PortletResponse response) {
+		TestResult result = new TestResult();
+		result.setDescription("Ensure If the getWriter() method "
+				+ "is called before the setContentType() method, it will throw "
+				+ "an IllegalStateException.");
+		result.setSpecPLT("12.3.1");
+
+		RenderResponse renderResponse = (RenderResponse) response;
+		ensureContentTypeNotSet(renderResponse, result);
+		if (result.getReturnCode() == TestResult.WARNING) {
+			return result;
+		}
+
+		try {
+			renderResponse.getWriter();
+			result.setReturnCode(TestResult.FAILED);
+			result.setResultMessage("Method getWriter() didn't "
+					+ "throw an IllegalStateException when content type is "
+					+ "not set before.");
+		} catch (IllegalStateException ex) {
+			// We are expecting this exception!
+			result.setReturnCode(TestResult.PASSED);
+		} catch (IOException ex) {
+			TestUtils.failOnException("Method getWriter() throws "
+					+ "an unexpected IOException", ex, result);
+		}
+		return result;
+	}
+
+
+	// Private Methods ---------------------------------------------------------
+
+	/**
+	 * Ensures that the content type of the current render response is not set.
+	 * If the content type is already set, this method sets the test result to
+	 * WARNING with a warning message. Otherwise, this method does nothing.
+	 * @param response  the render response to check.
+	 * @param result  the test result.
+	 */
+	private void ensureContentTypeNotSet(RenderResponse response,
+	                                     TestResult result) {
+		String contentType = response.getContentType();
+		if (contentType != null) {
+			if (LOG.isWarnEnabled()) {
+				LOG.warn("Unable to run test: content type is already set ("
+						+ contentType + ").");
+			}
+        	result.setReturnCode(TestResult.WARNING);
+        	result.setResultMessage("The content type of the render response "
+        			+ "is not as expected (" + contentType + " != null).");
+		}
+	}
+
+}

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



Mime
View raw message