dev@javaserverfaces.java.net

[REVIEW] Fix for CR 6241351

From: Ryan Lubke <Ryan.Lubke_at_Sun.COM>
Date: Fri, 22 Jul 2005 11:07:59 -0700

Fix for CR 6241351. Ensure Collections and their associated Iterators
returned by entrySet(), keySet(), values()
honor Map contract (where it makes sense) so that remove of elements
from Collection or Iterator results in the value
being removed from the underlying map and thus from the underlying
object the Maps represent.


SECTION: Modified Files
----------------------------
M src/com/sun/faces/context/ExternalContextImpl.java
  - Added custom Set/Collection/Iterator classes to support the fix for
    CR 6241351. Only the Application, Session, and Request map
    and their associated Sets/Collections/Iterators have support
    for deletion of key/values from the underlying objects. All other
    maps will wrap the Collections returned by entrySet(), keySet(),
values()
    with the appropiate call to Collections.unmodifiable().
M test/com/sun/faces/context/TestExternalContextImpl.java
  - Enhanced existing tests to ensure this functionality works
  - uncommented CookieMap test

SECTION: Diffs
----------------------------
Index: src/com/sun/faces/context/ExternalContextImpl.java
===================================================================
RCS file:
/cvs/javaserverfaces-sources/jsf-ri/src/com/sun/faces/context/ExternalContextImpl.java,v
retrieving revision 1.33
diff -u -r1.33 ExternalContextImpl.java
--- src/com/sun/faces/context/ExternalContextImpl.java 18 Jul 2005
22:49:02 -0000 1.33
+++ src/com/sun/faces/context/ExternalContextImpl.java 22 Jul 2005
17:40:32 -0000
@@ -17,11 +17,14 @@
 import java.util.Collections;
 import java.util.Enumeration;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
+import java.util.AbstractSet;
+import java.util.NoSuchElementException;
+import java.util.AbstractCollection;
+import java.util.Collection;
 
 import javax.faces.FacesException;
 import javax.faces.context.ExternalContext;
@@ -148,8 +151,9 @@
 
 
     public Map getSessionMap() {
- if (sessionMap == null)
+ if (sessionMap == null) {
             sessionMap = new SessionMap((HttpServletRequest) request);
+ }
         return sessionMap;
     }
 
@@ -219,7 +223,7 @@
     public Iterator getRequestParameterNames() {
         final Enumeration namEnum = request.getParameterNames();
 
- Iterator result = new Iterator() {
+ return new Iterator() {
             public boolean hasNext() {
                 return namEnum.hasMoreElements();
             }
@@ -234,8 +238,6 @@
                 throw new UnsupportedOperationException();
             }
         };
-
- return result;
     }
 
 
