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/03/25 23:34:29 UTC

svn commit: r927614 - in /myfaces/portlet-bridge/testsuite/trunk/src/main: java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_4/section_4_2_12/ java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_6/section_6_1_3_1/ webapp/WEB-INF/

Author: mfreedman
Date: Thu Mar 25 22:34:28 2010
New Revision: 927614

URL: http://svn.apache.org/viewvc?rev=927614&view=rev
Log: (empty)

Added:
    myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_4/section_4_2_12/
    myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_4/section_4_2_12/GetFacesBridgeMethodTestPortlet.java
    myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_4/section_4_2_12/Tests.java
Modified:
    myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_6/section_6_1_3_1/Tests.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

Added: myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_4/section_4_2_12/GetFacesBridgeMethodTestPortlet.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_12/GetFacesBridgeMethodTestPortlet.java?rev=927614&view=auto
==============================================================================
--- myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_4/section_4_2_12/GetFacesBridgeMethodTestPortlet.java (added)
+++ myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_4/section_4_2_12/GetFacesBridgeMethodTestPortlet.java Thu Mar 25 22:34:28 2010
@@ -0,0 +1,94 @@
+/* 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_12;
+
+import org.apache.myfaces.portlet.faces.testsuite.common.portlet.GenericFacesTestSuitePortlet;
+import javax.portlet.faces.GenericFacesPortlet;
+import javax.portlet.faces.BridgeException;
+import javax.portlet.PortletRequest;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.PortletException;
+import java.io.IOException;
+
+import org.apache.myfaces.portlet.faces.testsuite.common.util.BridgeTCKResultWriter;
+
+/**
+ * Checks that GenericFacesPortlet#getFacesBridge method works as stated 
+ * in section 4.2.12.
+
+ * - There may be times, in particular when dealing with events using the 
+ *   standard portlet event model, in which a subclass needs to dispatch 
+ *   a request directly to the bridge.  To support this the 
+ *   GenericFacesPortlet, via this method, returns a properly initialized 
+ *   and active bridge which a subclass can use to call one of the 
+ *   doFacesRequest() methods.
+ */
+
+
+public class GetFacesBridgeMethodTestPortlet extends GenericFacesTestSuitePortlet
+{
+  @Override
+  public void doDispatch(RenderRequest request, RenderResponse response) 
+    throws PortletException, IOException
+  {
+    String contentType = getResponseContentType(request);
+    if (contentType != null)
+    {
+      String charSetEncoding = getResponseCharacterSetEncoding(request);
+      if (charSetEncoding != null)
+      {
+        StringBuilder buf = new StringBuilder(contentType);
+        buf.append(";");
+        buf.append(charSetEncoding);
+        response.setContentType(buf.toString());
+      } 
+      else
+      {
+        response.setContentType(contentType);
+      }
+    }
+
+    try
+    {
+      getFacesBridge(request, response).doFacesRequest(request, response);
+    } 
+    catch (BridgeException be)
+    {
+      throw new PortletException("getFacesBridge test failed:  error from Bridge while executing the render request", be);
+    }
+  }
+
+  @Override
+  public void processAction(ActionRequest request, ActionResponse response)
+    throws PortletException, IOException
+  {
+    try
+    {
+      getFacesBridge(request, response).doFacesRequest(request, response);
+    }
+    catch (BridgeException be)
+    {
+      throw new PortletException("getFacesBridge test failed:  error from Bridge while executing the action request", be);
+    }
+  }
+}

