You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by mf...@apache.org on 2010/01/19 22:21:44 UTC

svn commit: r900963 [1/2] - in /myfaces/portlet-bridge/testsuite/trunk/src: main/java/org/apache/myfaces/portlet/faces/testsuite/beans/ main/java/org/apache/myfaces/portlet/faces/testsuite/common/portlet/ main/java/org/apache/myfaces/portlet/faces/test...

Author: mfreedman
Date: Tue Jan 19 21:21:42 2010
New Revision: 900963

URL: http://svn.apache.org/viewvc?rev=900963&view=rev
Log:
Added Tests for Chapter 5.

Added:
    myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/beans/AnnotatedExcludedBean.java
    myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_5/
    myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_5/section_5_1_2/
    myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_5/section_5_1_2/BridgeClearRequestScopePortlet.java
    myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_5/section_5_1_2/Tests.java
    myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_5/section_5_2/
    myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_5/section_5_2/ManualBridgeInvokePortlet.java
    myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_5/section_5_2/Tests.java
    myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_5/section_5_3/
    myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_5/section_5_3/Tests.java
    myfaces/portlet-bridge/testsuite/trunk/src/main/webapp/tests/RedisplayActionRequestTest.jsp
    myfaces/portlet-bridge/testsuite/trunk/src/main/webapp/tests/RedisplayRenderNewModeRequestTest.jsp
Modified:
    myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/beans/TestRunnerBean.java
    myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/common/portlet/GenericFacesTestSuitePortlet.java
    myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/common/util/faces/application/TestSuiteViewHandlerImpl.java
    myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/common/util/faces/context/TCK_FacesContextFactoryImpl.java
    myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/common/util/faces/context/TCK_FacesContextImpl.java
    myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_3/PortletSetsViewTestPortlet.java
    myfaces/portlet-bridge/testsuite/trunk/src/main/webapp/WEB-INF/faces-config.xml
    myfaces/portlet-bridge/testsuite/trunk/src/main/webapp/WEB-INF/portlet.xml
    myfaces/portlet-bridge/testsuite/trunk/src/main/webapp/tests/RedisplayRenderRequestTest.jsp
    myfaces/portlet-bridge/testsuite/trunk/src/test/java/org/apache/myfaces/portlet/faces/tckharness/TckTestCase.java

