myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfreed...@apache.org
Subject svn commit: r891458 - in /myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_4: section_4_1/ section_4_2_1/ section_4_2_10/ section_4_2_11/ section_4_2_6/ section_4_2_7/ section_4_2_8/ section_...
Date Wed, 16 Dec 2009 22:27:33 GMT
Author: mfreedman
Date: Wed Dec 16 22:27:32 2009
New Revision: 891458

URL: http://svn.apache.org/viewvc?rev=891458&view=rev
Log:
Fix up yesterdays checkin on chapter 4 where the patch didn't properly add the following files.

Added:
    myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_4/section_4_1/
    myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_4/section_4_1/Tests.java
    myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_4/section_4_2_1/
    myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_4/section_4_2_1/InitMethodTestPortlet.java
    myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_4/section_4_2_10/
    myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_4/section_4_2_10/GetResponseContentTypeMethodTestPortlet.java
    myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_4/section_4_2_11/
    myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_4/section_4_2_11/GetResponseCharacterSetEncodingMethodTestPortlet.java
    myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_4/section_4_2_6/
    myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_4/section_4_2_6/GetBridgeClassNameMethodTestPortlet.java
    myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_4/section_4_2_7/
    myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_4/section_4_2_7/GetDefaultViewIdMapMethodTestPortlet.java
    myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_4/section_4_2_8/
    myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_4/section_4_2_8/GetExcludedRequestAttributesMethodTestPortlet.java
    myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_4/section_4_2_9/
    myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_4/section_4_2_9/IsPreserveActionParametersMethodTestPortlet.java

