Author: julien(a)jboss.com
Date: 2008-01-31 04:39:40 -0500 (Thu, 31 Jan 2008)
New Revision: 9676
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/DispatchedHttpServletRequest.java
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/tck/dispatcher/DispatchedContainerAttributesTestCase.java
Log:
- test case for getAttributeNames now
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-31
09:20:20 UTC (rev 9675)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/DispatchedHttpServletRequest.java 2008-01-31
09:39:40 UTC (rev 9676)
@@ -44,7 +44,6 @@
import java.util.Locale;
import java.util.Map;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.LinkedList;
import java.util.Set;
import java.util.HashSet;
@@ -250,16 +249,19 @@
public final Object getAttribute(String s)
{
- Map<String, String> containerAttributes =
containerAttributesStack.getLast();
- if (containerAttributes.containsKey(s))
+ if (s != null)
{
- return containerAttributes.get(s);
- }
+ Map<String, String> containerAttributes =
containerAttributesStack.getLast();
+ if (containerAttributes.containsKey(s))
+ {
+ return containerAttributes.get(s);
+ }
- //
- if (ALL_CONTAINER_ATTRIBUTES.contains(s))
- {
- return null;
+ //
+ if (ALL_CONTAINER_ATTRIBUTES.contains(s))
+ {
+ return null;
+ }
}
//
@@ -268,52 +270,25 @@
public final Enumeration getAttributeNames()
{
- final Map<String, String> containerAttributes =
containerAttributesStack.getLast();
- final Iterator<String> i =
preq.getAttributes().getAttributeNames((HttpServletRequest)getRequest());
+ Set<String> names =
Tools.toSet(preq.getAttributes().getAttributeNames(null));
- //
- return new Enumeration()
+ // Add super stuff that is not reserved
+ for (Enumeration e = super.getAttributeNames();e.hasMoreElements();)
{
- // The next element
- String next;
+ String name = (String)e.nextElement();
+ //
+ if (!ALL_CONTAINER_ATTRIBUTES.contains(name))
{
- next();
+ names.add(name);
}
+ }
- public boolean hasMoreElements()
- {
- return next != null;
- }
+ //
+ names.addAll(containerAttributesStack.getLast().keySet());
- public Object nextElement()
- {
- Object next = this.next;
- next();
- return next;
- }
-
- private void next()
- {
- next = null;
- while (true)
- {
- if (i.hasNext())
- {
- String next = i.next();
- if (!containerAttributes.containsKey(next))
- {
- this.next = next;
- break;
- }
- }
- else
- {
- break;
- }
- }
- }
- };
+ //
+ return Collections.enumeration(names);
}
public final void setAttribute(String s, Object o)
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-31
09:20:20 UTC (rev 9675)
+++
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/tck/dispatcher/DispatchedContainerAttributesTestCase.java 2008-01-31
09:39:40 UTC (rev 9676)
@@ -33,9 +33,11 @@
import org.jboss.portal.test.portlet.framework.UTP1;
import org.jboss.portal.test.portlet.framework.UTS1;
import org.jboss.portal.portlet.LifeCyclePhase;
+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;
+import static org.jboss.unit.api.Assert.fail;
import org.jboss.unit.remote.driver.handler.http.response.InvokeGetResponse;
import javax.portlet.Portlet;
@@ -58,6 +60,8 @@
import java.io.IOException;
import java.util.Map;
import java.util.HashMap;
+import java.util.Set;
+import java.util.HashSet;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -169,18 +173,41 @@
{
PortletContext portletContext =
((AbstractUniversalTestPortlet)portlet).getPortletContext();
dispatch(request, response, portletContext);
- assertMap(expectedAttributes, collectedAttributes);
- assertMap(expectedInfos, collectedInfos);
- }
- private void assertMap(Map<String, String> expectedMap, Map<String,
Object> actualMap)
- {
- assertEquals(expectedMap.keySet(), actualMap.keySet());
- for (Map.Entry<String, String> entry : expectedMap.entrySet())
+ //
+ for (Map.Entry<String, String> entry : expectedAttributes.entrySet())
{
+ String name = entry.getKey();
+ String expectedValue = entry.getValue();
+
+ //
+ if (expectedValue == null)
+ {
+ if (collectedAttributes.containsKey(name))
+ {
+ fail("The actual map " + collectedAttributes + " should not
contain the name " + name);
+ }
+ }
+ else
+ {
+ if (collectedAttributes.containsKey(name))
+ {
+ Object collectedValue = collectedAttributes.get(name);
+ assertEquals("Was expecting a value " + expectedValue + "
for key " + name + " but had instead " + collectedValue, expectedValue,
collectedValue);
+ }
+ else
+ {
+ fail("The actual map " + collectedAttributes + " should
contain the name " + name);
+ }
+ }
+ }
+
+ //
+ for (Map.Entry<String, String> entry : expectedInfos.entrySet())
+ {
String key = entry.getKey();
String expectedValue = entry.getValue();
- Object collectedValue = actualMap.get(key);
+ Object collectedValue = collectedInfos.get(key);
assertEquals("Was expecting a value " + expectedValue + " for key
" + key + " but had instead " + collectedValue, expectedValue,
collectedValue);
}
}
@@ -189,11 +216,15 @@
{
protected DriverResponse run(Servlet servlet, HttpServletRequest request,
HttpServletResponse response, PortletTestContext context) throws ServletException,
IOException
{
+ Set attributeNames = Tools.toSet(request.getAttributeNames());
collectedAttributes.clear();
- for (String key : expectedAttributes.keySet())
+ for (String name : expectedAttributes.keySet())
{
- Object value = request.getAttribute(key);
- collectedAttributes.put(key, value);
+ if (attributeNames.contains(name))
+ {
+ Object value = request.getAttribute(name);
+ collectedAttributes.put(name, value);
+ }
}
//
Show replies by date