Author: julien(a)jboss.com
Date: 2008-01-29 07:47:14 -0500 (Tue, 29 Jan 2008)
New Revision: 9628
Added:
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/tck/dispatcher/
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/tck/dispatcher/ObtainingDispatcherTestCase.java
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/unit/actions/PortletTestAction.java
modules/portlet/trunk/test/src/test/resources/jsr286/tck/dispatcher-war/
modules/portlet/trunk/test/src/test/resources/jsr286/tck/dispatcher-war/WEB-INF/
modules/portlet/trunk/test/src/test/resources/jsr286/tck/dispatcher-war/WEB-INF/portlet.xml
modules/portlet/trunk/test/src/test/resources/jsr286/tck/dispatcher-war/WEB-INF/web.xml
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/DispatchedHttpServletRequest.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/DispatchedHttpServletResponse.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/PortletRequestDispatcherImpl.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/PortletRequestImpl.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/PortletSessionImpl.java
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/unit/actions/PortletRenderTestAction.java
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/unit/base/AbstractUniversalTestPortlet.java
modules/portlet/trunk/test/src/test/build.xml
modules/portlet/trunk/test/src/test/resources/test/remote-jboss-unit.xml
Log:
- start to migrate existing 168 dispatcher tck tests to 286
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/DispatchedHttpServletRequest.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/DispatchedHttpServletRequest.java 2008-01-28
23:38:10 UTC (rev 9627)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/DispatchedHttpServletRequest.java 2008-01-29
12:47:14 UTC (rev 9628)
@@ -26,6 +26,11 @@
import org.jboss.portal.common.util.Tools;
import org.jboss.portal.common.util.ParameterMap;
import org.jboss.portal.portlet.impl.jsr168.api.RenderRequestImpl;
+import org.jboss.portal.portlet.impl.jsr168.api.PortletRequestImpl;
+import org.jboss.portal.portlet.impl.jsr168.api.ActionRequestImpl;
+import org.jboss.portal.portlet.impl.jsr168.api.EventRequestImpl;
+import org.jboss.portal.portlet.impl.jsr168.api.ResourceRequestImpl;
+import org.jboss.portal.portlet.impl.jsr168.api.ClientDataRequestImpl;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletInputStream;
@@ -33,51 +38,72 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletRequestWrapper;
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
+import javax.portlet.PortletSession;
import java.security.Principal;
import java.util.Enumeration;
import java.util.Locale;
import java.util.Map;
+import java.io.UnsupportedEncodingException;
+import java.io.IOException;
+import java.io.BufferedReader;
+import java.io.InputStream;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 6903 $
*/
-public class DispatchedHttpServletRequest extends HttpServletRequestWrapper
+public abstract class DispatchedHttpServletRequest extends HttpServletRequestWrapper
{
/** . */
- private static final String REQUEST_URI =
"javax.servlet.include.request_uri";
+ private static final int REQUEST_URI = 0;
/** . */
- private static final String CONTEXT_PATH =
"javax.servlet.include.context_path";
+ private static final int SERVLET_PATH = 1;
/** . */
- private static final String SERVLET_PATH =
"javax.servlet.include.servlet_path";
+ private static final int PATH_INFO = 2;
/** . */
- private static final String PATH_INFO = "javax.servlet.include.path_info";
+ private static final int QUERY_STRING = 3;
/** . */
- private static final String QUERY_STRING =
"javax.servlet.include.query_string";
+ private static final String[] INCLUDE_KEYS = {
+ "javax.servlet.include.request_uri",
+ "javax.servlet.include.servlet_path",
+ "javax.servlet.include.path_info",
+ "javax.servlet.include.query_string"
+ };
/** . */
+ private static final String[] FORWARD_KEYS = {
+ "javax.servlet.forward.request_uri",
+ "javax.servlet.forward.servlet_path",
+ "javax.servlet.forward.path_info",
+ "javax.servlet.forward.query_string"
+ };
+
+ /** . */
final DispatchType dispatchType;
/** . */
- private RenderRequestImpl rreq;
+ private final PortletRequestImpl preq;
/** . */
- private HttpServletRequest dreq;
+ private final HttpServletRequest dreq;
/** . */
private final Map<String, String[]> parameters;
+ /** . */
+ private final String[] keys;
+
+ /** . */
+ private final int sessionScope = PortletSession.APPLICATION_SCOPE;
+
public DispatchedHttpServletRequest(
DispatchType dispatchType,
- RenderRequestImpl rreq,
+ PortletRequestImpl preq,
HttpServletRequest dreq,
String path)
{
@@ -85,8 +111,9 @@
//
this.dispatchType = dispatchType;
- this.rreq = rreq;
+ this.preq = preq;
this.dreq = dreq;
+ this.keys = dispatchType == DispatchType.INCLUDE ? INCLUDE_KEYS : FORWARD_KEYS;
//
if (path != null)
@@ -123,209 +150,181 @@
//
if (queryString.length() > 0)
{
- this.parameters = ParameterMap.clone(rreq.getParameterMap());
+ this.parameters = ParameterMap.clone(preq.getParameterMap());
this.parameters.putAll(QueryStringParser.getInstance().parseQueryString(queryString));
}
else
{
- this.parameters = rreq.getParameterMap();
+ this.parameters = preq.getParameterMap();
}
}
else
{
- this.parameters = rreq.getParameterMap();
+ this.parameters = preq.getParameterMap();
}
}
// Must return null
- public String getProtocol()
+ public final String getRemoteAddr()
{
return null;
}
- public String getRemoteAddr()
+ public final String getRemoteHost()
{
return null;
}
- public String getRemoteHost()
+ public final String getRealPath(String s)
{
return null;
}
- public String getRealPath(String s)
+ public final String getLocalAddr()
{
return null;
}
- public StringBuffer getRequestURL()
+ public final String getLocalName()
{
return null;
}
+ public final StringBuffer getRequestURL()
+ {
+ return null;
+ }
+
+ // Must return 0
+
+ public final int getRemotePort()
+ {
+ return 0;
+ }
+
+ public final int getLocalPort()
+ {
+ return 0;
+ }
+
// Must return the path and query string information used to obtain the
PortletRequestDispatcher object
- public String getPathInfo()
+ public final String getPathInfo()
{
- return (String)getAttribute(PATH_INFO);
+ return (String)getAttribute(keys[PATH_INFO]);
}
- public String getQueryString()
+ public final String getPathTranslated()
{
- return (String)getAttribute(QUERY_STRING);
+ return "PathTranslated"; // todo
}
- public String getServletPath()
+ public final String getQueryString()
{
- return (String)getAttribute(SERVLET_PATH);
+ return (String)getAttribute(keys[QUERY_STRING]);
}
- public String getRequestURI()
+ public final String getRequestURI()
{
- return (String)getAttribute(REQUEST_URI);
+ return (String)getAttribute(keys[REQUEST_URI]);
}
- public String getPathTranslated()
+ public final String getServletPath()
{
- return "PathTranslated"; // todo
+ return (String)getAttribute(keys[SERVLET_PATH]);
}
// Must be equivalent to the method of the PortletRequest
- public String getScheme()
+ public final String getScheme()
{
- return rreq.getScheme();
+ return preq.getScheme();
}
- public String getServerName()
+ public final String getServerName()
{
- return rreq.getServerName();
+ return preq.getServerName();
}
- public int getServerPort()
+ public final int getServerPort()
{
- return rreq.getServerPort();
+ return preq.getServerPort();
}
- public Object getAttribute(String s)
+ public final Object getAttribute(String s)
{
- // First try the special values
-// Object value = attrs.get(s);
-// if (value != null)
-// {
-// return value;
-// }
-
- // Otherwise try the render request modified attributes
- return rreq.getAttributes().getAttribute(s, (HttpServletRequest)getRequest());
+ return preq.getAttributes().getAttribute(s, (HttpServletRequest)getRequest());
}
- public Enumeration getAttributeNames()
+ public final Enumeration getAttributeNames()
{
- return
Tools.toEnumeration(rreq.getAttributes().getAttributeNames((HttpServletRequest)getRequest()));
-// return new Enumeration()
-// {
-// // The next element
-// Object next;
-//
-// {
-// next();
-// }
-//
-// public boolean hasMoreElements()
-// {
-// return next != null;
-// }
-//
-// public Object nextElement()
-// {
-// Object next = this.next;
-// next();
-// return next;
-// }
-//
-// private void next()
-// {
-// next = null;
-// while (true)
-// {
-// if (i.hasNext())
-// {
-// Object next = i.next();
-// if (attrs != null && !attrs.containsKey(next))
-// {
-// this.next = next;
-// break;
-// }
-// }
-// else
-// {
-// break;
-// }
-// }
-// }
-// };
+ return
Tools.toEnumeration(preq.getAttributes().getAttributeNames((HttpServletRequest)getRequest()));
}
- public void setAttribute(String s, Object o)
+ public final void setAttribute(String s, Object o)
{
- rreq.getAttributes().setAttribute(s, o);
+ preq.getAttributes().setAttribute(s, o);
}
- public void removeAttribute(String s)
+ public final void removeAttribute(String s)
{
- rreq.getAttributes().removeAttribute(s);
+ preq.getAttributes().removeAttribute(s);
}
- public Locale getLocale()
+ public final Locale getLocale()
{
- return rreq.getLocale();
+ return preq.getLocale();
}
- public Enumeration getLocales()
+ public final Enumeration getLocales()
{
- return rreq.getLocales();
+ return preq.getLocales();
}
public boolean isSecure()
{
- return rreq.isSecure();
+ return preq.isSecure();
}
- public String getAuthType()
+ public final String getAuthType()
{
- return rreq.getAuthType();
+ return preq.getAuthType();
}
- public String getContextPath()
+ public final String getContextPath()
{
- return (String)getAttribute(CONTEXT_PATH);
+ return preq.getContextPath();
}
- public String getRemoteUser()
+ public final String getRemoteUser()
{
- return rreq.getRemoteUser();
+ return preq.getRemoteUser();
}
- public Principal getUserPrincipal()
+ public final Principal getUserPrincipal()
{
- return rreq.getUserPrincipal();
+ return preq.getUserPrincipal();
}
- public String getRequestedSessionId()
+ public final String getRequestedSessionId()
{
- return rreq.getRequestedSessionId();
+ return preq.getRequestedSessionId();
}
- public boolean isRequestedSessionIdValid()
+ public final boolean isRequestedSessionIdValid()
{
- return rreq.isRequestedSessionIdValid();
+ return preq.isRequestedSessionIdValid();
}
+ public final Cookie[] getCookies()
+ {
+ return preq.getCookies();
+ }
+
// Must be equivalent to the method of the PortletRequest with the provision defined
in PLT.16.1.1
- public String getParameter(String name)
+ public final String getParameter(String name)
{
if (name == null)
{
@@ -343,12 +342,12 @@
return null;
}
- public Enumeration getParameterNames()
+ public final Enumeration getParameterNames()
{
return Tools.toEnumeration(parameters.keySet().iterator());
}
- public String[] getParameterValues(String name)
+ public final String[] getParameterValues(String name)
{
if (name == null)
{
@@ -366,136 +365,258 @@
return null;
}
- public Map getParameterMap()
+ public final Map getParameterMap()
{
return parameters;
}
- // Do not operate and return null or zero
+ // Defined by life cycle phase
- public String getCharacterEncoding()
+ public abstract String getCharacterEncoding();
+
+ public abstract void setCharacterEncoding(String s) throws
UnsupportedEncodingException;
+
+ public abstract String getContentType();
+
+ public abstract ServletInputStream getInputStream() throws IOException;
+
+ public abstract BufferedReader getReader() throws IOException;
+
+ public abstract int getContentLength();
+
+ public abstract String getMethod();
+
+ // Must be based on properties provided by the getProperties method of the
PortletRequest interface
+
+ public final String getHeader(String s)
{
- return null;
+ return preq.getProperty(s);
}
- public void setCharacterEncoding(String s) throws UnsupportedEncodingException
+ public final Enumeration getHeaders(String s)
{
+ return preq.getProperties(s);
}
- public int getContentLength()
+ public final Enumeration getHeaderNames()
{
- return 0;
+ return preq.getPropertyNames();
}
- public String getContentType()
+ public final long getDateHeader(String s)
{
- return null;
+ return 0; // WTF ????
}
- public ServletInputStream getInputStream() throws IOException
+ public final int getIntHeader(String s)
{
- return null;
+ return 0; // WTF ????
}
- public BufferedReader getReader() throws IOException
+ // Must provide the functionnalities provided by the servlet specification 2.3
+
+ public final RequestDispatcher getRequestDispatcher(String s)
{
- return null;
+ return dreq.getRequestDispatcher(s);
}
- // Must be based on properties provided by the getProperties method of the
PortletRequest interface
-
- public String getHeader(String s)
+ public final boolean isUserInRole(String s)
{
- return rreq.getProperty(s);
+ return preq.isUserInRole(s);
}
- public Enumeration getHeaders(String s)
+ public final HttpSession getSession(boolean b)
{
- return rreq.getProperties(s);
+ return preq.getPortletSession(b).getHttpSession(PortletSession.APPLICATION_SCOPE);
}
- public Enumeration getHeaderNames()
+ public final HttpSession getSession()
{
- return rreq.getPropertyNames();
+ return preq.getPortletSession().getHttpSession(PortletSession.APPLICATION_SCOPE);
}
- public Cookie[] getCookies()
+ public final boolean isRequestedSessionIdFromCookie()
{
- return new Cookie[0];
+ return dreq.isRequestedSessionIdFromCookie();
}
- public long getDateHeader(String s)
+ public final boolean isRequestedSessionIdFromURL()
{
- return 0;
+ return dreq.isRequestedSessionIdFromURL();
}
- public int getIntHeader(String s)
+ public final boolean isRequestedSessionIdFromUrl()
{
- return 0;
+ return isRequestedSessionIdFromURL();
}
- // Must provide the functionnalities provided by the servlet specification 2.3
+ // The getProtocol method of the HttpServletRequest must always return �HTTP/1.1�
- public String getMethod()
+ public final String getProtocol()
{
- // The getMethod method of the HttpServletRequest must always return
"GET"
- return "GET";
+ return "HTTP/1.1";
}
- public RequestDispatcher getRequestDispatcher(String s)
+ public static abstract class ClientData extends DispatchedHttpServletRequest
{
- return dreq.getRequestDispatcher(s);
+
+ /** . */
+ private PortletServletInputStream in;
+
+ /** . */
+ private final ClientDataRequestImpl cdreq;
+
+ public ClientData(DispatchType dispatchType, ClientDataRequestImpl cdreq,
HttpServletRequest dreq, String path)
+ {
+ super(dispatchType, cdreq, dreq, path);
+
+ //
+ this.cdreq = cdreq;
+ }
+
+ public final String getCharacterEncoding()
+ {
+ return cdreq.getCharacterEncoding();
+ }
+
+ public final void setCharacterEncoding(String s) throws
UnsupportedEncodingException
+ {
+ cdreq.setCharacterEncoding(s);
+ }
+
+ public final String getContentType()
+ {
+ return cdreq.getContentType();
+ }
+
+ public final ServletInputStream getInputStream() throws IOException
+ {
+ if (in == null)
+ {
+ in = new PortletServletInputStream(cdreq);
+ }
+ return in;
+ }
+
+ public final BufferedReader getReader() throws IOException
+ {
+ return cdreq.getReader();
+ }
+
+ public final int getContentLength()
+ {
+ return cdreq.getContentLength();
+ }
+
+ public final String getMethod()
+ {
+ return cdreq.getMethod();
+ }
+
+ private static final class PortletServletInputStream extends ServletInputStream
+ {
+
+ /** . */
+ private final InputStream in;
+
+ private PortletServletInputStream(ClientDataRequestImpl req) throws IOException
+ {
+ in = req.getPortletInputStream();
+ }
+
+ public final int read() throws IOException
+ {
+ return in.read();
+ }
+ }
}
- public boolean isUserInRole(String s)
+ public static final class Action extends ClientData
{
- return false;
+
+ public Action(DispatchType dispatchType, ActionRequestImpl areq, HttpServletRequest
dreq, String path)
+ {
+ super(dispatchType, areq, dreq, path);
+ }
}
- public HttpSession getSession(boolean b)
+ public static final class Resource extends ClientData
{
- return dreq.getSession(b);
- }
- public HttpSession getSession()
- {
- return dreq.getSession();
+ public Resource(DispatchType dispatchType, ResourceRequestImpl rreq,
HttpServletRequest dreq, String path)
+ {
+ super(dispatchType, rreq, dreq, path);
+ }
}
- public boolean isRequestedSessionIdFromCookie()
+ public static abstract class Mime extends DispatchedHttpServletRequest
{
- return false;
- }
+ public Mime(DispatchType dispatchType, PortletRequestImpl preq, HttpServletRequest
dreq, String path)
+ {
+ super(dispatchType, preq, dreq, path);
+ }
- public boolean isRequestedSessionIdFromURL()
- {
- return false;
+ public final String getCharacterEncoding()
+ {
+ return null;
+ }
+
+ public final void setCharacterEncoding(String s) throws
UnsupportedEncodingException
+ {
+ }
+
+ public final String getContentType()
+ {
+ return null;
+ }
+
+ public final ServletInputStream getInputStream() throws IOException
+ {
+ return null;
+ }
+
+ public final BufferedReader getReader() throws IOException
+ {
+ return null;
+ }
+
+ public final int getContentLength()
+ {
+ return 0;
+ }
}
- public boolean isRequestedSessionIdFromUrl()
+ public static final class Event extends Mime
{
- return false;
- }
- // Belongs to servlet 2.4 - not specified how it should behave yet
+ /** . */
+ private final EventRequestImpl ereq;
- public int getRemotePort()
- {
- throw new UnsupportedOperationException("Not specified by spec");
- }
+ public Event(DispatchType dispatchType, EventRequestImpl ereq, HttpServletRequest
dreq, String path)
+ {
+ super(dispatchType, ereq, dreq, path);
- public String getLocalName()
- {
- throw new UnsupportedOperationException("Not specified by spec");
+ //
+ this.ereq = ereq;
+ }
+
+ public String getMethod()
+ {
+ return ereq.getMethod();
+ }
}
- public String getLocalAddr()
+ public static final class Render extends Mime
{
- throw new UnsupportedOperationException("Not specified by spec");
- }
- public int getLocalPort()
- {
- throw new UnsupportedOperationException("Not specified by spec");
+ public Render(DispatchType dispatchType, RenderRequestImpl rreq, HttpServletRequest
dreq, String path)
+ {
+ super(dispatchType, rreq, dreq, path);
+ }
+
+ public String getMethod()
+ {
+ return "GET";
+ }
}
}
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/DispatchedHttpServletResponse.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/DispatchedHttpServletResponse.java 2008-01-28
23:38:10 UTC (rev 9627)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/DispatchedHttpServletResponse.java 2008-01-29
12:47:14 UTC (rev 9628)
@@ -22,236 +22,364 @@
******************************************************************************/
package org.jboss.portal.portlet.impl.jsr168;
-import javax.portlet.RenderResponse;
+import org.jboss.portal.portlet.impl.jsr168.api.MimeResponseImpl;
+import org.jboss.portal.portlet.impl.jsr168.api.StateAwareResponseImpl;
+import org.jboss.portal.common.NotYetImplemented;
+
+import javax.portlet.PortletResponse;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;
import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.Writer;
import java.io.OutputStream;
-import java.io.PrintWriter;
import java.util.Locale;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 6639 $
*/
-public class DispatchedHttpServletResponse extends HttpServletResponseWrapper
+public abstract class DispatchedHttpServletResponse extends HttpServletResponseWrapper
{
/** . */
DispatchedHttpServletRequest req;
/** . */
- private RenderResponse rresp;
+ private PortletResponse presp;
- /** . */
- private ServletOutputStream sos;
-
public DispatchedHttpServletResponse(
DispatchedHttpServletRequest req,
- RenderResponse rresp,
+ PortletResponse presp,
HttpServletResponse dresp)
{
super(dresp);
//
-// switch (req.dispatchType)
-// {
-// case INCLUDE:
-// break;
-// case FORWARD:
-//
-// // Discard existing content
-// rresp.reset();
-//
-// //
-// break;
-// }
-
- //
this.req = req;
- this.rresp = rresp;
- this.sos = null;
+ this.presp = presp;
}
// Must return null
- public String encodeRedirectURL(String s)
+ public final String encodeRedirectURL(String s)
{
return null;
}
- public String encodeRedirectUrl(String s)
+ public final String encodeRedirectUrl(String s)
{
return null;
}
- // Must be equivalent to the methods of the RenderResponse
+ // Must be equivalent to the methods of the PortletResponse
- public String getCharacterEncoding()
+ public final String encodeURL(String s)
{
- return rresp.getCharacterEncoding();
+ return presp.encodeURL(s);
}
- public void setBufferSize(int i)
+ public final String encodeUrl(String s)
{
- rresp.setBufferSize(i);
+ return presp.encodeURL(s);
}
- public void flushBuffer() throws IOException
- {
- rresp.flushBuffer();
- }
+ // Must perform no operations
- public void resetBuffer()
+ public final void setContentType(String s)
{
- rresp.resetBuffer();
}
- public void reset()
+ public final void setContentLength(int i)
{
- rresp.reset();
}
- public int getBufferSize()
+ public final void setLocale(Locale locale)
{
- return rresp.getBufferSize();
}
- public boolean isCommitted()
+ public final void addCookie(Cookie cookie)
{
- return rresp.isCommitted();
}
- public ServletOutputStream getOutputStream() throws IOException
+ public final void sendError(int i) throws IOException
{
- if (sos == null)
- {
- sos = new ServletOutputStream()
- {
- /** . */
- private final OutputStream out = rresp.getPortletOutputStream();
-
- public void write(byte b[], int off, int len) throws IOException
- {
- out.write(b, off, len);
- }
-
- public void write(byte b[]) throws IOException
- {
- out.write(b);
- }
-
- public void write(int b) throws IOException
- {
- out.write(b);
- }
- };
- }
- return sos;
}
- public PrintWriter getWriter() throws IOException
+ public final void sendError(int i, String s) throws IOException
{
- return rresp.getWriter();
}
- public String encodeURL(String s)
+ public final void sendRedirect(String s) throws IOException
{
- return rresp.encodeURL(s);
}
- public String encodeUrl(String s)
+ public final void setDateHeader(String s, long l)
{
- return rresp.encodeURL(s);
}
- // Must perform no operations
-
- public void setContentType(String s)
+ public final void addDateHeader(String s, long l)
{
}
- public void setContentLength(int i)
+ public final void setHeader(String s, String s1)
{
}
- public void setLocale(Locale locale)
+ public final void addHeader(String s, String s1)
{
}
- public void addCookie(Cookie cookie)
+ public final void setIntHeader(String s, int i)
{
}
- public void sendError(int i) throws IOException
+ public final void addIntHeader(String s, int i)
{
}
- public void sendError(int i, String s) throws IOException
+ public final void setStatus(int i)
{
}
- public void sendRedirect(String s) throws IOException
+ public final void setStatus(int i, String s)
{
}
- public void setDateHeader(String s, long l)
- {
- }
- public void addDateHeader(String s, long l)
+ public final void setCharacterEncoding(String s)
{
+ throw new NotYetImplemented();
}
- public void setHeader(String s, String s1)
- {
- }
+ // Must return false
- public void addHeader(String s, String s1)
+ public boolean containsHeader(String s)
{
+ return false;
}
- public void setIntHeader(String s, int i)
- {
- }
+ // Defined by subclasses
- public void addIntHeader(String s, int i)
- {
- }
+ public abstract String getCharacterEncoding();
- public void setStatus(int i)
+ public abstract Locale getLocale();
+
+ public abstract void flushBuffer() throws IOException;
+
+ public abstract void resetBuffer();
+
+ public abstract void reset();
+
+ public abstract int getBufferSize();
+
+ public abstract boolean isCommitted();
+
+ public abstract ServletOutputStream getOutputStream() throws IOException;
+
+ public abstract String getContentType();
+
+ public abstract PrintWriter getWriter() throws IOException;
+
+ public abstract void setBufferSize(int i);
+
+ public static final class StateAware extends DispatchedHttpServletResponse
{
- }
- public void setStatus(int i, String s)
- {
+ /** . */
+ private final StateAwareResponseImpl mresp;
+
+ public StateAware(DispatchedHttpServletRequest req, StateAwareResponseImpl mresp,
HttpServletResponse dresp)
+ {
+ super(req, mresp, dresp);
+
+ //
+ this.mresp = mresp;
+ }
+
+ // Must return null
+
+ public String getCharacterEncoding()
+ {
+ return null;
+ }
+
+ public String getContentType()
+ {
+ return null;
+ }
+
+ public Locale getLocale()
+ {
+ return null;
+ }
+
+ public void resetBuffer()
+ {
+ }
+
+ public void reset()
+ {
+ }
+
+ // Must return 0
+
+ public int getBufferSize()
+ {
+ return 0;
+ }
+
+ // Ignore
+
+ public ServletOutputStream getOutputStream() throws IOException
+ {
+ return new ServletOutputStream()
+ {
+ public void write(int b) throws IOException
+ {
+ // Ignore
+ }
+ };
+ }
+
+ public PrintWriter getWriter() throws IOException
+ {
+ return new PrintWriter(new Writer()
+ {
+ public void write(char cbuf[], int off, int len) throws IOException
+ {
+ // Ignore
+ }
+
+ public void flush() throws IOException
+ {
+ // Ignore
+ }
+
+ public void close() throws IOException
+ {
+ // Ignore
+ }
+ });
+ }
+
+ // Must No op
+
+ public void setBufferSize(int i)
+ {
+ }
+
+ public void flushBuffer() throws IOException
+ {
+ }
+
+ // Must return true
+
+ public boolean isCommitted()
+ {
+ return true;
+ }
}
- public boolean containsHeader(String s)
+ public static final class Mime extends DispatchedHttpServletResponse
{
- // Must return false
- return false;
- }
- // Must be based on the getLocale method of the RenderResponse
+ /** . */
+ private final MimeResponseImpl mresp;
- public Locale getLocale()
- {
- return rresp.getLocale();
- }
+ /** . */
+ private ServletOutputStream sos;
- // Belongs to servlet 2.4 - not specified how it should behave yet
+ public Mime(DispatchedHttpServletRequest req, MimeResponseImpl mresp,
HttpServletResponse dresp)
+ {
+ super(req, mresp, dresp);
- public String getContentType()
- {
- throw new UnsupportedOperationException("Not specified by spec");
- }
+ //
+ this.mresp = mresp;
+ this.sos = null;
+ }
- public void setCharacterEncoding(String s)
- {
- throw new UnsupportedOperationException("Not specified by spec");
+ // Must be equivalent
+
+ public String getCharacterEncoding()
+ {
+ return mresp.getCharacterEncoding();
+ }
+
+ public void setBufferSize(int i)
+ {
+ mresp.setBufferSize(i);
+ }
+
+ public void flushBuffer() throws IOException
+ {
+ mresp.flushBuffer();
+ }
+
+ public void resetBuffer()
+ {
+ mresp.resetBuffer();
+ }
+
+ public void reset()
+ {
+ mresp.reset();
+ }
+
+ public int getBufferSize()
+ {
+ return mresp.getBufferSize();
+ }
+
+ public boolean isCommitted()
+ {
+ return mresp.isCommitted();
+ }
+
+ public ServletOutputStream getOutputStream() throws IOException
+ {
+ if (sos == null)
+ {
+ sos = new ServletOutputStream()
+ {
+ /** . */
+ private final OutputStream out = mresp.getPortletOutputStream();
+
+ public void write(byte b[], int off, int len) throws IOException
+ {
+ out.write(b, off, len);
+ }
+
+ public void write(byte b[]) throws IOException
+ {
+ out.write(b);
+ }
+
+ public void write(int b) throws IOException
+ {
+ out.write(b);
+ }
+ };
+ }
+ return sos;
+ }
+
+ public PrintWriter getWriter() throws IOException
+ {
+ return mresp.getWriter();
+ }
+
+ public Locale getLocale()
+ {
+ return mresp.getLocale();
+ }
+
+ public String getContentType()
+ {
+ return mresp.getContentType();
+ }
}
}
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/PortletRequestDispatcherImpl.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/PortletRequestDispatcherImpl.java 2008-01-28
23:38:10 UTC (rev 9627)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/PortletRequestDispatcherImpl.java 2008-01-29
12:47:14 UTC (rev 9628)
@@ -24,12 +24,9 @@
import org.jboss.portal.portlet.aspects.portlet.ContextDispatcherInterceptor;
import org.jboss.portal.portlet.invocation.PortletInvocation;
-import org.jboss.portal.portlet.impl.jsr168.APIConstants;
import org.jboss.portal.portlet.impl.jsr168.DispatchedHttpServletRequest;
import org.jboss.portal.portlet.impl.jsr168.DispatchedHttpServletResponse;
import org.jboss.portal.portlet.impl.jsr168.DispatchType;
-import org.jboss.portal.portlet.LifeCyclePhase;
-import org.jboss.portal.common.NotYetImplemented;
import javax.portlet.PortletException;
import javax.portlet.PortletRequestDispatcher;
@@ -39,7 +36,6 @@
import javax.portlet.PortletResponse;
import javax.portlet.ActionRequest;
import javax.portlet.EventRequest;
-import javax.portlet.ResourceRequest;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
@@ -91,24 +87,6 @@
PortletRequest req,
PortletResponse resp) throws PortletException, IOException
{
- LifeCyclePhase phase;
- if (req instanceof ActionRequest)
- {
- phase = LifeCyclePhase.ACTION;
- }
- else if (req instanceof EventRequest)
- {
- phase = LifeCyclePhase.EVENT;
- }
- else if (req instanceof RenderRequest)
- {
- phase = LifeCyclePhase.RENDER;
- }
- else if (req instanceof ResourceRequest)
- {
- phase = LifeCyclePhase.RESOURCE;
- }
-
try
{
// Get the invocation that is still in the request
@@ -119,8 +97,28 @@
HttpServletResponse dresp = invocation.getDispatchedResponse();
//
- DispatchedHttpServletRequest direq = new DispatchedHttpServletRequest(type,
(RenderRequestImpl)req, dreq, path);
- DispatchedHttpServletResponse diresp = new DispatchedHttpServletResponse(direq,
(RenderResponse)resp, dresp);
+ DispatchedHttpServletRequest direq;
+ DispatchedHttpServletResponse diresp;
+ if (req instanceof ActionRequest)
+ {
+ direq = new DispatchedHttpServletRequest.Action(type, (ActionRequestImpl)req,
dreq, path);
+ diresp = new DispatchedHttpServletResponse.StateAware(direq,
(StateAwareResponseImpl)resp, dresp);
+ }
+ else if (req instanceof EventRequest)
+ {
+ direq = new DispatchedHttpServletRequest.Event(type, (EventRequestImpl)req,
dreq, path);
+ diresp = new DispatchedHttpServletResponse.StateAware(direq,
(StateAwareResponseImpl)resp, dresp);
+ }
+ else if (req instanceof RenderRequest)
+ {
+ direq = new DispatchedHttpServletRequest.Render(type, (RenderRequestImpl)req,
dreq, path);
+ diresp = new DispatchedHttpServletResponse.Mime(direq,
(MimeResponseImpl)resp, dresp);
+ }
+ else
+ {
+ direq = new DispatchedHttpServletRequest.Resource(type,
(ResourceRequestImpl)req, dreq, path);
+ diresp = new DispatchedHttpServletResponse.Mime(direq,
(MimeResponseImpl)resp, dresp);
+ }
//
switch (type)
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/PortletRequestImpl.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/PortletRequestImpl.java 2008-01-28
23:38:10 UTC (rev 9627)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/PortletRequestImpl.java 2008-01-29
12:47:14 UTC (rev 9628)
@@ -50,7 +50,6 @@
import javax.portlet.PortletMode;
import javax.portlet.PortletPreferences;
import javax.portlet.PortletRequest;
-import javax.portlet.PortletSession;
import javax.portlet.PreferencesValidator;
import javax.portlet.RenderRequest;
import javax.portlet.WindowState;
@@ -360,12 +359,12 @@
//
- public PortletSession getPortletSession()
+ public PortletSessionImpl getPortletSession()
{
return getPortletSession(true);
}
- public PortletSession getPortletSession(boolean create)
+ public PortletSessionImpl getPortletSession(boolean create)
{
//
if (create)
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/PortletSessionImpl.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/PortletSessionImpl.java 2008-01-28
23:38:10 UTC (rev 9627)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/PortletSessionImpl.java 2008-01-29
12:47:14 UTC (rev 9628)
@@ -27,8 +27,12 @@
import javax.portlet.PortletContext;
import javax.portlet.PortletSession;
import javax.servlet.http.HttpSession;
+import javax.servlet.http.HttpSessionContext;
+import javax.servlet.ServletContext;
import java.util.Enumeration;
import java.util.Map;
+import java.util.Collections;
+import java.util.ArrayList;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -37,15 +41,28 @@
public class PortletSessionImpl implements PortletSession
{
+ /** . */
private HttpSession session;
+
+ /** . */
private String prefix;
+
+ /** . */
private PortletContext context;
+ /** . */
+ private HttpPortletSession applicationScopedHttpSession;
+
+ /** . */
+ private HttpPortletSession portletScopedHttpSession;
+
public PortletSessionImpl(HttpSession session, String id, PortletContext context)
{
this.session = session;
this.prefix = "javax.portlet.p." + id + "?";
this.context = context;
+ this.applicationScopedHttpSession = null;
+ this.portletScopedHttpSession = null;
}
public Object getAttribute(String s)
@@ -208,13 +225,40 @@
throw new NotYetImplemented();
}
- /** Return the underlying session. */
- HttpSession getHttpSession()
+ /**
+ * Returns the an implementation of
<code>javax.servlet.http.HttpSession</code> that wraps this
+ * portlet session and use the specified scope for manipulating attributes. This
session is used
+ * during the request dispatch to a servlet.
+ *
+ * @param scope the scope
+ * @return the wrapped session
+ */
+ public HttpSession getHttpSession(int scope)
{
- return session;
+ switch (scope)
+ {
+ case APPLICATION_SCOPE:
+ if (applicationScopedHttpSession == null)
+ {
+ applicationScopedHttpSession = new HttpPortletSession(this,
APPLICATION_SCOPE);
+ }
+ return applicationScopedHttpSession;
+ case PORTLET_SCOPE:
+ if (portletScopedHttpSession == null)
+ {
+ portletScopedHttpSession = new HttpPortletSession(this, PORTLET_SCOPE);
+ }
+ return portletScopedHttpSession;
+ default:
+ throw new IllegalArgumentException("Unrecognzed session scope " +
scope);
+ }
}
- /** Detect validity of the session based on the underlying session. */
+ /**
+ * Detect validity of the session based on the underlying session.
+ *
+ * @return true if the session is valid
+ */
boolean isValid()
{
try
@@ -228,4 +272,107 @@
}
}
+ private static class HttpPortletSession implements HttpSession
+ {
+
+ /** . */
+ private final PortletSessionImpl delegate;
+
+ /** . */
+ private final int scope;
+
+ private HttpPortletSession(PortletSessionImpl delegate, int scope)
+ {
+ this.delegate = delegate;
+ this.scope = scope;
+ }
+
+ public long getCreationTime()
+ {
+ return delegate.getCreationTime();
+ }
+
+ public String getId()
+ {
+ return delegate.getId();
+ }
+
+ public long getLastAccessedTime()
+ {
+ return delegate.getLastAccessedTime();
+ }
+
+ public ServletContext getServletContext()
+ {
+ return delegate.session.getServletContext();
+ }
+
+ public void setMaxInactiveInterval(int i)
+ {
+ delegate.setMaxInactiveInterval(i);
+ }
+
+ public int getMaxInactiveInterval()
+ {
+ return delegate.getMaxInactiveInterval();
+ }
+
+ public HttpSessionContext getSessionContext()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public Object getAttribute(String s)
+ {
+ return delegate.getAttribute(s, scope);
+ }
+
+ public Object getValue(String s)
+ {
+ return getAttribute(s);
+ }
+
+ public Enumeration getAttributeNames()
+ {
+ return delegate.getAttributeNames(scope);
+ }
+
+ public String[] getValueNames()
+ {
+ ArrayList<String> names = Collections.list(delegate.getAttributeNames());
+
+ //
+ return names.toArray(new String[names.size()]);
+ }
+
+ public void setAttribute(String s, Object o)
+ {
+ delegate.setAttribute(s, o, scope);
+ }
+
+ public void putValue(String s, Object o)
+ {
+ setAttribute(s, o);
+ }
+
+ public void removeAttribute(String s)
+ {
+ delegate.removeAttribute(s, scope);
+ }
+
+ public void removeValue(String s)
+ {
+ removeAttribute(s);
+ }
+
+ public void invalidate()
+ {
+ delegate.invalidate();
+ }
+
+ public boolean isNew()
+ {
+ return delegate.isNew();
+ }
+ }
}
Added:
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/tck/dispatcher/ObtainingDispatcherTestCase.java
===================================================================
---
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/tck/dispatcher/ObtainingDispatcherTestCase.java
(rev 0)
+++
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/tck/dispatcher/ObtainingDispatcherTestCase.java 2008-01-29
12:47:14 UTC (rev 9628)
@@ -0,0 +1,147 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.test.portlet.jsr286.tck.dispatcher;
+
+import org.jboss.portal.unit.PortletTestCase;
+import org.jboss.portal.unit.PortletTestContext;
+import org.jboss.portal.unit.actions.PortletRenderTestAction;
+import org.jboss.portal.unit.actions.PortletActionTestAction;
+import org.jboss.portal.unit.actions.PortletEventTestAction;
+import org.jboss.portal.unit.actions.PortletResourceTestAction;
+import org.jboss.portal.test.portlet.framework.UTP1;
+import org.jboss.portal.unit.annotations.TestCase;
+import org.jboss.portal.unit.Assertion;
+import org.jboss.unit.driver.DriverResponse;
+import org.jboss.unit.driver.response.EndTestResponse;
+import static org.jboss.unit.api.Assert.assertNotNull;
+import static org.jboss.unit.api.Assert.assertNull;
+import org.jboss.unit.remote.driver.handler.http.response.InvokeGetResponse;
+
+import javax.portlet.Portlet;
+import javax.portlet.PortletRequestDispatcher;
+import javax.portlet.PortletException;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.EventRequest;
+import javax.portlet.EventResponse;
+import javax.portlet.ResourceRequest;
+import javax.portlet.ResourceResponse;
+import java.io.IOException;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+(a)TestCase({Assertion.JSR168_121, Assertion.JSR168_122})
+public class ObtainingDispatcherTestCase
+{
+ public ObtainingDispatcherTestCase(PortletTestCase seq)
+ {
+ seq.bindAction(0, UTP1.RENDER_JOIN_POINT, new PortletRenderTestAction()
+ {
+ protected DriverResponse run(Portlet portlet, RenderRequest request,
RenderResponse response, PortletTestContext context) throws PortletException, IOException
+ {
+ check(portlet);
+
+ //
+ return new InvokeGetResponse(response.createActionURL().toString());
+ }
+ });
+ seq.bindAction(1, UTP1.ACTION_JOIN_POINT, new PortletActionTestAction()
+ {
+ protected void run(Portlet portlet, ActionRequest request, ActionResponse
response, PortletTestContext context) throws PortletException, IOException
+ {
+ check(portlet);
+
+ //
+ response.setEvent("Event", null);
+ }
+ });
+ seq.bindAction(1, UTP1.EVENT_JOIN_POINT, new PortletEventTestAction()
+ {
+ protected void run(Portlet portlet, EventRequest request, EventResponse
response, PortletTestContext context) throws PortletException, IOException
+ {
+ check(portlet);
+ }
+ });
+ seq.bindAction(1, UTP1.RENDER_JOIN_POINT, new PortletRenderTestAction()
+ {
+ protected DriverResponse run(Portlet portlet, RenderRequest request,
RenderResponse response, PortletTestContext context) throws PortletException, IOException
+ {
+ return new InvokeGetResponse(response.createResourceURL().toString());
+ }
+ });
+ seq.bindAction(2, UTP1.RESOURCE_JOIN_POINT, new PortletResourceTestAction()
+ {
+ protected DriverResponse run(Portlet portlet, ResourceRequest request,
ResourceResponse response, PortletTestContext context) throws PortletException,
IOException
+ {
+ check(portlet);
+
+ //
+ return new EndTestResponse();
+ }
+ });
+ }
+
+ private static void check(Portlet portlet)
+ {
+ UTP1 p = (UTP1)portlet;
+ //correct
+ PortletRequestDispatcher dispatcher =
p.getPortletContext().getNamedDispatcher("UniversalServletA");
+ assertNotNull(dispatcher);
+
+ //incorrect
+ dispatcher =
p.getPortletContext().getNamedDispatcher("FAKE_NAME_SERVLET");
+ assertNull(dispatcher);
+
+ //incorrect
+ dispatcher = p.getPortletContext().getNamedDispatcher("/");
+ assertNull(dispatcher);
+
+ //incorrect
+ dispatcher =
p.getPortletContext().getNamedDispatcher("/universalServletA");
+ assertNull(dispatcher);
+
+ //incorrect
+ dispatcher =
p.getPortletContext().getRequestDispatcher("UniversalServletA");
+ assertNull(dispatcher);
+
+ //incorrect
+ dispatcher =
p.getPortletContext().getRequestDispatcher("universalServletA");
+ assertNull(dispatcher);
+
+ //incorrect
+ //dispatcher =
getPortletContext().getRequestDispatcher("/UniversalServletA");
+ //assertNull(dispatcher);
+
+ //incorrect
+ //dispatcher = getPortletContext().getRequestDispatcher("/");
+ //assertNull(dispatcher);
+
+ //correct
+ dispatcher =
p.getPortletContext().getRequestDispatcher("/universalServletA");
+ assertNotNull(dispatcher);
+ }
+}
\ No newline at end of file
Modified:
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/unit/actions/PortletRenderTestAction.java
===================================================================
---
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/unit/actions/PortletRenderTestAction.java 2008-01-28
23:38:10 UTC (rev 9627)
+++
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/unit/actions/PortletRenderTestAction.java 2008-01-29
12:47:14 UTC (rev 9628)
@@ -24,7 +24,6 @@
import org.jboss.portal.unit.TestAction;
import org.jboss.portal.unit.PortletTestContext;
-import org.jboss.portal.unit.PortletTestContext;
import org.jboss.portal.common.NotYetImplemented;
import org.jboss.unit.driver.DriverResponse;
import org.jboss.unit.driver.response.FailureResponse;
@@ -34,8 +33,6 @@
import javax.portlet.PortletException;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
-import javax.portlet.ActionRequest;
-import javax.portlet.ActionResponse;
import java.io.IOException;
/**
Added:
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/unit/actions/PortletTestAction.java
===================================================================
---
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/unit/actions/PortletTestAction.java
(rev 0)
+++
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/unit/actions/PortletTestAction.java 2008-01-29
12:47:14 UTC (rev 9628)
@@ -0,0 +1,84 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.unit.actions;
+
+import org.jboss.portal.unit.TestAction;
+import org.jboss.portal.unit.PortletTestContext;
+import org.jboss.portal.common.NotYetImplemented;
+import org.jboss.unit.driver.DriverResponse;
+import org.jboss.unit.driver.response.FailureResponse;
+import org.jboss.unit.Failure;
+
+import javax.portlet.Portlet;
+import javax.portlet.PortletException;
+import javax.portlet.PortletRequest;
+import javax.portlet.PortletResponse;
+import java.io.IOException;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz@jboss.org">Boleslaw
Dawidowicz</a>
+ * @version $Revision: 7954 $
+ */
+public abstract class PortletTestAction extends TestAction
+{
+
+ public final DriverResponse execute(Portlet portlet, PortletRequest request,
PortletResponse response, PortletTestContext context) throws PortletException,
IOException
+ {
+ try
+ {
+ return runWithRuntimeException(portlet, request, response, context);
+ }
+ catch (AssertionError t)
+ {
+ getLogger().error("The test case failed", t);
+
+ //
+ return new FailureResponse(Failure.createFailure(t));
+ }
+ }
+
+ protected DriverResponse runWithRuntimeException(Portlet portlet, PortletRequest
request, PortletResponse response, PortletTestContext context) throws PortletException,
IOException
+ {
+ try
+ {
+ return run(portlet, request, response, context);
+ }
+ catch (Exception e)
+ {
+ if (e instanceof PortletException)
+ {
+ throw (PortletException)e;
+ }
+ if (e instanceof IOException)
+ {
+ throw (IOException)e;
+ }
+ throw new AssertionError(e);
+ }
+ }
+
+ protected DriverResponse run(Portlet portlet, PortletRequest request, PortletResponse
response, PortletTestContext context) throws PortletException, IOException
+ {
+ throw new NotYetImplemented();
+ }
+}
\ No newline at end of file
Modified:
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/unit/base/AbstractUniversalTestPortlet.java
===================================================================
---
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/unit/base/AbstractUniversalTestPortlet.java 2008-01-28
23:38:10 UTC (rev 9627)
+++
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/unit/base/AbstractUniversalTestPortlet.java 2008-01-29
12:47:14 UTC (rev 9628)
@@ -29,6 +29,7 @@
import org.jboss.portal.unit.actions.PortletRenderTestAction;
import org.jboss.portal.unit.actions.PortletEventTestAction;
import org.jboss.portal.unit.actions.PortletResourceTestAction;
+import org.jboss.portal.unit.actions.PortletTestAction;
import org.jboss.portal.unit.TestAction;
import org.jboss.portal.unit.PortletTestContext;
import org.jboss.portal.test.framework.server.NodeId;
@@ -156,11 +157,17 @@
{
ctx.setResponse(new FailureResponse(Failure.createAssertionFailure("No
action for " + ctx.getRequestCount() + " " + NodeId.locate() + "
" + actionJoinPoint)));
}
- else if (action instanceof PortletActionTestAction == false)
+ if (action instanceof PortletTestAction)
{
- ctx.setResponse(new
FailureResponse(Failure.createAssertionFailure("Action for " +
ctx.getRequestCount() + " " + NodeId.locate() + " " + actionJoinPoint
+ " is not an instance of " + PortletActionTestAction.class.getName() + "
but is " + action.getClass().getName())));
+ log.debug("Found action for jointpoint " + actionJoinPoint + "
: " + action);
+
+ //
+ DriverResponse response = ((PortletTestAction)action).execute(this, req,
resp, ctx);
+
+ //
+ ctx.setResponse(response);
}
- else
+ else if (action instanceof PortletActionTestAction)
{
log.debug("Found action for jointpoint " + actionJoinPoint + "
: " + action);
@@ -170,6 +177,12 @@
//
ctx.setResponse(response);
}
+ else
+ {
+ ctx.setResponse(new
FailureResponse(Failure.createAssertionFailure("Action for " +
ctx.getRequestCount() +
+ " " + NodeId.locate() + " " + actionJoinPoint + "
does not have the right type but has the type " +
+ action.getClass().getName())));
+ }
}
}
@@ -196,11 +209,17 @@
//
if (action != null)
{
- if (!(action instanceof PortletEventTestAction))
+ if (action instanceof PortletTestAction)
{
- ctx.setResponse(new
FailureResponse(Failure.createAssertionFailure("Action for " +
ctx.getRequestCount() + " " + NodeId.locate() + " " + actionJoinPoint
+ " is not an instance of " + PortletEventTestAction.class.getName() + "
but is " + action.getClass().getName())));
+ log.debug("Found action for jointpoint " + eventJoinPoint +
" : " + action);
+
+ //
+ DriverResponse response = ((PortletTestAction)action).execute(this,
req, resp, ctx);
+
+ //
+ ctx.setResponse(response);
}
- else
+ if (action instanceof PortletEventTestAction)
{
log.debug("Found action for jointpoint " + eventJoinPoint +
" : " + action);
@@ -210,6 +229,12 @@
//
ctx.setResponse(response);
}
+ else
+ {
+ ctx.setResponse(new
FailureResponse(Failure.createAssertionFailure("Action for " +
ctx.getRequestCount() +
+ " " + NodeId.locate() + " " + actionJoinPoint +
" does not have the right type but has the type " +
+ action.getClass().getName())));
+ }
}
}
}
@@ -254,11 +279,29 @@
//
if (action != null)
{
- log.debug("Found action for joinpoint " + renderJoinPoint + " :
" + action);
-
// Get the result
- DriverResponse response = ((PortletRenderTestAction)action).execute(this, req,
resp, ctx);
+ DriverResponse response;
+ if (action instanceof PortletTestAction)
+ {
+ log.debug("Found action for joinpoint " + renderJoinPoint + "
: " + action);
+ //
+ response = ((PortletTestAction)action).execute(this, req, resp, ctx);
+ }
+ else if (action instanceof PortletRenderTestAction)
+ {
+ log.debug("Found action for joinpoint " + renderJoinPoint + "
: " + action);
+
+ //
+ response = ((PortletRenderTestAction)action).execute(this, req, resp, ctx);
+ }
+ else
+ {
+ response = new FailureResponse(Failure.createAssertionFailure("Action
for " + ctx.getRequestCount() +
+ " " + NodeId.locate() + " " + resourceJoinPoint + "
does not have the right type but has the type " +
+ action.getClass().getName()));
+ }
+
// If we have one result it is meant to be returned to the client
if (response != null)
{
@@ -303,16 +346,18 @@
}
//
- if (action == null)
+ if (action instanceof PortletTestAction)
{
- ctx.setResponse(new FailureResponse(Failure.createAssertionFailure("No
action for " + ctx.getRequestCount() + " " + NodeId.locate() + "
" + resourceJoinPoint)));
+ log.debug("Found action for joinpoint " + resourceJoinPoint + " :
" + action);
+
+ // Get the result that must exist since it is the only joinpoint invoked during
this request
+ DriverResponse response = ((PortletTestAction)action).execute(this, req, resp,
ctx);
+
+ //
+ ctx.setResponse(response);
}
- else if (action instanceof PortletResourceTestAction == false)
+ else if (action instanceof PortletResourceTestAction)
{
- ctx.setResponse(new FailureResponse(Failure.createAssertionFailure("Action
for " + ctx.getRequestCount() + " " + NodeId.locate() + " " +
resourceJoinPoint + " is not an instance of " +
PortletResourceTestAction.class.getName() + " but is " +
action.getClass().getName())));
- }
- else
- {
log.debug("Found action for joinpoint " + resourceJoinPoint + " :
" + action);
// Get the result that must exist since it is the only joinpoint invoked during
this request
@@ -321,6 +366,12 @@
//
ctx.setResponse(response);
}
+ else
+ {
+ ctx.setResponse(new FailureResponse(Failure.createAssertionFailure("Action
for " + ctx.getRequestCount() +
+ " " + NodeId.locate() + " " + resourceJoinPoint + "
does not have the right type but has the type " +
+ action.getClass().getName())));
+ }
}
public void destroy()
Modified: modules/portlet/trunk/test/src/test/build.xml
===================================================================
--- modules/portlet/trunk/test/src/test/build.xml 2008-01-28 23:38:10 UTC (rev 9627)
+++ modules/portlet/trunk/test/src/test/build.xml 2008-01-29 12:47:14 UTC (rev 9628)
@@ -237,6 +237,7 @@
<package-misc-test test="log4j"/>
+ <package-jsr286-tck-test test="dispatcher"/>
<package-jsr286-tck-test test="portletconfig"/>
<package-jsr286-tck-test test="portletconfignonamespace"/>
<package-jsr286-tck-test test="event"/>
Added:
modules/portlet/trunk/test/src/test/resources/jsr286/tck/dispatcher-war/WEB-INF/portlet.xml
===================================================================
---
modules/portlet/trunk/test/src/test/resources/jsr286/tck/dispatcher-war/WEB-INF/portlet.xml
(rev 0)
+++
modules/portlet/trunk/test/src/test/resources/jsr286/tck/dispatcher-war/WEB-INF/portlet.xml 2008-01-29
12:47:14 UTC (rev 9628)
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ JBoss, a division of Red Hat ~
+ ~ Copyright 2006, Red Hat Middleware, LLC, and individual ~
+ ~ contributors as indicated by the @authors tag. See the ~
+ ~ copyright.txt in the distribution for a full listing of ~
+ ~ individual contributors. ~
+ ~ ~
+ ~ This is free software; you can redistribute it and/or modify it ~
+ ~ under the terms of the GNU Lesser General Public License as ~
+ ~ published by the Free Software Foundation; either version 2.1 of ~
+ ~ the License, or (at your option) any later version. ~
+ ~ ~
+ ~ This software is distributed in the hope that it will be useful, ~
+ ~ but WITHOUT ANY WARRANTY; without even the implied warranty of ~
+ ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ~
+ ~ Lesser General Public License for more details. ~
+ ~ ~
+ ~ You should have received a copy of the GNU Lesser General Public ~
+ ~ License along with this software; if not, write to the Free ~
+ ~ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA ~
+ ~ 02110-1301 USA, or see the FSF site:
http://www.fsf.org. ~
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
+
+<portlet-app
xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_1...
http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"
+ version="1.0">
+
+
+ <portlet>
+ <portlet-name>TestUniversalPortletA</portlet-name>
+
<portlet-class>org.jboss.portal.test.portlet.framework.UTP1</portlet-class>
+ <supports>
+ <mime-type>text/html</mime-type>
+ </supports>
+ <supported-processing-event>
+ <name>Event</name>
+ </supported-processing-event>
+ <supported-publishing-event>
+ <name>Event</name>
+ </supported-publishing-event>
+ </portlet>
+
+ <event-definition>
+ <name>Event</name>
+ </event-definition>
+
+</portlet-app>
Added:
modules/portlet/trunk/test/src/test/resources/jsr286/tck/dispatcher-war/WEB-INF/web.xml
===================================================================
---
modules/portlet/trunk/test/src/test/resources/jsr286/tck/dispatcher-war/WEB-INF/web.xml
(rev 0)
+++
modules/portlet/trunk/test/src/test/resources/jsr286/tck/dispatcher-war/WEB-INF/web.xml 2008-01-29
12:47:14 UTC (rev 9628)
@@ -0,0 +1,44 @@
+<?xml version="1.0"?>
+<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ JBoss, a division of Red Hat ~
+ ~ Copyright 2006, Red Hat Middleware, LLC, and individual ~
+ ~ contributors as indicated by the @authors tag. See the ~
+ ~ copyright.txt in the distribution for a full listing of ~
+ ~ individual contributors. ~
+ ~ ~
+ ~ This is free software; you can redistribute it and/or modify it ~
+ ~ under the terms of the GNU Lesser General Public License as ~
+ ~ published by the Free Software Foundation; either version 2.1 of ~
+ ~ the License, or (at your option) any later version. ~
+ ~ ~
+ ~ This software is distributed in the hope that it will be useful, ~
+ ~ but WITHOUT ANY WARRANTY; without even the implied warranty of ~
+ ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ~
+ ~ Lesser General Public License for more details. ~
+ ~ ~
+ ~ You should have received a copy of the GNU Lesser General Public ~
+ ~ License along with this software; if not, write to the Free ~
+ ~ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA ~
+ ~ 02110-1301 USA, or see the FSF site:
http://www.fsf.org. ~
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
+
+<!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>
+
+ <listener>
+
<listener-class>org.jboss.portal.unit.PortletTestSuite</listener-class>
+ </listener>
+
+ <servlet>
+ <servlet-name>UniversalServletA</servlet-name>
+
<servlet-class>org.jboss.portal.test.portlet.framework.UTS1</servlet-class>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>UniversalServletA</servlet-name>
+ <url-pattern>/universalServletA/*</url-pattern>
+ </servlet-mapping>
+
+</web-app>
Modified: modules/portlet/trunk/test/src/test/resources/test/remote-jboss-unit.xml
===================================================================
--- modules/portlet/trunk/test/src/test/resources/test/remote-jboss-unit.xml 2008-01-28
23:38:10 UTC (rev 9627)
+++ modules/portlet/trunk/test/src/test/resources/test/remote-jboss-unit.xml 2008-01-29
12:47:14 UTC (rev 9628)
@@ -149,6 +149,10 @@
<!--Spec TCK Assertions tests-->
<generic>
<class
name="org.jboss.unit.remote.driver.RemoteTestDriverClient"/>
+ <property name="archiveId"
value="test-jsr286-tck-dispatcher.war"/>
+ </generic>
+ <generic>
+ <class
name="org.jboss.unit.remote.driver.RemoteTestDriverClient"/>
<property name="archiveId"
value="test-jsr286-tck-portletconfig.war"/>
</generic>
<generic>