Added: myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/beans/AnnotatedExcludedBean.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/beans/AnnotatedExcludedBean.java?rev=900963&view=auto
==============================================================================
--- myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/beans/AnnotatedExcludedBean.java (added)
+++ myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/beans/AnnotatedExcludedBean.java Tue Jan 19 21:21:42 2010
@@ -0,0 +1,40 @@
+/* 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.beans;
+
+import javax.annotation.PreDestroy;
+
+import javax.faces.context.FacesContext;
+
+import javax.portlet.PortletRequest;
+import javax.portlet.faces.annotation.BridgePreDestroy;
+import javax.portlet.faces.annotation.BridgeRequestScopeAttributeAdded;
+import javax.portlet.faces.annotation.ExcludeFromManagedRequestScope;
+
+// Mark that this bean shouldn't be included.
+@ExcludeFromManagedRequestScope
+public class AnnotatedExcludedBean
+{
+ 
+  public AnnotatedExcludedBean()
+  {
+  }
+  
+}

Modified: myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/beans/TestRunnerBean.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/beans/TestRunnerBean.java?rev=900963&r1=900962&r2=900963&view=diff
==============================================================================
--- myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/beans/TestRunnerBean.java (original)
+++ myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/beans/TestRunnerBean.java Tue Jan 19 21:21:42 2010
@@ -114,8 +114,21 @@
   // Run the test and renders the result 
   public String getRenderTestResult()
   {
-    runTest();
-    return getTestResult();
+    return getTestResult(runTest());
+  }
+  
+  public String getRedisplayLinkName()
+  {
+    // Still running test is test is neither marked complete in the bean itself or in the session attribute
+    // Later exists for tests that span mode changes/scope changes where the test bean is lost.
+    if (!isTestComplete() && FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("org.apache.myfaces.portlet.faces.tck.testCompleted") == null)
+    {
+      return "Run Test";
+    }
+    else
+    {
+      return "Test Complete";
+    }
   }
 
   public void setTestResult(boolean passed, String detail)
@@ -128,11 +141,29 @@
   }
 
   // Merely renders the test result that was previously set.
+  public String getTestResult(String s)
+  {
+    if (mResultWriter == null)
+    {
+      if (s != null && !s.equals(Constants.TEST_SUCCESS) && !s.equals(Constants.TEST_FAILED))
+      {
+        return s;
+      }
+      else
+      {
+        setTestResult(false, "Test failed: A test result hasn't been set! Usually this indicates the request flow broken due to bridge failure.");
+      }
+    }
+      
+    return mResultWriter.toString();
+  }
+  
   public String getTestResult()
   {
     if (mResultWriter == null)
+    {
       setTestResult(false, "Test failed: A test result hasn't been set! Usually this indicates the request flow broken due to bridge failure.");
-      
+    }
       
     return mResultWriter.toString();
   }

Modified: myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/common/portlet/GenericFacesTestSuitePortlet.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/common/portlet/GenericFacesTestSuitePortlet.java?rev=900963&r1=900962&r2=900963&view=diff
==============================================================================
--- myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/common/portlet/GenericFacesTestSuitePortlet.java (original)
+++ myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/common/portlet/GenericFacesTestSuitePortlet.java Tue Jan 19 21:21:42 2010
@@ -26,6 +26,7 @@
 import javax.portlet.PortletConfig;
 import javax.portlet.PortletException;
 import javax.portlet.PortletRequest;
+import javax.portlet.PortletResponse;
 import javax.portlet.RenderRequest;
 import javax.portlet.RenderResponse;
 import javax.portlet.faces.Bridge;
@@ -82,6 +83,12 @@
   {
     return mTestName;
   }
+  
+  public Bridge getFacesBridge(PortletRequest request, PortletResponse response) throws PortletException
+  {
+    initTestRequest(request);
+    return super.getFacesBridge(request, response);
+  }
  
   private void initTestRequest(PortletRequest portletRequest)
   {

Modified: myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/common/util/faces/application/TestSuiteViewHandlerImpl.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/common/util/faces/application/TestSuiteViewHandlerImpl.java?rev=900963&r1=900962&r2=900963&view=diff
==============================================================================
--- myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/common/util/faces/application/TestSuiteViewHandlerImpl.java (original)
+++ myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/common/util/faces/application/TestSuiteViewHandlerImpl.java Tue Jan 19 21:21:42 2010
@@ -76,6 +76,22 @@
   {
     return mDelegate;
   }
+  
+  @Override
+  public UIViewRoot createView(FacesContext ctx, String viewId)
+    throws IllegalArgumentException, NullPointerException
+  {
+    ctx.getExternalContext().getRequestMap().put("org.apache.portlet.faces.tck.viewCreated", Boolean.TRUE);
+    return super.createView(ctx, viewId);
+  }
+  
+  @Override
+  public UIViewRoot restoreView(FacesContext ctx, String viewId)
+    throws FacesException, NullPointerException
+  {
+    ctx.getExternalContext().getRequestMap().put("org.apache.portlet.faces.tck.viewCreated", Boolean.FALSE);
+    return super.restoreView(ctx, viewId);
+  }
 
 
   @Override

Modified: myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/common/util/faces/context/TCK_FacesContextFactoryImpl.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/common/util/faces/context/TCK_FacesContextFactoryImpl.java?rev=900963&r1=900962&r2=900963&view=diff
==============================================================================
--- myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/common/util/faces/context/TCK_FacesContextFactoryImpl.java (original)
+++ myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/common/util/faces/context/TCK_FacesContextFactoryImpl.java Tue Jan 19 21:21:42 2010
@@ -28,6 +28,7 @@
 
 import javax.faces.lifecycle.LifecycleFactory;
 
+import javax.portlet.ActionRequest;
 import javax.portlet.PortletConfig;
 import javax.portlet.PortletContext;
 import javax.portlet.PortletRequest;
@@ -61,6 +62,12 @@
     // including that the bridge doesn't depend on its impl class being the instance
     if (isPortletRequest(request))
     {
+      // Verify we were passed the right objects
+      verifyPortletObjects(context, request, response);
+      
+      // verify portlet phase
+      verifyPortletPhase((PortletRequest) request);
+      
       // Verify we are using the right lifecycle
       verifyLifecycle((PortletContext) context, (PortletRequest) request, lifecycle);
       
@@ -93,6 +100,45 @@
     return false;
   }
   
+  private void verifyPortletPhase(PortletRequest request)
+  {
+    Bridge.PortletPhase phase = (Bridge.PortletPhase) request.getAttribute("javax.portlet.faces.phase"); 
+    if (request instanceof ActionRequest)
+    {
+      if (phase != null && phase == Bridge.PortletPhase.ACTION_PHASE)
+      {
+        request.setAttribute("javax.portlet.faces.tck.verifyPortletPhaseDuringActionPass", "Phase attribute correctly set during action ... ");
+      }
+      else
+      {
+        request.setAttribute("javax.portlet.faces.tck.verifyPortletPhaseDuringActionFail", "Phase attribute either not set or has incorrect value during action ... ");
+      }
+    }
+    else
+    {
+      if (phase != null && phase == Bridge.PortletPhase.RENDER_PHASE)
+      {
+        request.setAttribute("javax.portlet.faces.tck.verifyPortletPhaseDuringRenderPass", "Phase attribute correctly set during render.");
+      }
+      else
+      {
+        request.setAttribute("javax.portlet.faces.tck.verifyPortletPhaseDuringRenderFail", "Phase attribute either not set or has incorrect value during render.");
+      }
+    }
+  }
+  
+  private void verifyPortletObjects(Object context, Object request, Object response)
+  {
+    if (context instanceof PortletContext && request instanceof PortletRequest && response instanceof PortletResponse)
+    {
+      ((PortletRequest)request).setAttribute("javax.portlet.faces.tck.verifyPortletObjectsPass", "Correctly passed a PortletContext, PortletRequest, and PortletResponse in acquiring a FacesContext");
+    }
+    else
+    {
+      ((PortletRequest)request).setAttribute("javax.portlet.faces.tck.verifyPortletObjectsFail", "At least one of the objects passed to acquire a FacesContext wasn't a  PortletContext, PortletRequest, or PortletResponse");
+    }  
+  }
+  
   private void verifyLifecycle(PortletContext context, PortletRequest request, Lifecycle lifecycle)
   {
     String id = context.getInitParameter("javax.faces.LIFECYCLE_ID");

Modified: myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/common/util/faces/context/TCK_FacesContextImpl.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/common/util/faces/context/TCK_FacesContextImpl.java?rev=900963&r1=900962&r2=900963&view=diff
==============================================================================
--- myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/common/util/faces/context/TCK_FacesContextImpl.java (original)
+++ myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/common/util/faces/context/TCK_FacesContextImpl.java Tue Jan 19 21:21:42 2010
@@ -43,6 +43,7 @@
   {
     mWrapped = ctx;
     
+    FacesContext.setCurrentInstance(this);
   }
   
   // Start of JSF 1.2 API
@@ -137,6 +138,7 @@
 
   public void release()
   { 
+    getExternalContext().getRequestMap().put("org.apache.portlet.faces.tck.facesContextReleased", Boolean.TRUE);
     mWrapped.release();
   }
 

Modified: myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_3/PortletSetsViewTestPortlet.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_3/PortletSetsViewTestPortlet.java?rev=900963&r1=900962&r2=900963&view=diff
==============================================================================
--- myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_3/PortletSetsViewTestPortlet.java (original)
+++ myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_3/PortletSetsViewTestPortlet.java Tue Jan 19 21:21:42 2010
@@ -32,6 +32,7 @@
 import javax.portlet.RenderRequest;
 import javax.portlet.RenderResponse;
 import javax.portlet.faces.Bridge;
+import javax.portlet.faces.BridgeInvalidViewPathException;
 import javax.portlet.faces.BridgeUninitializedException;
 import javax.portlet.faces.GenericFacesPortlet;
 
@@ -39,11 +40,15 @@
 import org.apache.myfaces.portlet.faces.testsuite.common.portlet.GenericFacesTestSuitePortlet;
 import org.apache.myfaces.portlet.faces.testsuite.common.util.BridgeTCKResultWriter;
 
-public class PortletSetsViewTestPortlet extends GenericFacesTestSuitePortlet
+public class PortletSetsViewTestPortlet
+  extends GenericFacesTestSuitePortlet
 {
-  private final static String SETSVIEWID_TEST = "portletSetsViewIdTest";
-  private final static String SETSVIEWPATH_TEST = "portletSetsViewPathTest";
-  
+  private static final String SETSVIEWID_TEST = "portletSetsViewIdTest";
+  private static final String SETSVIEWPATH_TEST = 
+    "portletSetsViewPathTest";
+  private static final String SETSINVALIDVIEWPATH_TEST = 
+    "portletSetsInvalidViewPathTest";
+
   public void init(PortletConfig config)
     throws PortletException
   {
@@ -51,21 +56,68 @@
 
   }
 
-  
-  public void doDispatch(RenderRequest renderRequest, RenderResponse renderResponse)
+
+  public void doDispatch(RenderRequest renderRequest, 
+                         RenderResponse renderResponse)
     throws PortletException, IOException
   {
     if (getTestName().equals(SETSVIEWID_TEST))
     {
-      renderRequest.setAttribute(Bridge.VIEW_ID, "/tests/PortletSetsViewIdTestSuccess.jsp");
+      renderRequest.setAttribute(Bridge.VIEW_ID, 
+                                 "/tests/PortletSetsViewIdTestSuccess.jsp");
+      super.doDispatch(renderRequest, renderResponse);
     }
     else if (getTestName().equals(SETSVIEWPATH_TEST))
     {
-      renderRequest.setAttribute(Bridge.VIEW_PATH, "/tests/PortletSetsViewIdTestSuccess.jsf");
+      renderRequest.setAttribute(Bridge.VIEW_PATH, 
+                                 "/tests/PortletSetsViewIdTestSuccess.jsf");
+      super.doDispatch(renderRequest, renderResponse);
+    }
+    else if (getTestName().equals(SETSINVALIDVIEWPATH_TEST))
+    {
+      renderRequest.setAttribute(Bridge.VIEW_PATH, 
+                                 "/tests/InvalidViewPath.jsp");
+      Bridge bridge = super.getFacesBridge(renderRequest, renderResponse);
+      try
+      {
+        bridge.doFacesRequest(renderRequest, renderResponse);
+        outputInvalidViewPathTestResult(renderResponse, false);
+      }
+      catch (BridgeInvalidViewPathException e)
+      {
+        outputInvalidViewPathTestResult(renderResponse, true);
+      }
+      catch (Exception e)
+      {
+        outputInvalidViewPathTestResult(renderResponse, false);
+      }
     }
-   
-    super.doDispatch(renderRequest, renderResponse);
+
   }
-  
 
-}
\ No newline at end of file
+  private void outputInvalidViewPathTestResult(RenderResponse response, 
+                                               boolean pass)
+    throws IOException
+  {
+    if (getTestName().equals(SETSINVALIDVIEWPATH_TEST))
+    {
+      response.setContentType("text/html");
+      PrintWriter out = response.getWriter();
+      BridgeTCKResultWriter resultWriter = 
+        new BridgeTCKResultWriter(getTestName());
+
+      if (pass)
+      {
+        resultWriter.setStatus(BridgeTCKResultWriter.PASS);
+        resultWriter.setDetail("Correctly threw BridgeInvalidViewPathException when passed a bad path.");
+      }
+      else
+      {
+        resultWriter.setStatus(BridgeTCKResultWriter.FAIL);
+        resultWriter.setDetail("Didn't throw BridgeInvalidViewPathException when passed a bad path.");
+      }
+
+      out.println(resultWriter.toString());
+    }
+  }
+}

Added: myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_5/section_5_1_2/BridgeClearRequestScopePortlet.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_5/section_5_1_2/BridgeClearRequestScopePortlet.java?rev=900963&view=auto
==============================================================================
--- myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_5/section_5_1_2/BridgeClearRequestScopePortlet.java (added)
+++ myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_5/section_5_1_2/BridgeClearRequestScopePortlet.java Tue Jan 19 21:21:42 2010
@@ -0,0 +1,145 @@
+/* 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_5.section_5_1_2;
+
+import java.io.IOException;
+
+import java.io.PrintWriter;
+
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.faces.FactoryFinder;
+import javax.faces.application.FacesMessage;
+import javax.faces.event.PhaseEvent;
+import javax.faces.event.PhaseId;
+import javax.faces.event.PhaseListener;
+
+import javax.faces.lifecycle.LifecycleFactory;
+
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletException;
+import javax.portlet.PortletRequest;
+import javax.portlet.PortletResponse;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.portlet.faces.Bridge;
+import javax.portlet.faces.BridgeUninitializedException;
+import javax.portlet.faces.GenericFacesPortlet;
+
+import org.apache.myfaces.portlet.faces.testsuite.common.Constants;
+import org.apache.myfaces.portlet.faces.testsuite.common.portlet.GenericFacesTestSuitePortlet;
+import org.apache.myfaces.portlet.faces.testsuite.common.util.BridgeTCKResultWriter;
+
+public class BridgeClearRequestScopePortlet extends GenericFacesTestSuitePortlet implements PhaseListener
+{
+ 
+  static final String MESSAGE_VALUE1 = "Test Message1 Retention.";
+  static final String MESSAGE_VALUE2 = "Test Message2 Retention.";
+  
+  public void init(PortletConfig config)
+    throws PortletException
+  {
+    super.init(config);
+
+  }
+  public void processAction(ActionRequest actionRequest, ActionResponse actionResponse)
+    throws PortletException, IOException
+  {
+    Map<String, Object> m = copyAttributes(actionRequest);
+    addLifecycleListener();
+    super.processAction(actionRequest, actionResponse);
+    removeLifecycleListener();
+    clearAttributes(actionRequest, m);
+  }
+  
+  public void doDispatch(RenderRequest renderRequest, RenderResponse renderResponse)
+    throws PortletException, IOException
+  {
+    super.doDispatch(renderRequest, renderResponse);
+  }
+
+
+  private Map<String, Object> copyAttributes(ActionRequest r)
+  {
+    Map<String, Object> m = new HashMap(20);
+    Enumeration<String> e = r.getAttributeNames();
+    while (e.hasMoreElements())
+    {
+      String key = e.nextElement();
+      Object o = r.getAttribute(key);
+      m.put(key, o);
+    }
+    return m;
+  }
+  
+  private void clearAttributes(ActionRequest r, Map<String, Object> m)
+  {
+
+    Enumeration<String> e = r.getAttributeNames();
+    while (e.hasMoreElements())
+    {
+      String key = e.nextElement();
+      if (!m.containsKey(key))
+      {
+        r.removeAttribute(key);
+      }
+    }
+  }
+  
+  private void addLifecycleListener()
+  {
+    LifecycleFactory factory = (LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
+    for (Iterator<String> lIds = factory.getLifecycleIds(); lIds.hasNext();)
+    {
+      factory.getLifecycle(lIds.next()).addPhaseListener(this);
+    }
+  }
+  
+  private void removeLifecycleListener()
+  {
+    LifecycleFactory factory = (LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
+    for (Iterator<String> lIds = factory.getLifecycleIds(); lIds.hasNext();)
+    {
+      factory.getLifecycle(lIds.next()).removePhaseListener(this);
+    }
+  }
+  
+  // PhaseListener methods
+  public PhaseId getPhaseId()
+  {
+    return PhaseId.INVOKE_APPLICATION;
+  }
+  
+  public void beforePhase(PhaseEvent e)
+  {
+  }
+  
+  public void afterPhase(PhaseEvent e)
+  {
+    // Now that we are after the navigation and have the new view tree -- add the message
+    e.getFacesContext().addMessage(e.getFacesContext().getViewRoot().getClientId(e.getFacesContext()), new FacesMessage(MESSAGE_VALUE1));
+    e.getFacesContext().addMessage(e.getFacesContext().getViewRoot().getClientId(e.getFacesContext()), new FacesMessage(MESSAGE_VALUE2));
+  }
+}
\ No newline at end of file

Added: myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_5/section_5_1_2/Tests.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_5/section_5_1_2/Tests.java?rev=900963&view=auto
==============================================================================
--- myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_5/section_5_1_2/Tests.java (added)
+++ myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_5/section_5_1_2/Tests.java Tue Jan 19 21:21:42 2010
@@ -0,0 +1,748 @@
+/* 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_5.section_5_1_2;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.HashMap;
+
+import java.util.Set;
+
+import javax.faces.FacesException;
+import javax.faces.FactoryFinder;
+import javax.faces.application.FacesMessage;
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+
+import javax.faces.event.PhaseEvent;
+import javax.faces.event.PhaseId;
+import javax.faces.event.PhaseListener;
+
+import javax.faces.lifecycle.LifecycleFactory;
+
+import javax.portlet.ActionResponse;
+import javax.portlet.PortalContext;
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletContext;
+import javax.portlet.PortletMode;
+import javax.portlet.PortletPreferences;
+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.beans.AnnotatedExcludedBean;
+import org.apache.myfaces.portlet.faces.testsuite.common.Constants;
+
+public class Tests
+  extends Object
+{
+  static final String MESSAGE_VALUE1 = "Test Message1 Retention.";
+  static final String MESSAGE_VALUE2 = "Test Message2 Retention.";
+  static final String REQUEST_ATTR_VALUE = "T1";
+  
+  // Test is MultiRequest -- Render/Action
+  // Test #5.1
+  @BridgeTest(test = "requestScopeContentsTest")
+  public String requestScopeContentsTest(TestRunnerBean testRunner)
+  {
+    FacesContext ctx = FacesContext.getCurrentInstance();
+    ExternalContext extCtx = ctx.getExternalContext();
+    UIViewRoot viewRoot = ctx.getViewRoot();
+    Map m = extCtx.getRequestMap();
+    
+    // In the action portion create/attach things to request scope that should either be preserved or
+    // are explicitly excluded -- test for presence/absence in render
+    if (BridgeUtil.getPortletRequestPhase() ==
+        Bridge.PortletPhase.ACTION_PHASE)
+    {
+      // mark the test as compelte -- put in session in case the bridge fails in preserving the request scope
+      extCtx.getSessionMap().put("org.apache.myfaces.portlet.faces.tck.testComplete", Boolean.TRUE);
+      // Add elements that should be preserved:
+      // Messages need to be added after InvokeApplication (i.e. once navigation has occurred -- so we attach to the right ViewRoot
+      // The lifecycleListener is in the portlet that drives this test 
+      
+     
+      m.put("org.apache.myfaces.portlet.faces.tck.TestRequestScope_a", REQUEST_ATTR_VALUE);
+      
+      // Add elements that should be excluded
+      m.put("org.apache.myfaces.portlet.faces.tck.TestRequestScope_b", new AnnotatedExcludedBean());
+      // Don't need to add additional excludedAttributes tests as they are covered in chapter 6 tests
+      
+      PortletConfig config = (PortletConfig) ctx.getELContext().getELResolver().getValue(ctx.getELContext(), null, "portletConfig");
+      if (config == null)
+      {
+        throw new IllegalStateException("Unable to acquire the portletConfig!");
+      }
+      m.put("org.apache.myfaces.portlet.faces.tck.PortletConfig", config);
+      
+      m.put("org.apache.myfaces.portlet.faces.tck.PortletContext", extCtx.getContext());
+      m.put("org.apache.myfaces.portlet.faces.tck.PortletRequest", extCtx.getRequest());
+      m.put("org.apache.myfaces.portlet.faces.tck.PortletResponse", extCtx.getResponse());
+      m.put("org.apache.myfaces.portlet.faces.tck.PortletSession", extCtx.getSession(true));
+      PortletRequest r = (PortletRequest) extCtx.getRequest();
+      PortletPreferences prefs = r.getPreferences();
+      m.put("org.apache.myfaces.portlet.faces.tck.PortletPreferences", prefs);      
+      PortalContext pc = r.getPortalContext();
+      m.put("org.apache.myfaces.portlet.faces.tck.PortalContext", pc);
+        
+      m.put("org.apache.myfaces.portlet.faces.tck.FacesContext", ctx);
+      m.put("org.apache.myfaces.portlet.faces.tck.ExternalContext", extCtx);
+      
+      // Note:  no way to test the servlet objects
+      
+      m.put("javax.portlet.TestRequestScope", REQUEST_ATTR_VALUE);
+      m.put("javax.portlet.faces.TestRequestScope", REQUEST_ATTR_VALUE);
+      m.put("javax.faces.TestRequestScope", REQUEST_ATTR_VALUE);
+      m.put("javax.servlet.TestRequestScope", REQUEST_ATTR_VALUE);
+      m.put("javax.servlet.include.TestRequestScope", REQUEST_ATTR_VALUE);  
+      
+      return "requestScopeContentsTest"; // action Navigation result
+    }
+    else
+    {     
+      if (extCtx.getSessionMap().get("org.apache.myfaces.portlet.faces.tck.testComplete") == null)
+      {
+        return "Test is still in progress ...";
+      }
+      else
+      {
+        extCtx.getSessionMap().remove("org.apache.myfaces.portlet.faces.tck.testComplete");
+        testRunner.setTestComplete(true);
+      }
+      // Now verify that what should have been carried forward has and what shouldn't hasn't.
+      
+      // Check for the message we aded
+      boolean found1 = false;
+      boolean found2 = false;
+      for (Iterator<FacesMessage> i = ctx.getMessages(viewRoot.getClientId(ctx)); i.hasNext();)
+      {
+        FacesMessage message = i.next();
+        if (message.getSummary().equals(MESSAGE_VALUE1) && !found2)
+        {
+          found1 = true;
+        }
+        else if (message.getSummary().equals(MESSAGE_VALUE2) && found1)
+        {
+          found2 = true;
+        }
+      }
+
+      if (!found1 || !found2)
+      {
+        testRunner.setTestResult(false,
+                                 "Messages added to UIViewRoot not retained as expected. Either there weren't preserved or they weren't preserved in the correct order.");
+        return Constants.TEST_FAILED;
+      }
+      
+      String s = (String) m.get("org.apache.myfaces.portlet.faces.tck.TestRequestScope_a");
+      if (s == null || !s.equals(REQUEST_ATTR_VALUE))
+      {
+        testRunner.setTestResult(false,
+                                 "Expected request attribute not retained: org.apache.myfaces.portlet.faces.tck.TestRequestScope_a.");
+        return Constants.TEST_FAILED;
+      }
+      
+      // Add elements that should be excluded
+      Object o = m.get("org.apache.myfaces.portlet.faces.tck.TestRequestScope_b");
+      if (o != null)
+      {
+        testRunner.setTestResult(false,
+                                 "Attribute annotated (for exclusion) unexpectedly retained: org.apache.myfaces.portlet.faces.tck.TestRequestScope_b.");
+        return Constants.TEST_FAILED;
+      }
+      
+      o = m.get("org.apache.myfaces.portlet.faces.tck.PortletConfig");
+      if (o != null)
+      {
+        testRunner.setTestResult(false,
+                                 "Attribute containing PortletConfig unexpectedly retained: org.apache.myfaces.portlet.faces.tck.PortletConfig.");
+        return Constants.TEST_FAILED;
+      }
+      
+      o = m.get("org.apache.myfaces.portlet.faces.tck.PortletContext");
+      if (o != null)
+      {
+        testRunner.setTestResult(false,
+                                 "Attribute containing PortletContext unexpectedly retained: org.apache.myfaces.portlet.faces.tck.PortletContext.");
+        return Constants.TEST_FAILED;
+      }
+
+      o = m.get("org.apache.myfaces.portlet.faces.tck.PortletRequest");
+      if (o != null)
+      {
+        testRunner.setTestResult(false,
+                                 "Attribute containing PortletRequest unexpectedly retained: org.apache.myfaces.portlet.faces.tck.PortletRequest.");
+        return Constants.TEST_FAILED;
+      }
+      
+      o = m.get("org.apache.myfaces.portlet.faces.tck.PortletResponse");
+      if (o != null)
+      {
+        testRunner.setTestResult(false,
+                                 "Attribute containing PortletResponse unexpectedly retained: org.apache.myfaces.portlet.faces.tck.PortletResponse.");
+        return Constants.TEST_FAILED;
+      }
+      
+      o = m.get("org.apache.myfaces.portlet.faces.tck.PortletSession");
+      if (o != null)
+      {
+        testRunner.setTestResult(false,
+                                 "Attribute containing PortletSession unexpectedly retained: org.apache.myfaces.portlet.faces.tck.PortletSession.");
+        return Constants.TEST_FAILED;
+      }
+      
+      o = m.get("org.apache.myfaces.portlet.faces.tck.PortletPreferences");
+      if (o != null)
+      {
+        testRunner.setTestResult(false,
+                                 "Attribute containing PortletPreferences unexpectedly retained: org.apache.myfaces.portlet.faces.tck.PortletPreferences.");
+        return Constants.TEST_FAILED;
+      }
+      
+      o = m.get("org.apache.myfaces.portlet.faces.tck.PortalContext");
+      if (o != null)
+      {
+        testRunner.setTestResult(false,
+                                 "Attribute containing PortalContext unexpectedly retained: org.apache.myfaces.portlet.faces.tck.PortalContext.");
+        return Constants.TEST_FAILED;
+      }
+        
+      o = m.get("org.apache.myfaces.portlet.faces.tck.FacesContext");
+      if (o != null)
+      {
+        testRunner.setTestResult(false,
+                                 "Attribute containing FacesContext unexpectedly retained: org.apache.myfaces.portlet.faces.tck.FacesContext.");
+        return Constants.TEST_FAILED;
+      }
+
+      o = m.get("org.apache.myfaces.portlet.faces.tck.ExternalContext");
+      if (o != null)
+      {
+        testRunner.setTestResult(false,
+                                 "Attribute containing ExternalContext unexpectedly retained: org.apache.myfaces.portlet.faces.tck.ExternalContext.");
+        return Constants.TEST_FAILED;
+      }
+      
+      // Note:  no way to test the servlet objects
+      
+      o = m.get("javax.portlet.TestRequestScope");
+      if (o != null)
+      {
+        testRunner.setTestResult(false,
+                                 "Attribute in the javax.portlet namesapce unexpectedly retained: javax.portlet.TestRequestScope.");
+        return Constants.TEST_FAILED;
+      }
+      
+      o = m.get("javax.portlet.faces.TestRequestScope");
+      if (o != null)
+      {
+        testRunner.setTestResult(false,
+                                 "Attribute in the javax.portlet.faces namesapce unexpectedly retained: javax.portlet.faces.TestRequestScope.");
+        return Constants.TEST_FAILED;
+      }
+
+      o = m.get("javax.faces.TestRequestScope");
+      if (o != null)
+      {
+        testRunner.setTestResult(false,
+                                 "Attribute in the javax.faces namesapce unexpectedly retained: javax.faces.TestRequestScope.");
+        return Constants.TEST_FAILED;
+      }
+      
+      o = m.get("javax.servlet.TestRequestScope");
+      if (o != null)
+      {
+        testRunner.setTestResult(false,
+                                 "Attribute in the javax.servlet namesapce unexpectedly retained: javax.servlet.TestRequestScope.");
+        return Constants.TEST_FAILED;
+      }
+       
+      o = m.get("javax.servlet.include.TestRequestScope");
+      if (o != null)
+      {
+        testRunner.setTestResult(false,
+                                 "Attribute in the javax.servlet.include namesapce unexpectedly retained: javax.servlet.include.TestRequestScope.");
+        return Constants.TEST_FAILED;
+      }
+      
+      testRunner.setTestResult(true,
+                               "Correctly retained expected attributes and excluded expected attributes.");
+      return Constants.TEST_SUCCESS;
+    }
+  }
+  
+  // Test is MultiAction(2)Request -- Render/Action
+  // Test #5.2
+  @BridgeTest(test = "requestScopeRestartedOnActionTest")
+  public String requestScopeRestartedOnActionTest(TestRunnerBean testRunner)
+  {
+    FacesContext ctx = FacesContext.getCurrentInstance();
+    ExternalContext extCtx = ctx.getExternalContext();
+    
+    // In the action portion create/attach things to request scope that should either be preserved or
+    // are explicitly excluded -- test for presence/absence in render
+    if (BridgeUtil.getPortletRequestPhase() ==
+        Bridge.PortletPhase.ACTION_PHASE)
+    {
+      Map<String, Object> m = extCtx.getSessionMap();
+      Boolean b = (Boolean) m.get("org.apache.myfaces.portlet.faces.tck.firstActionOccurred");
+      if (b == null)
+      {
+        // This is the first action
+        m.put("org.apache.myfaces.portlet.faces.tck.firstActionOccurred", new Boolean(true));
+        
+        // push a new request attribute that we can test later doesn't exist
+        FacesContext.getCurrentInstance().getExternalContext().getRequestMap().put("org.apache.myfaces.portlet.faces.tck.TestRequestScope_a", REQUEST_ATTR_VALUE);
+        return "requestScopeRestartedOnActionTest_Action1";
+      }
+      else
+      {
+        // Test for the attribute put in the first action
+        String s = (String) FacesContext.getCurrentInstance().getExternalContext().getRequestMap().get("org.apache.myfaces.portlet.faces.tck.TestRequestScope_a");
+        if (s == null)
+        {
+          testRunner.setTestResult(true,
+                                   "Request scope attribute not retained across requests.");          
+        }
+        else
+        {
+          testRunner.setTestResult(false,
+                                   "Request scope attribute retained across action requests.");
+        }
+
+        testRunner.setTestComplete(true);
+        return "requestScopeRestartedOnActionTest_Action2";
+      }
+    }
+    else
+    {
+      if (testRunner.isTestComplete())
+      {
+        if (testRunner.getTestStatus())
+          {
+            return Constants.TEST_SUCCESS;
+          }
+        else
+        {
+          return Constants.TEST_FAILED;
+        }
+      }
+      else
+      {
+        return Constants.TEST_SUCCESS;
+      }
+    }
+  }
+  
+  // Test is MultiRequest -- Render/Action
+  // Test #5.3
+  @BridgeTest(test = "requestNoScopeOnRedirectTest")
+  public String requestNoScopeOnRedirectTest(TestRunnerBean testRunner)
+  {
+    FacesContext ctx = FacesContext.getCurrentInstance();
+    ExternalContext extCtx = ctx.getExternalContext();
+    Map m = extCtx.getRequestMap();
+    
+    // In the action portion create/attach things to request scope that should either be preserved or
+    // are explicitly excluded -- test for presence/absence in render
+    if (BridgeUtil.getPortletRequestPhase() ==
+        Bridge.PortletPhase.ACTION_PHASE)
+    {
+      // Add elements that should be preserved but won't be because we are redirecting
+      m.put("org.apache.myfaces.portlet.faces.tck.TestRequestScope_a", REQUEST_ATTR_VALUE);
+      
+      return "requestNoScopeOnRedirectTest"; // action Navigation result
+    }
+    else
+    {
+      testRunner.setTestComplete(true);
+     
+      // Now verify that no scope data was carried forward.
+      
+     
+      String s = (String) m.get("org.apache.myfaces.portlet.faces.tck.TestRequestScope_a");
+      if (s == null)
+      {
+        testRunner.setTestResult(true,
+                                 "Request attribute not retained as expected.");
+        return Constants.TEST_SUCCESS;
+      }
+      else 
+      {
+        testRunner.setTestResult(false,
+                                 "Request attribute unexpectedly retained through a redirect.");
+        return Constants.TEST_FAILED;
+      }
+    }
+  }
+  
+  // Test is MultiRequest -- Render/Action
+  // Test #5.4
+  @BridgeTest(test = "requestNoScopeOnModeChangeTest")
+  public String requestNoScopeOnModeChangeTest(TestRunnerBean testRunner)
+  {
+    FacesContext ctx = FacesContext.getCurrentInstance();
+    ExternalContext extCtx = ctx.getExternalContext();
+    Map m = extCtx.getRequestMap();
+    
+    // In the action portion create/attach things to request scope that should either be preserved or
+    // are explicitly excluded -- test for presence/absence in render
+    if (BridgeUtil.getPortletRequestPhase() ==
+        Bridge.PortletPhase.ACTION_PHASE)
+    {
+      // Add elements that should be preserved but won't be because we are redirecting
+      m.put("org.apache.myfaces.portlet.faces.tck.TestRequestScope_a", REQUEST_ATTR_VALUE);
+      
+      return "requestNoScopeOnModeChangeTest"; // action Navigation result
+    }
+    else
+    {
+      testRunner.setTestComplete(true);
+     
+      // Now verify that no scope data was carried forward.
+      
+     
+      String s = (String) m.get("org.apache.myfaces.portlet.faces.tck.TestRequestScope_a");
+      if (s == null)
+      {
+        testRunner.setTestResult(true,
+                                 "Request attribute not retained as expected.");
+        return Constants.TEST_SUCCESS;
+      }
+      else 
+      {
+        testRunner.setTestResult(false,
+                                 "Request attribute unexpectedly retained though the portlet mode changed.");
+        return Constants.TEST_FAILED;
+      }
+    }
+  }
+  
+  // Test #5.5 -- covered by #5.1 -- I.e. it jusst says that request scope is preserved through render
+  
+  // Test is MultiRequest -- Render/Action
+  // Test #5.6
+  @BridgeTest(test = "requestPreserveActionParamsTest")
+  public String requestPreserveActionParamsTest(TestRunnerBean testRunner)
+  { 
+    // In the action portion create/attach things to request scope that should either be preserved or
+    // are explicitly excluded -- test for presence/absence in render
+    if (BridgeUtil.getPortletRequestPhase() ==
+        Bridge.PortletPhase.ACTION_PHASE)
+    {
+      
+      return "requestPreserveActionParamsTest"; // action Navigation result
+    }
+    else
+    {
+      testRunner.setTestComplete(true);
+     
+      // Now verify that no scope data was carried forward.
+      
+      FacesContext ctx = FacesContext.getCurrentInstance();
+      ExternalContext extCtx = ctx.getExternalContext();
+      Map<String, String> paramMap = extCtx.getRequestParameterMap();
+
+      // loop through the Map and verify that 'value1' and 'value2' aren't there.
+      boolean foundField1 = false;
+      boolean foundField2 = false;
+      Set<Map.Entry<String, String>> set = paramMap.entrySet();
+      for (Iterator<Map.Entry<String, String>> params = set.iterator();
+           params.hasNext(); )
+      {
+        Map.Entry<String, String> e = params.next();
+        String key = e.getKey();
+
+        // Can't look up by key because JSF munges this id
+        if (key.indexOf("formDataField1") > -1)
+          foundField1 = true;
+        if (key.indexOf("formDataField2") > -1)
+          foundField2 = true;
+      }
+      if (!foundField1)
+      {
+        testRunner.setTestResult(false,
+                                 "Expected action parameter 'field1' not correctly preserved.");
+        return Constants.TEST_FAILED;
+      }
+      else if (!foundField2)
+      {
+        testRunner.setTestResult(false,
+                                 "Expected action parameter 'field2' not correctly preserved.");
+        return Constants.TEST_FAILED;
+      }
+      else 
+      {
+        testRunner.setTestResult(true,
+                                 "Action parameters correctly preserved.");
+        return Constants.TEST_SUCCESS;
+      }
+    }
+  }  
+  
+  // Test is MultiRequest -- Render/Action
+  // Test #5.7
+  @BridgeTest(test = "requestRenderIgnoresScopeViaCreateViewTest")
+  public String requestRenderIgnoresScopeViaCreateViewTest(TestRunnerBean testRunner)
+  { 
+    // In the action portion create/attach things to request scope that should either be preserved or
+    // are explicitly excluded -- test for presence/absence in render
+    if (BridgeUtil.getPortletRequestPhase() ==
+        Bridge.PortletPhase.ACTION_PHASE)
+    {
+      
+      return "requestRenderIgnoresScopeViaCreateViewTest"; // action Navigation result
+    }
+    else
+    {
+      FacesContext ctx = FacesContext.getCurrentInstance();
+      ExternalContext extCtx = ctx.getExternalContext();
+      
+      // If redisplay hasn't been invoked yet -- merely return
+      if (extCtx.getRequestParameterMap().get("org.apache.portlet.faces.tck.redisplay") == null)
+      {
+        return "requestRenderIgnoresScopeViaCreateViewTest";
+      }
+      testRunner.setTestComplete(true);
+     
+      // Now verify create was used and not restore.
+      Boolean b = (Boolean) extCtx.getRequestMap().get("org.apache.portlet.faces.tck.viewCreated");
+      
+      if (Boolean.TRUE.equals(b))
+      {
+        testRunner.setTestResult(true,
+                               "CreateView used when view restored in a mismatched scope.");
+        return Constants.TEST_SUCCESS;
+      }
+      else
+      {
+        testRunner.setTestResult(false,
+                                 "CreateView not used when view restored in a mismatched scope.");
+        return Constants.TEST_FAILED;
+      }
+    }
+  } 
+
+  // Test is MultiRequest -- Render/Action
+  // Test #5.8
+  @BridgeTest(test = "requestRenderRedisplayTest")
+  public String requestRenderRedisplayTest(TestRunnerBean testRunner)
+  { 
+    FacesContext ctx = FacesContext.getCurrentInstance();
+    ExternalContext extCtx = ctx.getExternalContext();
+    
+    // In the action portion create/attach things to request scope that should either be preserved or
+    // are explicitly excluded -- test for presence/absence in render
+    if (BridgeUtil.getPortletRequestPhase() ==
+        Bridge.PortletPhase.ACTION_PHASE)
+    {
+      // Add elements that should be preserved but won't be because we are redirecting
+      extCtx.getRequestMap().put("org.apache.myfaces.portlet.faces.tck.TestRequestScope_a", REQUEST_ATTR_VALUE);
+      return "requestRenderRedisplayTest"; // action Navigation result
+    }
+    else
+    {   
+      // If redisplay hasn't been invoked yet -- merely return
+      if (extCtx.getRequestParameterMap().get("org.apache.portlet.faces.tck.redisplay") == null)
+      {
+        return "requestRenderRedisplayTest";
+      }
+      testRunner.setTestComplete(true);
+     
+      String s = (String) extCtx.getRequestMap().get("org.apache.myfaces.portlet.faces.tck.TestRequestScope_a");
+      if (s != null)
+      {
+        testRunner.setTestResult(true,
+                                 "Request attribute retained as expected through a redisplay.");
+        return Constants.TEST_SUCCESS;
+      }
+      else 
+      {
+        testRunner.setTestResult(false,
+                                 "Request attribute not retained as expected through a redisplay.");
+        return Constants.TEST_FAILED;
+      }
+    }
+  }
+  
+  // Test is MultiRequest -- Render/Action
+  // Test #5.9
+  @BridgeTest(test = "requestRedisplayOutOfScopeTest")
+  public String requestRedisplayOutOfScopeTest(TestRunnerBean testRunner)
+  { 
+    FacesContext ctx = FacesContext.getCurrentInstance();
+    ExternalContext extCtx = ctx.getExternalContext();
+    
+    // In the action portion create/attach things to request scope that should either be preserved or
+    // are explicitly excluded -- test for presence/absence in render
+    if (BridgeUtil.getPortletRequestPhase() ==
+        Bridge.PortletPhase.ACTION_PHASE)
+    {
+      extCtx.getRequestMap().put("org.apache.myfaces.portlet.faces.tck.TestRequestScope_a", REQUEST_ATTR_VALUE);
+      return "requestRedisplayOutOfScopeTest"; // action Navigation result
+    }
+    else
+    {
+      // If redisplay hasn't been invoked yet -- merely return
+      if (extCtx.getRequestParameterMap().get("org.apache.portlet.faces.tck.redisplay") == null)
+      {
+        return "requestRedisplayOutOfScopeTest";
+      }
+      testRunner.setTestComplete(true);
+     
+      String s = (String) extCtx.getRequestMap().get("org.apache.myfaces.portlet.faces.tck.TestRequestScope_a");
+      if (s == null)
+      {
+        testRunner.setTestResult(true,
+                                 "Second render correctly didn't use original request scope as we entered a new mode.");
+        return Constants.TEST_SUCCESS;
+      }
+      else 
+      {
+        testRunner.setTestResult(false,
+                                 "Second render incorrectly used original request scope though we entered a new mode.");
+        return Constants.TEST_FAILED;
+      }
+    }
+  } 
+  
+  // Test is MultiRequest -- Render/Action
+  // Test #5.10
+  @BridgeTest(test = "excludedAttributesTest")
+  public String excludedAttributesTest(TestRunnerBean testRunner)
+  { 
+    FacesContext ctx = FacesContext.getCurrentInstance();
+    ExternalContext extCtx = ctx.getExternalContext();
+    UIViewRoot viewRoot = ctx.getViewRoot();
+    Map m = extCtx.getRequestMap();
+    
+    // In the action portion create/attach things to request scope that should either be preserved or
+    // are explicitly excluded -- test for presence/absence in render
+    if (BridgeUtil.getPortletRequestPhase() ==
+        Bridge.PortletPhase.ACTION_PHASE)
+    {
+      // Add elements that should be preserved:
+      // Messages need to be added after InvokeApplication (i.e. once navigation has occurred -- so we attach to the right ViewRoot
+      // The lifecycleListener is in the portlet that drives this test 
+     
+      m.put("org.apache.myfaces.portlet.faces.tck.IncludedAttr", REQUEST_ATTR_VALUE);
+      m.put("org.apache.myfaces.portlet.faces.tck.WildcardFacesConfigTest.include.IncludedAttr", REQUEST_ATTR_VALUE);
+      m.put("org.apache.myfaces.portlet.faces.tck.WildcardPortletXmlTest.include.IncludedAttr", REQUEST_ATTR_VALUE);
+      
+      
+      // Add elements that should be excluded
+      m.put("org.apache.myfaces.portlet.faces.tck.ExcludeByAnnotation", new AnnotatedExcludedBean());
+      m.put("org.apache.myfaces.portlet.faces.tck.ExcludeByFacesConfigRef", REQUEST_ATTR_VALUE);
+      m.put("org.apache.myfaces.portlet.faces.tck.WildcardFacesConfigTest.ExcludeByFacesConfigRef", REQUEST_ATTR_VALUE);
+      m.put("org.apache.myfaces.portlet.faces.tck.ExcludeByPortletXmlRef", REQUEST_ATTR_VALUE);
+      m.put("org.apache.myfaces.portlet.faces.tck.WildcardPortletXmlTest.ExcludeByPortletXmlRef", REQUEST_ATTR_VALUE);
+           
+      return "excludedAttributesTest"; // action Navigation result
+    }
+    else
+    {
+      testRunner.setTestComplete(true);
+     
+      // Now verify that what should have been carried forward has and what shouldn't hasn't.
+      
+      String s = (String) m.get("org.apache.myfaces.portlet.faces.tck.IncludedAttr");
+      if (s == null || !s.equals(REQUEST_ATTR_VALUE))
+      {
+        testRunner.setTestResult(false,
+                                 "Expected request attribute not retained: org.apache.myfaces.portlet.faces.tck.IncludedAttr.");
+        return Constants.TEST_FAILED;
+      }
+      
+      s = (String) m.get("org.apache.myfaces.portlet.faces.tck.WildcardFacesConfigTest.include.IncludedAttr");
+      if (s == null || !s.equals(REQUEST_ATTR_VALUE))
+      {
+        testRunner.setTestResult(false,
+                                 "Expected request attribute not retained: org.apache.myfaces.portlet.faces.tck.WildcardFacesConfigTest.include.IncludedAttr.");
+        return Constants.TEST_FAILED;
+      }
+      
+      s = (String) m.get("org.apache.myfaces.portlet.faces.tck.WildcardPortletXmlTest.include.IncludedAttr");
+      if (s == null || !s.equals(REQUEST_ATTR_VALUE))
+      {
+        testRunner.setTestResult(false,
+                                 "Expected request attribute not retained: org.apache.myfaces.portlet.faces.tck.WildcardPortletXmlTest.include.IncludedAttr.");
+        return Constants.TEST_FAILED;
+      }
+      
+      // Check elements that should be excluded
+      Object o = m.get("org.apache.myfaces.portlet.faces.tck.ExcludeByAnnotation");
+      if (o != null)
+      {
+        testRunner.setTestResult(false,
+                                 "Attribute annotated (for exclusion) unexpectedly retained: org.apache.myfaces.portlet.faces.tck.ExcludeByAnnotation.");
+        return Constants.TEST_FAILED;
+      }
+      
+      o = m.get("org.apache.myfaces.portlet.faces.tck.ExcludeByFacesConfigRef");
+      if (o != null)
+      {
+        testRunner.setTestResult(false,
+                                 "Attribute annotated (for exclusion) unexpectedly retained: org.apache.myfaces.portlet.faces.tck.ExcludeByFacesConfigRef.");
+        return Constants.TEST_FAILED;
+      }
+      
+      o = m.get("org.apache.myfaces.portlet.faces.tck.WildcardFacesConfigTest.ExcludeByFacesConfigRef");
+      if (o != null)
+      {
+        testRunner.setTestResult(false,
+                                 "Attribute annotated (for exclusion) unexpectedly retained: org.apache.myfaces.portlet.faces.tck.WildcardFacesConfigTest.ExcludeByFacesConfigRef.");
+        return Constants.TEST_FAILED;
+      }
+
+      o = m.get("org.apache.myfaces.portlet.faces.tck.ExcludeByPortletXmlRef");
+      if (o != null)
+      {
+        testRunner.setTestResult(false,
+                                 "Attribute annotated (for exclusion) unexpectedly retained: org.apache.myfaces.portlet.faces.tck.ExcludeByPortletXmlRef.");
+        return Constants.TEST_FAILED;
+      }
+      
+      
+      o = m.get("org.apache.myfaces.portlet.faces.tck.WildcardPortletXmlTest.ExcludeByPortletXmlRef");
+      if (o != null)
+      {
+        testRunner.setTestResult(false,
+                                 "Attribute annotated (for exclusion) unexpectedly retained: org.apache.myfaces.portlet.faces.tck.WildcardPortletXmlTest.ExcludeByPortletXmlRef.");
+        return Constants.TEST_FAILED;
+      }
+      
+
+      
+      testRunner.setTestResult(true,
+                               "Correctly retained expected attributes and excluded expected attributes.");
+      return Constants.TEST_SUCCESS;
+    }
+  }
+  
+  
+  // Test #5.11 TBD we need to figure out how to test messages.  Maybe with a redisplay?
+  
+}

Added: myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_5/section_5_2/ManualBridgeInvokePortlet.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_5/section_5_2/ManualBridgeInvokePortlet.java?rev=900963&view=auto
==============================================================================
--- myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_5/section_5_2/ManualBridgeInvokePortlet.java (added)
+++ myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_5/section_5_2/ManualBridgeInvokePortlet.java Tue Jan 19 21:21:42 2010
@@ -0,0 +1,184 @@
+/* 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_5.section_5_2;
+
+import java.io.IOException;
+
+import java.io.PrintWriter;
+
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletException;
+import javax.portlet.PortletRequest;
+import javax.portlet.PortletResponse;
+import javax.portlet.PortletSecurityException;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.portlet.faces.Bridge;
+import javax.portlet.faces.BridgeDefaultViewNotSpecifiedException;
+import javax.portlet.faces.BridgeInvalidViewPathException;
+import javax.portlet.faces.BridgeUninitializedException;
+import javax.portlet.faces.GenericFacesPortlet;
+
+import org.apache.myfaces.portlet.faces.testsuite.annotation.BridgeTest;
+import org.apache.myfaces.portlet.faces.testsuite.common.Constants;
+import org.apache.myfaces.portlet.faces.testsuite.common.portlet.GenericFacesTestSuitePortlet;
+import org.apache.myfaces.portlet.faces.testsuite.common.util.BridgeTCKResultWriter;
+
+public class ManualBridgeInvokePortlet
+  extends GenericFacesTestSuitePortlet
+{
+  private static final String EXCEPTIONTHROWN_NODEFAULTVIEWID_TEST = "exceptionThrownWhenNoDefaultViewIdTest";
+  private static final String VIEWIDWITHPARAM_TEST = "viewIdWithParam_1_Test";
+  private static final String FACESCONTEXTRELEASED_ACTION_TEST = "facesContextReleasedActionTest";
+  private static final String PORTLETPHASEREMOVED_ACTION_TEST = "portletPhaseRemovedActionTest";
+  private static final String FACESCONTEXTRELEASED_RENDER_TEST = "facesContextReleasedRenderTest";
+  private static final String PORTLETPHASEREMOVED_RENDER_TEST = "portletPhaseRemovedRenderTest";
+  private static final String BRIDGESETSCONTENTTYPE_TEST = "bridgeSetsContentTypeTest";
+
+
+  public void init(PortletConfig config)
+    throws PortletException
+  {
+    super.init(config);
+
+  }
+  
+  public void processAction(ActionRequest request, ActionResponse response) throws
+    PortletException, PortletSecurityException, IOException
+  {
+    super.processAction(request, response);
+    if (getTestName().equals(FACESCONTEXTRELEASED_ACTION_TEST))
+    {
+      if (request.getAttribute("org.apache.portlet.faces.tck.facesContextReleased") != null)
+      {
+        request.getPortletSession(true).setAttribute("org.apache.portlet.faces.tck.testResult", Boolean.TRUE);
+        request.getPortletSession().setAttribute("org.apache.portlet.faces.tck.testDetail", "Correctly released FacesContext at end of doFacesRequest (action).");
+      }
+      else
+      {
+        request.getPortletSession(true).setAttribute("org.apache.portlet.faces.tck.testResult", Boolean.FALSE);
+        request.getPortletSession().setAttribute("org.apache.portlet.faces.tck.testDetail", "Didn't release FacesContext at end of doFacesRequest (action).");        
+      }
+    }
+    else if (getTestName().equals(PORTLETPHASEREMOVED_ACTION_TEST))
+    {
+      if (request.getAttribute(Bridge.PORTLET_LIFECYCLE_PHASE) == null)
+      {
+        request.getPortletSession(true).setAttribute("org.apache.portlet.faces.tck.testResult", Boolean.TRUE);
+        request.getPortletSession().setAttribute("org.apache.portlet.faces.tck.testDetail", "Correctly removed PortletPhase attrbiute at end of doFacesRequest (action).");
+      }
+      else
+      {
+        request.getPortletSession(true).setAttribute("org.apache.portlet.faces.tck.testResult", Boolean.FALSE);
+        request.getPortletSession().setAttribute("org.apache.portlet.faces.tck.testDetail", "Didn't removed PortletPhase attrbiute at end of doFacesRequest (action).");        
+      }
+    }
+  }
+
+
+  public void doDispatch(RenderRequest renderRequest, 
+                         RenderResponse renderResponse)
+    throws PortletException, IOException
+  {
+    if (getTestName().equals(EXCEPTIONTHROWN_NODEFAULTVIEWID_TEST))
+    {
+
+      Bridge bridge = super.getFacesBridge(renderRequest, renderResponse);
+      try
+      {
+        bridge.doFacesRequest(renderRequest, renderResponse);
+      }
+      catch (BridgeDefaultViewNotSpecifiedException e)
+      {
+        outputTestResult(renderResponse, Boolean.TRUE, "Correctly threw BridgeDefaultViewNotSpecifiedException when no default defined.");
+      }
+      catch (Exception e)
+      {
+        outputTestResult(renderResponse, Boolean.FALSE, "Didn't throw BridgeDefaultViewNotSpecifiedException when no default defined.");
+      }
+    }
+    else if (getTestName().equals(BRIDGESETSCONTENTTYPE_TEST))
+    {
+      // By invoking the bridge directly (and not setting the contentType)
+      // we force the bridge to have to do the work
+      Bridge bridge = super.getFacesBridge(renderRequest, renderResponse);
+      bridge.doFacesRequest(renderRequest, renderResponse);
+    }
+    else if (getTestName().equals(VIEWIDWITHPARAM_TEST))
+    {
+      renderRequest.setAttribute(Bridge.VIEW_ID, "/tests/SingleRequestTest.jsp?param1=testValue");
+      super.doDispatch(renderRequest, renderResponse);
+    }
+    else if (getTestName().equals(FACESCONTEXTRELEASED_ACTION_TEST) || getTestName().equals(PORTLETPHASEREMOVED_ACTION_TEST))
+    {
+      // Output in the Test method fort his test
+      super.doDispatch(renderRequest, renderResponse);
+    }
+    else if (getTestName().equals(FACESCONTEXTRELEASED_RENDER_TEST))
+    {
+      super.doDispatch(renderRequest, renderResponse);
+      if (renderRequest.getAttribute("org.apache.portlet.faces.tck.facesContextReleased") != null)
+      {
+        outputTestResult(renderResponse, Boolean.TRUE, "Correctly release FacesContext at end of render.");
+      }
+      else
+      {
+        outputTestResult(renderResponse, Boolean.FALSE, "FacesContext not release at end of render.");        
+      }      
+    }
+    else if (getTestName().equals(PORTLETPHASEREMOVED_RENDER_TEST))
+    {
+      super.doDispatch(renderRequest, renderResponse);
+      if (renderRequest.getAttribute(Bridge.PORTLET_LIFECYCLE_PHASE) == null)
+      {
+        outputTestResult(renderResponse, Boolean.TRUE, "Correctly removed Portlet Phase attribute at end of render.");
+      }
+      else
+      {
+        outputTestResult(renderResponse, Boolean.FALSE, "Didn't remove Portlet Phase attribute at end of render.");        
+      }       
+    }
+  }
+
+  private void outputTestResult(RenderResponse response, 
+                                               Boolean pass, String detail)
+    throws IOException
+  {
+    response.setContentType("text/html");
+    PrintWriter out = response.getWriter();
+    BridgeTCKResultWriter resultWriter = 
+    new BridgeTCKResultWriter(getTestName());
+
+    if (pass.booleanValue())
+    {
+      resultWriter.setStatus(BridgeTCKResultWriter.PASS);
+      resultWriter.setDetail(detail);
+    }
+    else
+    {
+      resultWriter.setStatus(BridgeTCKResultWriter.FAIL);
+      resultWriter.setDetail(detail);
+    }
+
+    out.println(resultWriter.toString());
+  }
+}

Added: myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_5/section_5_2/Tests.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_5/section_5_2/Tests.java?rev=900963&view=auto
==============================================================================
--- myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_5/section_5_2/Tests.java (added)
+++ myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_5/section_5_2/Tests.java Tue Jan 19 21:21:42 2010
@@ -0,0 +1,557 @@
+/* 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_5.section_5_2;
+
+import java.io.IOException;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.HashMap;
+
+import java.util.Set;
+
+import javax.faces.FacesException;
+import javax.faces.FactoryFinder;
+import javax.faces.application.FacesMessage;
+import javax.faces.application.ViewHandler;
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+
+import javax.faces.event.PhaseEvent;
+import javax.faces.event.PhaseId;
+import javax.faces.event.PhaseListener;
+
+import javax.faces.lifecycle.LifecycleFactory;
+
+import javax.faces.render.ResponseStateManager;
+
+import javax.portlet.ActionResponse;
+import javax.portlet.PortalContext;
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletContext;
+import javax.portlet.PortletMode;
+import javax.portlet.PortletPreferences;
+import javax.portlet.PortletRequest;
+
+import javax.portlet.RenderRequest;
+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.beans.AnnotatedExcludedBean;
+import org.apache.myfaces.portlet.faces.testsuite.common.Constants;
+
+public class Tests
+  extends Object implements PhaseListener
+{
+  
+  // Test #5.13 (also by proxy verifies #5.12
+  @BridgeTest(test = "verifyPortletObjectsTest")
+  public String verifyPortletObjectsTest(TestRunnerBean testRunner)
+  {
+    FacesContext ctx = FacesContext.getCurrentInstance();
+    ExternalContext extCtx = ctx.getExternalContext();
+    Map m = extCtx.getRequestMap();
+    
+    testRunner.setTestComplete(true);
+    
+    // Are we in the rightview???
+    String s = (String) m.get("javax.portlet.faces.tck.verifyPortletObjectsPass");
+    if (s != null)
+    {
+      testRunner.setTestResult(true, s);
+      return Constants.TEST_SUCCESS;
+    }
+    else
+    {
+      testRunner.setTestResult(false,
+                               (String) m.get("javax.portlet.faces.tck.verifyPortletObjectsFail"));
+      return Constants.TEST_FAILED;
+    }
+  }
+  
+  // Test is MultiRequest -- Render/Action
+  // Test #5.14
+  @BridgeTest(test = "verifyPortletPhaseTest")
+  public String verifyPortletPhaseTest(TestRunnerBean testRunner)
+  { 
+    FacesContext ctx = FacesContext.getCurrentInstance();
+    ExternalContext extCtx = ctx.getExternalContext();
+    Map m = extCtx.getRequestMap();
+    
+    // In the action portion create/attach things to request scope that should either be preserved or
+    // are explicitly excluded -- test for presence/absence in render
+    if (BridgeUtil.getPortletRequestPhase() ==
+        Bridge.PortletPhase.ACTION_PHASE)
+    {
+          
+      return "verifyPortletPhaseTest"; // action Navigation result
+    }
+    else
+    {
+      testRunner.setTestComplete(true);
+     
+      // Now verify that what should have been carried forward has and what shouldn't hasn't.
+      
+      String s = (String) m.get("javax.portlet.faces.tck.verifyPortletPhaseDuringActionPass");
+      String s1 = (String) m.get("javax.portlet.faces.tck.verifyPortletPhaseDuringRenderPass");
+      
+      if (s != null && s1 != null)
+      {
+        testRunner.setTestResult(true, s + s1);
+        return Constants.TEST_SUCCESS;
+      }
+      
+      if (s == null)
+      {
+        s = (String) m.get("javax.portlet.faces.tck.verifyPortletPhaseDuringActionFail");
+      }
+      
+      if (s1 == null)
+      {
+        s1 = (String) m.get("javax.portlet.faces.tck.verifyPortletPhaseDuringRenderFail");
+      }
+      
+      testRunner.setTestResult(false,s + s1);
+      return Constants.TEST_FAILED;    
+
+    }
+  }
+  
+  // Test is MultiRequest -- Render/Action
+  // Test #5.18
+  @BridgeTest(test = "renderRedirectTest")
+  public String renderRedirectTest(TestRunnerBean testRunner)
+  { 
+    FacesContext ctx = FacesContext.getCurrentInstance();
+    ExternalContext extCtx = ctx.getExternalContext();
+    Map m = extCtx.getRequestMap();
+    
+    // In the action portion create/attach things to request scope that should either be preserved or
+    // are explicitly excluded -- test for presence/absence in render
+    if (BridgeUtil.getPortletRequestPhase() ==
+        Bridge.PortletPhase.ACTION_PHASE)
+    {
+          
+      return "renderRedirectTest"; // action Navigation result
+    }
+    else
+    {
+      String viewId = ctx.getViewRoot().getViewId();
+      if (viewId.equals("/tests/MultiRequestTestResultRenderCheck.jsp"))
+      {
+        // issue the redirect
+        ViewHandler viewHandler = ctx.getApplication().getViewHandler();
+        try
+        {
+          extCtx.redirect(viewHandler.getActionURL(ctx, "/tests/RedisplayRenderRequestTest.jsp"));
+        }
+        catch (IOException e)
+        {
+          testRunner.setTestComplete(true);
+          testRunner.setTestResult(false,
+                                   "Call to render redirect threw an IOException: " + e.getMessage());
+          return Constants.TEST_FAILED;
+        }
+        return "renderRedirectTest";
+      }
+      else if (viewId.equals("/tests/RedisplayRenderRequestTest.jsp"))
+      {
+        // If redisplay hasn't been invoked yet -- merely return
+        if (extCtx.getSessionMap().get("org.apache.portlet.faces.tck.redisplay") == null)
+        {
+          // because this is a redirect during render -- we can't pass new/additional parameters on
+          // the redisplay -- since the bridge ignores them (it uses the ones from the original redirect
+          // so instead mark that we have done the redisplay in the session
+          extCtx.getSessionMap().put("org.apache.portlet.faces.tck.redisplay", Boolean.TRUE);
+          return "renderRedirectTest";
+        }
+      
+        testRunner.setTestComplete(true);
+        extCtx.getSessionMap().remove("org.apache.portlet.faces.tck.redisplay");
+         
+        testRunner.setTestResult(true, 
+                                 "Redisplay after redirect correctly rendered the redirected view.");
+        return Constants.TEST_SUCCESS;
+      }
+      else
+      {
+        testRunner.setTestComplete(true);
+        extCtx.getSessionMap().remove("org.apache.portlet.faces.tck.redisplay");
+        testRunner.setTestResult(false, 
+                                 "Ended up in an unexpected view during renderRedirect test:");
+        return Constants.TEST_FAILED;    
+      }
+    }
+  }
+  
+  // Test is MultiRequest -- Render/Action
+  // Test #5.19
+  @BridgeTest(test = "ignoreCurrentViewIdModeChangeTest")
+  public String ignoreCurrentViewIdModeChangeTest(TestRunnerBean testRunner)
+  { 
+    FacesContext ctx = FacesContext.getCurrentInstance();
+    ExternalContext extCtx = ctx.getExternalContext();
+    
+    // In the action portion create/attach things to request scope that should either be preserved or
+    // are explicitly excluded -- test for presence/absence in render
+    if (BridgeUtil.getPortletRequestPhase() ==
+        Bridge.PortletPhase.ACTION_PHASE)
+    {
+      return "ignoreCurrentViewIdModeChangeTest"; // action Navigation result
+    }
+    else
+    {
+      // If redisplay hasn't been invoked yet -- merely return
+      if (extCtx.getRequestParameterMap().get("org.apache.portlet.faces.tck.redisplay") == null)
+      {
+        return "ignoreCurrentViewIdModeChangeTest";
+      }
+      // We should now be in the default view for edit Mode
+      String viewId = ctx.getViewRoot().getViewId();
+      
+      testRunner.setTestComplete(true);
+      if (viewId.equals("/tests/MultiRequestTestResultRenderCheck.jsp"))
+      {
+        testRunner.setTestResult(true,
+                                 "Second render correctly used the default view because there was a mode change.");
+        return Constants.TEST_SUCCESS;
+      }
+      else 
+      {
+        testRunner.setTestResult(false,
+                                 "Second render incorrectly rerendered existing view though there was a view change.");
+        return Constants.TEST_FAILED;
+      }
+    }
+  }
+  
+  // Test is MultiRequest -- Render/Action
+  // Test #5.20
+  @BridgeTest(test = "exceptionThrownWhenNoDefaultViewIdTest")
+  public String exceptionThrownWhenNoDefaultViewIdTest(TestRunnerBean testRunner)
+  { 
+    FacesContext ctx = FacesContext.getCurrentInstance();
+    ExternalContext extCtx = ctx.getExternalContext();
+    
+    // In the action portion create/attach things to request scope that should either be preserved or
+    // are explicitly excluded -- test for presence/absence in render
+    if (BridgeUtil.getPortletRequestPhase() ==
+        Bridge.PortletPhase.ACTION_PHASE)
+    {
+      return "exceptionThrownWhenNoDefaultViewIdTest"; // action Navigation result
+    }
+    else
+    {
+      // If redisplay hasn't been invoked yet -- merely return
+      if (extCtx.getRequestParameterMap().get("org.apache.portlet.faces.tck.redisplay") == null)
+      {
+        return "exceptionThrownWhenNoDefaultViewIdTest";
+      }
+      
+      // Note we should never get here because the default viewId isn't defined.
+      // We should now be in the default view for edit Mode
+      testRunner.setTestComplete(true);
+      
+      testRunner.setTestResult(false,
+                                "Unexpectedly ended up in render -- should of had a BridgeDefaultViewNotSpecifiedException thrown.");
+      return Constants.TEST_FAILED;
+    }
+  }
+  
+  // Test is MultiRequest -- Render/Action
+  // Test #5.20 (first test of 2) -- viewId set directly by portlet using request attribute 
+  @BridgeTest(test = "viewIdWithParam_1_Test")
+  public String viewIdWithParam_1_Test(TestRunnerBean testRunner)
+  { 
+    FacesContext ctx = FacesContext.getCurrentInstance();
+    
+    testRunner.setTestComplete(true);
+    
+    // Parameter encoded in the faces-config.xml target
+    String pVal =
+      ctx.getExternalContext().getRequestParameterMap().get("param1");
+    if (pVal != null && pVal.equals("testValue"))
+    {
+      testRunner.setTestResult(true,
+                               "Bridge correctly included parameter from viewId querystring when viewId set explicitly.");
+      return Constants.TEST_SUCCESS;
+    }
+    else
+    {
+      if (pVal == null)
+        testRunner.setTestResult(false,
+                                 "Bridge didn't included parameter from viewId querystring when viewId set explicitly.");
+      else
+        testRunner.setTestResult(false,
+                                 "Bridge didn't properly include parameter from viewId querystring when viewId set explicitly.  The resulting request contained the wrong parameter value. Expected: testValue  Received: " +
+                                 pVal);
+    }
+    return Constants.TEST_FAILED;
+  }
+  
+  // Test is MultiRequest -- Render/Action
+  // Test #5.20 (second test of 2) -- viewId set in the default viewId (initparam) 
+  @BridgeTest(test = "viewIdWithParam_2_Test")
+  public String viewIdWithParam_2_Test(TestRunnerBean testRunner)
+  { 
+    FacesContext ctx = FacesContext.getCurrentInstance();
+    
+    testRunner.setTestComplete(true);
+    
+    // Parameter encoded in the faces-config.xml target
+    String pVal =
+      ctx.getExternalContext().getRequestParameterMap().get("param1");
+    if (pVal != null && pVal.equals("testValue"))
+    {
+      testRunner.setTestResult(true,
+                               "Bridge correctly included parameter from viewId querystring when using default viewId.");
+      return Constants.TEST_SUCCESS;
+    }
+    else
+    {
+      if (pVal == null)
+        testRunner.setTestResult(false,
+                                 "Bridge didn't included parameter from viewId querystring when using default viewId.");
+      else
+        testRunner.setTestResult(false,
+                                 "Bridge didn't properly include parameter from viewId querystring when using default viewId.  The resulting request contained the wrong parameter value. Expected: testValue  Received: " +
+                                 pVal);
+    }
+    return Constants.TEST_FAILED;
+  }
+  
+  // Test is MultiRequest -- Render/Action
+  // Test #5.25
+  @BridgeTest(test = "facesContextReleasedActionTest")
+  public String facesContextReleasedActionTest(TestRunnerBean testRunner)
+  { 
+    FacesContext ctx = FacesContext.getCurrentInstance();
+    ExternalContext extCtx = ctx.getExternalContext();
+    
+    // In the action portion create/attach things to request scope that should either be preserved or
+    // are explicitly excluded -- test for presence/absence in render
+    if (BridgeUtil.getPortletRequestPhase() ==
+        Bridge.PortletPhase.ACTION_PHASE)
+    {
+      return "facesContextReleasedActionTest"; // action Navigation result
+    }
+    else
+    {
+      testRunner.setTestComplete(true);
+      // Values set by portlet at end of action
+      boolean result = ((Boolean)extCtx.getSessionMap().get("org.apache.portlet.faces.tck.testResult")).booleanValue();
+      testRunner.setTestResult(result,
+                                (String)extCtx.getSessionMap().get("org.apache.portlet.faces.tck.testDetail"));
+      
+      if (result)
+        return Constants.TEST_SUCCESS;
+      else
+      return Constants.TEST_FAILED;
+    }
+  }  
+  
+  // Test is MultiRequest -- Render/Action
+  // Test #5.26
+  @BridgeTest(test = "portletPhaseRemovedActionTest")
+  public String portletPhaseRemovedActionTest(TestRunnerBean testRunner)
+  { 
+    FacesContext ctx = FacesContext.getCurrentInstance();
+    ExternalContext extCtx = ctx.getExternalContext();
+    
+    // In the action portion create/attach things to request scope that should either be preserved or
+    // are explicitly excluded -- test for presence/absence in render
+    if (BridgeUtil.getPortletRequestPhase() ==
+        Bridge.PortletPhase.ACTION_PHASE)
+    {
+      return "portletPhaseRemovedActionTest"; // action Navigation result
+    }
+    else
+    {
+      testRunner.setTestComplete(true);
+      
+      // Values set by portlet at end of action
+      boolean result = ((Boolean)extCtx.getSessionMap().get("org.apache.portlet.faces.tck.testResult")).booleanValue();
+      testRunner.setTestResult(result,
+                                (String)extCtx.getSessionMap().get("org.apache.portlet.faces.tck.testDetail"));
+      
+      if (result)
+        return Constants.TEST_SUCCESS;
+      else
+      return Constants.TEST_FAILED;
+    }
+  }  
+  
+  // Test is Render test
+  // Test #5.29  
+  @BridgeTest(test = "bridgeSetsContentTypeTest")
+  public String bridgeSetsContentTypeTest(TestRunnerBean testRunner)
+  { 
+    FacesContext ctx = FacesContext.getCurrentInstance();
+    ExternalContext extCtx = ctx.getExternalContext();
+    
+    testRunner.setTestComplete(true);
+    
+    // Parameter encoded in the faces-config.xml target
+    String responseCT = extCtx.getResponseContentType();
+    String requestedCT = ((RenderRequest)extCtx.getRequest()).getResponseContentType();
+    
+    if (responseCT != null && requestedCT != null && responseCT.equals(requestedCT))
+    {
+      testRunner.setTestResult(true,
+                               "Bridge correctly set the proper (default) content type when not set by portlet.");
+      return Constants.TEST_SUCCESS;
+    }
+    else
+    {
+      testRunner.setTestResult(false,
+                               "Bridge didn't set the proper (default) content type when not set by portlet.  Current: " + responseCT + " expected: " + requestedCT);
+      return Constants.TEST_FAILED;
+    }
+  }
+  
+  // Test is MultiRequest -- Render/Action
+  // Test #5.31
+  @BridgeTest(test = "isPostbackTest")
+  public String isPostbackTest(TestRunnerBean testRunner)
+  {    
+    // In the action portion create/attach things to request scope that should either be preserved or
+    // are explicitly excluded -- test for presence/absence in render
+    if (BridgeUtil.getPortletRequestPhase() ==
+        Bridge.PortletPhase.ACTION_PHASE)
+    {
+      return "isPostbackTest"; // action Navigation result
+    }
+    else
+    {
+      FacesContext ctx = FacesContext.getCurrentInstance();
+      ExternalContext extCtx = ctx.getExternalContext();
+      
+      testRunner.setTestComplete(true);
+      if (ctx.getRenderKit().getResponseStateManager().isPostback(ctx))
+      {
+        testRunner.setTestResult(true,
+                                "Render after action properly encoded so ResponseStateManager.isPostback is true.");
+        return Constants.TEST_SUCCESS;  
+      }
+      else
+      {
+        testRunner.setTestResult(false,
+                                "Render after action isn't properly encoded in that ResponseStateManager.isPostback is false.");
+        return Constants.TEST_FAILED;
+      }
+    }
+  } 
+
+  // Test is SingleRequest -- Render/Action
+  // Test #5.33 -- 
+  @BridgeTest(test = "renderPhaseListenerTest")
+  public String renderPhaseListenerTest(TestRunnerBean testRunner)
+  { 
+    FacesContext ctx = FacesContext.getCurrentInstance();
+    ExternalContext extCtx = ctx.getExternalContext();
+    Map<String, Object> m = extCtx.getRequestMap();
+    
+    testRunner.setTestComplete(true);
+      
+    //Phase Listener (below) has set these attributes
+    PhaseId lastBeforePhaseId = (PhaseId) m.get("org.apache.portlet.faces.tck.lastBeforePhase");
+    PhaseId lastAfterPhaseId = (PhaseId) m.get("org.apache.portlet.faces.tck.lastAfterPhase");
+    
+    if (lastBeforePhaseId == null || lastAfterPhaseId == null)
+    {
+      testRunner.setTestResult(false,
+                               "Render incorrectly didn't invoke either or both the RESTORE_VIEW before/after listener.");
+      return Constants.TEST_FAILED;
+    }
+    else if (lastBeforePhaseId == PhaseId.RESTORE_VIEW && lastAfterPhaseId == PhaseId.RESTORE_VIEW)
+    {
+      testRunner.setTestResult(true,
+                                "Render properly invoked the RESTORE_VIEW phase including calling its before/after listeners and didnt' execute any other action phases.");
+      return Constants.TEST_SUCCESS;  
+    }
+    else
+    {
+      testRunner.setTestResult(false,
+                               "Render incorrectly executed an action phase/listener post RESTORE_VIEW: lastBeforePhase: " +
+                               lastBeforePhaseId.toString() + " lastAfterPhase: " + lastAfterPhaseId.toString());
+      return Constants.TEST_FAILED;
+    }
+  }   
+  
+  public PhaseId getPhaseId()
+  {
+    return PhaseId.ANY_PHASE;
+  }
+  
+  public void beforePhase(PhaseEvent event)
+  {
+    PhaseId phase = event.getPhaseId();
+    
+    // Do nothing if in render phase
+    if (phase == PhaseId.RENDER_RESPONSE)
+    {
+      return;
+    }
+    
+    
+    FacesContext ctx = event.getFacesContext();
+    Map<String, Object> m = ctx.getExternalContext().getRequestMap();
+    String testname = (String) m.get(Constants.TEST_NAME);
+    Bridge.PortletPhase portletPhase = (Bridge.PortletPhase) m.get(Bridge.PORTLET_LIFECYCLE_PHASE);
+    if (testname.equals("renderPhaseListenerTest") && portletPhase.equals(Bridge.PortletPhase.RENDER_PHASE))
+    {
+      m.put("org.apache.portlet.faces.tck.lastBeforePhase", phase);
+    }
+  }
+  
+  public void afterPhase(PhaseEvent event)
+  {
+    PhaseId phase = event.getPhaseId();
+    
+    // Do nothing if in render phase
+    if (phase == PhaseId.RENDER_RESPONSE)
+    {
+      return;
+    }
+    
+    
+    FacesContext ctx = event.getFacesContext();
+    Map<String, Object> m = ctx.getExternalContext().getRequestMap();
+    String testname = (String) m.get(Constants.TEST_NAME);
+    Bridge.PortletPhase portletPhase = (Bridge.PortletPhase) m.get(Bridge.PORTLET_LIFECYCLE_PHASE);
+    if (testname.equals("renderPhaseListenerTest") && portletPhase.equals(Bridge.PortletPhase.RENDER_PHASE))
+    {
+      m.put("org.apache.portlet.faces.tck.lastAfterPhase", phase);
+    }
+    
+    if (testname.equals("facesContextReleasedRenderTest") || testname.equals("portletPhaseRemovedRenderTest"))
+    {
+      // prematurely prevent render from happening as the Portlet needs to write to the response once it verifys that the 
+      // corresponding elements were cleaned up
+      ctx.responseComplete();
+    }
+  }
+     
+}