Author: julien(a)jboss.com
Date: 2008-06-27 10:53:01 -0400 (Fri, 27 Jun 2008)
New Revision: 11172
Added:
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/ext/portletmode/
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/ext/portletmode/PortletModeTestCase.java
modules/portlet/trunk/test/src/test/resources/jsr286/ext/portletmode-war/
modules/portlet/trunk/test/src/test/resources/jsr286/ext/portletmode-war/WEB-INF/
modules/portlet/trunk/test/src/test/resources/jsr286/ext/portletmode-war/WEB-INF/portlet.xml
modules/portlet/trunk/test/src/test/resources/jsr286/ext/portletmode-war/WEB-INF/web.xml
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/PortletRequestImpl.java
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/unit/Assertion.java
modules/portlet/trunk/test/src/test/build.xml
modules/portlet/trunk/test/src/test/resources/jsr286/ext/portletrequests-war/WEB-INF/portlet.xml
modules/portlet/trunk/test/src/test/resources/test/remote-jboss-unit.xml
Log:
test case for custom portlet modes
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-06-27
14:48:49 UTC (rev 11171)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/PortletRequestImpl.java 2008-06-27
14:53:01 UTC (rev 11172)
@@ -46,6 +46,7 @@
import org.jboss.portal.portlet.state.PropertyContext;
import org.jboss.portal.portlet.info.CapabilitiesInfo;
import org.jboss.portal.portlet.info.ModeInfo;
+import org.jboss.portal.portlet.info.PortletManagedModeInfo;
import org.jboss.portal.Mode;
import javax.portlet.PortalContext;
@@ -580,6 +581,9 @@
// Get content type
ContentInfo si = invocation.getContext().getMarkupInfo();
+ //
+ org.jboss.portal.portlet.spi.PortalContext portalContext
=invocation.getPortalContext();
+
// Get the modes for this content type
CapabilitiesInfo capabilities = container.getInfo().getCapabilities();
@@ -587,7 +591,13 @@
Set<Mode> modes = new HashSet<Mode>();
for (ModeInfo modeInfo : capabilities.getModes(si.getMediaType()))
{
- modes.add(modeInfo.getMode());
+ Mode mode = modeInfo.getMode();
+
+ //
+ if (modeInfo instanceof PortletManagedModeInfo ||
portalContext.getModes().contains(mode))
+ {
+ modes.add(mode);
+ }
}
//
Added:
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/ext/portletmode/PortletModeTestCase.java
===================================================================
---
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/ext/portletmode/PortletModeTestCase.java
(rev 0)
+++
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/ext/portletmode/PortletModeTestCase.java 2008-06-27
14:53:01 UTC (rev 11172)
@@ -0,0 +1,238 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2008, 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.ext.portletmode;
+
+import org.jboss.portal.unit.PortletTestCase;
+import org.jboss.portal.unit.PortletTestContext;
+import org.jboss.portal.unit.Assertion;
+import org.jboss.portal.unit.annotations.TestCase;
+import org.jboss.portal.unit.actions.PortletRenderTestAction;
+import org.jboss.portal.unit.actions.PortletActionTestAction;
+import org.jboss.portal.test.portlet.framework.UTP1;
+import org.jboss.portal.common.util.Tools;
+import org.jboss.unit.driver.DriverResponse;
+import org.jboss.unit.driver.response.EndTestResponse;
+
+import javax.portlet.Portlet;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.portlet.PortletException;
+import javax.portlet.PortletMode;
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.PortletURL;
+import javax.portlet.PortletModeException;
+import javax.portlet.PortletRequest;
+import java.io.IOException;
+import java.util.List;
+
+import static org.jboss.unit.api.Assert.*;
+import org.jboss.unit.remote.driver.handler.http.response.InvokeGetResponse;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+(a)TestCase({Assertion.EXT_PORTLET_MODE_1})
+public class PortletModeTestCase
+{
+
+ /** . */
+ private static final PortletMode CUSTOM_PORTAL = new
PortletMode("CUSTOM_PORTAL");
+
+ /** . */
+ private static final PortletMode CUSTOM_PORTLET = new
PortletMode("CUSTOM_PORTLET");
+
+ /** . */
+ private static final PortletMode NON_EXISTING = new
PortletMode("NON_EXISTING");
+
+ /** . */
+ private static final List<PortletMode> legalModes =
Tools.toList(PortletMode.VIEW, PortletMode.HELP, CUSTOM_PORTLET);
+
+ /** . */
+ private static final List<PortletMode> illegalModes =
Tools.toList(PortletMode.EDIT, CUSTOM_PORTAL, NON_EXISTING);
+
+ public PortletModeTestCase(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
+ {
+ assertEquals(PortletMode.VIEW, request.getPortletMode());
+
+ //
+ testRequest(request, legalModes, illegalModes);
+
+ //
+ testURL(response.createActionURL(), legalModes, illegalModes);
+ testURL(response.createRenderURL(), legalModes, illegalModes);
+
+ //
+ PortletURL url = response.createActionURL();
+ url.setPortletMode(PortletMode.HELP);
+ return new InvokeGetResponse(url.toString());
+ }
+ });
+ seq.bindAction(1, UTP1.ACTION_JOIN_POINT, new PortletActionTestAction()
+ {
+ protected void run(Portlet portlet, ActionRequest request, ActionResponse
response, PortletTestContext context) throws PortletException, IOException
+ {
+ assertEquals(PortletMode.HELP, request.getPortletMode());
+
+ //
+ testRequest(request, legalModes, illegalModes);
+
+ //
+ testResponse(response, legalModes, illegalModes);
+
+ //
+ response.setPortletMode(PortletMode.HELP);
+ }
+ });
+ seq.bindAction(1, UTP1.RENDER_JOIN_POINT, new PortletRenderTestAction()
+ {
+ protected DriverResponse run(Portlet portlet, RenderRequest request,
RenderResponse response, PortletTestContext context) throws PortletException, IOException
+ {
+ assertEquals(PortletMode.HELP, request.getPortletMode());
+
+ //
+ testRequest(request, legalModes, illegalModes);
+
+ //
+ testURL(response.createActionURL(), legalModes, illegalModes);
+ testURL(response.createRenderURL(), legalModes, illegalModes);
+
+ //
+ PortletURL url = response.createActionURL();
+ url.setPortletMode(CUSTOM_PORTLET);
+ return new InvokeGetResponse(url.toString());
+ }
+ });
+ seq.bindAction(2, UTP1.ACTION_JOIN_POINT, new PortletActionTestAction()
+ {
+ protected void run(Portlet portlet, ActionRequest request, ActionResponse
response, PortletTestContext context) throws PortletException, IOException
+ {
+ assertEquals(CUSTOM_PORTLET, request.getPortletMode());
+
+ //
+ testRequest(request, legalModes, illegalModes);
+
+ //
+ testResponse(response, legalModes, illegalModes);
+
+ //
+ response.setPortletMode(CUSTOM_PORTLET);
+ }
+ });
+ seq.bindAction(2, UTP1.RENDER_JOIN_POINT, new PortletRenderTestAction()
+ {
+ protected DriverResponse run(Portlet portlet, RenderRequest request,
RenderResponse response, PortletTestContext context) throws PortletException, IOException
+ {
+ assertEquals(CUSTOM_PORTLET, request.getPortletMode());
+
+ //
+ testRequest(request, legalModes, illegalModes);
+
+ //
+ testURL(response.createActionURL(), legalModes, illegalModes);
+ testURL(response.createRenderURL(), legalModes, illegalModes);
+
+ //
+ return new EndTestResponse();
+ }
+ });
+ }
+
+ private void testURL(
+ PortletURL url,
+ List<PortletMode> legalModes,
+ List<PortletMode> illegalModes)
+ {
+ for (PortletMode mode : legalModes)
+ {
+ try
+ {
+ url.setPortletMode(mode);
+ }
+ catch (PortletModeException expected)
+ {
+ fail("Was not expecting a portlet mode exception");
+ }
+ }
+ for (PortletMode mode : illegalModes)
+ {
+ try
+ {
+ url.setPortletMode(mode);
+ fail("Was expecting a portlet mode exception");
+ }
+ catch (PortletModeException expected)
+ {
+ }
+ }
+ }
+
+ private void testResponse(
+ ActionResponse response,
+ List<PortletMode> legalModes,
+ List<PortletMode> illegalModes)
+ {
+ for (PortletMode mode : legalModes)
+ {
+ try
+ {
+ response.setPortletMode(mode);
+ }
+ catch (PortletModeException expected)
+ {
+ fail("Was not expecting a portlet mode exception");
+ }
+ }
+ for (PortletMode mode : illegalModes)
+ {
+ try
+ {
+ response.setPortletMode(mode);
+ fail("Was expecting a portlet mode exception");
+ }
+ catch (PortletModeException expected)
+ {
+ }
+ }
+ }
+
+ private void testRequest(
+ PortletRequest url,
+ List<PortletMode> legalModes,
+ List<PortletMode> illegalModes)
+ {
+ for (PortletMode mode : legalModes)
+ {
+ assertTrue(url.isPortletModeAllowed(mode));
+ }
+ for (PortletMode mode : illegalModes)
+ {
+ assertFalse(url.isPortletModeAllowed(mode));
+ }
+ }
+}
Modified:
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/unit/Assertion.java
===================================================================
---
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/unit/Assertion.java 2008-06-27
14:48:49 UTC (rev 11171)
+++
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/unit/Assertion.java 2008-06-27
14:53:01 UTC (rev 11172)
@@ -1899,6 +1899,8 @@
" If a resource parameter is set that has the same name as a render parameter,
the render" +
" parameter must be the last entry in the parameter value array."),
+ EXT_PORTLET_MODE_1(new EXT("PortletMode"), "Test custom portlet modes
wether they are portal or portlet managed."),
+
EXT_PORTLET_RESPONSES_1(new EXT("PortletResponse"), "Test that
character encoding is ignored as specified by the spec in PLT.12.3.1"),
EXT_PORTLET_RESPONSES_2(new EXT("PortletResponse"), "Not setting the
content type before getting a stream will use the content type defined" +
" by the portlet request response content type."),
Modified: modules/portlet/trunk/test/src/test/build.xml
===================================================================
--- modules/portlet/trunk/test/src/test/build.xml 2008-06-27 14:48:49 UTC (rev 11171)
+++ modules/portlet/trunk/test/src/test/build.xml 2008-06-27 14:53:01 UTC (rev 11172)
@@ -16,8 +16,8 @@
<antcall target="package-tests"/>
- <!--<antcall target="tests.call.single"/>-->
- <!--<antcall target="tests.call.all"/>-->
+ <antcall target="tests.call.single"/>
+ <antcall target="tests.call.all"/>
</target>
@@ -389,6 +389,7 @@
<package-jsr286-ext-test test="portletinterface"/>
<package-jsr286-ext-test test="event"/>
<package-jsr286-ext-test test="eventsupport"/>
+ <package-jsr286-ext-test test="portletmode"/>
<!-- -->
<jar jarfile="${test.temp.lib}/portlet-test-lib.jar">
Added:
modules/portlet/trunk/test/src/test/resources/jsr286/ext/portletmode-war/WEB-INF/portlet.xml
===================================================================
---
modules/portlet/trunk/test/src/test/resources/jsr286/ext/portletmode-war/WEB-INF/portlet.xml
(rev 0)
+++
modules/portlet/trunk/test/src/test/resources/jsr286/ext/portletmode-war/WEB-INF/portlet.xml 2008-06-27
14:53:01 UTC (rev 11172)
@@ -0,0 +1,51 @@
+<?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_2_0.xsd"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2...
http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
+ version="2.0">
+
+ <portlet>
+ <portlet-name>UniversalTestPortletA</portlet-name>
+
<portlet-class>org.jboss.portal.test.portlet.framework.UTP1</portlet-class>
+ <supports>
+ <mime-type>text/html</mime-type>
+ <portlet-mode>VIEW</portlet-mode>
+ <portlet-mode>HELP</portlet-mode>
+ <portlet-mode>CUSTOM_PORTAL</portlet-mode>
+ <portlet-mode>CUSTOM_PORTLET</portlet-mode>
+ </supports>
+ </portlet>
+
+ <custom-portlet-mode>
+ <portlet-mode>CUSTOM_PORTAL</portlet-mode>
+ </custom-portlet-mode>
+
+ <custom-portlet-mode>
+ <portlet-mode>CUSTOM_PORTLET</portlet-mode>
+ <portal-managed>false</portal-managed>
+ </custom-portlet-mode>
+
+</portlet-app>
Added:
modules/portlet/trunk/test/src/test/resources/jsr286/ext/portletmode-war/WEB-INF/web.xml
===================================================================
---
modules/portlet/trunk/test/src/test/resources/jsr286/ext/portletmode-war/WEB-INF/web.xml
(rev 0)
+++
modules/portlet/trunk/test/src/test/resources/jsr286/ext/portletmode-war/WEB-INF/web.xml 2008-06-27
14:53:01 UTC (rev 11172)
@@ -0,0 +1,32 @@
+<?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>
+</web-app>
Modified:
modules/portlet/trunk/test/src/test/resources/jsr286/ext/portletrequests-war/WEB-INF/portlet.xml
===================================================================
---
modules/portlet/trunk/test/src/test/resources/jsr286/ext/portletrequests-war/WEB-INF/portlet.xml 2008-06-27
14:48:49 UTC (rev 11171)
+++
modules/portlet/trunk/test/src/test/resources/jsr286/ext/portletrequests-war/WEB-INF/portlet.xml 2008-06-27
14:53:01 UTC (rev 11172)
@@ -90,6 +90,15 @@
</supported-publishing-event>
</portlet>
+ <custom-portlet-mode>
+ <portlet-mode>CUSTOM_PORTAL</portlet-mode>
+ </custom-portlet-mode>
+
+ <custom-portlet-mode>
+ <portlet-mode>CUSTOM_PORTLET</portlet-mode>
+ <portal-managed>false</portal-managed>
+ </custom-portlet-mode>
+
<event-definition>
<name>Event</name>
</event-definition>
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-06-27
14:48:49 UTC (rev 11171)
+++ modules/portlet/trunk/test/src/test/resources/test/remote-jboss-unit.xml 2008-06-27
14:53:01 UTC (rev 11172)
@@ -235,6 +235,10 @@
<class
name="org.jboss.unit.remote.driver.RemoteTestDriverClient"/>
<property name="archiveId"
value="test-jsr286-ext-event.war"/>
</generic>
+ <generic>
+ <class
name="org.jboss.unit.remote.driver.RemoteTestDriverClient"/>
+ <property name="archiveId"
value="test-jsr286-ext-portletmode.war"/>
+ </generic>
<!--Misc Tests-->
<!--