@@ -270,11 +272,11 @@
 
      
     public String getRequestContentType() {
- return (((HttpServletRequest) request).getContentType());
+ return (request.getContentType());
     }
 
     public String getResponseContentType() {
- return (((HttpServletResponse) response).getContentType());
+ return (response.getContentType());
     }
 
     /**
@@ -297,7 +299,7 @@
 
 
     public URL getResource(String path) {
- URL url = null;
+ URL url;
         try {
             url = servletContext.getResource(path);
         } catch (MalformedURLException e) {
@@ -421,29 +423,223 @@
         }
 
     }
-
-
 }
 
 abstract class BaseContextMap extends AbstractMap {
 
- // Unsupported by all Maps.
+ private Set entrySet;
+ private Set keySet;
+ private Collection values;
+
+ // Supported by maps if overridden
     public void clear() {
         throw new UnsupportedOperationException();
     }
 
 
- // Unsupported by all Maps.
+ // Supported by maps if overridden
     public void putAll(Map t) {
         throw new UnsupportedOperationException();
     }
 
+ public Set entrySet() {
+ if (entrySet == null) {
+ entrySet = new EntrySet();
+ }
+
+ return entrySet;
+ }
+
+ public Set keySet() {
+ if (keySet == null) {
+ keySet = new KeySet();
+ }
+
+ return keySet;
+ }
+
+ public Collection values() {
+ if (values == null) {
+ values = new ValueCollection();
+ }
+
+ return values;
+ }
+
 
     // Supported by maps if overridden
     public Object remove(Object key) {
         throw new UnsupportedOperationException();
     }
 
+ protected boolean removeKey(String key) {
+ return (this.remove(key) != null);
+ }
+
+ protected boolean removeValue(Object value) {
+ boolean valueRemoved = false;
+ if (value == null) {
+ return false;
+ }
+ System.out.println("VALUE IS: " + value);
+ if (containsValue(value)) {
+ System.out.println("MAP CONTENTS: " + this.toString());
+ for (Iterator i = entrySet().iterator(); i.hasNext(); ) {
+ Map.Entry e = (Map.Entry) i.next();
+ if (value.equals(e.getValue())) {
+ System.out.println("REMOVING VALUE FOR KEY: " +
e.getKey());
+ valueRemoved = (remove(e.getKey()) != null);
+ }
+ }
+ }
+ return valueRemoved;
+ }
+
+ protected abstract Iterator getEntryIterator();
+ protected abstract Iterator getKeyIterator();
+ protected abstract Iterator getValueIterator();
+
+ abstract class BaseSet extends AbstractSet {
+
+ public int size() {
+ int size = 0;
+ for (Iterator i = iterator(); i.hasNext(); size++) {
+ i.next();
+ }
+ return size;
+ }
+
+ }
+
+ class EntrySet extends BaseSet {
+
+ public Iterator iterator() {
+ return getEntryIterator();
+ }
+
+ public boolean remove(Object o) {
+ if (!(o instanceof Map.Entry)) {
+ return false;
+ }
+ return removeKey((String) ((Map.Entry) o).getKey());
+ }
+
+ }
+
+ class KeySet extends BaseSet {
+
+ public Iterator iterator() {
+ return getKeyIterator();
+ }
+
+ public boolean remove(Object o) {
+ if (!(o instanceof String)) {
+ return false;
+ }
+ return removeKey((String) o);
+ }
+ }
+
+ class ValueCollection extends AbstractCollection {
+
+ public int size() {
+ int size = 0;
+ for (Iterator i = iterator(); i.hasNext(); size++) {
+ i.next();
+ }
+ return size;
+ }
+
+ public Iterator iterator() {
+ return getValueIterator();
+ }
+
+ public boolean remove(Object o) {
+ return removeValue(o);
+ }
+ }
+
+ abstract class BaseIterator implements Iterator {
+
+ protected Enumeration e;
+ protected String currentKey;
+ protected boolean removeCalled = false;
+
+ BaseIterator(Enumeration e) {
+ this.e = e;
+ }
+
+ public boolean hasNext() {
+ return e.hasMoreElements();
+ }
+ }
+
+ class EntryIterator extends BaseIterator {
+
+ EntryIterator(Enumeration e) {
+ super(e);
+ }
+
+ public void remove() {
+ if (currentKey != null && !removeCalled) {
+ removeCalled = true;
+ removeKey(currentKey);
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public Object next() {
+ removeCalled = false;
+ currentKey = (String) e.nextElement();
+ return new Entry(currentKey, get(currentKey));
+ }
+ }
+
+ class KeyIterator extends BaseIterator {
+
+ KeyIterator(Enumeration e) {
+ super(e);
+ }
+
+ public void remove() {
+ if (currentKey != null && !removeCalled) {
+ removeCalled = true;
+ removeKey(currentKey);
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public Object next() {
+ removeCalled = false;
+ currentKey = (String) e.nextElement();
+ return currentKey;
+ }
+ }
+
+ class ValueIterator extends BaseIterator {
+
+ ValueIterator(Enumeration e) {
+ super(e);
+ }
+
+ public void remove() {
+ if (currentKey != null && !removeCalled) {
+ removeCalled = true;
+ removeValue(get(currentKey));
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public Object next() {
+ removeCalled = false;
+ currentKey = (String) e.nextElement();
+ return get(currentKey);
+ }
+ }
+
 
     static class Entry implements Map.Entry {
 
@@ -481,8 +677,9 @@
 
 
         public boolean equals(Object obj) {
- if (obj == null || !(obj instanceof Map.Entry))
+ if (obj == null || !(obj instanceof Map.Entry)) {
                 return false;
+ }
 
             Map.Entry input = (Map.Entry) obj;
             Object inputKey = input.getKey();
@@ -504,11 +701,25 @@
 
     private final ServletContext servletContext;
 
-
     ApplicationMap(ServletContext servletContext) {
         this.servletContext = servletContext;
     }
 
+ public void clear() {
+ for (Enumeration e = servletContext.getAttributeNames();
+ e.hasMoreElements(); ) {
+ servletContext.removeAttribute((String) e.nextElement());
+ }
+ }
+
+ // Supported by maps if overridden
+ public void putAll(Map t) {
+ for (Iterator i = t.entrySet().iterator(); i.hasNext(); ) {
+ Map.Entry entry = (Map.Entry) i.next();
+ servletContext.setAttribute((String) entry.getKey(),
+ entry.getValue());
+ }
+ }
 
     public Object get(Object key) {
         if (key == null) {
@@ -540,20 +751,10 @@
     }
 
 
- public Set entrySet() {
- Set entries = new HashSet();
- for (Enumeration e = servletContext.getAttributeNames();
- e.hasMoreElements();) {
- String key = (String) e.nextElement();
- entries.add(new Entry(key, servletContext.getAttribute(key)));
- }
- return entries;
- }
-
-
     public boolean equals(Object obj) {
- if (obj == null || !(obj instanceof ApplicationMap))
+ if (obj == null || !(obj instanceof ApplicationMap)) {
             return false;
+ }
         return super.equals(obj);
     }
 
@@ -566,17 +767,49 @@
         return hashCode;
     }
 
+ // --------------------------------------------- Methods from
BaseContextMap
+
+
+
+ protected Iterator getEntryIterator() {
+ return new EntryIterator(servletContext.getAttributeNames());
+ }
+
+ protected Iterator getKeyIterator() {
+ return new KeyIterator(servletContext.getAttributeNames());
+ }
+
+ protected Iterator getValueIterator() {
+ return new ValueIterator(servletContext.getAttributeNames());
+ }
+
 } // END ApplicationMap
 
 class SessionMap extends BaseContextMap {
 
     private final HttpServletRequest request;
 
-
     SessionMap(HttpServletRequest request) {
         this.request = request;
     }
 
+ public void clear() {
+ HttpSession session = getSession();
+ for (Enumeration e = getSession().getAttributeNames();
+ e.hasMoreElements(); ) {
+ session.removeAttribute((String) e.nextElement());
+ }
+ }
+
+ // Supported by maps if overridden
+ public void putAll(Map t) {
+ HttpSession session = getSession();
+ for (Iterator i = t.entrySet().iterator(); i.hasNext(); ) {
+ Map.Entry entry = (Map.Entry) i.next();
+ session.setAttribute((String) entry.getKey(),
+ entry.getValue());
+ }
+ }
 
     public Object get(Object key) {
         if (key == null) {
@@ -609,22 +842,10 @@
         return (result);
     }
 
-
- public Set entrySet() {
- Set entries = new HashSet();
- HttpSession session = getSession();
- for (Enumeration e = session.getAttributeNames();
- e.hasMoreElements();) {
- String key = (String) e.nextElement();
- entries.add(new Entry(key, session.getAttribute(key)));
- }
- return entries;
- }
-
-
     public boolean equals(Object obj) {
- if (obj == null || !(obj instanceof SessionMap))
+ if (obj == null || !(obj instanceof SessionMap)) {
             return false;
+ }
         return super.equals(obj);
     }
 
@@ -641,6 +862,20 @@
         return hashCode;
     }
 
+ // --------------------------------------------- Methods from
BaseContextMap
+
+ protected Iterator getEntryIterator() {
+ return new EntryIterator(getSession().getAttributeNames());
+ }
+
+ protected Iterator getKeyIterator() {
+ return new KeyIterator(getSession().getAttributeNames());
+ }
+
+ protected Iterator getValueIterator() {
+ return new ValueIterator(getSession().getAttributeNames());
+ }
+
 } // END SessionMap
 
 class RequestMap extends BaseContextMap {
@@ -652,6 +887,21 @@
         this.request = request;
     }
 
+ public void clear() {
+ for (Enumeration e = request.getAttributeNames();
+ e.hasMoreElements(); ) {
+ request.removeAttribute((String) e.nextElement());
+ }
+ }
+
+ // Supported by maps if overridden
+ public void putAll(Map t) {
+ for (Iterator i = t.entrySet().iterator(); i.hasNext(); ) {
+ Map.Entry entry = (Map.Entry) i.next();
+ request.setAttribute((String) entry.getKey(),
+ entry.getValue());
+ }
+ }
 
     public Object get(Object key) {
         if (key == null) {
@@ -682,21 +932,10 @@
         return (result);
     }
 
-
- public Set entrySet() {
- Set entries = new HashSet();
- for (Enumeration e = request.getAttributeNames();
- e.hasMoreElements();) {
- String key = (String) e.nextElement();
- entries.add(new Entry(key, request.getAttribute(key)));
- }
- return entries;
- }
-
-
     public boolean equals(Object obj) {
- if (obj == null || !(obj instanceof RequestMap))
+ if (obj == null || !(obj instanceof RequestMap)) {
             return false;
+ }
         return super.equals(obj);
     }
 
@@ -708,6 +947,20 @@
         return hashCode;
     }
 
+ // --------------------------------------------- Methods from
BaseContextMap
+
+ protected Iterator getEntryIterator() {
+ return new EntryIterator(request.getAttributeNames());
+ }
+
+ protected Iterator getKeyIterator() {
+ return new KeyIterator(request.getAttributeNames());
+ }
+
+ protected Iterator getValueIterator() {
+ return new ValueIterator(request.getAttributeNames());
+ }
+
 } // END RequestMap
 
 class RequestParameterMap extends BaseContextMap {
@@ -730,17 +983,17 @@
         return request.getParameter(key.toString());
     }
 
-
     public Set entrySet() {
- Set entries = new HashSet();
- for (Enumeration e = request.getParameterNames();
- e.hasMoreElements();) {
- String paramName = (String) e.nextElement();
- entries.add(new Entry(paramName,
request.getParameter(paramName)));
- }
- return entries;
+ return Collections.unmodifiableSet(super.entrySet());
+ }
+
+ public Set keySet() {
+ return Collections.unmodifiableSet(super.keySet());
     }
 
+ public Collection values() {
+ return Collections.unmodifiableCollection(super.values());
+ }
 
     public boolean equals(Object obj) {
         if (obj == null ||
@@ -758,6 +1011,20 @@
         return hashCode;
     }
 
+ // --------------------------------------------- Methods from
BaseContextMap
+
+ protected Iterator getEntryIterator() {
+ return new EntryIterator(request.getParameterNames());
+ }
+
+ protected Iterator getKeyIterator() {
+ return new KeyIterator(request.getParameterNames());
+ }
+
+ protected Iterator getValueIterator() {
+ return new ValueIterator(request.getParameterNames());
+ }
+
 } // END RequestParameterMap
 
 class RequestParameterValuesMap extends BaseContextMap {
@@ -780,18 +1047,17 @@
         return request.getParameterValues(key.toString());
     }
 
-
     public Set entrySet() {
- Set entries = new HashSet();
- for (Enumeration e = request.getParameterNames();
- e.hasMoreElements();) {
- String paramName = (String) e.nextElement();
- entries.add(
- new Entry(paramName,
request.getParameterValues(paramName)));
- }
- return entries;
+ return Collections.unmodifiableSet(super.entrySet());
+ }
+
+ public Set keySet() {
+ return Collections.unmodifiableSet(super.keySet());
     }
 
+ public Collection values() {
+ return Collections.unmodifiableCollection(super.values());
+ }
 
     public boolean equals(Object obj) {
         if (obj == null ||
@@ -809,6 +1075,20 @@
         return hashCode;
     }
 
+ // --------------------------------------------- Methods from
BaseContextMap
+
+ protected Iterator getEntryIterator() {
+ return new EntryIterator(request.getParameterNames());
+ }
+
+ protected Iterator getKeyIterator() {
+ return new KeyIterator(request.getParameterNames());
+ }
+
+ protected Iterator getValueIterator() {
+ return new ValueIterator(request.getParameterNames());
+ }
+
 } // END RequestParameterValuesMap
 
 class RequestHeaderMap extends BaseContextMap {
@@ -831,15 +1111,16 @@
         return (request.getHeader(key.toString()));
     }
 
-
     public Set entrySet() {
- Set entries = new HashSet();
- for (Enumeration e = request.getHeaderNames();
- e.hasMoreElements();) {
- String headerName = (String) e.nextElement();
- entries.add(new Entry(headerName,
request.getHeader(headerName)));
- }
- return entries;
+ return Collections.unmodifiableSet(super.entrySet());
+ }
+
+ public Set keySet() {
+ return Collections.unmodifiableSet(super.keySet());
+ }
+
+ public Collection values() {
+ return Collections.unmodifiableCollection(super.values());
     }
 
 
@@ -859,6 +1140,20 @@
         return hashCode;
     }
 
+ // --------------------------------------------- Methods from
BaseContextMap
+
+ protected Iterator getEntryIterator() {
+ return new EntryIterator(request.getHeaderNames());
+ }
+
+ protected Iterator getKeyIterator() {
+ return new KeyIterator(request.getHeaderNames());
+ }
+
+ protected Iterator getValueIterator() {
+ return new ValueIterator(request.getHeaderNames());
+ }
+
 } // END RequestHeaderMap
 
 class RequestHeaderValuesMap extends BaseContextMap {
@@ -881,17 +1176,17 @@
         return (request).getHeaders(key.toString());
     }
 
-
     public Set entrySet() {
- Set entries = new HashSet();
- for (Enumeration e = request.getHeaderNames();
- e.hasMoreElements();) {
- String headerName = (String) e.nextElement();
- entries.add(new Entry(headerName,
request.getHeaders(headerName)));
- }
- return entries;
+ return Collections.unmodifiableSet(super.entrySet());
     }
 
+ public Set keySet() {
+ return Collections.unmodifiableSet(super.keySet());
+ }
+
+ public Collection values() {
+ return Collections.unmodifiableCollection(super.values());
+ }
 
     public boolean equals(Object obj) {
         if (obj == null ||
@@ -905,8 +1200,9 @@
     // Override of containsValue was necessary as
Enumeration.equals(Enumeration)
     // returned false.
     public boolean containsValue(Object value) {
- if (value == null || !(value instanceof Enumeration))
+ if (value == null || !(value instanceof Enumeration)) {
             return false;
+ }
 
         int valHash = 0;
         int valCount = 0;
@@ -933,8 +1229,9 @@
                 thisHash += thisMap.nextElement().hashCode();
                 thisCount++;
             }
- if (thisCount == valCount && thisHash == valHash)
+ if (thisCount == valCount && thisHash == valHash) {
                 return true;
+ }
         }
         return false;
     }
@@ -956,6 +1253,21 @@
         }
         return hashSum;
     }
+
+ // --------------------------------------------- Methods from
BaseContextMap
+
+ protected Iterator getEntryIterator() {
+ return new EntryIterator(request.getHeaderNames());
+ }
+
+ protected Iterator getKeyIterator() {
+ return new KeyIterator(request.getHeaderNames());
+ }
+
+ protected Iterator getValueIterator() {
+ return new ValueIterator(request.getHeaderNames());
+ }
+
 } // END RequestHeaderValuesMap
 
 class RequestCookieMap extends BaseContextMap {
@@ -994,19 +1306,17 @@
         return result;
     }
 
-
     public Set entrySet() {
- Set entries = new HashSet();
- Cookie[] cookies = request.getCookies();
+ return Collections.unmodifiableSet(super.entrySet());
+ }
 
- if (cookies != null) {
- for (int i = 0; i < cookies.length; i++) {
- entries.add(new Entry(cookies[i].getName(), cookies[i]));
- }
- }
- return entries;
+ public Set keySet() {
+ return Collections.unmodifiableSet(super.keySet());
     }
 
+ public Collection values() {
+ return Collections.unmodifiableCollection(super.values());
+ }
 
     public boolean equals(Object obj) {
         if (obj == null ||
@@ -1024,6 +1334,49 @@
         return hashCode;
     }
 
+ // --------------------------------------------- Methods from
BaseContextMap
+
+
+ protected Iterator getEntryIterator() {
+ return new EntryIterator(
+ new CookieArrayEnumerator(request.getCookies()));
+ }
+
+ protected Iterator getKeyIterator() {
+ return new KeyIterator(
+ new CookieArrayEnumerator(request.getCookies()));
+ }
+
+ protected Iterator getValueIterator() {
+ return new ValueIterator(
+ new CookieArrayEnumerator(request.getCookies()));
+ }
+
+ private static class CookieArrayEnumerator implements Enumeration {
+
+ Cookie[] cookies;
+ int curIndex = -1;
+ int upperBound;
+
+ public CookieArrayEnumerator(Cookie[] cookies) {
+ this.cookies = cookies;
+ upperBound = cookies.length;
+ }
+
+ public boolean hasMoreElements() {
+ return (curIndex + 2 <= upperBound);
+ }
+
+ public Object nextElement() {
+ curIndex++;
+ if (curIndex < upperBound) {
+ return cookies[curIndex].getName();
+ } else {
+ throw new NoSuchElementException();
+ }
+ }
+ }
+
 } // END RequestCookiesMap
 
 class InitParameterMap extends BaseContextMap {
@@ -1047,20 +1400,17 @@
         return servletContext.getInitParameter(keyString);
     }
 
-
     public Set entrySet() {
- Set entries = new HashSet();
+ return Collections.unmodifiableSet(super.entrySet());
+ }
 
- for (Enumeration e = servletContext.getInitParameterNames();
- e.hasMoreElements();) {
- String initParamName = (String) e.nextElement();
- entries.add(new Entry(initParamName,
- servletContext.getInitParameter(
- initParamName)));
- }
- return entries;
+ public Set keySet() {
+ return Collections.unmodifiableSet(super.keySet());
     }
 
+ public Collection values() {
+ return Collections.unmodifiableCollection(super.values());
+ }
 
     public boolean equals(Object obj) {
         if (obj == null ||
@@ -1077,6 +1427,21 @@
         }
         return hashCode;
     }
+
+ // --------------------------------------------- Methods from
BaseContextMap
+
+ protected Iterator getEntryIterator() {
+ return new EntryIterator(servletContext.getInitParameterNames());
+ }
+
+ protected Iterator getKeyIterator() {
+ return new KeyIterator(servletContext.getInitParameterNames());
+ }
+
+ protected Iterator getValueIterator() {
+ return new ValueIterator(servletContext.getInitParameterNames());
+ }
+
 } // END InitParameterMap
 
 
Index: test/com/sun/faces/context/TestExternalContextImpl.java
===================================================================
RCS file:
/cvs/javaserverfaces-sources/jsf-ri/test/com/sun/faces/context/TestExternalContextImpl.java,v
retrieving revision 1.15
diff -u -r1.15 TestExternalContextImpl.java
--- test/com/sun/faces/context/TestExternalContextImpl.java 6 May
2005 22:02:06 -0000 1.15
+++ test/com/sun/faces/context/TestExternalContextImpl.java 22 Jul
2005 17:40:32 -0000
@@ -18,6 +18,7 @@
 import javax.servlet.ServletRequest;
 import javax.servlet.ServletResponse;
 import javax.servlet.http.HttpSession;
+import javax.servlet.http.Cookie;
 
 import java.io.InputStream;
 import java.util.ArrayList;
@@ -29,6 +30,7 @@
 import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
+import java.util.Collection;
 
 /**
  * <B>TestExternalContextImpl</B> is a class ...
@@ -336,6 +338,8 @@
         supported[IS_EMPTY] = true;
         supported[KEY_SET] = true;
         supported[SIZE] = true;
+ supported[PUT_ALL] = true;
+ supported[CLEAR] = true;
 
         testUnsupportedExceptions(applicationMap, supported);
 
@@ -363,6 +367,150 @@
         assertTrue(!applicationMap.equals(null));
         assertTrue(!applicationMap.equals(new HashMap()));
         applicationMap.remove("foo");
+
+ if (applicationMap.isEmpty()) {
+ applicationMap.put("some", "value");
+ }
+ /* Commented out since it appears that certain attributes
+ cannot be removed from the ServletContext when running against
+ glassfish
+ Map cloneMap = new HashMap(applicationMap);
+ applicationMap.clear();
+ assertTrue(applicationMap.isEmpty());
+ applicationMap.putAll(cloneMap);
+ assertTrue(!applicationMap.isEmpty());*/
+
+ // ensure EntrySet operations reflect on the underlying map.
+ applicationMap.put("key1", "value1");
+ Set entrySet = applicationMap.entrySet();
+ for (Iterator i = entrySet.iterator(); i.hasNext(); ) {
+ Map.Entry entry = (Map.Entry) i.next();
+ if ("key1".equals(entry.getKey())) {
+ entrySet.remove(entry);
+ }
+ }
+ assertTrue(applicationMap.get("key1") == null);
+
+ applicationMap.put("key1", "value1");
+
+ entrySet = applicationMap.entrySet();
+ int currentSize = applicationMap.size();
+ ArrayList list = new ArrayList();
+ for (Iterator i = entrySet.iterator(); i.hasNext(); ) {
+ Map.Entry entry = (Map.Entry) i.next();
+ if ("key1".equals(entry.getKey())) {
+ list.add(entry);
+ break;
+ }
+ }
+ entrySet.removeAll(list);
+ assertTrue(applicationMap.size() == (currentSize - 1));
+
+ //Map cloneMap = new HashMap(applicationMap);
+ applicationMap.put("key1", "value1");
+ list = new ArrayList();
+ for (Iterator i = entrySet.iterator(); i.hasNext(); ) {
+ Map.Entry entry = (Map.Entry) i.next();
+ if ("key1".equals(entry.getKey())) {
+ list.add(entry);
+ break;
+ }
+ }
+ /* Commented out since it appears that certain attributes
+ cannot be removed from the ServletContext when running against
+ glassfish
+ assertTrue(entrySet.retainAll(list));
+ assertTrue(applicationMap.size() == 1);
+ applicationMap.clear();
+ applicationMap.putAll(cloneMap); */
+
+ // next validate Iterator.remove goes through to the backing Map.
+ applicationMap.put("key1", "value1");
+ for (Iterator i = applicationMap.entrySet().iterator();
i.hasNext(); ) {
+ Map.Entry entry = (Map.Entry) i.next();
+ if ("key1".equals(entry.getKey())) {
+ i.remove();
+ }
+ }
+ assertTrue(applicationMap.get("key1") == null);
+
+ applicationMap.put("key1", "value1");
+ for (Iterator i = applicationMap.keySet().iterator();
i.hasNext(); ) {
+ String entry = (String) i.next();
+ if ("key1".equals(entry)) {
+ i.remove();
+ }
+ }
+ assertTrue(applicationMap.get("key1") == null);
+
+ applicationMap.put("key1", "value1");
+ applicationMap.put("key2", "value1");
+ for (Iterator i = applicationMap.values().iterator();
i.hasNext(); ) {
+ Object val = i.next();
+ if ("value1".equals(val)) {
+ i.remove();
+ }
+ }
+ assertTrue(applicationMap.get("key1") == null);
+ assertTrue(applicationMap.get("key2") == null);
+
+
+ // ensure IllegalStateException if Iterator isn't properly
positioned
+ Iterator i = applicationMap.entrySet().iterator();
+ try {
+ i.remove();
+ assertTrue(false);
+ } catch (Exception e) {
+ assertTrue(e instanceof IllegalStateException);
+ }
+
+ i = applicationMap.keySet().iterator();
+ try {
+ i.remove();
+ assertTrue(false);
+ } catch (Exception e) {
+ assertTrue(e instanceof IllegalStateException);
+ }
+
+ i = applicationMap.values().iterator();
+ try {
+ i.remove();
+ assertTrue(false);
+ } catch (Exception e) {
+ assertTrue(e instanceof IllegalStateException);
+ }
+
+ // ensure IllegalStateException if Iterator.remove() is called
more than
+ // once per each next() call
+ i = applicationMap.entrySet().iterator();
+ i.next();
+ i.remove();
+ try {
+ i.remove();
+ assertTrue(false);
+ } catch (Exception e) {
+ assertTrue(e instanceof IllegalStateException);
+ }
+
+ i = applicationMap.keySet().iterator();
+ i.next();
+ i.remove();
+ try {
+ i.remove();
+ assertTrue(false);
+ } catch (Exception e) {
+ assertTrue(e instanceof IllegalStateException);
+ }
+
+ i = applicationMap.values().iterator();
+ i.next();
+ i.remove();
+ try {
+ i.remove();
+ assertTrue(false);
+ } catch (Exception e) {
+ assertTrue(e instanceof IllegalStateException);
+ }
     }
 
 
