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/10/19 23:55:52 UTC
svn commit: r1024428 [2/4] - in /myfaces/portlet-bridge/tck/trunk_2.0.x: ./
portlet-bridge-tck-main/src/main/webapp/WEB-INF/
portlet-bridge-tck-main/src/main/webapp/tests/
portlet-bridge-tck-section6-2-configured-response-wrapper/
portlet-bridge-tck-se...
Added: myfaces/portlet-bridge/tck/trunk_2.0.x/portlet-bridge-tck-section6-2-configured-response-wrapper/src/main/java/org/apache/myfaces/portlet/faces/tck/TCKRenderResponseWrapper.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/tck/trunk_2.0.x/portlet-bridge-tck-section6-2-configured-response-wrapper/src/main/java/org/apache/myfaces/portlet/faces/tck/TCKRenderResponseWrapper.java?rev=1024428&view=auto
==============================================================================
--- myfaces/portlet-bridge/tck/trunk_2.0.x/portlet-bridge-tck-section6-2-configured-response-wrapper/src/main/java/org/apache/myfaces/portlet/faces/tck/TCKRenderResponseWrapper.java (added)
+++ myfaces/portlet-bridge/tck/trunk_2.0.x/portlet-bridge-tck-section6-2-configured-response-wrapper/src/main/java/org/apache/myfaces/portlet/faces/tck/TCKRenderResponseWrapper.java Tue Oct 19 21:55:51 2010
@@ -0,0 +1,382 @@
+/* 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.tck;
+
+import java.io.ByteArrayOutputStream;
+import java.io.CharArrayWriter;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.io.Writer;
+
+import java.nio.ByteBuffer;
+
+import javax.faces.context.FacesContext;
+
+import javax.portlet.RenderResponse;
+import javax.portlet.filter.RenderResponseWrapper;
+
+import javax.servlet.http.HttpServletResponse;
+
+import javax.portlet.faces.BridgeWriteBehindResponse;
+
+public class TCKRenderResponseWrapper
+ extends RenderResponseWrapper
+ implements BridgeWriteBehindResponse
+{
+
+ private DirectByteArrayServletOutputStream mByteStream;
+ private CharArrayWriter mCharWriter;
+ private PrintWriter mPrintWriter;
+ private int mStatus = HttpServletResponse.SC_OK;
+ private boolean mHasWriteBehindMarkup = false;
+
+ public TCKRenderResponseWrapper()
+ {
+ super((RenderResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse());
+ }
+
+
+ public TCKRenderResponseWrapper(RenderResponse wrapped)
+ {
+ super(wrapped);
+ }
+
+ public void flushBuffer()
+ {
+ if (isChars())
+ {
+ mPrintWriter.flush();
+ }
+ }
+
+ public int getBufferSize()
+ {
+ if (isBytes())
+ {
+ return mByteStream.size();
+ }
+ else if (isChars())
+ {
+ return mCharWriter.size();
+ }
+ else
+ return 0;
+ }
+
+
+ public void reset()
+ {
+ super.reset();
+ if (isBytes())
+ {
+ mByteStream.reset();
+ }
+ else if (isChars())
+ {
+ mPrintWriter.flush();
+ mCharWriter.reset();
+ }
+ }
+
+ public void resetBuffer()
+ {
+ super.resetBuffer();
+ if (isBytes())
+ {
+ mByteStream.reset();
+ }
+ else if (isChars())
+ {
+ mPrintWriter.flush();
+ mCharWriter.reset();
+ }
+ }
+
+
+ public OutputStream getPortletOutputStream()
+ throws IOException
+ {
+ if (mPrintWriter != null)
+ {
+ throw new IllegalStateException();
+ }
+ if (mByteStream == null)
+ {
+ mByteStream = new DirectByteArrayServletOutputStream();
+ }
+ return mByteStream;
+ }
+
+ public PrintWriter getWriter()
+ throws IOException
+ {
+ if (mByteStream != null)
+ {
+ throw new IllegalStateException();
+ }
+ if (mPrintWriter == null)
+ {
+ mCharWriter = new CharArrayWriter(4096);
+ mPrintWriter = new PrintWriter(mCharWriter);
+ }
+
+ return mPrintWriter;
+ }
+
+ public int getStatus()
+ {
+ return mStatus;
+ }
+
+ public boolean isBytes()
+ {
+ return (mByteStream != null);
+ }
+
+ public boolean isChars()
+ {
+ return (mCharWriter != null);
+ }
+
+ public byte[] getBytes()
+ {
+ if (isBytes())
+ {
+ return mByteStream.toByteArray();
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public char[] getChars()
+ {
+ if (isChars())
+ {
+ mCharWriter.flush();
+ return mCharWriter.toCharArray();
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public String toString()
+ {
+ if (isChars())
+ {
+ mCharWriter.flush();
+ return mCharWriter.toString();
+ }
+ else if (isBytes())
+ {
+ return mByteStream.toString();
+ }
+ else
+ return null;
+ }
+
+ public void clearWrappedResponse()
+ throws IOException
+ {
+ resetBuffers();
+ }
+
+ /**
+ * Flush the current buffered content to the wrapped
+ * response (this could be a Servlet or Portlet response)
+ * @throws IOException if content cannot be written
+ */
+ public void flushMarkupToWrappedResponse()
+ throws IOException
+ {
+ RenderResponse response = getResponse();
+
+ flushBuffer();
+
+ if (isBytes())
+ {
+ response.getPortletOutputStream().write(getBytes());
+ mByteStream.reset();
+ }
+ else if (isChars())
+ {
+ response.getWriter().write(getChars());
+ mCharWriter.reset();
+ }
+
+ }
+
+ /**
+ * This is the Mojarra specific API used by its tags to flush the pre-view content
+ * to the wrapped response. Works automatically in newer Mojarra -- one's that use
+ * inspection to determine if the API is supported.
+ * @throws IOException if content cannot be written
+ */
+ public void flushContentToWrappedResponse()
+ throws IOException
+ {
+ mHasWriteBehindMarkup = true;
+
+ flushMarkupToWrappedResponse();
+
+ }
+
+ /**
+ * This is the MyFaces specific API used by its tags to flush the pre-view content
+ * to the wrapped response. MyFaces doesn't yet use reflection so this will only work if you
+ * subclass with a class that claims it implements the MyFaces interface.
+ * @throws IOException if content cannot be written
+ */
+ public void flushToWrappedResponse()
+ throws IOException
+ {
+ mHasWriteBehindMarkup = true;
+
+ flushMarkupToWrappedResponse();
+
+ }
+
+ /**
+ * Flush the current buffered content to the provided <code>Writer</code>
+ * @param writer target <code>Writer</code>
+ * @param encoding the encoding that should be used
+ * @throws IOException if content cannot be written
+ */
+ public void flushToWriter(Writer writer, String encoding)
+ throws IOException
+ {
+ flushBuffer();
+
+ if (isBytes())
+ {
+ throw new IOException("Invalid flushToWriter as the code is writing bytes to an OutputStream.");
+ }
+ else if (isChars())
+ {
+ writer.write(getChars());
+ mCharWriter.reset();
+ }
+ }
+
+ /**
+ * Clear the internal buffers.
+ * @throws IOException if some odd error occurs
+ */
+ public void resetBuffers()
+ throws IOException
+ {
+ if (isBytes())
+ {
+ mByteStream.reset();
+ }
+ else if (isChars())
+ {
+ mPrintWriter.flush();
+ mCharWriter.reset();
+ }
+ }
+
+ /**
+ * Called by the bridge to detect whether this response actively participated
+ * in the Faces writeBehind support and hence has data that should be written
+ * after the View is rendered. Typically, this method will return <code>true</code>
+ * if the Faces write behind implementation specific flush api has been called
+ * on this response, otherwise <code>false</code>
+ *
+ * @return an indication of whether the response actually particpated in the writeBehind mechanism.
+ */
+ public boolean hasFacesWriteBehindMarkup()
+ {
+ return mHasWriteBehindMarkup;
+ }
+
+
+ // ----------------------------------------------------------- Inner Classes
+
+
+ private class DirectByteArrayServletOutputStream
+ extends OutputStream
+ {
+ private DirectByteArrayOutputStream mByteArrayOutputStream;
+
+ public DirectByteArrayServletOutputStream()
+ {
+ mByteArrayOutputStream = new DirectByteArrayOutputStream(4096);
+ }
+
+ public void write(int n)
+ {
+ mByteArrayOutputStream.write(n);
+ }
+
+ public byte[] toByteArray()
+ {
+ return mByteArrayOutputStream.toByteArray();
+ }
+
+ public int size()
+ {
+ return mByteArrayOutputStream.size();
+ }
+
+ public void reset()
+ {
+ mByteArrayOutputStream.reset();
+ }
+
+ }
+
+
+ private class DirectByteArrayOutputStream
+ extends ByteArrayOutputStream
+ {
+
+
+ // -------------------------------------------------------- Constructors
+
+
+ public DirectByteArrayOutputStream(int initialCapacity)
+ {
+ super(initialCapacity);
+ }
+
+
+ // ------------------------------------------------------- PublicMethods
+
+
+ /**
+ * Return the buffer backing this ByteArrayOutputStream as a
+ * ByteBuffer.
+ * @return buf wrapped in a ByteBuffer
+ */
+ public ByteBuffer getByteBuffer()
+ {
+ return (ByteBuffer.wrap(buf, 0, count));
+ }
+
+ }
+
+
+ // end of class BridgeRenderFilterResponseWrapper
+}
Added: myfaces/portlet-bridge/tck/trunk_2.0.x/portlet-bridge-tck-section6-2-configured-response-wrapper/src/main/java/org/apache/myfaces/portlet/faces/tck/TCKResourceResponseWrapper.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/tck/trunk_2.0.x/portlet-bridge-tck-section6-2-configured-response-wrapper/src/main/java/org/apache/myfaces/portlet/faces/tck/TCKResourceResponseWrapper.java?rev=1024428&view=auto
==============================================================================
--- myfaces/portlet-bridge/tck/trunk_2.0.x/portlet-bridge-tck-section6-2-configured-response-wrapper/src/main/java/org/apache/myfaces/portlet/faces/tck/TCKResourceResponseWrapper.java (added)
+++ myfaces/portlet-bridge/tck/trunk_2.0.x/portlet-bridge-tck-section6-2-configured-response-wrapper/src/main/java/org/apache/myfaces/portlet/faces/tck/TCKResourceResponseWrapper.java Tue Oct 19 21:55:51 2010
@@ -0,0 +1,385 @@
+/* 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.tck;
+
+import java.io.ByteArrayOutputStream;
+import java.io.CharArrayWriter;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.io.Writer;
+
+import java.nio.ByteBuffer;
+
+import javax.faces.context.FacesContext;
+
+import javax.portlet.RenderResponse;
+import javax.portlet.ResourceResponse;
+
+import javax.portlet.filter.ResourceResponseWrapper;
+
+import javax.servlet.http.HttpServletResponse;
+
+import javax.portlet.faces.BridgeWriteBehindResponse;
+
+
+public class TCKResourceResponseWrapper
+ extends ResourceResponseWrapper
+ implements BridgeWriteBehindResponse
+{
+
+ private DirectByteArrayServletOutputStream mByteStream;
+ private CharArrayWriter mCharWriter;
+ private PrintWriter mPrintWriter;
+ private int mStatus = HttpServletResponse.SC_OK;
+ private boolean mHasWriteBehindMarkup = false;
+
+ public TCKResourceResponseWrapper()
+ {
+ super((ResourceResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse());
+ }
+
+
+ public TCKResourceResponseWrapper(ResourceResponse wrapped)
+ {
+ super(wrapped);
+ }
+
+ public void flushBuffer()
+ {
+ if (isChars())
+ {
+ mPrintWriter.flush();
+ }
+ }
+
+ public int getBufferSize()
+ {
+ if (isBytes())
+ {
+ return mByteStream.size();
+ }
+ else if (isChars())
+ {
+ return mCharWriter.size();
+ }
+ else
+ return 0;
+ }
+
+
+ public void reset()
+ {
+ super.reset();
+ if (isBytes())
+ {
+ mByteStream.reset();
+ }
+ else if (isChars())
+ {
+ mPrintWriter.flush();
+ mCharWriter.reset();
+ }
+ }
+
+ public void resetBuffer()
+ {
+ super.resetBuffer();
+ if (isBytes())
+ {
+ mByteStream.reset();
+ }
+ else if (isChars())
+ {
+ mPrintWriter.flush();
+ mCharWriter.reset();
+ }
+ }
+
+
+ public OutputStream getPortletOutputStream()
+ throws IOException
+ {
+ if (mPrintWriter != null)
+ {
+ throw new IllegalStateException();
+ }
+ if (mByteStream == null)
+ {
+ mByteStream = new DirectByteArrayServletOutputStream();
+ }
+ return mByteStream;
+ }
+
+ public PrintWriter getWriter()
+ throws IOException
+ {
+ if (mByteStream != null)
+ {
+ throw new IllegalStateException();
+ }
+ if (mPrintWriter == null)
+ {
+ mCharWriter = new CharArrayWriter(4096);
+ mPrintWriter = new PrintWriter(mCharWriter);
+ }
+
+ return mPrintWriter;
+ }
+
+ public int getStatus()
+ {
+ return mStatus;
+ }
+
+ public boolean isBytes()
+ {
+ return (mByteStream != null);
+ }
+
+ public boolean isChars()
+ {
+ return (mCharWriter != null);
+ }
+
+ public byte[] getBytes()
+ {
+ if (isBytes())
+ {
+ return mByteStream.toByteArray();
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public char[] getChars()
+ {
+ if (isChars())
+ {
+ mCharWriter.flush();
+ return mCharWriter.toCharArray();
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public String toString()
+ {
+ if (isChars())
+ {
+ mCharWriter.flush();
+ return mCharWriter.toString();
+ }
+ else if (isBytes())
+ {
+ return mByteStream.toString();
+ }
+ else
+ return null;
+ }
+
+ public void clearWrappedResponse()
+ throws IOException
+ {
+ resetBuffers();
+ }
+
+ /**
+ * Flush the current buffered content to the wrapped
+ * response (this could be a Servlet or Portlet response)
+ * @throws IOException if content cannot be written
+ */
+ public void flushMarkupToWrappedResponse()
+ throws IOException
+ {
+ ResourceResponse response = getResponse();
+
+ flushBuffer();
+
+ if (isBytes())
+ {
+ response.getPortletOutputStream().write(getBytes());
+ mByteStream.reset();
+ }
+ else if (isChars())
+ {
+ response.getWriter().write(getChars());
+ mCharWriter.reset();
+ }
+
+ }
+
+ /**
+ * This is the Mojarra specific API used by its tags to flush the pre-view content
+ * to the wrapped response. Works automatically in newer Mojarra -- one's that use
+ * inspection to determine if the API is supported.
+ * @throws IOException if content cannot be written
+ */
+ public void flushContentToWrappedResponse()
+ throws IOException
+ {
+ mHasWriteBehindMarkup = true;
+
+ flushMarkupToWrappedResponse();
+
+ }
+
+ /**
+ * This is the MyFaces specific API used by its tags to flush the pre-view content
+ * to the wrapped response. MyFaces doesn't yet use reflection so this will only work if you
+ * subclass with a class that claims it implements the MyFaces interface.
+ * @throws IOException if content cannot be written
+ */
+ public void flushToWrappedResponse()
+ throws IOException
+ {
+ mHasWriteBehindMarkup = true;
+
+ flushMarkupToWrappedResponse();
+
+ }
+
+ /**
+ * Flush the current buffered content to the provided <code>Writer</code>
+ * @param writer target <code>Writer</code>
+ * @param encoding the encoding that should be used
+ * @throws IOException if content cannot be written
+ */
+ public void flushToWriter(Writer writer, String encoding)
+ throws IOException
+ {
+ flushBuffer();
+
+ if (isBytes())
+ {
+ throw new IOException("Invalid flushToWriter as the code is writing bytes to an OutputStream.");
+ }
+ else if (isChars())
+ {
+ writer.write(getChars());
+ mCharWriter.reset();
+ }
+ }
+
+ /**
+ * Clear the internal buffers.
+ * @throws IOException if some odd error occurs
+ */
+ public void resetBuffers()
+ throws IOException
+ {
+ if (isBytes())
+ {
+ mByteStream.reset();
+ }
+ else if (isChars())
+ {
+ mPrintWriter.flush();
+ mCharWriter.reset();
+ }
+ }
+
+ /**
+ * Called by the bridge to detect whether this response actively participated
+ * in the Faces writeBehind support and hence has data that should be written
+ * after the View is rendered. Typically, this method will return <code>true</code>
+ * if the Faces write behind implementation specific flush api has been called
+ * on this response, otherwise <code>false</code>
+ *
+ * @return an indication of whether the response actually particpated in the writeBehind mechanism.
+ */
+ public boolean hasFacesWriteBehindMarkup()
+ {
+ return mHasWriteBehindMarkup;
+ }
+
+
+ // ----------------------------------------------------------- Inner Classes
+
+
+ private class DirectByteArrayServletOutputStream
+ extends OutputStream
+ {
+ private DirectByteArrayOutputStream mByteArrayOutputStream;
+
+ public DirectByteArrayServletOutputStream()
+ {
+ mByteArrayOutputStream = new DirectByteArrayOutputStream(4096);
+ }
+
+ public void write(int n)
+ {
+ mByteArrayOutputStream.write(n);
+ }
+
+ public byte[] toByteArray()
+ {
+ return mByteArrayOutputStream.toByteArray();
+ }
+
+ public int size()
+ {
+ return mByteArrayOutputStream.size();
+ }
+
+ public void reset()
+ {
+ mByteArrayOutputStream.reset();
+ }
+
+ }
+
+
+ private class DirectByteArrayOutputStream
+ extends ByteArrayOutputStream
+ {
+
+
+ // -------------------------------------------------------- Constructors
+
+
+ public DirectByteArrayOutputStream(int initialCapacity)
+ {
+ super(initialCapacity);
+ }
+
+
+ // ------------------------------------------------------- PublicMethods
+
+
+ /**
+ * Return the buffer backing this ByteArrayOutputStream as a
+ * ByteBuffer.
+ * @return buf wrapped in a ByteBuffer
+ */
+ public ByteBuffer getByteBuffer()
+ {
+ return (ByteBuffer.wrap(buf, 0, count));
+ }
+
+ }
+
+
+ // end of class BridgeRenderFilterResponseWrapper
+}
Added: myfaces/portlet-bridge/tck/trunk_2.0.x/portlet-bridge-tck-section6-2-configured-response-wrapper/src/main/webapp/WEB-INF/faces-config.xml
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/tck/trunk_2.0.x/portlet-bridge-tck-section6-2-configured-response-wrapper/src/main/webapp/WEB-INF/faces-config.xml?rev=1024428&view=auto
==============================================================================
--- myfaces/portlet-bridge/tck/trunk_2.0.x/portlet-bridge-tck-section6-2-configured-response-wrapper/src/main/webapp/WEB-INF/faces-config.xml (added)
+++ myfaces/portlet-bridge/tck/trunk_2.0.x/portlet-bridge-tck-section6-2-configured-response-wrapper/src/main/webapp/WEB-INF/faces-config.xml Tue Oct 19 21:55:51 2010
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<faces-config version="1.2" xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:bridge="http://www.apache.org/myfaces/xml/ns/bridge/bridge-extension"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">
+
+ <application>
+ <locale-config>
+ <default-locale>en</default-locale>
+ <supported-locale>de</supported-locale>
+ <supported-locale>fr</supported-locale>
+ <supported-locale>es</supported-locale>
+ </locale-config>
+ <application-extension>
+ <bridge:write-behind-response-wrappers>
+ <bridge:render-response-wrapper-class>org.apache.myfaces.portlet.faces.tck.TCKRenderResponseWrapper</bridge:render-response-wrapper-class>
+ <bridge:resource-response-wrapper-class>org.apache.myfaces.portlet.faces.tck.TCKResourceResponseWrapper</bridge:resource-response-wrapper-class>
+ </bridge:write-behind-response-wrappers>
+ </application-extension>
+ </application>
+
+ <managed-bean>
+ <managed-bean-name>chapter6_2_1Tests</managed-bean-name>
+ <managed-bean-class>org.apache.myfaces.portlet.faces.testsuite.tests.chapter_6.section_6_2_1.Tests</managed-bean-class>
+ <managed-bean-scope>request</managed-bean-scope>
+ </managed-bean>
+
+ <managed-bean>
+ <managed-bean-name>test</managed-bean-name>
+ <managed-bean-class>org.apache.myfaces.portlet.faces.testsuite.beans.TestRunnerBean</managed-bean-class>
+ <managed-bean-scope>request</managed-bean-scope>
+ </managed-bean>
+
+</faces-config>
Added: myfaces/portlet-bridge/tck/trunk_2.0.x/portlet-bridge-tck-section6-2-configured-response-wrapper/src/main/webapp/WEB-INF/portlet.xml
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/tck/trunk_2.0.x/portlet-bridge-tck-section6-2-configured-response-wrapper/src/main/webapp/WEB-INF/portlet.xml?rev=1024428&view=auto
==============================================================================
--- myfaces/portlet-bridge/tck/trunk_2.0.x/portlet-bridge-tck-section6-2-configured-response-wrapper/src/main/webapp/WEB-INF/portlet.xml (added)
+++ myfaces/portlet-bridge/tck/trunk_2.0.x/portlet-bridge-tck-section6-2-configured-response-wrapper/src/main/webapp/WEB-INF/portlet.xml Tue Oct 19 21:55:51 2010
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd
+ http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
+ id="UsesConfiguredResponseWrapperTest" version="2.0">
+
+ <portlet>
+ <portlet-name>chapter6_2_1Tests-usesConfiguredRenderResponseWrapperTest-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/UsesConfiguredRenderResponseWrapperTest.jsp</value>
+ </init-param>
+
+ <expiration-cache>0</expiration-cache>
+
+ <supports>
+ <mime-type>text/html</mime-type>
+ </supports>
+ <portlet-info>
+ <title>chapter6_2_1Tests-usesConfiguredRenderResponseWrapperTest-portlet</title>
+ </portlet-info>
+ </portlet>
+
+ <portlet>
+ <portlet-name>chapter6_2_1Tests-usesConfiguredResourceResponseWrapperTest-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/ResourceRequestTest.jsp</value>
+ </init-param>
+
+ <expiration-cache>0</expiration-cache>
+
+ <supports>
+ <mime-type>text/html</mime-type>
+ </supports>
+ <portlet-info>
+ <title>chapter6_2_1Tests-usesConfiguredResourceResponseWrapperTest-portlet</title>
+ </portlet-info>
+ </portlet>
+
+</portlet-app>
Added: myfaces/portlet-bridge/tck/trunk_2.0.x/portlet-bridge-tck-section6-2-configured-response-wrapper/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/tck/trunk_2.0.x/portlet-bridge-tck-section6-2-configured-response-wrapper/src/main/webapp/WEB-INF/web.xml?rev=1024428&view=auto
==============================================================================
--- myfaces/portlet-bridge/tck/trunk_2.0.x/portlet-bridge-tck-section6-2-configured-response-wrapper/src/main/webapp/WEB-INF/web.xml (added)
+++ myfaces/portlet-bridge/tck/trunk_2.0.x/portlet-bridge-tck-section6-2-configured-response-wrapper/src/main/webapp/WEB-INF/web.xml Tue Oct 19 21:55:51 2010
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!DOCTYPE web-app PUBLIC '-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN' 'http://java.sun.com/dtd/web-app_2_3.dtd'>
+<web-app>
+ <display-name>bridge_Test_web_section6-2-configured-response-wrapper</display-name>
+ <context-param>
+ <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
+ <param-value>.jsp</param-value>
+ </context-param>
+ <context-param>
+ <param-name>javax.portlet.faces.LIFECYCLE_ID</param-name>
+ <param-value>TCKLifecycle</param-value>
+ </context-param>
+
+
+ <!-- Faces Servlet -->
+ <servlet>
+ <servlet-name>faces</servlet-name>
+ <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
+ </servlet>
+
+
+ <!-- Faces Servlet Mappings -->
+ <!--
+ In this demo application, I chose to use suffix mapping. I did this because it makes urls
+ in the portlet world look nicer in the source. The portlet url should be the same
+ reguardless.
+ -->
+ <servlet-mapping>
+ <servlet-name>faces</servlet-name>
+ <url-pattern>*.jsf</url-pattern>
+ </servlet-mapping>
+</web-app>
Added: myfaces/portlet-bridge/tck/trunk_2.0.x/portlet-bridge-tck-section6-2-configured-response-wrapper/src/main/webapp/tests/ResourceRequestTest.jsp
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/tck/trunk_2.0.x/portlet-bridge-tck-section6-2-configured-response-wrapper/src/main/webapp/tests/ResourceRequestTest.jsp?rev=1024428&view=auto
==============================================================================
--- myfaces/portlet-bridge/tck/trunk_2.0.x/portlet-bridge-tck-section6-2-configured-response-wrapper/src/main/webapp/tests/ResourceRequestTest.jsp (added)
+++ myfaces/portlet-bridge/tck/trunk_2.0.x/portlet-bridge-tck-section6-2-configured-response-wrapper/src/main/webapp/tests/ResourceRequestTest.jsp Tue Oct 19 21:55:51 2010
@@ -0,0 +1,29 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+"http://www.w3.org/TR/html4/loose.dtd">
+<%@ page contentType="text/html;charset=UTF-8"
+ isELIgnored="false"
+ import="javax.faces.context.*, javax.faces.application.*, java.lang.Boolean" %>
+
+<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
+<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
+
+<f:view>
+ <html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
+ <title>JSR 301 Multi-Request TCK Test</title>
+ </head>
+ <body>
+ <h:form>
+ <h:panelGrid columns="1">
+ <h:outputText value="Test result in iFrame."/>
+ </h:panelGrid>
+ </h:form>
+<%
+ ExternalContext extCtx = FacesContext.getCurrentInstance().getExternalContext();
+ String resource = extCtx.encodeActionURL("portlet:resource?_jsfBridgeViewId=/tests/UsesConfiguredResourceResponseWrapperTest.jsp");
+ out.println("<iframe src=\"" + resource + "\" width=\"100%\" height=\"400px\"/>");
+%>
+ </body>
+ </html>
+</f:view>
Added: myfaces/portlet-bridge/tck/trunk_2.0.x/portlet-bridge-tck-section6-2-configured-response-wrapper/src/main/webapp/tests/UsesConfiguredRenderResponseWrapperTest.jsp
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/tck/trunk_2.0.x/portlet-bridge-tck-section6-2-configured-response-wrapper/src/main/webapp/tests/UsesConfiguredRenderResponseWrapperTest.jsp?rev=1024428&view=auto
==============================================================================
--- myfaces/portlet-bridge/tck/trunk_2.0.x/portlet-bridge-tck-section6-2-configured-response-wrapper/src/main/webapp/tests/UsesConfiguredRenderResponseWrapperTest.jsp (added)
+++ myfaces/portlet-bridge/tck/trunk_2.0.x/portlet-bridge-tck-section6-2-configured-response-wrapper/src/main/webapp/tests/UsesConfiguredRenderResponseWrapperTest.jsp Tue Oct 19 21:55:51 2010
@@ -0,0 +1,56 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+"http://www.w3.org/TR/html4/loose.dtd">
+<%@ page contentType="text/html;charset=UTF-8"
+ isELIgnored="false"
+ session="true"
+ import="java.util.*,
+ javax.faces.context.*, javax.faces.component.*,
+ javax.servlet.*, javax.portlet.*,
+ javax.portlet.faces.*, javax.portlet.faces.preference.*" %>
+
+<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
+<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
+<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
+
+ <html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
+ <title>Chapter 6_5 Tests</title>
+ </head>
+ <body>
+
+<%
+ // Note: JSP code runs before the JSF EL is executed
+
+ FacesContext elFacesContext = FacesContext.getCurrentInstance();
+ ExternalContext elExternalContext = elFacesContext.getExternalContext();
+ RenderResponse renderResponse = (RenderResponse) elExternalContext.getResponse();
+ Map m = elExternalContext.getRequestMap();
+
+ String detail = null;
+
+ if (renderResponse.getClass().getName().equals("org.apache.myfaces.portlet.faces.tck.TCKRenderResponseWrapper"))
+ {
+ m.put("org.apache.myfaces.portlet.faces.TCK.status", Boolean.TRUE);
+ m.put("org.apache.myfaces.portlet.faces.TCK.detail", "ExternalContext correctly returns a response object that implements the configured TCKRenderResponseWrapper during a render (dispatch).");
+ }
+ else
+ {
+ m.put("org.apache.myfaces.portlet.faces.TCK.status", Boolean.FALSE);
+ m.put("org.apache.myfaces.portlet.faces.TCK.detail", "ExternalContext incorrectly returns a response object that doesn't implement the configured TCKRenderResponseWrapper during a render (dispatch). Instead we got: " + renderResponse.getClass().getName());
+ }
+
+%>
+
+<f:view>
+ <h:form>
+ <h:panelGrid columns="1">
+ <h:outputText escape = "false" value="#{test.renderTestResult}"/>
+ </h:panelGrid>
+ </h:form>
+</f:view>
+</body>
+</html>
+
+
Added: myfaces/portlet-bridge/tck/trunk_2.0.x/portlet-bridge-tck-section6-2-configured-response-wrapper/src/main/webapp/tests/UsesConfiguredResourceResponseWrapperTest.jsp
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/tck/trunk_2.0.x/portlet-bridge-tck-section6-2-configured-response-wrapper/src/main/webapp/tests/UsesConfiguredResourceResponseWrapperTest.jsp?rev=1024428&view=auto
==============================================================================
--- myfaces/portlet-bridge/tck/trunk_2.0.x/portlet-bridge-tck-section6-2-configured-response-wrapper/src/main/webapp/tests/UsesConfiguredResourceResponseWrapperTest.jsp (added)
+++ myfaces/portlet-bridge/tck/trunk_2.0.x/portlet-bridge-tck-section6-2-configured-response-wrapper/src/main/webapp/tests/UsesConfiguredResourceResponseWrapperTest.jsp Tue Oct 19 21:55:51 2010
@@ -0,0 +1,56 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+"http://www.w3.org/TR/html4/loose.dtd">
+<%@ page contentType="text/html;charset=UTF-8"
+ isELIgnored="false"
+ session="true"
+ import="java.util.*,
+ javax.faces.context.*, javax.faces.component.*,
+ javax.servlet.*, javax.portlet.*,
+ javax.portlet.faces.*, javax.portlet.faces.preference.*" %>
+
+<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
+<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
+<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
+
+ <html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
+ <title>Chapter 6_5 Tests</title>
+ </head>
+ <body>
+
+<%
+ // Note: JSP code runs before the JSF EL is executed
+
+ FacesContext elFacesContext = FacesContext.getCurrentInstance();
+ ExternalContext elExternalContext = elFacesContext.getExternalContext();
+ ResourceResponse resourceResponse = (ResourceResponse) elExternalContext.getResponse();
+ Map m = elExternalContext.getRequestMap();
+
+ String detail = null;
+
+ if (resourceResponse.getClass().getName().equals("org.apache.myfaces.portlet.faces.tck.TCKResourceResponseWrapper"))
+ {
+ m.put("org.apache.myfaces.portlet.faces.TCK.status", Boolean.TRUE);
+ m.put("org.apache.myfaces.portlet.faces.TCK.detail", "ExternalContext correctly returns a response object that implements the configured TCKResourceResponseWrapper during a resource (dispatch).");
+ }
+ else
+ {
+ m.put("org.apache.myfaces.portlet.faces.TCK.status", Boolean.FALSE);
+ m.put("org.apache.myfaces.portlet.faces.TCK.detail", "ExternalContext incorrectly returns a response object that doesn't implement the configured TCKResourceResponseWrapper during a resource (dispatch). Instead we got: " + resourceResponse.getClass().getName());
+ }
+
+%>
+
+<f:view>
+ <h:form>
+ <h:panelGrid columns="1">
+ <h:outputText escape = "false" value="#{test.renderTestResult}"/>
+ </h:panelGrid>
+ </h:form>
+</f:view>
+</body>
+</html>
+
+
Modified: myfaces/portlet-bridge/tck/trunk_2.0.x/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_3/BridgeDestroyTestPortlet.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/tck/trunk_2.0.x/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_3/BridgeDestroyTestPortlet.java?rev=1024428&r1=1024427&r2=1024428&view=diff
==============================================================================
--- myfaces/portlet-bridge/tck/trunk_2.0.x/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_3/BridgeDestroyTestPortlet.java (original)
+++ myfaces/portlet-bridge/tck/trunk_2.0.x/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_3/BridgeDestroyTestPortlet.java Tue Oct 19 21:55:51 2010
@@ -331,7 +331,7 @@ public class BridgeDestroyTestPortlet ex
private void runResourceDestroyTest(ResourceRequest request, ResourceResponse response) throws PortletException, IOException
{
- BridgeTCKResultWriter resultWriter = new BridgeTCKResultWriter(DESTROY_EVENT_TEST);
+ BridgeTCKResultWriter resultWriter = new BridgeTCKResultWriter(DESTROY_RESOURCE_TEST);
// Run test
Bridge bridge = getFacesBridge(request, response);
Modified: myfaces/portlet-bridge/tck/trunk_2.0.x/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/tck/trunk_2.0.x/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_5/section_5_2/Tests.java?rev=1024428&r1=1024427&r2=1024428&view=diff
==============================================================================
--- myfaces/portlet-bridge/tck/trunk_2.0.x/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_5/section_5_2/Tests.java (original)
+++ myfaces/portlet-bridge/tck/trunk_2.0.x/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_5/section_5_2/Tests.java Tue Oct 19 21:55:51 2010
@@ -612,6 +612,53 @@ public class Tests
}
}
+ // Test is SingleRequest -- Render/Action
+ // Test #5.33 --
+ @BridgeTest(test = "eventPhaseListenerTest")
+ public String eventPhaseListenerTest(TestRunnerBean testRunner)
+ {
+ FacesContext ctx = FacesContext.getCurrentInstance();
+ ExternalContext extCtx = ctx.getExternalContext();
+ Map<String, Object> m = extCtx.getRequestMap();
+
+ if (BridgeUtil.getPortletRequestPhase() ==
+ Bridge.PortletPhase.ACTION_PHASE)
+ {
+ StateAwareResponse response = (StateAwareResponse) extCtx.getResponse();
+ response.setEvent(new QName(TestEventHandler.EVENT_QNAME, TestEventHandler.EVENT_NAME), testRunner.getTestName());
+ return "eventPhaseListenerTest"; // action Navigation result
+ }
+ else
+ {
+
+ 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,
+ "Event incorrectly didn't invoke either or both the RESTORE_VIEW before/after listener. Its also possible the event wasn't received.");
+ return Constants.TEST_FAILED;
+ }
+ else if (lastBeforePhaseId == PhaseId.RESTORE_VIEW && lastAfterPhaseId == PhaseId.RESTORE_VIEW)
+ {
+ testRunner.setTestResult(true,
+ "Event 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,
+ "Event 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;
@@ -625,14 +672,18 @@ public class Tests
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))
+
+ if (testname.equals("renderPhaseListenerTest") && (portletPhase.equals(Bridge.PortletPhase.RENDER_PHASE)))
+ {
+ m.put("org.apache.portlet.faces.tck.lastBeforePhase", phase);
+ }
+ else if (testname.equals("eventPhaseListenerTest") && (portletPhase.equals(Bridge.PortletPhase.EVENT_PHASE)))
{
m.put("org.apache.portlet.faces.tck.lastBeforePhase", phase);
}
@@ -657,6 +708,10 @@ public class Tests
{
m.put("org.apache.portlet.faces.tck.lastAfterPhase", phase);
}
+ else if (testname.equals("eventPhaseListenerTest") && (portletPhase.equals(Bridge.PortletPhase.EVENT_PHASE)))
+ {
+ m.put("org.apache.portlet.faces.tck.lastAfterPhase", phase);
+ }
if ((portletPhase.equals(Bridge.PortletPhase.RENDER_PHASE) && (testname.equals("facesContextReleasedRenderTest") || testname.equals("portletPhaseRemovedRenderTest"))) ||
(portletPhase.equals(Bridge.PortletPhase.RESOURCE_PHASE) && (testname.equals("facesContextReleasedResourceTest") || testname.equals("portletPhaseRemovedResourceTest"))))
@@ -1136,6 +1191,8 @@ public class Tests
m.get("org.apache.myfaces.portlet.faces.tck.pprSubmitted") != null)
{
testRunner.setTestComplete(true);
+
+ m.remove("org.apache.myfaces.portlet.faces.tck.pprSubmitted");
if (m.get("testAttr") != null && ((String)m.get("testAttr")).equals(testRunner.getTestName()))
{
Modified: myfaces/portlet-bridge/tck/trunk_2.0.x/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_5/section_5_3/Tests.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/tck/trunk_2.0.x/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_5/section_5_3/Tests.java?rev=1024428&r1=1024427&r2=1024428&view=diff
==============================================================================
--- myfaces/portlet-bridge/tck/trunk_2.0.x/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_5/section_5_3/Tests.java (original)
+++ myfaces/portlet-bridge/tck/trunk_2.0.x/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_5/section_5_3/Tests.java Tue Oct 19 21:55:51 2010
@@ -249,6 +249,9 @@ public class Tests
(!Boolean.TRUE.equals((Boolean)extCtx.getSessionMap().get("tck.processPRPInRestoreViewPhaseTest.modelPRPSet"))))
return;
+ // Marked as true so command link name would change.
+ extCtx.getSessionMap().put("org.apache.myfaces.portlet.faces.tck.testCompleted", Boolean.TRUE);
+
// verify not set in RestoreView
if (phase == PhaseId.RESTORE_VIEW)
{
@@ -309,6 +312,9 @@ public class Tests
extCtx.getSessionMap().remove("tck.processPRPInRestoreViewPhaseTest.modelPRPSet");
+ // Marked as true in the phaseListener so command link name would change.
+ extCtx.getSessionMap().remove("org.apache.myfaces.portlet.faces.tck.testCompleted");
+
if (extCtx.getRequestMap().get("tck.notSetBeforeRestoreView") == null)
{
testRunner.setTestResult(false,
Added: myfaces/portlet-bridge/tck/trunk_2.0.x/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_6/section_6_1_3_1/TestEventHandler.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/tck/trunk_2.0.x/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_6/section_6_1_3_1/TestEventHandler.java?rev=1024428&view=auto
==============================================================================
--- myfaces/portlet-bridge/tck/trunk_2.0.x/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_6/section_6_1_3_1/TestEventHandler.java (added)
+++ myfaces/portlet-bridge/tck/trunk_2.0.x/src/main/java/org/apache/myfaces/portlet/faces/testsuite/tests/chapter_6/section_6_1_3_1/TestEventHandler.java Tue Oct 19 21:55:51 2010
@@ -0,0 +1,461 @@
+/* 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_6.section_6_1_3_1;
+
+import java.io.IOException;
+
+import java.io.PrintWriter;
+
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.Locale;
+import java.util.Map;
+
+import java.util.Set;
+
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+
+import javax.portlet.Event;
+import javax.portlet.PortletRequest;
+import javax.portlet.faces.Bridge;
+import javax.portlet.faces.BridgeEventHandler;
+import javax.portlet.faces.BridgeUtil;
+import javax.portlet.faces.event.EventNavigationResult;
+
+import org.apache.myfaces.portlet.faces.testsuite.annotation.BridgeTest;
+import org.apache.myfaces.portlet.faces.testsuite.common.Constants;
+
+public class TestEventHandler
+ implements BridgeEventHandler
+{
+
+ public static final String EVENT_RECEIVED = "org.apache.myfaces.portlet.faces.tck.eventReceived";
+ public static final String EVENT_TEST_RESULT = "org.apache.myfaces.portlet.faces.tck.eventTestResult";
+ public static final String EVENTATTR = "portlet.bridge.tck.testAttr";
+ public static final String EVENT_QNAME = "http://myfaces.apache.org/portlet-bridge/event_ns";
+ public static final String EVENT_NAME = "myfaces.apache.org.tck.testEvent";
+
+ public TestEventHandler() {
+
+ }
+
+ public EventNavigationResult handleEvent(FacesContext context, Event event)
+ {
+ String testName = (String) event.getValue();
+
+ if (testName.equalsIgnoreCase("getRequestHeaderMapEventTest"))
+ {
+ getRequestHeaderMapEventTest();
+ }
+ else if (testName.equalsIgnoreCase("getRequestHeaderValuesMapEventTest"))
+ {
+ getRequestHeaderValuesMapEventTest();
+ }
+ else if (testName.equalsIgnoreCase("getRequestCharacterEncodingEventTest"))
+ {
+ getRequestCharacterEncodingEventTest();
+ }
+ else if (testName.equalsIgnoreCase("getRequestContentTypeEventTest"))
+ {
+ getRequestContentTypeEventTest();
+ }
+ else if (testName.equalsIgnoreCase("getResponseCharacterEncodingEventTest"))
+ {
+ getResponseCharacterEncodingEventTest();
+ }
+ else if (testName.equalsIgnoreCase("getResponseContentTypeEventTest"))
+ {
+ getResponseContentTypeEventTest();
+ }
+ else if (testName.equalsIgnoreCase("redirectEventTest"))
+ {
+ redirectEventTest();
+ }
+
+
+ // URL encoded in the faces-config.xml -- based on the testname
+ return new EventNavigationResult(null, testName);
+ }
+
+ private void getRequestHeaderMapEventTest()
+ {
+
+ FacesContext ctx = FacesContext.getCurrentInstance();
+ ExternalContext extCtx = ctx.getExternalContext();
+ Map<String, Object> requestMap = extCtx.getRequestMap();
+
+
+ // Test the following:
+ // 1. Map is immutable
+ // 2. Map contains properties from the portlet request (that it should)
+ // 2. Doesn't contain the Content-Type property
+ // 3. Does include the Accept and Accept-Language
+
+ Map headerMap = extCtx.getRequestHeaderMap();
+ Enumeration propertyNames =
+ ((PortletRequest) extCtx.getRequest()).getPropertyNames();
+
+ // Test for immutability
+ try
+ {
+ String s = (String) headerMap.put("TestKey", "TestValue");
+ requestMap.put(EVENT_TEST_RESULT, "Failed: The Map returned from getRequestHeaderMap isn't immutable.");
+ return;
+ }
+ catch (Exception e)
+ {
+ // we expect to get an exception
+ }
+
+ Set<Map.Entry<String, String>> set = headerMap.entrySet();
+ int propsFound = 0;
+ for (Iterator<Map.Entry<String, String>> headers = set.iterator();
+ headers.hasNext(); )
+ {
+ Map.Entry<String, String> e = headers.next();
+ String key = e.getKey();
+ if (key.equalsIgnoreCase("content-type"))
+ {
+ requestMap.put(EVENT_TEST_RESULT, "Failed: The Map returned from getRequestHeaderMap contains a content-type header but shouldn't.");
+ return;
+ }
+ else if (key.equalsIgnoreCase("content-length"))
+ {
+ requestMap.put(EVENT_TEST_RESULT, "Failed: The Map returned from getRequestHeaderMap contains a content-length header but shouldn't.");
+ return;
+ }
+ else if (key.equalsIgnoreCase("accept"))
+ {
+ boolean found = false;
+ // parse the accept header into its parts
+ String[] accepts = trim(e.getValue().split(","));
+
+ Enumeration em =
+ ((PortletRequest) extCtx.getRequest()).getResponseContentTypes();
+
+ // Now ensure that all entries in the getResponseContentTypes enum are in the property
+ while (em.hasMoreElements())
+ {
+ String rct = ((String) em.nextElement());
+ found = false;
+ for (int i = 0; i < accepts.length; i++)
+ {
+ if (rct.regionMatches(true, 0, accepts[i], 0, rct.length()))
+ {
+ found = true;
+ break;
+ }
+ }
+ if (!found)
+ {
+ requestMap.put(EVENT_TEST_RESULT, "Failed: The Map returned from getRequestHeaderMap is missing a key returned in request.getResponseContentTypes: " +
+ rct);
+ return;
+ }
+ }
+ }
+ else if (key.equalsIgnoreCase("accept-language"))
+ {
+ // parse the accept header into its parts
+ String[] accepts = trim(e.getValue().split(","));
+
+ Enumeration em =
+ ((PortletRequest) extCtx.getRequest()).getLocales();
+
+ // Now ensure the two match
+ int found = 0;
+ while (em.hasMoreElements())
+ {
+ String rct =
+ ((Locale) em.nextElement()).toString().replace('_', '-');
+
+ for (int i = 0; i < accepts.length; i++)
+ {
+ if (rct.regionMatches(true, 0, accepts[i], 0, rct.length()))
+ {
+ found += 1;
+ break;
+ }
+ }
+ }
+ if (found != accepts.length)
+ {
+ requestMap.put(EVENT_TEST_RESULT, "Failed: The Map returned from getRequestHeaderMap didn't contain an Accept-Language key with a value containing each of the locales returned from request.getResponseLocales segmented by a comma.");
+ return;
+ }
+ }
+ }
+ requestMap.put(EVENT_TEST_RESULT, Constants.TEST_SUCCESS);
+ }
+
+ private void getRequestHeaderValuesMapEventTest()
+ {
+
+ FacesContext ctx = FacesContext.getCurrentInstance();
+ ExternalContext extCtx = ctx.getExternalContext();
+ Map<String, Object> requestMap = extCtx.getRequestMap();
+
+
+ // Test the following:
+ // 1. Map is immutable
+ // 2. Map contains properties from the portlet request (that it should)
+ // 2. Doesn't contain the Content-Type property
+ // 3. Does include the Accept and Accept-Language
+
+ Map<String, String[]> headerMap = extCtx.getRequestHeaderValuesMap();
+ Enumeration propertyNames =
+ ((PortletRequest) extCtx.getRequest()).getPropertyNames();
+
+ // Test for immutability
+ try
+ {
+ String[] s = (String[]) headerMap.put("TestKey", new String[]
+ { "TestValue" });
+
+ requestMap.put(EVENT_TEST_RESULT, "Failed: The Map returned from getRequestHeaderValuesMap isn't immutable.");
+ return;
+ }
+ catch (Exception e)
+ {
+ // we expect to get an exception
+ }
+
+ Set<Map.Entry<String, String[]>> set = headerMap.entrySet();
+ int propsFound = 0;
+ for (Iterator<Map.Entry<String, String[]>> headers = set.iterator();
+ headers.hasNext(); )
+ {
+ Map.Entry<String, String[]> e = headers.next();
+ String key = e.getKey();
+ if (key.equalsIgnoreCase("content-type"))
+ {
+ requestMap.put(EVENT_TEST_RESULT, "Failed: The Map returned from getRequestHeaderValuesMap contains a content-type header but shouldn't.");
+ return;
+ }
+ else if (key.equalsIgnoreCase("content-length"))
+ {
+ requestMap.put(EVENT_TEST_RESULT, "Failed: The Map returned from getRequestHeaderValuesMap contains a content-length header but shouldn't.");
+ return;
+ }
+ else if (key.equalsIgnoreCase("accept"))
+ {
+ boolean found = false;
+ // parse the accept header into its parts
+ String[] acceptsValues = e.getValue();
+ String[] accepts = null;
+ int count = 0;
+ for (int i = 0; i < acceptsValues.length; i++)
+ {
+ String[] temp = trim(acceptsValues[i].split(","));
+ if (accepts == null)
+ {
+ accepts = new String[temp.length];
+ }
+ else
+ {
+ String[] acceptsTemp =
+ new String[accepts.length + temp.length];
+ System.arraycopy(accepts, 0, acceptsTemp, 0, count);
+ accepts = acceptsTemp;
+ }
+ System.arraycopy(temp, 0, accepts, count, temp.length);
+ count += temp.length;
+ }
+
+ Enumeration em =
+ ((PortletRequest) extCtx.getRequest()).getResponseContentTypes();
+
+ // Now ensure that all entries in the getResponseContentTypes enum are in the property
+ while (em.hasMoreElements())
+ {
+ String rct = ((String) em.nextElement());
+ found = false;
+ for (int i = 0; i < accepts.length; i++)
+ {
+ if (rct.regionMatches(true, 0, accepts[i], 0, rct.length()))
+ {
+ found = true;
+ break;
+ }
+ }
+ if (!found)
+ {
+ requestMap.put(EVENT_TEST_RESULT, "Failed: The Map returned from getRequestHeaderValuesMap is missing a key returned in request.getResponseContentTypes: " +
+ rct);
+ return;
+ }
+ }
+ }
+ else if (key.equalsIgnoreCase("accept-language"))
+ {
+ // parse the accept header into its parts
+ String[] acceptLangValues = e.getValue();
+ String[] accepts = null;
+ int count = 0;
+ for (int i = 0; i < acceptLangValues.length; i++)
+ {
+ String[] temp = trim(acceptLangValues[i].split(","));
+ if (accepts == null)
+ {
+ accepts = new String[temp.length];
+ }
+ else
+ {
+ String[] acceptsTemp =
+ new String[accepts.length + temp.length];
+ System.arraycopy(accepts, 0, acceptsTemp, 0, count);
+ accepts = acceptsTemp;
+ }
+ System.arraycopy(temp, 0, accepts, count, temp.length);
+ }
+
+ Enumeration em =
+ ((PortletRequest) extCtx.getRequest()).getLocales();
+
+ // Now ensure the two match
+ int found = 0;
+ while (em.hasMoreElements())
+ {
+ String rct =
+ ((Locale) em.nextElement()).toString().replace('_', '-');
+
+ for (int i = 0; i < accepts.length; i++)
+ {
+ if (rct.regionMatches(true, 0, accepts[i], 0, rct.length()))
+ {
+ found += 1;
+ break;
+ }
+ }
+ }
+ if (found != accepts.length)
+ {
+ requestMap.put(EVENT_TEST_RESULT, "Failed: The Map returned from getRequestHeaderValuesMap didn't contain an Accept-Language key with a value containing each of the locales returned from request.getResponseLocales segmented by a comma.");
+ return;
+ }
+ }
+ }
+ requestMap.put(EVENT_TEST_RESULT, Constants.TEST_SUCCESS);
+ }
+
+ private String[] trim(String[] toTrim)
+ {
+ for (int i = 0; i < toTrim.length; i++)
+ {
+ toTrim[i] = toTrim[i].trim();
+ }
+ return toTrim;
+ }
+
+ private void getRequestCharacterEncodingEventTest()
+ {
+ FacesContext ctx = FacesContext.getCurrentInstance();
+ ExternalContext extCtx = ctx.getExternalContext();
+ Map<String, Object> requestMap = extCtx.getRequestMap();
+
+ String charEncoding = extCtx.getRequestCharacterEncoding();
+
+ if (charEncoding != null)
+ {
+ requestMap.put(EVENT_TEST_RESULT,
+ "extCtx.getRequestCharacterEncoding() incorrectly returned non-null value when called during the event phase: " + charEncoding);
+ }
+ else
+ {
+ requestMap.put(EVENT_TEST_RESULT, Constants.TEST_SUCCESS);
+ }
+ }
+
+ private void getRequestContentTypeEventTest()
+ {
+ FacesContext ctx = FacesContext.getCurrentInstance();
+ ExternalContext extCtx = ctx.getExternalContext();
+ Map<String, Object> requestMap = extCtx.getRequestMap();
+
+ String contentType = extCtx.getRequestContentType();
+
+ if (contentType != null)
+ {
+ requestMap.put(EVENT_TEST_RESULT,
+ "extCtx.getRequestContentType() incorrectly returned non-null value when called during the event phase: " + contentType);
+ }
+ else
+ {
+ requestMap.put(EVENT_TEST_RESULT, Constants.TEST_SUCCESS);
+ }
+ }
+
+ private void getResponseCharacterEncodingEventTest()
+ {
+ FacesContext ctx = FacesContext.getCurrentInstance();
+ ExternalContext extCtx = ctx.getExternalContext();
+ Map<String, Object> requestMap = extCtx.getRequestMap();
+
+ try
+ {
+ String encoding = extCtx.getResponseCharacterEncoding();
+ requestMap.put(EVENT_TEST_RESULT,
+ "extCtx.getResponseCharacterEncoding() didn't throw an IllegalStateException when called during an Event.");
+ }
+ catch (IllegalStateException e)
+ {
+ requestMap.put(EVENT_TEST_RESULT, Constants.TEST_SUCCESS);
+ }
+ }
+
+ private void getResponseContentTypeEventTest()
+ {
+ FacesContext ctx = FacesContext.getCurrentInstance();
+ ExternalContext extCtx = ctx.getExternalContext();
+ Map<String, Object> requestMap = extCtx.getRequestMap();
+
+ try
+ {
+ String encoding = extCtx.getResponseContentType();
+ requestMap.put(EVENT_TEST_RESULT,
+ "extCtx.getResponseContentType() didn't throw an IllegalStateException when called during an Event.");
+ }
+ catch (IllegalStateException e)
+ {
+ requestMap.put(EVENT_TEST_RESULT, Constants.TEST_SUCCESS);
+ }
+
+ }
+
+ private void redirectEventTest()
+ {
+ FacesContext ctx = FacesContext.getCurrentInstance();
+ ExternalContext extCtx = ctx.getExternalContext();
+ Map<String, Object> requestMap = extCtx.getRequestMap();
+
+ String target = ctx.getApplication().getViewHandler().getActionURL(ctx, "/tests/RedirectTestResultRenderCheck.jsp");
+ try
+ {
+ extCtx.redirect(target);
+ requestMap.put(EVENT_TEST_RESULT, Constants.TEST_SUCCESS);
+ }
+ catch (Exception e)
+ {
+ requestMap.put(EVENT_TEST_RESULT,
+ "Calling extCtx.redirect() threw an exception: " + e.getMessage());
+ }
+ }
+}