struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tm...@apache.org
Subject svn commit: r446876 - in /struts/struts2/trunk/core/src: main/java/org/apache/struts2/dispatcher/SessionMap.java test/java/org/apache/struts2/dispatcher/SessionMapTest.java
Date Sat, 16 Sep 2006 13:57:43 GMT
Author: tmjee
Date: Sat Sep 16 06:57:43 2006
New Revision: 446876

URL: http://svn.apache.org/viewvc?view=rev&rev=446876
Log:
WW-1448
  -  SessionAware Session map clear() method not functioning correctly


Modified:
    struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/SessionMap.java
    struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/SessionMapTest.java

Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/SessionMap.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/SessionMap.java?view=diff&rev=446876&r1=446875&r2=446876
==============================================================================
--- struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/SessionMap.java
(original)
+++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/SessionMap.java
Sat Sep 16 06:57:43 2006
@@ -19,6 +19,7 @@
 
 import java.io.Serializable;
 import java.util.AbstractMap;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.Enumeration;
 import java.util.HashSet;
@@ -84,14 +85,13 @@
         }
 
         synchronized (session) {
-            if (entries != null ) {
-                for ( Iterator iter = entries.iterator(); iter.hasNext(); ) {
-                    Object key = iter.next();
-                    session.removeAttribute(key.toString());
-                }
-                entries = null;
+        	Enumeration<String> attributeNamesEnum = session.getAttributeNames();
+            String[] attributeNames = Collections.<String>list(attributeNamesEnum).toArray(new
String[0]);
+            for (int a=0; a< attributeNames.length; a++) {
+            	session.removeAttribute(attributeNames[a]);
             }
         }
+        
     }
 
     /**

Modified: struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/SessionMapTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/SessionMapTest.java?view=diff&rev=446876&r1=446875&r2=446876
==============================================================================
--- struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/SessionMapTest.java
(original)
+++ struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/SessionMapTest.java
Sat Sep 16 06:57:43 2006
@@ -17,7 +17,12 @@
  */
 package org.apache.struts2.dispatcher;
 
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Enumeration;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import javax.servlet.http.HttpServletRequest;
@@ -28,6 +33,7 @@
 import com.mockobjects.constraint.Constraint;
 import com.mockobjects.constraint.IsAnything;
 import com.mockobjects.constraint.IsEqual;
+import com.mockobjects.dynamic.ConstraintMatcher;
 import com.mockobjects.dynamic.Mock;
 
 
@@ -40,8 +46,34 @@
 
 
     public void testClearInvalidatesTheSession() throws Exception {
+    	List<String> attributeNames = new ArrayList<String>();
+    	attributeNames.add("test");
+    	attributeNames.add("anotherTest");
+    	Enumeration attributeNamesEnum = Collections.enumeration(attributeNames);
+    	
         MockSessionMap sessionMap = new MockSessionMap((HttpServletRequest) requestMock.proxy());
+        sessionMock.expect("setAttribute", 
+        		new Constraint[] {
+        			new IsEqual("test"), new IsEqual("test value")
+        		});
+        sessionMock.expect("setAttribute", 
+        		new Constraint[] {
+        			new IsEqual("anotherTest"), new IsEqual("another test value")
+        		});
+        sessionMock.expectAndReturn("getAttributeNames", attributeNamesEnum);
+        sessionMock.expect("removeAttribute", 
+        		new Constraint[]{
+        			new IsEqual("test")
+        		});
+        sessionMock.expect("removeAttribute", 
+        		new Constraint[]{
+        			new IsEqual("anotherTest")
+        		});
+        sessionMap.put("test", "test value");
+        sessionMap.put("anotherTest", "another test value");
         sessionMap.clear();
+        assertNull(sessionMap.get("test"));
+        assertNull(sessionMap.get("anotherTest"));
         sessionMock.verify();
     }
 
@@ -149,6 +181,11 @@
             map.put(key, value); //put the value into our map after putting it in the superclass
map to avoid polluting the get call.
 
             return originalValue;
+        }
+        
+        public void clear() {
+        	super.clear();
+        	map.clear();
         }
     }
 }



Mime
View raw message