Added: myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_4/section_4_1/Tests.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_4/section_4_1/Tests.java?rev=891458&view=auto
==============================================================================
--- myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_4/section_4_1/Tests.java (added)
+++ myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_4/section_4_1/Tests.java Wed Dec 16 22:27:32 2009
@@ -0,0 +1,218 @@
+/* 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.myfaces.portlet.faces.testsuite.tests.chapter_4.section_4_1;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.HashMap;
+
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+
+import javax.portlet.ActionResponse;
+import javax.portlet.PortletContext;
+import javax.portlet.PortletRequest;
+
+import javax.portlet.faces.Bridge;
+import javax.portlet.faces.BridgeUtil;
+
+import org.apache.myfaces.portlet.faces.testsuite.annotation.BridgeTest;
+import org.apache.myfaces.portlet.faces.testsuite.beans.TestRunnerBean;
+import org.apache.myfaces.portlet.faces.testsuite.common.Constants;
+
+public class Tests
+  extends Object
+{
+  @BridgeTest(test = "portletInitializationParametersTest")
+  public String portletInitializationParametersTest(TestRunnerBean testRunner)
+  {
+    // Section 4.1
+    // Tests whether the GenericFacesPortlet portlet initialization 
+    // parameters have been correctly set as Bridge attributes.
+    String PARAM_NAMESPACE = "javax.portlet.faces.chapter4_1Tests-portletInitializationParametersTest-portlet.";
+    Map<String, Object> expectedInitParams = new HashMap<String, Object>();
+    Map<String, String> viewIds = new HashMap<String, String>();
+    viewIds.put("view", "/tests/MultiRequestTest.jsp");
+    viewIds.put("edit", "/tests/MultiRequestTest.jsp");
+    viewIds.put("help", "/tests/MultiRequestTest.jsp");
+    expectedInitParams.put("defaultViewIdMap", viewIds);
+    List excluded = new ArrayList();
+    excluded.add("test1");
+    excluded.add("test2");
+    expectedInitParams.put("excludedRequestAttributes", excluded);
+    expectedInitParams.put("preserveActionParams", Boolean.TRUE);
+    expectedInitParams.put("defaultContentType", "text/xml");
+    expectedInitParams.put("defaultCharacterSetEncoding", "UTF-8");
+    
+
+    ExternalContext extCtx = FacesContext.getCurrentInstance().getExternalContext();
+    // Map requestAttributes = extCtx.getRequestMap();
+    // System.out.println("************  +++++++++ ");
+    //for (String name: requestAttributes)
+    //{
+    //  System.out.println("************ " + name  + " +++++++++ ");
+    //}
+    for (String name: extCtx.getApplicationMap().keySet())
+    {
+      if (name.indexOf("chapter4_1") != -1)
+      {
+        System.out.println("**** " + name  + ": " + extCtx.getApplicationMap().get(name));
+      }
+    }
+    StringBuilder notFoundMsg = new StringBuilder();
+
+    boolean pass = checkAttrs(extCtx.getApplicationMap(), PARAM_NAMESPACE, expectedInitParams, notFoundMsg);
+
+    if (notFoundMsg.length() != 0)
+    {
+      notFoundMsg.append(".  ");
+    }
+
+    if (BridgeUtil.getPortletRequestPhase() ==
+        Bridge.PortletPhase.ACTION_PHASE)
+    {  
+ System.out.println("1a");
+      if (pass)
+      {
+ System.out.println("1b");
+ System.out.println("1c");
+      }
+      else
+      {
+        // Missing init params
+        extCtx.getSessionMap().put("test.action.failed", "  Missing or incorrect init-params during action request: " + notFoundMsg); 
+      }
+ System.out.println("1d");
+      return "portletInitializationParametersTest"; // action Navigation result
+    }
+    else
+    {
+      boolean actionPass = extCtx.getSessionMap().get("test.action.failed") == null;
+      boolean completePass = pass && actionPass;
+      StringBuilder msg = new StringBuilder();
+
+      if (pass)
+      {
+        msg.append("Portlet initialisation parameters visible as portlet context attributes during render request.  ");
+      }
+      else
+      {
+        msg.append("Missing or incorrect init-params during render request: " + notFoundMsg);
+      }
+
+      if (actionPass)
+      {
+        msg.append("  Portlet initialisation parameters visible as portlet context attributes during action request.  ");
+      }
+      else
+      {
+        msg.append((String)extCtx.getSessionMap().get("test.action.failed"));
+      }
+
+      testRunner.setTestResult(completePass, msg.toString());
+      if (completePass)
+      {
+        return Constants.TEST_SUCCESS;
+      }
+      else
+      {
+        return Constants.TEST_FAILED;
+      }
+    }
+  }
+
+  public boolean checkAttrs(Map attributes, String namespace, Map<String, Object> expectedInitParams, StringBuilder notFoundMsg)
+  {
+System.out.println("* 1");    
+    if (attributes == null)
+    {
+      return false;
+    }
+    boolean pass = true;
+
+System.out.println("* 2");
+    for (String key: expectedInitParams.keySet())
+    {
+      // Run through the expected init param attributes.  They will either be
+      // key=string, value=object, or key=defaultViewIdMap, value=map of 
+      //modes (where key = string and value=string)
+      
+      if ("defaultViewIdMap".equals(key))
+      {
+        System.out.println("1");
+        Map<String,String> defaultViewIdMap = (Map<String,String>)expectedInitParams.get("defaultViewIdMap");
+        System.out.println("2");
+        Map<String,String> attributeViewIdMap = (Map<String,String>)attributes.get(namespace + "defaultViewIdMap");
+        System.out.println("3");
+        if (attributeViewIdMap == null)
+        {
+        System.out.println("4");
+          buildMsg(notFoundMsg, "init-param name = " + key);
+          pass = false;
+          break;
+        }
+
+        for (String mode: defaultViewIdMap.keySet())
+        {
+        System.out.println("5");
+          if (!(defaultViewIdMap.get(mode).equals(attributeViewIdMap.get(mode))))
+          {
+        System.out.println("6");
+            pass = false;
+          }
+        }
+      }
+      else
+      {
+        Object param = expectedInitParams.get(key);
+        System.out.println("6 param=" + param + " key= " + key );
+        System.out.println("6a namespace + key  = " + namespace + key + " value= " + key );
+        try{
+        System.out.println("6b value= " + attributes.get(namespace + key) );
+
+        if (!(param.equals(attributes.get(namespace + key))))
+        {
+          System.out.println("7");
+          buildMsg(notFoundMsg, "init-param name = " + key + ", value = " + expectedInitParams.get(key));
+          pass = false;
+        }
+        }
+        catch (Exception e)
+        {
+          System.out.println("7a: " + e.toString());
+        }
+      }
+    }
+    System.out.println("8");
+    return pass;
+  }
+
+  private void buildMsg(StringBuilder completeMsg, String msg)
+  {
+    if (completeMsg.length() != 0)
+    {
+      completeMsg.append(", ");
+    }
+    
+    completeMsg.append(msg);
+  }
+}

Added: myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_4/section_4_2_1/InitMethodTestPortlet.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_4/section_4_2_1/InitMethodTestPortlet.java?rev=891458&view=auto
==============================================================================
--- myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_4/section_4_2_1/InitMethodTestPortlet.java (added)
+++ myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_4/section_4_2_1/InitMethodTestPortlet.java Wed Dec 16 22:27:32 2009
@@ -0,0 +1,243 @@
+/* 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.myfaces.portlet.faces.testsuite.tests.chapter_4.section_4_2_1;
+
+import org.apache.myfaces.portlet.faces.testsuite.common.portlet.GenericFacesTestSuitePortlet;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.portlet.PortletException;
+import javax.portlet.PortletConfig;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.List;
+import java.util.Map;
+import java.util.ArrayList;
+import java.util.Hashtable;
+
+import org.apache.myfaces.portlet.faces.testsuite.common.util.BridgeTCKResultWriter;
+
+/**
+ * Checks that GenericFacesPortlet#init method works as stated in section 
+ * 4.2.1.  Checks that
+ * - getExcludedRequestAttributes has been called and the portlet context 
+ *   attribute, qualified with the portlet name is set up
+ * - isPreserveActionParameters has been called and the portlet context 
+ *   attribute, qualified with the portlet name is set up
+ * - getDefaultViewIdMap has been called and the portlet context attribute
+ *   set
+ */
+
+public class InitMethodTestPortlet extends GenericFacesTestSuitePortlet
+{
+
+  private static String TEST_FAIL_PREFIX = "test.fail.";
+  private static String TEST_PASS_PREFIX = "test.pass.";
+
+  private boolean bGetBridgeClassNameCalled;
+
+  private boolean bGetExcludedRequestAttributesCalled;
+  private boolean bGetExcludedRequestAttributesPassed = true;
+  private List<String> mExcludedRequestAttrs = new ArrayList();
+
+  private boolean bIsPreserveActionParametersCalled;
+  private boolean bIsPreserveActionParametersPassed = true;
+  private boolean bIsPreserveActionParametersResult;
+  
+  private boolean bGetDefaultViewIdMapCalled;
+  private boolean bGetDefaultViewIdMapPassed = true;
+  private Map<String,String> mDefaultViewIdMap = new Hashtable<String,String>();
+  
+  private StringBuilder mMsg = new StringBuilder();
+
+  // private static String[] EXCLUDED_ATTRS = {"exclude1", "exclude2"};
+  private static String[] VIEW_IDS = {"view", "edit", "help"};
+
+  public void init(PortletConfig portletConfig) throws PortletException
+  {
+    super.init(portletConfig);
+    
+    boolean bTestPassed = true;
+
+    StringBuilder msg = new StringBuilder();
+
+    // getBridgeClassName test
+    if (bGetBridgeClassNameCalled)
+    {
+      msg.append("getBridgeClassName() called.");
+    }
+    else
+    {
+      bTestPassed = false;
+      msg.append("getBridgeClassName() not called.");
+    }
+
+    // Check that the excluded request portlet context attributes correspond
+    // to those returned from getExcludedRequestAttributes.
+    if (bGetExcludedRequestAttributesCalled)
+    {
+      msg.append("  getExcludedRequestAttributes() called.");
+    }
+    else
+    {
+      bTestPassed = false;
+      msg.append("  getExcludedRequestAttributes() not called.");
+    }
+
+    List<String> attrs = (List<String>)getPortletContext().getAttribute("javax.portlet.faces." + getPortletName() + ".excludedRequestAttributes");
+    for (String expectedAttr: mExcludedRequestAttrs)
+    {
+      if (!attrs.contains(expectedAttr))
+      {
+        bTestPassed = false;
+        msg.append("  Missing excluded request attribute ")
+           .append(expectedAttr).append(".");
+      }
+      
+    }
+
+    // Check that the preserveActionParams portlet context attribute is set 
+    // to the same value as isPreserveActionParameters.
+    if (bIsPreserveActionParametersCalled)
+    {
+      msg.append("  isPreserveActionParameters() called.");
+    }
+    else
+    {
+      bTestPassed = false;
+      msg.append("  isPreserveActionParameters() not called.");
+    }
+
+    Boolean contextValue = (Boolean)getPortletContext().getAttribute("javax.portlet.faces." + getPortletName() + ".preserveActionParams");
+
+    if (!Boolean.valueOf(bIsPreserveActionParametersResult).equals(contextValue))
+    {
+      msg.append("  Value of the preserveActionParams context attribute is ")
+         .append(contextValue)
+         .append(", expected value is ")
+         .append(Boolean.valueOf(bIsPreserveActionParametersResult))
+         .append(".");
+      bTestPassed = false;
+    }
+    
+    // Check that the associated PortletContext attributes are set according to
+    // getDefaultViewIdMap.
+    if (bGetDefaultViewIdMapCalled)
+    {
+      msg.append("  getDefaultViewIdMapCalled() called.");
+    }
+    else
+    {
+      msg.append("  getDefaultViewIdMapCalled() not called.");
+      bTestPassed = false;
+    }
+
+    Map viewIdMapAttr = (Map)getPortletContext().getAttribute("javax.portlet.faces." + getPortletName() + ".defaultViewIdMap");
+    if (!mDefaultViewIdMap.isEmpty())
+    {
+      if (viewIdMapAttr == null)
+      {
+        msg.append("  Portlet context attribute javax.portlet.faces.")
+           .append(getPortletName())
+           .append(".defaultViewIdMap has not been set.");
+      }
+      else
+      {
+        for (String mode: mDefaultViewIdMap.keySet())
+        {
+          if (viewIdMapAttr.get(mode) == null)
+          {
+            bTestPassed = false;
+            msg.append("  Mode, ")
+               .append(mode)
+               .append(", has been set in the map returned by getDefaultViewIdMap but has not been set in javax.portlet.faces.")
+               .append(getPortletName()).append(".defaultViewIdMap"); 
+          }
+        }
+      }
+    }
+    else
+    {
+      if (viewIdMapAttr != null)
+      {
+        msg.append("  Portlet context attribute javax.portlet.faces.")
+           .append(getPortletName())
+           .append(".defaultViewIdMap has been set while the getDefaultViewIdMap returns null.");
+        bTestPassed = false;
+      }
+    }
+
+    if (bTestPassed)
+    {
+      getPortletContext().setAttribute(TEST_PASS_PREFIX + getPortletName(), msg.toString());
+    }
+    else
+    {
+      getPortletContext().setAttribute(TEST_FAIL_PREFIX + getPortletName(), msg.toString());
+    }
+  }
+
+  public String getBridgeClassName()
+  {
+    bGetBridgeClassNameCalled = true;
+    return super.getBridgeClassName();
+  }
+
+  public boolean isPreserveActionParameters()
+  {
+    bIsPreserveActionParametersCalled = true;
+    bIsPreserveActionParametersResult = super.isPreserveActionParameters();
+    return bIsPreserveActionParametersResult;
+  }
+
+  public List<String> getExcludedRequestAttributes()
+  {
+    bGetExcludedRequestAttributesCalled = true;  
+    List<String> mExcludedRequestAttrs = super.getExcludedRequestAttributes();
+    return mExcludedRequestAttrs;
+  }
+
+  public Map getDefaultViewIdMap()
+  {
+    bGetDefaultViewIdMapCalled = true;
+    mDefaultViewIdMap = super.getDefaultViewIdMap();
+    return mDefaultViewIdMap;
+  }
+
+  public void render(RenderRequest request, RenderResponse response)
+    throws PortletException, IOException
+  {
+    response.setContentType("text/html");
+    PrintWriter out = response.getWriter();
+    BridgeTCKResultWriter resultWriter = new BridgeTCKResultWriter(getTestName());
+
+    if ((String)getPortletContext().getAttribute(TEST_PASS_PREFIX + getPortletName()) != null)
+    {
+      resultWriter.setStatus(BridgeTCKResultWriter.PASS);
+      resultWriter.setDetail((String)getPortletContext().getAttribute(TEST_PASS_PREFIX + getPortletName()));
+    }
+    else
+    {
+      resultWriter.setStatus(BridgeTCKResultWriter.FAIL);
+      resultWriter.setDetail((String)getPortletContext().getAttribute(TEST_FAIL_PREFIX + getPortletName()));
+    }
+
+    out.println(resultWriter.toString());
+  }
+}