@@ -382,6 +530,8 @@
         supported[IS_EMPTY] = true;
         supported[KEY_SET] = true;
         supported[SIZE] = true;
+ supported[PUT_ALL] = true;
+ supported[CLEAR] = true;
 
         testUnsupportedExceptions(sessionMap, supported);
 
@@ -407,6 +557,144 @@
         assertTrue(!sessionMap.equals(null));
         assertTrue(!sessionMap.equals(new HashMap()));
         sessionMap.remove("foo");
+ if (sessionMap.isEmpty()) {
+ sessionMap.put("some", "value");
+ }
+ Map cloneMap = new HashMap(sessionMap);
+ sessionMap.clear();
+ assertTrue(sessionMap.isEmpty());
+ sessionMap.putAll(cloneMap);
+ assertTrue(!sessionMap.isEmpty());
+
+ // ensure EntrySet operations reflect on the underlying map.
+ sessionMap.put("key1", "value1");
+ Set entrySet = sessionMap.entrySet();
+ for (Iterator i = entrySet.iterator(); i.hasNext(); ) {
+ Map.Entry entry = (Map.Entry) i.next();
+ if ("key1".equals(entry.getKey())) {
+ entrySet.remove(entry);
+ }
+ }
+ assertTrue(sessionMap.get("key1") == null);
+
+ sessionMap.put("key1", "value1");
+
+ entrySet = sessionMap.entrySet();
+ int currentSize = sessionMap.size();
+ ArrayList list = new ArrayList();
+ for (Iterator i = entrySet.iterator(); i.hasNext(); ) {
+ Map.Entry entry = (Map.Entry) i.next();
+ if ("key1".equals(entry.getKey())) {
+ list.add(entry);
+ break;
+ }
+ }
+ entrySet.removeAll(list);
+ assertTrue(sessionMap.size() == (currentSize - 1));
+
+ cloneMap = new HashMap(sessionMap);
+ sessionMap.put("key1", "value1");
+ list = new ArrayList();
+ for (Iterator i = entrySet.iterator(); i.hasNext(); ) {
+ Map.Entry entry = (Map.Entry) i.next();
+ if ("key1".equals(entry.getKey())) {
+ list.add(entry);
+ break;
+ }
+ }
+ assertTrue(entrySet.retainAll(list));
+ assertTrue(sessionMap.size() == 1);
+ sessionMap.clear();
+ sessionMap.putAll(cloneMap);
+
+ // next validate Iterator.remove goes through to the backing Map.
+ cloneMap = new HashMap(sessionMap);
+ for (Iterator i = sessionMap.entrySet().iterator();
i.hasNext(); ) {
+ i.next();
+ i.remove();
+ }
+ assertTrue(sessionMap.isEmpty());
+ sessionMap.putAll(cloneMap);
+
+ sessionMap.put("key1", "value1");
+ for (Iterator i = sessionMap.keySet().iterator(); i.hasNext(); ) {
+ String entry = (String) i.next();
+ if ("key1".equals(entry)) {
+ i.remove();
+ }
+ }
+ assertTrue(sessionMap.get("key1") == null);
+
+ sessionMap.put("key1", "value1");
+ sessionMap.put("key2", "value1");
+ for (Iterator i = sessionMap.values().iterator(); i.hasNext(); ) {
+ Object val = i.next();
+ if ("value1".equals(val)) {
+ i.remove();
+ }
+ }
+ assertTrue(sessionMap.get("key1") == null);
+ assertTrue(sessionMap.get("key2") == null);
+
+ // ensure IllegalStateException if Iterator isn't properly
positioned
+ Iterator i = sessionMap.entrySet().iterator();
+ try {
+ i.remove();
+ assertTrue(false);
+ } catch (Exception e) {
+ assertTrue(e instanceof IllegalStateException);
+ }
+
+ i = sessionMap.keySet().iterator();
+ try {
+ i.remove();
+ assertTrue(false);
+ } catch (Exception e) {
+ assertTrue(e instanceof IllegalStateException);
+ }
+
+ i = sessionMap.values().iterator();
+ try {
+ i.remove();
+ assertTrue(false);
+ } catch (Exception e) {
+ assertTrue(e instanceof IllegalStateException);
+ }
+
+ // ensure IllegalStateException if Iterator.remove() is called
more than
+ // once per each next() call
+ sessionMap.put("key1", "value1");
+ i = sessionMap.entrySet().iterator();
+ i.next();
+ i.remove();
+ try {
+ i.remove();
+ assertTrue(false);
+ } catch (Exception e) {
+ assertTrue(e instanceof IllegalStateException);
+ }
+
+ sessionMap.put("key1", "value1");
+ i = sessionMap.keySet().iterator();
+ i.next();
+ i.remove();
+ try {
+ i.remove();
+ assertTrue(false);
+ } catch (Exception e) {
+ assertTrue(e instanceof IllegalStateException);
+ }
+
+ sessionMap.put("key1", "value1");
+ i = sessionMap.values().iterator();
+ i.next();
+ i.remove();
+ try {
+ i.remove();
+ assertTrue(false);
+ } catch (Exception e) {
+ assertTrue(e instanceof IllegalStateException);
+ }
     }
 
 
