Author: julien(a)jboss.com
Date: 2008-01-23 11:39:54 -0500 (Wed, 23 Jan 2008)
New Revision: 9581
Added:
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/tck/resourceserving/DowngradeCacheabilityTestCase.java
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/ResourceResponseImpl.java
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/framework/UTP2.java
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/unit/actions/PortletResourceTestAction.java
modules/portlet/trunk/test/src/test/resources/jsr286/tck/resourceserving-war/WEB-INF/portlet.xml
Log:
- added resource serving cacheability test case
- implement createActionURL and createRenderURL throw ISE when cacheability is != than
PAGE
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/ResourceResponseImpl.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/ResourceResponseImpl.java 2008-01-23
16:07:45 UTC (rev 9580)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/ResourceResponseImpl.java 2008-01-23
16:39:54 UTC (rev 9581)
@@ -23,8 +23,11 @@
package org.jboss.portal.portlet.impl.jsr168.api;
import org.jboss.portal.portlet.invocation.PortletInvocation;
+import org.jboss.portal.portlet.invocation.ResourceInvocation;
+import org.jboss.portal.portlet.CacheabilityType;
import javax.portlet.ResourceResponse;
+import javax.portlet.PortletURL;
import java.util.Locale;
/**
@@ -34,9 +37,15 @@
public class ResourceResponseImpl extends MimeResponseImpl implements ResourceResponse
{
- public ResourceResponseImpl(PortletInvocation invocation, PortletRequestImpl preq)
+ /** . */
+ private final CacheabilityType cacheability;
+
+ public ResourceResponseImpl(ResourceInvocation invocation, PortletRequestImpl preq)
{
super(invocation, preq);
+
+ //
+ this.cacheability = invocation.getContext().getCacheability();
}
public void setLocale(Locale locale)
@@ -53,4 +62,28 @@
{
throw new UnsupportedOperationException();
}
+
+ public PortletURL createActionURL()
+ {
+ if (cacheability != CacheabilityType.PAGE)
+ {
+ throw new IllegalStateException("Cannot create action URL because the
current cache level " + cacheability +
+ " is not " + CacheabilityType.PAGE);
+ }
+
+ //
+ return super.createActionURL();
+ }
+
+ public PortletURL createRenderURL()
+ {
+ if (cacheability != CacheabilityType.PAGE)
+ {
+ throw new IllegalStateException("Cannot create render URL because the
current cache level " + cacheability +
+ " is not " + CacheabilityType.PAGE);
+ }
+
+ //
+ return super.createRenderURL();
+ }
}
Modified:
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/framework/UTP2.java
===================================================================
---
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/framework/UTP2.java 2008-01-23
16:07:45 UTC (rev 9580)
+++
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/framework/UTP2.java 2008-01-23
16:39:54 UTC (rev 9581)
@@ -46,6 +46,8 @@
public final static JoinPoint ACTION_JOIN_POINT = new JoinPoint(NAME,
JoinPointType.PORTLET_ACTION);
+ public final static JoinPoint RESOURCE_JOIN_POINT = new JoinPoint(NAME,
JoinPointType.PORTLET_RESOURCE);
+
/** Resets helper variables */
public void reset()
{
Added:
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/tck/resourceserving/DowngradeCacheabilityTestCase.java
===================================================================
---
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/tck/resourceserving/DowngradeCacheabilityTestCase.java
(rev 0)
+++
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/tck/resourceserving/DowngradeCacheabilityTestCase.java 2008-01-23
16:39:54 UTC (rev 9581)
@@ -0,0 +1,226 @@
+/******************************************************************************
+ * 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.resourceserving;
+
+import org.jboss.portal.unit.PortletTestCase;
+import org.jboss.portal.unit.PortletTestContext;
+import org.jboss.portal.unit.annotations.TestCase;
+import org.jboss.portal.unit.actions.PortletRenderTestAction;
+import org.jboss.portal.unit.actions.PortletResourceTestAction;
+import org.jboss.portal.test.portlet.framework.UTP2;
+import org.jboss.unit.driver.DriverResponse;
+import org.jboss.unit.driver.response.EndTestResponse;
+import org.jboss.unit.remote.driver.handler.http.response.InvokeGetResponse;
+
+import static org.jboss.unit.api.Assert.*;
+
+import javax.portlet.Portlet;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.portlet.PortletException;
+import javax.portlet.ResourceURL;
+import javax.portlet.ResourceRequest;
+import javax.portlet.ResourceResponse;
+import java.io.IOException;
+
+/**
+ * cxxx:
+ * Only URLs with a cache level FULL are allowed in the response of the
+ * serveResource call triggered via a ResourceURL with a cache level FULL. The
+ * same restriction is true for all downstream URLs that result from this
+ * serveResource call. Setting a cachability different from must result in an
+ * IllegalStateException.
+ *
+ * cxxxi:
+ * Attempts to create URLs that are not of type FULL
+ * or are not resource URLs in the current or a downstream response must result in
+ * an IllegalStateException25
+ *
+ * cxxxii:
+ * Creating other URLs, e.g. resource URLs of type or
+ * action or render URLs, must result in an IllegalStateException
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+@TestCase()
+public class DowngradeCacheabilityTestCase
+{
+ public DowngradeCacheabilityTestCase(PortletTestCase seq)
+ {
+ seq.bindAction(0, UTP2.RENDER_JOIN_POINT, new PortletRenderTestAction()
+ {
+ protected DriverResponse run(Portlet portlet, RenderRequest request,
RenderResponse response, PortletTestContext context) throws PortletException, IOException
+ {
+ ResourceURL resourceURL = response.createResourceURL();
+ assertEquals(ResourceURL.PAGE, resourceURL.getCacheability());
+ resourceURL.setCacheability(ResourceURL.PORTLET);
+ assertEquals(ResourceURL.PORTLET, resourceURL.getCacheability());
+ return new InvokeGetResponse(resourceURL.toString());
+ }
+ });
+ seq.bindAction(1, UTP2.RESOURCE_JOIN_POINT, new PortletResourceTestAction()
+ {
+ protected DriverResponse run(Portlet portlet, ResourceRequest request,
ResourceResponse response, PortletTestContext context) throws PortletException,
IOException
+ {
+ sendEmptyResponse(response);
+
+ //
+ assertEquals(ResourceURL.PORTLET, request.getCacheability());
+
+ //
+ try
+ {
+ response.createActionURL();
+ fail();
+ }
+ catch (IllegalStateException ignore)
+ {
+ }
+
+ //
+ try
+ {
+ response.createRenderURL();
+ fail();
+ }
+ catch (IllegalStateException ignore)
+ {
+ }
+
+ //
+ ResourceURL resourceURL = response.createResourceURL();
+ assertEquals(ResourceURL.PORTLET, resourceURL.getCacheability());
+
+ //
+ try
+ {
+ resourceURL.setCacheability(ResourceURL.PAGE);
+ fail();
+ }
+ catch (IllegalStateException ignore)
+ {
+ }
+ assertEquals(ResourceURL.PORTLET, resourceURL.getCacheability());
+
+ //
+ resourceURL.setCacheability(ResourceURL.PORTLET);
+ assertEquals(ResourceURL.PORTLET, resourceURL.getCacheability());
+
+ //
+ return new InvokeGetResponse(resourceURL.toString());
+ }
+ });
+ seq.bindAction(2, UTP2.RESOURCE_JOIN_POINT, new PortletResourceTestAction()
+ {
+ protected DriverResponse run(Portlet portlet, ResourceRequest request,
ResourceResponse response, PortletTestContext context) throws PortletException,
IOException
+ {
+ sendEmptyResponse(response);
+
+ //
+ assertEquals(ResourceURL.PORTLET, request.getCacheability());
+ ResourceURL resourceURL = response.createResourceURL();
+ assertEquals(ResourceURL.PORTLET, resourceURL.getCacheability());
+ resourceURL.setCacheability(ResourceURL.FULL);
+ assertEquals(ResourceURL.FULL, resourceURL.getCacheability());
+ return new InvokeGetResponse(resourceURL.toString());
+ }
+ });
+ seq.bindAction(3, UTP2.RESOURCE_JOIN_POINT, new PortletResourceTestAction()
+ {
+ protected DriverResponse run(Portlet portlet, ResourceRequest request,
ResourceResponse response, PortletTestContext context) throws PortletException,
IOException
+ {
+ sendEmptyResponse(response);
+
+ //
+ assertEquals(ResourceURL.FULL, request.getCacheability());
+
+ //
+ try
+ {
+ response.createActionURL();
+ fail();
+ }
+ catch (IllegalStateException ignore)
+ {
+ }
+
+ //
+ try
+ {
+ response.createRenderURL();
+ fail();
+ }
+ catch (IllegalStateException ignore)
+ {
+ }
+
+ //
+ ResourceURL resourceURL = response.createResourceURL();
+ assertEquals(ResourceURL.FULL, resourceURL.getCacheability());
+
+ //
+ try
+ {
+ resourceURL.setCacheability(ResourceURL.PORTLET);
+ fail();
+ }
+ catch (IllegalStateException ignore)
+ {
+ }
+ assertEquals(ResourceURL.FULL, resourceURL.getCacheability());
+
+ //
+ try
+ {
+ resourceURL.setCacheability(ResourceURL.PAGE);
+ fail();
+ }
+ catch (IllegalStateException ignore)
+ {
+ }
+ assertEquals(ResourceURL.FULL, resourceURL.getCacheability());
+
+ //
+ resourceURL.setCacheability(ResourceURL.FULL);
+ assertEquals(ResourceURL.FULL, resourceURL.getCacheability());
+
+ //
+ return new InvokeGetResponse(resourceURL.toString());
+ }
+ });
+ seq.bindAction(4, UTP2.RESOURCE_JOIN_POINT, new PortletResourceTestAction()
+ {
+ protected DriverResponse run(Portlet portlet, ResourceRequest request,
ResourceResponse response, PortletTestContext context) throws PortletException,
IOException
+ {
+ sendEmptyResponse(response);
+
+ //
+ assertEquals(ResourceURL.FULL, request.getCacheability());
+ ResourceURL resourceURL = response.createResourceURL();
+ assertEquals(ResourceURL.FULL, resourceURL.getCacheability());
+ return new EndTestResponse();
+ }
+ });
+ }
+}
Modified:
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/unit/actions/PortletResourceTestAction.java
===================================================================
---
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/unit/actions/PortletResourceTestAction.java 2008-01-23
16:07:45 UTC (rev 9580)
+++
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/unit/actions/PortletResourceTestAction.java 2008-01-23
16:39:54 UTC (rev 9581)
@@ -35,6 +35,7 @@
import javax.portlet.ResourceRequest;
import javax.portlet.ResourceResponse;
import java.io.IOException;
+import java.io.PrintWriter;
/**
* @author <a href="mailto:boleslaw.dawidowicz@jboss.org">Boleslaw
Dawidowicz</a>
@@ -82,4 +83,11 @@
{
throw new NotYetImplemented();
}
+
+ protected final void sendEmptyResponse(ResourceResponse response) throws IOException
+ {
+ response.setContentType("text/html");
+ PrintWriter writer = response.getWriter();
+ writer.close();
+ }
}
\ No newline at end of file
Modified:
modules/portlet/trunk/test/src/test/resources/jsr286/tck/resourceserving-war/WEB-INF/portlet.xml
===================================================================
---
modules/portlet/trunk/test/src/test/resources/jsr286/tck/resourceserving-war/WEB-INF/portlet.xml 2008-01-23
16:07:45 UTC (rev 9580)
+++
modules/portlet/trunk/test/src/test/resources/jsr286/tck/resourceserving-war/WEB-INF/portlet.xml 2008-01-23
16:39:54 UTC (rev 9581)
@@ -35,4 +35,12 @@
</supports>
</portlet>
+ <portlet>
+ <portlet-name>UniversalTestPortletB</portlet-name>
+
<portlet-class>org.jboss.portal.test.portlet.framework.UTP2</portlet-class>
+ <supports>
+ <mime-type>text/html</mime-type>
+ </supports>
+ </portlet>
+
</portlet-app>