Added: myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_4/section_4_2_10/GetResponseContentTypeMethodTestPortlet.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_4/section_4_2_10/GetResponseContentTypeMethodTestPortlet.java?rev=891458&view=auto
==============================================================================
--- myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_4/section_4_2_10/GetResponseContentTypeMethodTestPortlet.java (added)
+++ myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_4/section_4_2_10/GetResponseContentTypeMethodTestPortlet.java Wed Dec 16 22:27:32 2009
@@ -0,0 +1,111 @@
+/* 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.myfaces.portlet.faces.testsuite.tests.chapter_4.section_4_2_10;
+
+import org.apache.myfaces.portlet.faces.testsuite.common.portlet.GenericFacesTestSuitePortlet;
+import javax.portlet.faces.GenericFacesPortlet;
+import javax.portlet.PortletRequest;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.portlet.PortletException;
+import java.io.PrintWriter;
+import java.io.IOException;
+
+import org.apache.myfaces.portlet.faces.testsuite.common.util.BridgeTCKResultWriter;
+
+/**
+ * Checks that GenericFacesPortlet#getResponseContentType method works as stated 
+ * in section 4.2.10.
+ * -  If not overridden, the GenericFacesPortlet returns the value of the 
+ *    portlet initialization parameter javax.portlet.faces.defaultContentType, 
+ *    or, if this parameter doesn't exist, the portlet container's indication of
+ *    the preferred content type for this request. 
+ */
+
+
+public class GetResponseContentTypeMethodTestPortlet extends GenericFacesTestSuitePortlet
+{
+  private static String TEST_FAIL_PREFIX = "test.fail.";
+  private static String TEST_PASS_PREFIX = "test.pass.";
+  private static String DEFAULT_CONTENT_TYPE_INIT_PARAM =
+    "javax.portlet.faces.defaultContentType";
+ 
+  public String getResponseContentType(PortletRequest request)
+  {
+    String returnType = super.getResponseContentType(request);
+
+    String expectedContentType = getPortletConfig().getInitParameter(DEFAULT_CONTENT_TYPE_INIT_PARAM);
+    StringBuilder msg = new StringBuilder();
+    if (expectedContentType == null)
+    {
+      msg.append("No portlet initialization parameter set.");
+      expectedContentType = request.getResponseContentType();
+    }
+    else
+    {
+      msg.append("Portlet initialization parameter set to ")
+         .append(expectedContentType).append(".  ");
+    }
+
+    msg.append("getResponseContentType() returned ")
+       .append(returnType);
+
+    if (expectedContentType.equals(returnType))
+    {
+      getPortletContext().setAttribute(TEST_PASS_PREFIX + getPortletName(), msg.toString());
+    }
+    else
+    {
+      getPortletContext().setAttribute(TEST_FAIL_PREFIX + getPortletName(), msg.toString());
+    }
+
+    return returnType;
+  }
+
+  public void render(RenderRequest request, RenderResponse response)
+    throws PortletException, IOException
+  {
+    // Call the method thereby running the test
+    getResponseContentType(request);
+
+    // Actually set the content type manually, the test might have used
+    // an invalid value.
+    response.setContentType("text/html");
+
+    PrintWriter out = response.getWriter();
+
+    boolean pass = getPortletContext().getAttribute(TEST_FAIL_PREFIX + getPortletName()) == null;
+
+    BridgeTCKResultWriter resultWriter = new BridgeTCKResultWriter(getTestName());
+
+    if (pass)
+    {
+      resultWriter.setStatus(BridgeTCKResultWriter.PASS);
+      resultWriter.setDetail((String)getPortletContext().getAttribute(TEST_PASS_PREFIX + getPortletName()));
+    }
+    else
+    {
+      resultWriter.setStatus(BridgeTCKResultWriter.FAIL);
+      resultWriter.setDetail((String)getPortletContext().getAttribute(TEST_FAIL_PREFIX + getPortletName()));
+    }
+
+    out.println(resultWriter.toString());
+  }
+}