@@ -426,6 +714,8 @@
         supported[IS_EMPTY] = true;
         supported[KEY_SET] = true;
         supported[SIZE] = true;
+ supported[PUT_ALL] = true;
+ supported[CLEAR] = true;
         testUnsupportedExceptions(requestMap, supported);
 
         System.out.println(" Testing supported methods of
RequestMap...");
@@ -450,6 +740,148 @@
         assertTrue(!requestMap.equals(null));
         assertTrue(!requestMap.equals(new HashMap()));
         requestMap.remove("foo");
+
+ if (requestMap.isEmpty()) {
+ requestMap.put("some", "value");
+ }
+ Map cloneMap = new HashMap(requestMap);
+ requestMap.clear();
+ assertTrue(requestMap.isEmpty());
+ requestMap.putAll(cloneMap);
+ assertTrue(!requestMap.isEmpty());
+
+ // ensure EntrySet operations reflect on the underlying map.
+ requestMap.put("key1", "value1");
+ Set entrySet = requestMap.entrySet();
+ for (Iterator i = entrySet.iterator(); i.hasNext(); ) {
+ Map.Entry entry = (Map.Entry) i.next();
+ if ("key1".equals(entry.getKey())) {
+ entrySet.remove(entry);
+ }
+ }
+ assertTrue(requestMap.get("key1") == null);
+
+ requestMap.put("key1", "value1");
+
+ entrySet = requestMap.entrySet();
+ int currentSize = requestMap.size();
+ ArrayList list = new ArrayList();
+ for (Iterator i = entrySet.iterator(); i.hasNext(); ) {
+ Map.Entry entry = (Map.Entry) i.next();
+ if ("key1".equals(entry.getKey())) {
+ list.add(entry);
+ break;
+ }
+ }
+ entrySet.removeAll(list);
+ assertTrue(requestMap.size() == (currentSize - 1));
+
+ cloneMap = new HashMap(requestMap);
+ requestMap.put("key1", "value1");
+ list = new ArrayList();
+ for (Iterator i = entrySet.iterator(); i.hasNext(); ) {
+ Map.Entry entry = (Map.Entry) i.next();
+ if ("key1".equals(entry.getKey())) {
+ list.add(entry);
+ break;
+ }
+ }
+ assertTrue(entrySet.retainAll(list));
+ assertTrue(requestMap.size() == 1);
+ requestMap.clear();
+ requestMap.putAll(cloneMap);
+
+ // next validate Iterator.remove goes through to the backing Map.
+ cloneMap = new HashMap(requestMap);
+ for (Iterator i = requestMap.entrySet().iterator();
i.hasNext(); ) {
+ i.next();
+ i.remove();
+ }
+ assertTrue(requestMap.isEmpty());
+ requestMap.putAll(cloneMap);
+
+ requestMap.put("key1", "value1");
+ for (Iterator i = requestMap.keySet().iterator(); i.hasNext(); ) {
+ String entry = (String) i.next();
+ if ("key1".equals(entry)) {
+ i.remove();
+ }
+ }
+ assertTrue(requestMap.get("key1") == null);
+
+ requestMap.put("key1", "value1");
+ requestMap.put("key2", "value1");
+ for (Iterator i = requestMap.values().iterator(); i.hasNext(); ) {
+ Object val = i.next();
+ if ("value1".equals(val)) {
+ i.remove();
+ }
+ }
+ assertTrue(requestMap.get("key1") == null);
+ assertTrue(requestMap.get("key2") == null);
+
+ // ensure IllegalStateException if Iterator isn't properly
positioned
+ requestMap.put("key1", "value1");
+ Iterator i = requestMap.entrySet().iterator();
+ try {
+ i.remove();
+ assertTrue(false);
+ } catch (Exception e) {
+ assertTrue(e instanceof IllegalStateException);
+ }
+
+ requestMap.put("key1", "value1");
+ i = requestMap.keySet().iterator();
+ try {
+ i.remove();
+ assertTrue(false);
+ } catch (Exception e) {
+ assertTrue(e instanceof IllegalStateException);
+ }
+
+ requestMap.put("key1", "value1");
+ i = requestMap.values().iterator();
+ try {
+ i.remove();
+ assertTrue(false);
+ } catch (Exception e) {
+ assertTrue(e instanceof IllegalStateException);
+ }
+
+ // ensure IllegalStateException if Iterator.remove() is called
more than
+ // once per each next() call
+ requestMap.put("key1", "value1");
+ i = requestMap.entrySet().iterator();
+ i.next();
+ i.remove();
+ try {
+ i.remove();
+ assertTrue(false);
+ } catch (Exception e) {
+ assertTrue(e instanceof IllegalStateException);
+ }
+
+ requestMap.put("key1", "value1");
+ i = requestMap.keySet().iterator();
+ i.next();
+ i.remove();
+ try {
+ i.remove();
+ assertTrue(false);
+ } catch (Exception e) {
+ assertTrue(e instanceof IllegalStateException);
+ }
+
+ requestMap.put("key1", "value1");
+ i = requestMap.values().iterator();
+ i.next();
+ i.remove();
+ try {
+ i.remove();
+ assertTrue(false);
+ } catch (Exception e) {
+ assertTrue(e instanceof IllegalStateException);
+ }
     }
 
 
