struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nil...@apache.org
Subject svn commit: r564476 - in /struts/struts2/trunk/plugins/portlet: ./ src/main/java/org/apache/struts2/portlet/ src/test/java/org/apache/struts2/portlet/
Date Fri, 10 Aug 2007 06:07:49 GMT
Author: nilsga
Date: Thu Aug  9 23:07:48 2007
New Revision: 564476

URL: http://svn.apache.org/viewvc?view=rev&rev=564476
Log:
WW-1836 Refactored unit tests for PortletSessionMap and PortletRequestMap. Also removed some
unecessary logging.

Added:
    struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/MockPortletRequest.java
    struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/MockPortletSession.java
Modified:
    struts/struts2/trunk/plugins/portlet/pom.xml
    struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/portlet/PortletRequestMap.java
    struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/portlet/PortletSessionMap.java
    struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/PortletRequestMapTest.java
    struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/PortletSessionMapTest.java

Modified: struts/struts2/trunk/plugins/portlet/pom.xml
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/portlet/pom.xml?view=diff&rev=564476&r1=564475&r2=564476
==============================================================================
--- struts/struts2/trunk/plugins/portlet/pom.xml (original)
+++ struts/struts2/trunk/plugins/portlet/pom.xml Thu Aug  9 23:07:48 2007
@@ -112,6 +112,13 @@
             <scope>test</scope>
         </dependency>
 		
+		 <dependency>
+            <groupId>log4j</groupId>
+            <artifactId>log4j</artifactId>
+            <version>1.2.9</version>
+            <scope>test</scope>
+        </dependency>
+		
         <!-- Mocks for unit testing (by Spring) -->
         <dependency>
             <groupId>org.springframework</groupId>