Added: myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_4/section_4_2_11/GetResponseCharacterSetEncodingMethodTestPortlet.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_4/section_4_2_11/GetResponseCharacterSetEncodingMethodTestPortlet.java?rev=891458&view=auto
==============================================================================
--- myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_4/section_4_2_11/GetResponseCharacterSetEncodingMethodTestPortlet.java (added)
+++ myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_4/section_4_2_11/GetResponseCharacterSetEncodingMethodTestPortlet.java Wed Dec 16 22:27:32 2009
@@ -0,0 +1,108 @@
+/* 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.myfaces.portlet.faces.testsuite.tests.chapter_4.section_4_2_11;
+
+import org.apache.myfaces.portlet.faces.testsuite.common.portlet.GenericFacesTestSuitePortlet;
+import javax.portlet.faces.GenericFacesPortlet;
+import javax.portlet.PortletRequest;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.portlet.PortletException;
+import java.io.PrintWriter;
+import java.io.IOException;
+
+import org.apache.myfaces.portlet.faces.testsuite.common.util.BridgeTCKResultWriter;
+
+/**
+ * Checks that GenericFacesPortlet#getResponseCharacterSetEncoding method works as stated 
+ * in section 4.2.11.
+ * -  The GenericFacesPortlet implements getResponseCharacterSetEncoding by 
+ *    returning the value of the portlet initialization parameter 
+ *    javax.portlet.faces.defaultCharacterSetEncoding or null if this 
+ *    parameter doesn't exist.
+ */
+
+
+public class GetResponseCharacterSetEncodingMethodTestPortlet extends GenericFacesTestSuitePortlet
+{
+  private static String TEST_FAIL_PREFIX = "test.fail.";
+  private static String TEST_PASS_PREFIX = "test.pass.";
+  private static String DEFAULT_CHARSET_ENCODING_INIT_PARAM =
+    "javax.portlet.faces.defaultCharacterSetEncoding";
+ 
+  public String getResponseCharacterSetEncoding(PortletRequest request)
+  {
+    String returnEncoding = super.getResponseCharacterSetEncoding(request);
+
+    String expectedDefaultCharset = getPortletConfig().getInitParameter(DEFAULT_CHARSET_ENCODING_INIT_PARAM);
+
+    StringBuilder msg = new StringBuilder();
+    if (expectedDefaultCharset == null)
+    {
+      msg.append("No portlet initialization parameter set. ");
+    }
+    else
+    {
+      msg.append("Portlet initialization parameter set to ")
+         .append(expectedDefaultCharset).append(".  ");
+    }
+
+    msg.append("getResponseCharacterSetEncoding() returned ")
+       .append(returnEncoding);
+
+    if ((expectedDefaultCharset == null && returnEncoding == null) ||
+        expectedDefaultCharset.equals(returnEncoding))
+    {
+      getPortletContext().setAttribute(TEST_PASS_PREFIX + getPortletName(), msg.toString());
+    }
+    else
+    {
+      getPortletContext().setAttribute(TEST_FAIL_PREFIX + getPortletName(), msg.toString());
+    }
+
+    return returnEncoding;
+  }
+
+  public void render(RenderRequest request, RenderResponse response)
+    throws PortletException, IOException
+  {
+    // Call the method thereby running the test
+    getResponseCharacterSetEncoding(request);
+
+    response.setContentType("text/html");
+
+    PrintWriter out = response.getWriter();
+
+    BridgeTCKResultWriter resultWriter = new BridgeTCKResultWriter(getTestName());
+
+    if (getPortletContext().getAttribute(TEST_FAIL_PREFIX + getPortletName()) == null)
+    {
+      resultWriter.setStatus(BridgeTCKResultWriter.PASS);
+      resultWriter.setDetail((String)getPortletContext().getAttribute(TEST_PASS_PREFIX + getPortletName()));
+    }
+    else
+    {
+      resultWriter.setStatus(BridgeTCKResultWriter.FAIL);
+      resultWriter.setDetail((String)getPortletContext().getAttribute(TEST_FAIL_PREFIX + getPortletName()));
+    }
+
+    out.println(resultWriter.toString());
+  }
+}