@@ -494,6 +926,58 @@
             
getFacesContext().getExternalContext().getRequestParameterMap()));
         assertTrue(!requestParameterMap.equals(null));
         assertTrue(!requestParameterMap.equals(new HashMap()));
+
+ // ensure we can't modify the map using Iterator.remove();
+ Iterator i = requestParameterMap.entrySet().iterator();
+ i.next();
+ try {
+ i.remove();
+ assertTrue(false);
+ } catch (Exception e) {
+ assertTrue(e instanceof UnsupportedOperationException);
+ }
+
+ i = requestParameterMap.keySet().iterator();
+ i.next();
+ try {
+ i.remove();
+ assertTrue(false);
+ } catch (Exception e) {
+ assertTrue(e instanceof UnsupportedOperationException);
+ }
+
+ i = requestParameterMap.values().iterator();
+ i.next();
+ try {
+ i.remove();
+ assertTrue(false);
+ } catch (Exception e) {
+ assertTrue(e instanceof UnsupportedOperationException);
+ }
+
+ // ensure we can't remove elements from the Set.
+ try {
+ requestParameterMap.entrySet().remove("test");
+ assertTrue(false);
+ } catch (Exception e) {
+ assertTrue(e instanceof UnsupportedOperationException);
+ }
+
+ // ensure we can't remove elements from the Set.
+ try {
+ requestParameterMap.keySet().remove("test");
+ assertTrue(false);
+ } catch (Exception e) {
+ assertTrue(e instanceof UnsupportedOperationException);
+ }
+
+ // ensure we can't remove elements from the Set.
+ try {
+ requestParameterMap.values().remove("test");
+ assertTrue(false);
+ } catch (Exception e) {
+ assertTrue(e instanceof UnsupportedOperationException);
+ }
     }
 
 
