Author: julien(a)jboss.com
Date: 2008-02-27 05:54:18 -0500 (Wed, 27 Feb 2008)
New Revision: 10136
Added:
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr168/ext/session/PortletScopedAttributesAreApplicationScopedAttributesTestCase.java
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/PortletSessionImpl.java
Log:
- fix a bug in portlet session and add test case for it
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-02-27
10:26:26 UTC (rev 10135)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/PortletSessionImpl.java 2008-02-27
10:54:18 UTC (rev 10136)
@@ -83,49 +83,50 @@
public Enumeration<String> getAttributeNames(int scope)
{
- final boolean app = scope == APPLICATION_SCOPE;
- return new Enumeration<String>()
+ if (scope == APPLICATION_SCOPE)
{
- private Enumeration e;
- private String next;
-
+ return (Enumeration<String>)session.getAttributeNames();
+ }
+ else
+ {
+ return new Enumeration<String>()
{
- e = session.getAttributeNames();
- next = null;
- next();
- }
+ private Enumeration e;
+ private String next;
- public boolean hasMoreElements()
- {
- return next != null;
- }
+ {
+ e = session.getAttributeNames();
+ next = null;
+ next();
+ }
- public String nextElement()
- {
- String result = next;
- next = null;
- next();
- return result;
- }
+ public boolean hasMoreElements()
+ {
+ return next != null;
+ }
- private void next()
- {
- while (e.hasMoreElements())
+ public String nextElement()
{
- String attribute = (String)e.nextElement();
- if (app && !attribute.startsWith("javax.portlet."))
+ String result = next;
+ next = null;
+ next();
+ return result;
+ }
+
+ private void next()
+ {
+ while (e.hasMoreElements())
{
- next = attribute;
- break;
+ String attribute = (String)e.nextElement();
+ if (attribute.startsWith(prefix))
+ {
+ next = attribute.substring(prefix.length());
+ break;
+ }
}
- else if (!app && attribute.startsWith(prefix))
- {
- next = attribute.substring(prefix.length());
- break;
- }
}
- }
- };
+ };
+ }
}
public long getCreationTime()
Added:
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr168/ext/session/PortletScopedAttributesAreApplicationScopedAttributesTestCase.java
===================================================================
---
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr168/ext/session/PortletScopedAttributesAreApplicationScopedAttributesTestCase.java
(rev 0)
+++
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr168/ext/session/PortletScopedAttributesAreApplicationScopedAttributesTestCase.java 2008-02-27
10:54:18 UTC (rev 10136)
@@ -0,0 +1,72 @@
+/******************************************************************************
+ * 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.jsr168.ext.session;
+
+import org.jboss.portal.unit.annotations.TestCase;
+import org.jboss.portal.unit.PortletTestCase;
+import org.jboss.portal.unit.PortletTestContext;
+import org.jboss.portal.unit.actions.PortletRenderTestAction;
+import org.jboss.portal.test.portlet.framework.UTP1;
+import org.jboss.unit.driver.DriverResponse;
+import org.jboss.unit.driver.response.EndTestResponse;
+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.PortletSession;
+import javax.portlet.PortletSessionUtil;
+import java.io.IOException;
+import java.util.Enumeration;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+@TestCase
+public class PortletScopedAttributesAreApplicationScopedAttributesTestCase
+{
+
+ public PortletScopedAttributesAreApplicationScopedAttributesTestCase(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
+ {
+ PortletSession session = request.getPortletSession();
+ session.setAttribute("foo", "bar");
+ Enumeration e = session.getAttributeNames(PortletSession.APPLICATION_SCOPE);
+ assertNotNull(e);
+ assertTrue(e.hasMoreElements());
+ String scopedFoo = (String)e.nextElement();
+ assertNotNull(scopedFoo);
+ assertEquals("foo",
PortletSessionUtil.decodeAttributeName(scopedFoo));
+ assertEquals(PortletSession.PORTLET_SCOPE,
PortletSessionUtil.decodeScope(scopedFoo));
+ Object bar = session.getAttribute(scopedFoo,
PortletSession.APPLICATION_SCOPE);
+ assertEquals("bar", bar);
+ return new EndTestResponse();
+ }
+ });
+ }
+}