Added: myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_4/section_4_2_6/GetBridgeClassNameMethodTestPortlet.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_4/section_4_2_6/GetBridgeClassNameMethodTestPortlet.java?rev=891458&view=auto
==============================================================================
--- myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_4/section_4_2_6/GetBridgeClassNameMethodTestPortlet.java (added)
+++ myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_4/section_4_2_6/GetBridgeClassNameMethodTestPortlet.java Wed Dec 16 22:27:32 2009
@@ -0,0 +1,194 @@
+/* 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.myfaces.portlet.faces.testsuite.tests.chapter_4.section_4_2_6;
+
+import org.apache.myfaces.portlet.faces.testsuite.common.portlet.GenericFacesTestSuitePortlet;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.portlet.PortletException;
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletContext;
+import java.io.PrintWriter;
+import java.util.List;
+import java.util.Map;
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.UnsupportedEncodingException;
+
+import org.apache.myfaces.portlet.faces.testsuite.common.util.BridgeTCKResultWriter;
+
+/**
+ * Checks that GenericFacesPortlet#getBridgeClassName method works as stated in section 
+ * 4.2.6.  Compares return value with the expected value.
+ */
+
+
+public class GetBridgeClassNameMethodTestPortlet extends GenericFacesTestSuitePortlet
+{
+  public static String TEST_NAME="getBridgeClassNameMethodTest";
+  
+  private static String TEST_ATTR_PREFIX = "test.";
+  private static String TEST_RUN = "testRun";
+  private static String TEST_FAIL = "testFailMsg";
+  private static String TEST_PASS = "testPassMsg";
+  private static String TEST_BRIDGE_SERVICE_CLASSPATH = "META-INF/services/javax.portlet.faces.Bridge";
+
+  public String getBridgeClassName()
+  {
+    String bridgeClassName = super.getBridgeClassName();
+
+    if (getPortletConfig().getPortletContext().getAttribute(TEST_ATTR_PREFIX + getPortletName() + TEST_RUN) == null)
+    {
+      getPortletConfig().getPortletContext().setAttribute(TEST_ATTR_PREFIX + getPortletName() + TEST_RUN, Boolean.TRUE);
+
+      // Get expected class name from PortletContext attribute
+      String expectedClassName = getPortletConfig().getPortletContext().getInitParameter("javax.portlet.faces.BridgeClassName");
+
+      StringBuilder failMsg = new StringBuilder();
+
+      if (expectedClassName == null)
+      {
+        expectedClassName = getFromServicesPath(getPortletConfig().getPortletContext(), TEST_BRIDGE_SERVICE_CLASSPATH);
+      }
+
+      StringBuilder msg = new StringBuilder();
+
+                            
+      if (expectedClassName == null)
+      {
+        msg.append("Bridge class name not set.");
+        getPortletConfig().getPortletContext().setAttribute(TEST_ATTR_PREFIX + TEST_FAIL, msg.toString());
+      }
+      else
+      {
+        msg.append("Expected bridge class name is ")
+           .append(expectedClassName)
+           .append(", value returned from getBridgeClassName() is ")
+           .append(bridgeClassName)
+           .append(".");
+      
+        if (expectedClassName.equals(bridgeClassName))
+        {
+          getPortletConfig().getPortletContext().setAttribute(TEST_ATTR_PREFIX + TEST_PASS, msg.toString());
+        }
+        else
+        {
+          getPortletConfig().getPortletContext().setAttribute(TEST_ATTR_PREFIX + TEST_FAIL, msg.toString());
+        }
+      }
+    }
+    return bridgeClassName;
+  }
+
+  private String getFromServicesPath(PortletContext context, String resourceName)
+  {
+    // Check for a services definition
+    String result = null;
+    BufferedReader reader = null;
+    InputStream stream = null;
+    try
+    {
+      ClassLoader cl = Thread.currentThread().getContextClassLoader();
+      if (cl == null)
+      {
+        return null;
+      }
+
+      stream = cl.getResourceAsStream(resourceName);
+      if (stream != null)
+      {
+        // Deal with systems whose native encoding is possibly
+        // different from the way that the services entry was created
+        try
+        {
+          reader = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
+        } catch (UnsupportedEncodingException e)
+        {
+          reader = new BufferedReader(new InputStreamReader(stream));
+        }
+        result = reader.readLine();
+        if (result != null)
+        {
+          result = result.trim();
+        }
+        reader.close();
+        reader = null;
+        stream = null;
+      }
+    } catch (IOException e)
+    {
+    } catch (SecurityException e)
+    {
+    } finally
+    {
+      if (reader != null)
+      {
+        try
+        {
+          reader.close();
+          stream = null;
+        } catch (Throwable t)
+        {
+          ;
+        }
+        reader = null;
+      }
+      if (stream != null)
+      {
+        try
+        {
+          stream.close();
+        } catch (Throwable t)
+        {
+          ;
+        }
+        stream = null;
+      }
+    }
+    return result;
+  }
+
+  public void render(RenderRequest request, RenderResponse response)
+    throws PortletException, IOException
+  {
+    String passMsg = (String)getPortletConfig().getPortletContext().getAttribute(TEST_ATTR_PREFIX + TEST_PASS);
+
+    response.setContentType("text/html");
+    PrintWriter out = response.getWriter();
+    BridgeTCKResultWriter resultWriter = new BridgeTCKResultWriter(TEST_NAME);
+
+    if (passMsg != null)
+    {
+      resultWriter.setStatus(BridgeTCKResultWriter.PASS);
+      resultWriter.setDetail(passMsg);
+    }
+    else
+    {
+      resultWriter.setStatus(BridgeTCKResultWriter.FAIL);
+      resultWriter.setDetail((String)getPortletConfig().getPortletContext().getAttribute(TEST_ATTR_PREFIX + TEST_FAIL));
+    }
+
+    out.println(resultWriter.toString());
+  }
+}