@@ -546,6 +1030,58 @@
                 .getRequestParameterValuesMap()));
         assertTrue(!requestParameterValuesMap.equals(null));
         assertTrue(!requestParameterValuesMap.equals(new HashMap()));
+
+ // ensure we can't modify the map using Iterator.remove();
+ Iterator i = requestParameterValuesMap.entrySet().iterator();
+ i.next();
+ try {
+ i.remove();
+ assertTrue(false);
+ } catch (Exception e) {
+ assertTrue(e instanceof UnsupportedOperationException);
+ }
+
+ i = requestParameterValuesMap.keySet().iterator();
+ i.next();
+ try {
+ i.remove();
+ assertTrue(false);
+ } catch (Exception e) {
+ assertTrue(e instanceof UnsupportedOperationException);
+ }
+
+ i = requestParameterValuesMap.values().iterator();
+ i.next();
+ try {
+ i.remove();
+ assertTrue(false);
+ } catch (Exception e) {
+ assertTrue(e instanceof UnsupportedOperationException);
+ }
+
+ // ensure we can't remove elements from the Set.
+ try {
+ requestParameterValuesMap.entrySet().remove("test");
+ assertTrue(false);
+ } catch (Exception e) {
+ assertTrue(e instanceof UnsupportedOperationException);
+ }
+
+ // ensure we can't remove elements from the Set.
+ try {
+ requestParameterValuesMap.keySet().remove("test");
+ assertTrue(false);
+ } catch (Exception e) {
+ assertTrue(e instanceof UnsupportedOperationException);
+ }
+
+ // ensure we can't remove elements from the Set.
+ try {
+ requestParameterValuesMap.values().remove("test");
+ assertTrue(false);
+ } catch (Exception e) {
+ assertTrue(e instanceof UnsupportedOperationException);
+ }
     }
 
 