Added: myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_4/section_4_2_12/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_2_12/Tests.java?rev=927614&view=auto
==============================================================================
--- myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_4/section_4_2_12/Tests.java (added)
+++ myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_4/section_4_2_12/Tests.java Thu Mar 25 22:34:28 2010
@@ -0,0 +1,55 @@
+/* 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_12;
+
+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 = "getFacesBridgeMethodTest")
+  public String getFacesBridgeMethodTest(TestRunnerBean testRunner)
+  {
+    // Section 4.2.12
+    // The Run Test action simply forwards to a results page.
+    if (BridgeUtil.getPortletRequestPhase() ==
+        Bridge.PortletPhase.ACTION_PHASE)
+    {
+      return "getFacesBridgeMethodTest";
+    }
+    else
+    {
+      testRunner.setTestComplete(true);
+
+      testRunner.setTestResult(true,
+                             "Successfully performed an action request and a render request by means of a GenericFacesPortlet subclass using the bridge returned by GenericFacesPortlet.getFacesBridge().");
+      return Constants.TEST_SUCCESS;  
+    }
+  }
+}

Modified: myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_6/section_6_1_3_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_6/section_6_1_3_1/Tests.java?rev=927614&r1=927613&r2=927614&view=diff
==============================================================================
--- myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_6/section_6_1_3_1/Tests.java (original)
+++ myfaces/portlet-bridge/testsuite/trunk/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_6/section_6_1_3_1/Tests.java Thu Mar 25 22:34:28 2010
@@ -20,6 +20,7 @@
 package org.apache.myfaces.portlet.faces.testsuite.tests.chapter_6.section_6_1_3_1;
 
 
+import java.io.Reader;
 import java.io.UnsupportedEncodingException;
 
 import java.net.URLDecoder;
@@ -1534,7 +1535,7 @@ public class Tests
       String testEncoding = null;
       // read the parameters to ensure setting the encoding is invalid.
       Map m = ((PortletRequest) extCtx.getRequest()).getParameterMap();
-
+      
       if (s == null || (s != null && !s.equalsIgnoreCase(utf8)))
       {
         testEncoding = utf8;
@@ -3853,4 +3854,93 @@ public class Tests
       return Constants.TEST_FAILED;
     }
   }
+  
+  // Test is SingleRequest -- tests whether parameters encoded in the defaultViewId's
+  //                          queryString are exposed as request parameters.
+  // Test #6.99
+  @BridgeTest(test = "encodeURLEscapingTest")
+  public String encodeURLEscapingTest(TestRunnerBean testRunner)
+  {
+    testRunner.setTestComplete(true);
+
+    FacesContext ctx = FacesContext.getCurrentInstance();
+    ExternalContext extCtx = ctx.getExternalContext();
+
+    // test encodeActionURL preserves the xml escape encoding in the url it returns
+    if (isStrictXhtmlEncoded(extCtx.encodeActionURL("/tests/SingleRequestTest.jsp?parm1=a&param2=b")))
+    {
+      testRunner.setTestResult(false,
+                               "EncodeActionURL incorrectly returned an url including xml escaping when the input url wasn't escaped.");
+      return Constants.TEST_FAILED;
+    }
+    
+    if (!isStrictXhtmlEncoded(extCtx.encodeActionURL("/tests/SingleRequestTest.jsp?parm1=a&param2=b")))
+    {
+      testRunner.setTestResult(false,
+                               "EncodeActionURL incorrectly returned an url without xml escaping when the input url was escaped.");
+      return Constants.TEST_FAILED;
+    }
+    
+    if (isStrictXhtmlEncoded(extCtx.encodeActionURL("/tests/SingleRequestTest.jsp")))
+    {
+      testRunner.setTestResult(false,
+                               "EncodeActionURL incorrectly returned an url including xml escaping when the input url contained no indication (no query string).");
+      return Constants.TEST_FAILED;
+    }
+    
+    if (isStrictXhtmlEncoded(extCtx.encodeResourceURL("/tests/SingleRequestTest.jsp?parm1=a&param2=b")))
+    {
+      testRunner.setTestResult(false,
+                               "EncodeResourceURL incorrectly returned an url including xml escaping when the input url wasn't escaped.");
+      return Constants.TEST_FAILED;
+    }
+    
+    if (!isStrictXhtmlEncoded(extCtx.encodeResourceURL("/tests/SingleRequestTest.jsp?parm1=a&param2=b")))
+    {
+      testRunner.setTestResult(false,
+                               "EncodeResourceURL incorrectly returned an url without xml escaping when the input url was escaped.");
+      return Constants.TEST_FAILED;
+    }
+    
+    if (isStrictXhtmlEncoded(extCtx.encodeResourceURL("/tests/SingleRequestTest.jsp")))
+    {
+      testRunner.setTestResult(false,
+                               "EncodeResourceURL incorrectly returned an url including xml escaping when the input url contained no indication (no query string).");
+      return Constants.TEST_FAILED;
+    }
+    
+    // Otherwise all was good.
+
+    testRunner.setTestResult(true,
+                              "encodeActionURL and encodeResourceURL both correctly xml escaped urls it should and didn't xml escape urls it shouldn't");
+    return Constants.TEST_SUCCESS;
+
+  }
+  
+  private boolean isStrictXhtmlEncoded(String url)
+  {
+    // check for use of & in query string
+    int currentPos = url.indexOf('?');
+
+    if (currentPos == -1) return false;
+    
+    boolean isStrict = false;    
+    while (true)
+    {
+      int ampPos = url.indexOf('&', currentPos);
+      int xhtmlAmpPos = url.indexOf("&", currentPos);
+      // no more & to process -- so return current value of isStrict
+      if (ampPos == -1)
+      {
+        return isStrict;
+      }
+      // if the amp we found doesn't start an & then its not strict
+      if (ampPos != xhtmlAmpPos)
+      {
+        return false;
+      }
+      isStrict = true;
+      currentPos = ampPos + 1;
+    }
+  }
 }

Modified: myfaces/portlet-bridge/testsuite/trunk/src/main/webapp/WEB-INF/faces-config.xml
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/testsuite/trunk/src/main/webapp/WEB-INF/faces-config.xml?rev=927614&r1=927613&r2=927614&view=diff
==============================================================================
--- myfaces/portlet-bridge/testsuite/trunk/src/main/webapp/WEB-INF/faces-config.xml (original)
+++ myfaces/portlet-bridge/testsuite/trunk/src/main/webapp/WEB-INF/faces-config.xml Thu Mar 25 22:34:28 2010
@@ -31,6 +31,11 @@
     <managed-bean-scope>request</managed-bean-scope>
   </managed-bean> 
   <managed-bean>
+    <managed-bean-name>chapter4_2_12Tests</managed-bean-name>
+    <managed-bean-class>org.apache.myfaces.portlet.faces.testsuite.tests.chapter_4.section_4_2_12.Tests</managed-bean-class>
+    <managed-bean-scope>request</managed-bean-scope>
+  </managed-bean> 
+  <managed-bean>
     <managed-bean-name>chapter5_1_2Tests</managed-bean-name>
     <managed-bean-class>org.apache.myfaces.portlet.faces.testsuite.tests.chapter_5.section_5_1_2.Tests</managed-bean-class>
     <managed-bean-scope>request</managed-bean-scope>
@@ -122,6 +127,15 @@
       <to-view-id>/tests/MultiRequestTestResultRenderCheck.jsp</to-view-id>
     </navigation-case>
   </navigation-rule>
+
+  <!-- Chapter 4 Test -->
+  <navigation-rule>
+    <from-view-id>/tests/MultiRequestTest.jsp</from-view-id>
+    <navigation-case>
+      <from-outcome>getFacesBridgeMethodTest</from-outcome>
+      <to-view-id>/tests/MultiRequestTestResultRenderCheck.jsp</to-view-id>
+    </navigation-case>
+  </navigation-rule>
   
   <!-- Chapter 5 Tests -->
   <navigation-rule>

Modified: myfaces/portlet-bridge/testsuite/trunk/src/main/webapp/WEB-INF/portlet.xml
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/testsuite/trunk/src/main/webapp/WEB-INF/portlet.xml?rev=927614&r1=927613&r2=927614&view=diff
==============================================================================
--- myfaces/portlet-bridge/testsuite/trunk/src/main/webapp/WEB-INF/portlet.xml (original)
+++ myfaces/portlet-bridge/testsuite/trunk/src/main/webapp/WEB-INF/portlet.xml Thu Mar 25 22:34:28 2010
@@ -487,6 +487,22 @@
         </portlet-info>
     </portlet>
 
+    <portlet>
+        <portlet-name>chapter4_2_12Tests-getFacesBridgeMethodTest-portlet</portlet-name>
+        <portlet-class>org.apache.myfaces.portlet.faces.testsuite.tests.chapter_4.section_4_2_12.GetFacesBridgeMethodTestPortlet</portlet-class>
+        <init-param>
+          <name>javax.portlet.faces.defaultViewId.view</name>
+          <value>/tests/MultiRequestTest.jsp</value>
+        </init-param>
+        <expiration-cache>0</expiration-cache>
+        <supports>
+            <mime-type>text/html</mime-type>
+        </supports>
+        <portlet-info>
+            <title>chapter4_2_12Tests-getDefaultViewIdMapMethodTest-portlet</title>
+        </portlet-info>
+    </portlet>
+
     <!-- *************************************************************** -->
     <!-- *                                                             * -->
     <!-- * Tests: Chapter 5                                            * -->
@@ -1606,6 +1622,25 @@
         </portlet-info>
     </portlet>
 -->    
+
+    <portlet>
+        <portlet-name>chapter6_1_3_1Tests-encodeURLEscapingTest-portlet</portlet-name>
+        <portlet-class>org.apache.myfaces.portlet.faces.testsuite.common.portlet.GenericFacesTestSuitePortlet</portlet-class>
+        
+        <init-param>
+          <name>javax.portlet.faces.defaultViewId.view</name>
+          <value>/tests/SingleRequestTest.jsp</value>
+        </init-param>
+
+        <expiration-cache>0</expiration-cache>
+        
+       <supports>
+         <mime-type>text/html</mime-type>
+       </supports>
+        <portlet-info>
+                <title>chapter6_1_3_1Tests-encodeURLEscapingTest-portlet</title>
+        </portlet-info>
+    </portlet>
  
      <!-- *************************************************************** -->
     <!-- *                                                             * -->