Added: myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_4/section_4_2_7/GetDefaultViewIdMapMethodTestPortlet.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_4/section_4_2_7/GetDefaultViewIdMapMethodTestPortlet.java?rev=891458&view=auto
==============================================================================
--- myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_4/section_4_2_7/GetDefaultViewIdMapMethodTestPortlet.java (added)
+++ myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_4/section_4_2_7/GetDefaultViewIdMapMethodTestPortlet.java Wed Dec 16 22:27:32 2009
@@ -0,0 +1,123 @@
+/* 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.myfaces.portlet.faces.testsuite.tests.chapter_4.section_4_2_7;
+
+import org.apache.myfaces.portlet.faces.testsuite.common.portlet.GenericFacesTestSuitePortlet;
+import javax.portlet.faces.GenericFacesPortlet;
+import javax.faces.context.FacesContext;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.portlet.PortletException;
+import javax.portlet.PortletConfig;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.List;
+import java.util.Map;
+import java.util.Enumeration;
+
+import org.apache.myfaces.portlet.faces.testsuite.common.util.BridgeTCKResultWriter;
+
+/**
+ * Checks that GenericFacesPortlet#getDefaultViewIdMap method works as stated 
+ * in section 4.2.7.
+ * - The default view id for a portlet mode is defined as a portlet 
+ *   initialization parameter named javax.portlet.faces.defaultViewId.[mode].
+ *   This test confirms that the method returns a map where the key is the 
+ *   string version of [mode] and the map value is the portlet initialization 
+ *   parameter value.
+ */
+
+
+public class GetDefaultViewIdMapMethodTestPortlet extends GenericFacesTestSuitePortlet
+{
+  private static String TEST_NAME="getDefaultViewIdMapMethodTest";
+
+  private static String TEST_FAIL_PREFIX= "test.fail.";
+  private static String TEST_PASS_PREFIX = "test.pass.";
+  private static String DEFAULT_VIEW_ID_INIT_PARAM =
+    "javax.portlet.faces.defaultViewId.";
+ 
+  public Map getDefaultViewIdMap()
+  {
+    Map returnMap = super.getDefaultViewIdMap();
+    getPortletContext().setAttribute(TEST_PASS_PREFIX + getPortletName(), Boolean.TRUE);
+    Enumeration<String> names = getPortletConfig().getInitParameterNames();
+    while (names.hasMoreElements())
+    {
+      
+      String name = names.nextElement();
+      if (name.startsWith(DEFAULT_VIEW_ID_INIT_PARAM))
+      {  
+        String mode = name.substring(DEFAULT_VIEW_ID_INIT_PARAM.length());
+        String viewId = (String)returnMap.get(mode);
+        if (!getPortletConfig().getInitParameter(name).equals(viewId))
+        {
+          getPortletContext().setAttribute(TEST_FAIL_PREFIX + getPortletName() + "." + mode, Boolean.TRUE);
+          getPortletContext().removeAttribute(TEST_PASS_PREFIX + getPortletName());
+        }
+      }
+    }
+    return returnMap;
+  }
+
+  public void render(RenderRequest request, RenderResponse response)
+    throws PortletException, IOException
+  {
+    response.setContentType("text/html");
+    PrintWriter out = response.getWriter();
+
+    boolean pass = getPortletContext().getAttribute(TEST_PASS_PREFIX + getPortletName()) != null;
+
+    StringBuilder failMsg = null;
+    if (!pass)
+    {
+      failMsg = new StringBuilder();
+
+      Enumeration<String> names = getPortletContext().getAttributeNames();
+      while (names.hasMoreElements())
+      {
+        String name = names.nextElement();
+        out.println("--- " + name + " ---");
+        int idx = name.indexOf(TEST_FAIL_PREFIX + getPortletName() + ".");
+        
+        if (name.startsWith(TEST_FAIL_PREFIX))
+        {
+          String prefix = TEST_FAIL_PREFIX + getPortletName() + ".";
+          failMsg.append("Missing mode: " + name.substring(prefix.length()) + ".");
+        }
+      }
+    }
+
+    BridgeTCKResultWriter resultWriter = new BridgeTCKResultWriter(TEST_NAME);
+
+    if (pass)
+    {
+      resultWriter.setStatus(BridgeTCKResultWriter.PASS);
+      resultWriter.setDetail("getDefaultViewIdMap() method returns successfully.");
+    }
+    else
+    {
+      resultWriter.setStatus(BridgeTCKResultWriter.FAIL);
+      resultWriter.setDetail(failMsg.toString());
+    }
+
+    out.println(resultWriter.toString());
+  }
+}