Modified: struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/portlet/PortletRequestMap.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/portlet/PortletRequestMap.java?view=diff&rev=564476&r1=564475&r2=564476
==============================================================================
--- struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/portlet/PortletRequestMap.java
(original)
+++ struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/portlet/PortletRequestMap.java
Thu Aug  9 23:07:48 2007
@@ -49,15 +49,6 @@
      */
     public PortletRequestMap(PortletRequest request) {
         this.request = request;
-        if(LOG.isDebugEnabled()) {
-            LOG.debug("Dumping request parameters: ");
-            Iterator params = request.getParameterMap().keySet().iterator();
-            while(params.hasNext()) {
-                String key = (String)params.next();
-                String val = request.getParameter(key);
-                LOG.debug(key + " = " + val);
-            }
-        }
     }
 
     /**

Modified: struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/portlet/PortletSessionMap.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/portlet/PortletSessionMap.java?view=diff&rev=564476&r1=564475&r2=564476
==============================================================================
--- struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/portlet/PortletSessionMap.java
(original)
+++ struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/portlet/PortletSessionMap.java
Thu Aug  9 23:07:48 2007
@@ -52,15 +52,6 @@
      */
     public PortletSessionMap(PortletRequest request) {
         this.session = request.getPortletSession();
-        if(LOG.isDebugEnabled()) {
-            LOG.debug("Dumping session info: ");
-            Enumeration enumeration = session.getAttributeNames();
-            while(enumeration.hasMoreElements()) {
-                String key = (String)enumeration.nextElement();
-                Object val = session.getAttribute(key);
-                LOG.debug(key + " = " + val);
-            }
-        }
     }
 
     /**

Added: struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/MockPortletRequest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/MockPortletRequest.java?view=auto&rev=564476
==============================================================================
--- struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/MockPortletRequest.java
(added)
+++ struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/MockPortletRequest.java
Thu Aug  9 23:07:48 2007
@@ -0,0 +1,165 @@
+package org.apache.struts2.portlet;
+
+import java.security.Principal;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+
+import javax.portlet.PortalContext;
+import javax.portlet.PortletMode;
+import javax.portlet.PortletPreferences;
+import javax.portlet.PortletRequest;
+import javax.portlet.PortletSession;
+import javax.portlet.WindowState;
+
+public class MockPortletRequest implements PortletRequest {
+
+	private Map<String, String[]> params;
+	private Map<String, Object> requestAttributes;
+	private Map<String, Object>	session;
+	
+	public MockPortletRequest(Map<String, String[]> params, Map<String, Object>
requestAttributes, Map<String, Object> session) {
+		this.params = params;
+		this.requestAttributes = requestAttributes;
+		this.session = session;
+	}
+	
+	public Object getAttribute(String arg0) {
+		return requestAttributes.get(arg0);
+	}
+
+	public Enumeration getAttributeNames() {
+		return Collections.enumeration(new HashMap<String, Object>(requestAttributes).keySet());
+	}
+
+	public String getAuthType() {
+		return null;
+	}
+
+	public String getContextPath() {
+		return null;
+	}
+
+	public Locale getLocale() {
+		return null;
+	}
+
+	public Enumeration getLocales() {
+		return null;
+	}
+
+	public String getParameter(String arg0) {
+		return params.get(arg0)[0];
+	}
+
+	public Map getParameterMap() {
+		return params;
+	}
+
+	public Enumeration getParameterNames() {
+		return Collections.enumeration(new HashMap<String, String[]>(params).keySet());
+	}
+
+	public String[] getParameterValues(String arg0) {
+		return params.get(arg0);
+	}
+
+	public PortalContext getPortalContext() {
+		return null;
+	}
+
+	public PortletMode getPortletMode() {
+		return null;
+	}
+
+	public PortletSession getPortletSession() {
+		return getPortletSession(true);
+	}
+
+	public PortletSession getPortletSession(boolean arg0) {
+		return new MockPortletSession(session);
+	}
+
+	public PortletPreferences getPreferences() {
+		return null;
+	}
+
+	public Enumeration getProperties(String arg0) {
+		return null;
+	}
+
+	public String getProperty(String arg0) {
+		return null;
+	}
+
+	public Enumeration getPropertyNames() {
+		return null;
+	}
+
+	public String getRemoteUser() {
+		return null;
+	}
+
+	public String getRequestedSessionId() {
+		return null;
+	}
+
+	public String getResponseContentType() {
+		return null;
+	}
+
+	public Enumeration getResponseContentTypes() {		
+		return null;
+	}
+
+	public String getScheme() {
+		return null;
+	}
+
+	public String getServerName() {
+		return null;
+	}
+
+	public int getServerPort() {
+		return 0;
+	}
+
+	public Principal getUserPrincipal() {
+		return null;
+	}
+
+	public WindowState getWindowState() {
+		return null;
+	}
+
+	public boolean isPortletModeAllowed(PortletMode arg0) {
+		return false;
+	}
+
+	public boolean isRequestedSessionIdValid() {
+		return false;
+	}
+
+	public boolean isSecure() {
+		return false;
+	}
+
+	public boolean isUserInRole(String arg0) {
+		return false;
+	}
+
+	public boolean isWindowStateAllowed(WindowState arg0) {
+		return false;
+	}
+
+	public void removeAttribute(String arg0) {	
+		requestAttributes.remove(arg0);
+	}
+
+	public void setAttribute(String arg0, Object arg1) {
+		requestAttributes.put(arg0, arg1);
+	}
+
+}
\ No newline at end of file

Added: struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/MockPortletSession.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/MockPortletSession.java?view=auto&rev=564476
==============================================================================
--- struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/MockPortletSession.java
(added)
+++ struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/MockPortletSession.java
Thu Aug  9 23:07:48 2007
@@ -0,0 +1,82 @@
+package org.apache.struts2.portlet;
+
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.Map;
+
+import javax.portlet.PortletContext;
+import javax.portlet.PortletSession;
+
+public class MockPortletSession implements PortletSession {
+
+	private Map<String, Object> session;
+	
+	public MockPortletSession(Map<String, Object> session) {
+		this.session = session;
+	}
+	
+	public Object getAttribute(String arg0) {
+		return session.get(arg0);
+	}
+
+	public Object getAttribute(String arg0, int arg1) {
+		return session.get(arg0);
+	}
+
+	public Enumeration getAttributeNames() {
+		return Collections.enumeration(session.keySet());
+	}
+
+	public Enumeration getAttributeNames(int arg0) {
+		return Collections.enumeration(session.keySet());
+	}
+
+	public long getCreationTime() {
+		return 0;
+	}
+
+	public String getId() {
+		return null;
+	}
+
+	public long getLastAccessedTime() {
+		return 0;
+	}
+
+	public int getMaxInactiveInterval() {
+		return 0;
+	}
+
+	public PortletContext getPortletContext() {
+		return null;
+	}
+
+	public void invalidate() {
+		session.clear();
+	}
+
+	public boolean isNew() {
+		return false;
+	}
+
+	public void removeAttribute(String arg0) {
+		session.remove(arg0);
+	}
+
+	public void removeAttribute(String arg0, int arg1) {
+		session.remove(arg0);
+	}
+
+	public void setAttribute(String arg0, Object arg1) {
+		session.put(arg0, arg1);
+	}
+
+	public void setAttribute(String arg0, Object arg1, int arg2) {
+		session.put(arg0, arg1);
+	}
+
+	public void setMaxInactiveInterval(int arg0) {
+		
+	}
+
+}

Modified: struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/PortletRequestMapTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/PortletRequestMapTest.java?view=diff&rev=564476&r1=564475&r2=564476
==============================================================================
--- struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/PortletRequestMapTest.java
(original)
+++ struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/PortletRequestMapTest.java
Thu Aug  9 23:07:48 2007
@@ -24,6 +24,7 @@
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.Enumeration;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -42,98 +43,64 @@
  */
 public class PortletRequestMapTest extends MockObjectTestCase {
 
-    public void testSetAttribute() {
-
-    }
-
     public void testGet() {
-        Mock mockRequest = mock(PortletRequest.class, "testGet");
-        mockRequest.expects(once()).method("getAttribute").with(eq("testAttribute")).will(returnValue("testValue"));
-        PortletRequestMap map = new PortletRequestMap((PortletRequest)mockRequest.proxy());
+    	PortletRequest request = new MockPortletRequest(new HashMap<String, String[]>(),
new HashMap<String, Object>(), null);
+    	request.setAttribute("testAttribute", "testValue");
+
+    	PortletRequestMap map = new PortletRequestMap(request);
         String value = (String)map.get("testAttribute");
-        mockRequest.verify();
         assertEquals("testValue", value);
     }
 
     public void testPut() {
-        Mock mockRequest = mock(PortletRequest.class, "testPut");
-        Object value = new String("testValue");
-        Constraint[] params = new Constraint[]{eq("testAttribute"), eq(value)};
-        mockRequest.expects(once()).method("setAttribute").with(params);
-        mockRequest.expects(once()).method("getAttribute").with(eq("testAttribute")).will(returnValue(value));
-        PortletRequestMap map = new PortletRequestMap((PortletRequest)mockRequest.proxy());
-        Object obj = map.put("testAttribute", value);
-        mockRequest.verify();
-        assertEquals(obj, value);
+    	PortletRequest request = new MockPortletRequest(new HashMap<String, String[]>(),
new HashMap<String, Object>(), null);
+    	PortletRequestMap map = new PortletRequestMap(request);
+        Object obj = map.put("testAttribute", "testValue1");
+        
+        assertEquals(obj, "testValue1");
+        assertEquals("testValue1", request.getAttribute("testAttribute"));
     }
 
     public void testClear() {
-        Mock mockRequest = mock(PortletRequest.class, "testClear");
-
-        mockRequest.expects(once()).method("removeAttribute").with(eq("a"));
-        mockRequest.expects(once()).method("removeAttribute").with(eq("b"));
+    	Map<String, Object> attribs = new HashMap<String, Object>();
+    	attribs.put("testAttribute1", "testValue1");
+    	attribs.put("testAttribute2", "testValue2");
+    	PortletRequest request = new MockPortletRequest(new HashMap<String, String[]>(),
attribs, null);
 
-        ArrayList dummy = new ArrayList();
-        dummy.add("a");
-        dummy.add("b");
 
-        mockRequest.expects(once()).method("getAttributeNames").will(returnValue(Collections.enumeration(dummy)));
-
-        PortletRequestMap map = new PortletRequestMap((PortletRequest)mockRequest.proxy());
+        PortletRequestMap map = new PortletRequestMap(request);
         map.clear();
-        mockRequest.verify();
+
+        assertEquals(0, attribs.size());
     }
 
     public void testRemove() {
-        Mock mockRequest = mock(PortletRequest.class);
-
-        PortletRequest req = (PortletRequest)mockRequest.proxy();
-
+    	Map<String, Object> attribs = new HashMap<String, Object>();
+    	attribs.put("testAttribute1", "testValue1");
 
-        mockRequest.expects(once()).method("getAttribute").with(eq("dummyKey")).will(returnValue("dummyValue"));
+        PortletRequest request = new MockPortletRequest(new HashMap<String, String[]>(),
attribs, null);
 
-        mockRequest.expects(once()).method("removeAttribute").with(eq("dummyKey"));
-
-        PortletRequestMap map = new PortletRequestMap(req);
-        Object ret = map.remove("dummyKey");
-        assertEquals("dummyValue", ret);
+        PortletRequestMap map = new PortletRequestMap(request);
+        assertEquals("testValue1", map.remove("testAttribute1"));
+        assertNull(request.getAttribute("testAttribute1"));
     }
 
     public void testEntrySet() {
-        Mock mockRequest = mock(PortletRequest.class);
-
-        PortletRequest req = (PortletRequest)mockRequest.proxy();
-
-        Enumeration names = new Enumeration() {
-
-            List keys = Arrays.asList(new Object[]{"key1", "key2"});
-            Iterator it = keys.iterator();
-
-            public boolean hasMoreElements() {
-                return it.hasNext();
-            }
-
-            public Object nextElement() {
-                return it.next();
-            }
-
-        };
-
-        mockRequest.stubs().method("getAttributeNames").will(returnValue(names));
-        mockRequest.stubs().method("getAttribute").with(eq("key1")).will(returnValue("value1"));
-        mockRequest.stubs().method("getAttribute").with(eq("key2")).will(returnValue("value2"));
+    	PortletRequest request = new MockPortletRequest(new HashMap<String, String[]>(),
new HashMap<String, Object>(), null);
+    	request.setAttribute("testAttribute1", "testValue1");
+    	request.setAttribute("testAttribute2", "testValue2");
 
-        PortletRequestMap map = new PortletRequestMap(req);
+        PortletRequestMap map = new PortletRequestMap(request);
         Set entries = map.entrySet();
 
         assertEquals(2, entries.size());
         Iterator it = entries.iterator();
         Map.Entry entry = (Map.Entry)it.next();
-        assertEquals("key2", entry.getKey());
-        assertEquals("value2", entry.getValue());
+        assertEquals("testAttribute1", entry.getKey());
+        assertEquals("testValue1", entry.getValue());
         entry = (Map.Entry)it.next();
-        assertEquals("key1", entry.getKey());
-        assertEquals("value1", entry.getValue());
+        assertEquals("testAttribute2", entry.getKey());
+        assertEquals("testValue2", entry.getValue());
 
     }
 

Modified: struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/PortletSessionMapTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/PortletSessionMapTest.java?view=diff&rev=564476&r1=564475&r2=564476
==============================================================================
--- struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/PortletSessionMapTest.java
(original)
+++ struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/PortletSessionMapTest.java
Thu Aug  9 23:07:48 2007
@@ -20,61 +20,43 @@
  */
 package org.apache.struts2.portlet;
 
-import java.util.Arrays;
-import java.util.Enumeration;
+import java.util.HashMap;
 import java.util.Iterator;
-import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
 import javax.portlet.PortletRequest;
 import javax.portlet.PortletSession;
 
-import org.jmock.Mock;
-import org.jmock.MockObjectTestCase;
-import org.jmock.core.Constraint;
+import junit.framework.TestCase;
 
 
 /**
  * PortletSessionMapTest. Insert description.
  *
  */
-public class PortletSessionMapTest extends MockObjectTestCase {
+public class PortletSessionMapTest extends TestCase {
 
     public void testPut() {
 
-        Mock mockSession = mock(PortletSession.class);
-        Mock mockRequest = mock(PortletRequest.class);
-
-        PortletRequest req = (PortletRequest)mockRequest.proxy();
-        PortletSession session = (PortletSession)mockSession.proxy();
-
-        mockRequest.expects(once()).method("getPortletSession").will(returnValue(session));
-        Constraint[] params = new Constraint[]{eq("testAttribute1"), eq("testValue1")};
-        mockSession.expects(once()).method("setAttribute").with(params);
-        mockSession.expects(once()).method("getAttribute").with(eq("testAttribute1")).will(returnValue("testValue1"));
-        params = new Constraint[]{eq("testAttribute2"), eq("testValue2")};
-        mockSession.expects(once()).method("setAttribute").with(params);
-        mockSession.expects(once()).method("getAttribute").with(eq("testAttribute2")).will(returnValue("testValue2"));
-
-        PortletSessionMap map = new PortletSessionMap(req);
-        map.put("testAttribute1", "testValue1");
-        map.put("testAttribute2", "testValue2");
+    	MockPortletRequest request = new MockPortletRequest(null, null, new HashMap<String,
Object>());
 
+        PortletSessionMap map = new PortletSessionMap(request);
+        assertEquals("testValue1", map.put("testAttribute1", "testValue1"));
+        assertEquals("testValue2", map.put("testAttribute2", "testValue2"));
+
+        PortletSession session = request.getPortletSession();
+        // Assert that the values has been propagated to the session
+        assertEquals("testValue1", session.getAttribute("testAttribute1"));
+        assertEquals("testValue2", session.getAttribute("testAttribute2"));
     }
 
     public void testGet() {
-        Mock mockSession = mock(PortletSession.class);
-        Mock mockRequest = mock(PortletRequest.class);
-
-        PortletRequest req = (PortletRequest)mockRequest.proxy();
-        PortletSession session = (PortletSession)mockSession.proxy();
-
-        mockRequest.expects(once()).method("getPortletSession").will(returnValue(session));
-        mockSession.expects(once()).method("getAttribute").with(eq("testAttribute1")).will(returnValue("testValue1"));
-        mockSession.expects(once()).method("getAttribute").with(eq("testAttribute2")).will(returnValue("testValue2"));
-
-        PortletSessionMap map = new PortletSessionMap(req);
+    	MockPortletRequest request = new MockPortletRequest(null, null, new HashMap<String,
Object>());
+    	PortletSession session = request.getPortletSession();
+    	session.setAttribute("testAttribute1", "testValue1");
+    	session.setAttribute("testAttribute2", "testValue2");
+        PortletSessionMap map = new PortletSessionMap(request);
         Object val1 = map.get("testAttribute1");
         Object val2 = map.get("testAttribute2");
         assertEquals("testValue1", val1);
@@ -82,75 +64,46 @@
     }
 
     public void testClear() {
-        Mock mockSession = mock(PortletSession.class);
-        Mock mockRequest = mock(PortletRequest.class);
-
-        PortletRequest req = (PortletRequest)mockRequest.proxy();
-        PortletSession session = (PortletSession)mockSession.proxy();
+    	Map<String, Object> sessionMap = new HashMap<String, Object>();
+    	sessionMap.put("testAttribute1", "testValue1");
+    	sessionMap.put("testAttribute2", "testValue2");
 
-        mockRequest.expects(once()).method("getPortletSession").will(returnValue(session));
-        mockSession.expects(once()).method("invalidate");
+        PortletRequest req = new MockPortletRequest(null, null, sessionMap);
 
         PortletSessionMap map = new PortletSessionMap(req);
         map.clear();
+        
+        assertEquals(0, sessionMap.size());
     }
 
     public void testRemove() {
-        Mock mockSession = mock(PortletSession.class);
-        Mock mockRequest = mock(PortletRequest.class);
-
-        PortletRequest req = (PortletRequest)mockRequest.proxy();
-        PortletSession session = (PortletSession)mockSession.proxy();
-
-
-        mockRequest.expects(once()).method("getPortletSession").will(returnValue(session));
-        mockSession.stubs().method("getAttribute").with(eq("dummyKey")).will(returnValue("dummyValue"));
-        mockSession.expects(once()).method("removeAttribute").with(eq("dummyKey"));
-
-        PortletSessionMap map = new PortletSessionMap(req);
-        Object ret = map.remove("dummyKey");
-        assertEquals("dummyValue", ret);
+    	MockPortletRequest request = new MockPortletRequest(null, null, new HashMap<String,
Object>());
+    	PortletSession session = request.getPortletSession();
+    	session.setAttribute("testAttribute1", "testValue1");
+
+        PortletSessionMap map = new PortletSessionMap(request);
+        Object ret = map.remove("testAttribute1");
+        assertEquals("testValue1", ret);
+        assertNull(session.getAttribute("testAttribute1"));
     }
 
     public void testEntrySet() {
-        Mock mockSession = mock(PortletSession.class);
-        Mock mockRequest = mock(PortletRequest.class);
-
-        PortletRequest req = (PortletRequest)mockRequest.proxy();
-        PortletSession session = (PortletSession)mockSession.proxy();
-
-        Enumeration names = new Enumeration() {
-
-            List keys = Arrays.asList(new Object[]{"key1", "key2"});
-            Iterator it = keys.iterator();
-
-            public boolean hasMoreElements() {
-                return it.hasNext();
-            }
+    	MockPortletRequest request = new MockPortletRequest(null, null, new HashMap<String,
Object>());
+    	PortletSession session = request.getPortletSession();
+    	session.setAttribute("testAttribute1", "testValue1");
+    	session.setAttribute("testAttribute2", "testValue2");
 
-            public Object nextElement() {
-                return it.next();
-            }
-
-        };
-
-        mockSession.stubs().method("getAttributeNames").will(returnValue(names));
-        mockSession.stubs().method("getAttribute").with(eq("key1")).will(returnValue("value1"));
-        mockSession.stubs().method("getAttribute").with(eq("key2")).will(returnValue("value2"));
-
-        mockRequest.expects(once()).method("getPortletSession").will(returnValue(session));
-
-        PortletSessionMap map = new PortletSessionMap(req);
+        PortletSessionMap map = new PortletSessionMap(request);
         Set entries = map.entrySet();
 
         assertEquals(2, entries.size());
         Iterator it = entries.iterator();
         Map.Entry entry = (Map.Entry)it.next();
-        assertEquals("key2", entry.getKey());
-        assertEquals("value2", entry.getValue());
+        assertEquals("testAttribute1", entry.getKey());
+        assertEquals("testValue1", entry.getValue());
         entry = (Map.Entry)it.next();
-        assertEquals("key1", entry.getKey());
-        assertEquals("value1", entry.getValue());
+        assertEquals("testAttribute2", entry.getKey());
+        assertEquals("testValue2", entry.getValue());
 
     }
 



Mime
View raw message