@@ -590,6 +1126,58 @@
             getFacesContext().getExternalContext().getRequestHeaderMap()));
         assertTrue(!requestHeaderMap.equals(null));
         assertTrue(!requestHeaderMap.equals(new HashMap()));
+
+ // ensure we can't modify the map using Iterator.remove();
+ Iterator i = requestHeaderMap.entrySet().iterator();
+ i.next();
+ try {
+ i.remove();
+ assertTrue(false);
+ } catch (Exception e) {
+ assertTrue(e instanceof UnsupportedOperationException);
+ }
+
+ i = requestHeaderMap.keySet().iterator();
+ i.next();
+ try {
+ i.remove();
+ assertTrue(false);
+ } catch (Exception e) {
+ assertTrue(e instanceof UnsupportedOperationException);
+ }
+
+ i = requestHeaderMap.values().iterator();
+ i.next();
+ try {
+ i.remove();
+ assertTrue(false);
+ } catch (Exception e) {
+ assertTrue(e instanceof UnsupportedOperationException);
+ }
+
+ // ensure we can't remove elements from the Set.
+ try {
+ requestHeaderMap.entrySet().remove("test");
+ assertTrue(false);
+ } catch (Exception e) {
+ assertTrue(e instanceof UnsupportedOperationException);
+ }
+
+ // ensure we can't remove elements from the Set.
+ try {
+ requestHeaderMap.keySet().remove("test");
+ assertTrue(false);
+ } catch (Exception e) {
+ assertTrue(e instanceof UnsupportedOperationException);
+ }
+
+ // ensure we can't remove elements from the Set.
+ try {
+ requestHeaderMap.values().remove("test");
+ assertTrue(false);
+ } catch (Exception e) {
+ assertTrue(e instanceof UnsupportedOperationException);
+ }
     }
 
 