Added: myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_4/section_4_2_8/GetExcludedRequestAttributesMethodTestPortlet.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_4/section_4_2_8/GetExcludedRequestAttributesMethodTestPortlet.java?rev=891458&view=auto
==============================================================================
--- myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_4/section_4_2_8/GetExcludedRequestAttributesMethodTestPortlet.java (added)
+++ myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_4/section_4_2_8/GetExcludedRequestAttributesMethodTestPortlet.java Wed Dec 16 22:27:32 2009
@@ -0,0 +1,165 @@
+/* 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.myfaces.portlet.faces.testsuite.tests.chapter_4.section_4_2_8;
+
+import org.apache.myfaces.portlet.faces.testsuite.common.portlet.GenericFacesTestSuitePortlet;
+import javax.portlet.faces.GenericFacesPortlet;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.portlet.PortletException;
+import java.io.PrintWriter;
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.myfaces.portlet.faces.testsuite.common.util.BridgeTCKResultWriter;
+
+/**
+ * Checks that GenericFacesPortlet#getExcludedRequestAttributes method works as stated 
+ * in section 4.2.8.
+ * - Excluded request attributes are defined in a portlet initialisation
+ *   parameter with name javax.portlet.faces.excludedRequestAttributes and 
+ *   value one or more comma separated strings.  This test 
+ *   confirms that the method returns a list of string values based on
+ *   parsing the initialisation parameter value.
+ */
+
+
+public class GetExcludedRequestAttributesMethodTestPortlet extends GenericFacesTestSuitePortlet
+{
+  private static String TEST_FAIL_PREFIX = "test.fail.";
+  private static String TEST_PASS_PREFIX = "test.pass.";
+  private static String EXCLUDED_REQUEST_ATTRIBUTES_INIT_PARAM =
+    "javax.portlet.faces.excludedRequestAttributes";
+ 
+  public List<String> getExcludedRequestAttributes()
+  {
+    List<String> returnList = super.getExcludedRequestAttributes();
+    getPortletContext().setAttribute(TEST_PASS_PREFIX + getPortletName(), Boolean.TRUE);
+
+    String excludedAttrValue = getPortletConfig().getInitParameter(EXCLUDED_REQUEST_ATTRIBUTES_INIT_PARAM);
+    if (excludedAttrValue == null)
+    {
+      if (returnList == null)
+      {
+        getPortletContext().setAttribute(TEST_PASS_PREFIX + getPortletName(), "getExcludedRequestAttributes() correctly returned null.");
+        return returnList;
+      }
+      else
+      {
+        StringBuilder failMsg = new StringBuilder();
+        failMsg.append("getExcludedRequestAttributes() incorrectly returned null.  Expected attribute names are: ");
+        boolean listStarted = false;
+        for (String name: returnList)
+        {
+          if (listStarted)
+          {
+            failMsg.append(", ");
+          }
+          else
+          {
+            listStarted = true;
+          }
+          failMsg.append(name);
+        }
+        
+        getPortletContext().setAttribute(TEST_FAIL_PREFIX + getPortletName(), failMsg.toString());
+        return returnList;
+      }
+    }
+
+    StringBuilder passMsg = new StringBuilder();
+    StringBuilder failMsg = new StringBuilder();
+
+    String[] excludedAttrs = excludedAttrValue.split(",");
+
+    for (String expectedAttribute: excludedAttrs)
+    {
+      expectedAttribute = expectedAttribute.trim();
+      boolean found = false;
+      for (String methodAttribute: returnList)
+      {
+        if (expectedAttribute.equals(methodAttribute))
+        {
+          found = true;
+          if (passMsg.length() == 0)
+          {
+            passMsg.append("getExcludedRequestAttributes() correctly returned the following excluded request attribute names: ");
+          }
+          else
+          {
+            passMsg.append(", ");
+          }
+          passMsg.append(expectedAttribute);
+        }
+      }
+      if (!found)
+      {
+        // Expected list value not found
+        if (failMsg.length() == 0)
+        {
+          failMsg.append("getExcludedRequestAttributes() did not correctly return the following excluded request attribute names: ");
+        }
+        else
+        {
+          failMsg.append(", ");
+        }
+        failMsg.append(expectedAttribute);
+      }
+    }
+
+    if (failMsg.length() != 0)
+    {
+      failMsg.append(".");
+      getPortletContext().setAttribute(TEST_FAIL_PREFIX + getPortletName(), failMsg.toString());
+    }
+    
+    if (passMsg.length() != 0)
+    {
+      passMsg.append(".");
+      getPortletContext().setAttribute(TEST_PASS_PREFIX + getPortletName(), passMsg.toString());
+    }
+
+    return returnList;
+  }
+
+  public void render(RenderRequest request, RenderResponse response)
+    throws PortletException, IOException
+  {
+    response.setContentType("text/html");
+    PrintWriter out = response.getWriter();
+
+    boolean pass = getPortletContext().getAttribute(TEST_FAIL_PREFIX + getPortletName()) == null;
+
+    BridgeTCKResultWriter resultWriter = new BridgeTCKResultWriter(getTestName());
+
+    if (pass)
+    {
+      resultWriter.setStatus(BridgeTCKResultWriter.PASS);
+      resultWriter.setDetail((String)getPortletContext().getAttribute(TEST_PASS_PREFIX + getPortletName()));
+    }
+    else
+    {
+      resultWriter.setStatus(BridgeTCKResultWriter.FAIL);
+      resultWriter.setDetail((String)getPortletContext().getAttribute(TEST_FAIL_PREFIX + getPortletName()));
+    }
+
+    out.println(resultWriter.toString());
+  }
+}

