Author: julien(a)jboss.com
Date: 2008-01-29 20:10:46 -0500 (Tue, 29 Jan 2008)
New Revision: 9643
Added:
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/tck/dispatcher/NamedForwardContainerAttributesTestCase.java
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/tck/dispatcher/NamedIncludeContainerAttributesTestCase.java
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/tck/dispatcher/RequestForwardContainerAttributesTestCase.java
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/tck/dispatcher/RequestIncludeContainerAttributesTestCase.java
Modified:
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/tck/dispatcher/DispatchedContainerAttributesTestCase.java
Log:
refactor the container attributes test cases in order to be able to support the double
dispatch test cases (life is tough sometime)
Modified:
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/tck/dispatcher/DispatchedContainerAttributesTestCase.java
===================================================================
---
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/tck/dispatcher/DispatchedContainerAttributesTestCase.java 2008-01-30
00:13:13 UTC (rev 9642)
+++
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/tck/dispatcher/DispatchedContainerAttributesTestCase.java 2008-01-30
01:10:46 UTC (rev 9643)
@@ -32,7 +32,6 @@
import org.jboss.portal.unit.actions.PortletResourceTestAction;
import org.jboss.portal.test.portlet.framework.UTP1;
import org.jboss.portal.test.portlet.framework.UTS1;
-import org.jboss.portal.common.util.Tools;
import org.jboss.unit.driver.DriverResponse;
import org.jboss.unit.driver.response.EndTestResponse;
import static org.jboss.unit.api.Assert.assertEquals;
@@ -42,7 +41,6 @@
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.portlet.PortletException;
-import javax.portlet.PortletRequestDispatcher;
import javax.portlet.PortletRequest;
import javax.portlet.PortletResponse;
import javax.portlet.ActionRequest;
@@ -51,12 +49,15 @@
import javax.portlet.EventResponse;
import javax.portlet.ResourceRequest;
import javax.portlet.ResourceResponse;
+import javax.portlet.PortletContext;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
-import java.util.List;
+import java.util.Map;
+import java.util.Collections;
+import java.util.HashMap;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -65,14 +66,73 @@
public abstract class DispatchedContainerAttributesTestCase
{
- private Object requestURI;
- private Object contextPath;
- private Object servletPath;
- private Object pathInfo;
- private Object queryString;
+ /** . */
+ public static final Map<String, String> EXPECTED_INCLUDE_ATTRIBUTES_SET =
buildIncludedSetMap();
- public DispatchedContainerAttributesTestCase(PortletTestCase seq)
+ /** . */
+ public static final Map<String, String> EXPECTED_FORWARD_ATTRIBUTES_SET =
buildForwardSetMap();
+
+ /** . */
+ public static final Map<String, String> EXPECTED_INCLUDE_ATTRIBUTES_NOT_SET =
buildIncludedNotSetMap();
+
+ /** . */
+ public static final Map<String, String> EXPECTED_FORWARD_ATTRIBUTES_NOT_SET =
buildForwardNotSetMap();
+
+ private static Map<String, String> buildIncludedSetMap()
{
+ Map<String, String> map = new HashMap<String, String>();
+ map.put("javax.servlet.include.request_uri",
"/test-jsr286-tck-dispatcher/universalServletA/pathinfo");
+ map.put("javax.servlet.include.context_path",
"/test-jsr286-tck-dispatcher");
+ map.put("javax.servlet.include.servlet_path",
"/universalServletA");
+ map.put("javax.servlet.include.path_info", "/pathinfo");
+ map.put("javax.servlet.include.query_string", "foo=bar");
+ return Collections.unmodifiableMap(map);
+ }
+
+ private static Map<String, String> buildForwardSetMap()
+ {
+ Map<String, String> map = new HashMap<String, String>();
+ map.put("javax.servlet.forward.request_uri",
"/test-jsr286-tck-dispatcher/universalServletA/pathinfo");
+ map.put("javax.servlet.forward.context_path",
"/test-jsr286-tck-dispatcher");
+ map.put("javax.servlet.forward.servlet_path",
"/universalServletA");
+ map.put("javax.servlet.forward.path_info", "/pathinfo");
+ map.put("javax.servlet.forward.query_string", "foo=bar");
+ return Collections.unmodifiableMap(map);
+ }
+
+ private static Map<String, String> buildIncludedNotSetMap()
+ {
+ Map<String, String> map = new HashMap<String, String>();
+ map.put("javax.servlet.include.request_uri", null);
+ map.put("javax.servlet.include.context_path", null);
+ map.put("javax.servlet.include.servlet_path", null);
+ map.put("javax.servlet.include.path_info", null);
+ map.put("javax.servlet.include.query_string", null);
+ return Collections.unmodifiableMap(map);
+ }
+
+ private static Map<String, String> buildForwardNotSetMap()
+ {
+ Map<String, String> map = new HashMap<String, String>();
+ map.put("javax.servlet.forward.request_uri", null);
+ map.put("javax.servlet.forward.context_path", null);
+ map.put("javax.servlet.forward.servlet_path", null);
+ map.put("javax.servlet.forward.path_info", null);
+ map.put("javax.servlet.forward.query_string", null);
+ return Collections.unmodifiableMap(map);
+ }
+
+ /** . */
+ private final Map<String, String> expectedAttributes;
+
+ /** . */
+ private final Map<String, Object> collectedAttributes;
+
+ public DispatchedContainerAttributesTestCase(PortletTestCase seq, Map<String,
String> expectedAttributes)
+ {
+ this.expectedAttributes = expectedAttributes;
+ this.collectedAttributes = new HashMap<String, Object>();
+
seq.bindAction(0, UTP1.RENDER_JOIN_POINT, new PortletRenderTestAction()
{
protected DriverResponse run(Portlet portlet, RenderRequest request,
RenderResponse response, PortletTestContext context) throws IOException, PortletException
@@ -121,10 +181,8 @@
seq.bindAction(2, UTS1.SERVICE_JOIN_POINT, service);
}
- protected abstract void dispatch(PortletRequestDispatcher dispatcher, PortletRequest
request, PortletResponse response) throws IOException, PortletException;
+ protected abstract void dispatch(PortletRequest request, PortletResponse response,
PortletContext portletContext) throws IOException, PortletException;
- protected abstract String getDispatchType();
-
private void checkAttributes(
Portlet portlet,
PortletRequest request,
@@ -133,65 +191,36 @@
//assert that servlet HAS access to specific request attributes
try
{
- PortletRequestDispatcher dispatcher =
((AbstractUniversalTestPortlet)portlet).getPortletContext().getRequestDispatcher("/universalServletA/pathinfo?foo=bar");
+ PortletContext portletContext =
((AbstractUniversalTestPortlet)portlet).getPortletContext();
- //
- dispatch(dispatcher, request, response);
+ dispatch(request, response, portletContext);
//
- assertEquals("/test-jsr286-tck-dispatcher/universalServletA/pathinfo",
requestURI);
- assertEquals("/test-jsr286-tck-dispatcher", contextPath);
- assertEquals("/universalServletA", servletPath);
- assertEquals("/pathinfo", pathInfo);
- assertEquals("foo=bar", queryString);
+ assertEquals(expectedAttributes.keySet(), collectedAttributes.keySet());
+ for (Map.Entry<String, String> entry : expectedAttributes.entrySet())
+ {
+ String key = entry.getKey();
+ String expectedValue = entry.getValue();
+ Object collectedValue = collectedAttributes.get(key);
+ assertEquals("Was expecting a value " + expectedValue + " for
key " + key + " but had instead " + collectedValue, expectedValue,
collectedValue);
+ }
}
finally
{
- requestURI = null;
- contextPath = null;
- servletPath = null;
- pathInfo = null;
- queryString = null;
+ collectedAttributes.clear();
}
-
- // Assert that servlet has NO access to specific request attributes
- // it shouldn't access that attributes because getNamedDispatcher was used
- try
- {
- PortletRequestDispatcher dispatcher =
((AbstractUniversalTestPortlet)portlet).getPortletContext().getNamedDispatcher("UniversalServletA");
-
- //
- dispatch(dispatcher, request, response);
-
- //
- assertEquals(null, requestURI);
- assertEquals(null, contextPath);
- assertEquals(null, servletPath);
- assertEquals(null, pathInfo);
- assertEquals(null, queryString);
- }
- finally
- {
- requestURI = null;
- contextPath = null;
- servletPath = null;
- pathInfo = null;
- queryString = null;
- }
}
ServletServiceTestAction service = new ServletServiceTestAction()
{
protected DriverResponse run(Servlet servlet, HttpServletRequest request,
HttpServletResponse response, PortletTestContext context) throws ServletException,
IOException
{
- String dispatchType = getDispatchType();
+ for (String key : expectedAttributes.keySet())
+ {
+ Object value = request.getAttribute(key);
+ collectedAttributes.put(key, value);
+ }
- requestURI = request.getAttribute("javax.servlet." + dispatchType +
".request_uri");
- contextPath = request.getAttribute("javax.servlet." + dispatchType +
".context_path");
- servletPath = request.getAttribute("javax.servlet." + dispatchType +
".servlet_path");
- pathInfo = request.getAttribute("javax.servlet." + dispatchType +
".path_info");
- queryString = request.getAttribute("javax.servlet." + dispatchType +
".query_string");
-
//
return null;
}
Added:
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/tck/dispatcher/NamedForwardContainerAttributesTestCase.java
===================================================================
---
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/tck/dispatcher/NamedForwardContainerAttributesTestCase.java
(rev 0)
+++
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/tck/dispatcher/NamedForwardContainerAttributesTestCase.java 2008-01-30
01:10:46 UTC (rev 9643)
@@ -0,0 +1,54 @@
+/******************************************************************************
+ * 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.Assertion;
+import org.jboss.portal.unit.annotations.TestCase;
+
+import javax.portlet.PortletRequestDispatcher;
+import javax.portlet.PortletRequest;
+import javax.portlet.PortletResponse;
+import javax.portlet.PortletException;
+import javax.portlet.PortletContext;
+import java.io.IOException;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+@TestCase
+public class NamedForwardContainerAttributesTestCase extends
DispatchedContainerAttributesTestCase
+{
+
+ public NamedForwardContainerAttributesTestCase(PortletTestCase seq)
+ {
+ super(seq, EXPECTED_FORWARD_ATTRIBUTES_NOT_SET);
+ }
+
+ protected void dispatch(PortletRequest request, PortletResponse response,
PortletContext portletContext) throws IOException, PortletException
+ {
+ PortletRequestDispatcher dispatcher =
portletContext.getNamedDispatcher("UniversalServletA");
+ dispatcher.forward(request, response);
+ }
+}
\ No newline at end of file
Added:
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/tck/dispatcher/NamedIncludeContainerAttributesTestCase.java
===================================================================
---
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/tck/dispatcher/NamedIncludeContainerAttributesTestCase.java
(rev 0)
+++
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/tck/dispatcher/NamedIncludeContainerAttributesTestCase.java 2008-01-30
01:10:46 UTC (rev 9643)
@@ -0,0 +1,53 @@
+/******************************************************************************
+ * 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.Assertion;
+import org.jboss.portal.unit.annotations.TestCase;
+
+import javax.portlet.PortletRequestDispatcher;
+import javax.portlet.PortletRequest;
+import javax.portlet.PortletResponse;
+import javax.portlet.PortletException;
+import javax.portlet.PortletContext;
+import java.io.IOException;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+(a)TestCase({Assertion.JSR168_127})
+public class NamedIncludeContainerAttributesTestCase extends
DispatchedContainerAttributesTestCase
+{
+ public NamedIncludeContainerAttributesTestCase(PortletTestCase seq)
+ {
+ super(seq, EXPECTED_INCLUDE_ATTRIBUTES_NOT_SET);
+ }
+
+ protected void dispatch(PortletRequest request, PortletResponse response,
PortletContext portletContext) throws IOException, PortletException
+ {
+ PortletRequestDispatcher dispatcher =
portletContext.getNamedDispatcher("UniversalServletA");
+ dispatcher.include(request, response);
+ }
+}
\ No newline at end of file
Copied:
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/tck/dispatcher/RequestForwardContainerAttributesTestCase.java
(from rev 9637,
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/tck/dispatcher/ForwardedContainerAttributesTestCase.java)
===================================================================
---
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/tck/dispatcher/RequestForwardContainerAttributesTestCase.java
(rev 0)
+++
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/tck/dispatcher/RequestForwardContainerAttributesTestCase.java 2008-01-30
01:10:46 UTC (rev 9643)
@@ -0,0 +1,53 @@
+/******************************************************************************
+ * 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.Assertion;
+import org.jboss.portal.unit.annotations.TestCase;
+
+import javax.portlet.PortletRequestDispatcher;
+import javax.portlet.PortletRequest;
+import javax.portlet.PortletResponse;
+import javax.portlet.PortletException;
+import javax.portlet.PortletContext;
+import java.io.IOException;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+@TestCase
+public class RequestForwardContainerAttributesTestCase extends
DispatchedContainerAttributesTestCase
+{
+ public RequestForwardContainerAttributesTestCase(PortletTestCase seq)
+ {
+ super(seq, EXPECTED_FORWARD_ATTRIBUTES_SET);
+ }
+
+ protected void dispatch(PortletRequest request, PortletResponse response,
PortletContext portletContext) throws IOException, PortletException
+ {
+ PortletRequestDispatcher dispatcher =
portletContext.getRequestDispatcher("/universalServletA/pathinfo?foo=bar");
+ dispatcher.forward(request, response);
+ }
+}
\ No newline at end of file
Copied:
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/tck/dispatcher/RequestIncludeContainerAttributesTestCase.java
(from rev 9637,
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/tck/dispatcher/IncludedContainerAttributesTestCase.java)
===================================================================
---
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/tck/dispatcher/RequestIncludeContainerAttributesTestCase.java
(rev 0)
+++
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/tck/dispatcher/RequestIncludeContainerAttributesTestCase.java 2008-01-30
01:10:46 UTC (rev 9643)
@@ -0,0 +1,53 @@
+/******************************************************************************
+ * 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.Assertion;
+import org.jboss.portal.unit.annotations.TestCase;
+
+import javax.portlet.PortletRequestDispatcher;
+import javax.portlet.PortletRequest;
+import javax.portlet.PortletResponse;
+import javax.portlet.PortletException;
+import javax.portlet.PortletContext;
+import java.io.IOException;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+(a)TestCase({Assertion.JSR168_127})
+public class RequestIncludeContainerAttributesTestCase extends
DispatchedContainerAttributesTestCase
+{
+ public RequestIncludeContainerAttributesTestCase(PortletTestCase seq)
+ {
+ super(seq, EXPECTED_INCLUDE_ATTRIBUTES_SET);
+ }
+
+ protected void dispatch(PortletRequest request, PortletResponse response,
PortletContext portletContext) throws IOException, PortletException
+ {
+ PortletRequestDispatcher dispatcher =
portletContext.getRequestDispatcher("/universalServletA/pathinfo?foo=bar");
+ dispatcher.include(request, response);
+ }
+}