@@ -656,11 +1244,60 @@
                 .getRequestHeaderValuesMap())); */
         assertTrue(!requestHeaderValuesMap.equals(null));
         assertTrue(!requestHeaderValuesMap.equals(new HashMap()));
+
+ // ensure we can't modify the map using Iterator.remove();
+ Iterator i = requestHeaderValuesMap.entrySet().iterator();
+ i.next();
+ try {
+ i.remove();
+ assertTrue(false);
+ } catch (Exception e) {
+ assertTrue(e instanceof UnsupportedOperationException);
+ }
+
+ i = requestHeaderValuesMap.keySet().iterator();
+ i.next();
+ try {
+ i.remove();
+ assertTrue(false);
+ } catch (Exception e) {
+ assertTrue(e instanceof UnsupportedOperationException);
+ }
+
+ i = requestHeaderValuesMap.values().iterator();
+ i.next();
+ try {
+ i.remove();
+ assertTrue(false);
+ } catch (Exception e) {
+ assertTrue(e instanceof UnsupportedOperationException);
+ }
+
+ // ensure we can't remove elements from the Set.
+ try {
+ requestHeaderValuesMap.entrySet().remove("test");
+ assertTrue(false);
+ } catch (Exception e) {
+ assertTrue(e instanceof UnsupportedOperationException);
+ }
+
+ // ensure we can't remove elements from the Set.
+ try {
+ requestHeaderValuesMap.keySet().remove("test");
+ assertTrue(false);
+ } catch (Exception e) {
+ assertTrue(e instanceof UnsupportedOperationException);
+ }
+
+ // ensure we can't remove elements from the Set.
+ try {
+ requestHeaderValuesMap.values().remove("test");
+ assertTrue(false);
+ } catch (Exception e) {
+ assertTrue(e instanceof UnsupportedOperationException);
+ }
     }
 
- // PENDING(craigmcc) - Comment out this test because on my platform
- // the getRequestCookies() call returns null
- /*
     public void beginRequestCookieMap(WebRequest theRequest) {
         theRequest.addCookie("foo", "bar");
     }
@@ -682,11 +1319,12 @@
         testUnsupportedExceptions(requestCookieMap, supported);
 
         System.out.println(" Testing supported methods of
RequestCookieMap...");
+ System.out.println("COOKIE MAP : " + requestCookieMap.toString());
         assertTrue(requestCookieMap.get("foo") instanceof Cookie);
         Cookie value = (Cookie)requestCookieMap.get("foo");
         assertTrue(value.getValue().equals("bar"));
         assertTrue(requestCookieMap.containsKey("foo"));
- assertTrue(requestCookieMap.containsValue("bar"));
+
assertTrue(requestCookieMap.containsValue(requestCookieMap.get("foo")));
 
         assertTrue(!requestCookieMap.entrySet().isEmpty());
         assertTrue(!requestCookieMap.values().isEmpty());
         assertTrue(!requestCookieMap.keySet().isEmpty());
@@ -697,8 +1335,60 @@
         getFacesContext().getExternalContext().getRequestCookieMap()));
         assertTrue(!requestCookieMap.equals(null));
         assertTrue(!requestCookieMap.equals(new HashMap()));
+
+ // ensure we can't modify the map using Iterator.remove();
+ Iterator i = requestCookieMap.entrySet().iterator();
+ i.next();
+ try {
+ i.remove();
+ assertTrue(false);
+ } catch (Exception e) {
+ assertTrue(e instanceof UnsupportedOperationException);
+ }
+
+ i = requestCookieMap.keySet().iterator();
+ i.next();
+ try {
+ i.remove();
+ assertTrue(false);
+ } catch (Exception e) {
+ assertTrue(e instanceof UnsupportedOperationException);
+ }
+
+ i = requestCookieMap.values().iterator();
+ i.next();
+ try {
+ i.remove();
+ assertTrue(false);
+ } catch (Exception e) {
+ assertTrue(e instanceof UnsupportedOperationException);
+ }
+
+ // ensure we can't remove elements from the Set.
+ try {
+ requestCookieMap.entrySet().remove("test");
+ assertTrue(false);
+ } catch (Exception e) {
+ assertTrue(e instanceof UnsupportedOperationException);
+ }
+
+ // ensure we can't remove elements from the Set.
+ try {
+ requestCookieMap.keySet().remove("test");
+ assertTrue(false);
+ } catch (Exception e) {
+ assertTrue(e instanceof UnsupportedOperationException);
+ }
+
+ // ensure we can't remove elements from the Set.
+ try {
+ requestCookieMap.values().remove("test");
+ assertTrue(false);
+ } catch (Exception e) {
+ assertTrue(e instanceof UnsupportedOperationException);
+ }
     }
- */
+
 
     public void testInitParameterMap() {
         System.out.println("Testing InitParameterMap...");
@@ -738,6 +1428,58 @@
             getFacesContext().getExternalContext().getInitParameterMap()));
         assertTrue(!initParameterMap.equals(null));
         assertTrue(!initParameterMap.equals(new HashMap()));
+
+ // ensure we can't modify the map using Iterator.remove();
+ Iterator i = initParameterMap.entrySet().iterator();
+ i.next();
+ try {
+ i.remove();
+ assertTrue(false);
+ } catch (Exception e) {
+ assertTrue(e instanceof UnsupportedOperationException);
+ }
+
+ i = initParameterMap.keySet().iterator();
+ i.next();
+ try {
+ i.remove();
+ assertTrue(false);
+ } catch (Exception e) {
+ assertTrue(e instanceof UnsupportedOperationException);
+ }
+
+ i = initParameterMap.values().iterator();
+ i.next();
+ try {
+ i.remove();
+ assertTrue(false);
+ } catch (Exception e) {
+ assertTrue(e instanceof UnsupportedOperationException);
+ }
+
+ // ensure we can't remove elements from the Set.
+ try {
+ initParameterMap.entrySet().remove("test");
+ assertTrue(false);
+ } catch (Exception e) {
+ assertTrue(e instanceof UnsupportedOperationException);
+ }
+
+ // ensure we can't remove elements from the Set.
+ try {
+ initParameterMap.keySet().remove("test");
+ assertTrue(false);
+ } catch (Exception e) {
+ assertTrue(e instanceof UnsupportedOperationException);
+ }
+
+ // ensure we can't remove elements from the Set.
+ try {
+ initParameterMap.values().remove("test");
+ assertTrue(false);
+ } catch (Exception e) {
+ assertTrue(e instanceof UnsupportedOperationException);
+ }
     }