Added: myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_4/section_4_2_9/IsPreserveActionParametersMethodTestPortlet.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_4/section_4_2_9/IsPreserveActionParametersMethodTestPortlet.java?rev=891458&view=auto
==============================================================================
--- myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_4/section_4_2_9/IsPreserveActionParametersMethodTestPortlet.java (added)
+++ myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_4/section_4_2_9/IsPreserveActionParametersMethodTestPortlet.java Wed Dec 16 22:27:32 2009
@@ -0,0 +1,107 @@
+/* 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.myfaces.portlet.faces.testsuite.tests.chapter_4.section_4_2_9;
+
+import org.apache.myfaces.portlet.faces.testsuite.common.portlet.GenericFacesTestSuitePortlet;
+import javax.portlet.faces.GenericFacesPortlet;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.portlet.PortletException;
+import java.io.PrintWriter;
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.myfaces.portlet.faces.testsuite.common.util.BridgeTCKResultWriter;
+
+/**
+ * Checks that GenericFacesPortlet#isPreserveActionParameters method works as stated 
+ * in section 4.2.9.
+ * - Returns the boolean value corresponding to the String value represented in
+ *   the portlet initialization parameter, javax.portlet.faces.preserveActionParams.  
+ *   If this initialization parameter doesn't exist, false is returned.
+ */
+
+public class IsPreserveActionParametersMethodTestPortlet extends GenericFacesTestSuitePortlet
+{
+  private static String TEST_FAIL_PREFIX = "test.fail.";
+  private static String TEST_PASS_PREFIX = "test.pass.";
+  private static String IS_PRESERVE_ACTION_PARAMS_INIT_PARAM =
+    "javax.portlet.faces.preserveActionParams";
+ 
+  public boolean isPreserveActionParameters()
+  {
+    boolean returnBoolean = super.isPreserveActionParameters();
+
+    String initParamValue = getPortletConfig().getInitParameter(IS_PRESERVE_ACTION_PARAMS_INIT_PARAM);
+
+    StringBuilder msg = new StringBuilder();
+    boolean expectedResult = false;
+
+    if (initParamValue == null)
+    {
+      msg.append("isPreserveActionParams is not set, method returned from isPreserveActionParams() is ");
+      expectedResult = false;
+    }
+    else
+    {
+      msg.append("isPreserveActionParams is set to ")
+         .append(initParamValue)
+         .append(", method returned from isPreserveActionParams() is ");
+      expectedResult = Boolean.valueOf(initParamValue);
+    }
+
+    msg.append(Boolean.toString(returnBoolean)).append(".");
+
+    if (expectedResult == returnBoolean)
+    {
+      getPortletContext().setAttribute(TEST_PASS_PREFIX + getPortletName(), msg.toString());
+    }
+    else
+    {
+      getPortletContext().setAttribute(TEST_FAIL_PREFIX + getPortletName(), msg.toString());
+    }
+
+    return returnBoolean;
+  }
+
+  public void render(RenderRequest request, RenderResponse response)
+    throws PortletException, IOException
+  {
+    response.setContentType("text/html");
+    PrintWriter out = response.getWriter();
+
+    boolean pass = getPortletContext().getAttribute(TEST_FAIL_PREFIX + getPortletName()) == null;
+
+    BridgeTCKResultWriter resultWriter = new BridgeTCKResultWriter(getTestName());
+
+    if (pass)
+    {
+      resultWriter.setStatus(BridgeTCKResultWriter.PASS);
+      resultWriter.setDetail((String)getPortletContext().getAttribute(TEST_PASS_PREFIX + getPortletName()));
+    }
+    else
+    {
+      resultWriter.setStatus(BridgeTCKResultWriter.FAIL);
+      resultWriter.setDetail((String)getPortletContext().getAttribute(TEST_FAIL_PREFIX + getPortletName()));
+    }
+
+    out.println(resultWriter.toString());
+  }
+}



Mime
View raw message