Index: test/org/apache/commons/chain/web/servlet/ServletWebContextTestCase.java =================================================================== --- test/org/apache/commons/chain/web/servlet/ServletWebContextTestCase.java (revision 190998) +++ test/org/apache/commons/chain/web/servlet/ServletWebContextTestCase.java (working copy) @@ -1,5 +1,5 @@ /* - * Copyright 1999-2004 The Apache Software Foundation + * Copyright 1999-2005 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,6 +26,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; +import javax.servlet.http.Cookie; import java.util.HashMap; import java.util.Iterator; import java.util.Map; @@ -92,6 +93,8 @@ ((MockHttpServletRequest) request).addParameter("pkey1", "pvalue1"); ((MockHttpServletRequest) request).addParameter("pkey2", "pvalue2a"); ((MockHttpServletRequest) request).addParameter("pkey2", "pvalue2b"); + ((MockHttpServletRequest) request).addCookie("ckey1", "cvalue1"); + ((MockHttpServletRequest) request).addCookie("ckey2", "cvalue2"); response = new MockHttpServletResponse(); context = createContext(); } @@ -458,6 +461,53 @@ } + // Test getCookies() + public void testCookies() { + + Map map = ((WebContext) context).getCookies(); + assertNotNull(map); + + // Initial contents + checkMapSize(map, 2); + Cookie cookie1 = (Cookie)map.get("ckey1"); + assertNotNull(cookie1); + assertEquals("cvalue1", cookie1.getValue()); + Cookie cookie2 = (Cookie)map.get("ckey2"); + assertNotNull(cookie2); + assertEquals("cvalue2", cookie2.getValue()); + assertTrue(map.containsKey("ckey1")); + assertTrue(map.containsKey("ckey2")); + assertTrue(map.containsValue(cookie1)); + assertTrue(map.containsValue(cookie2)); + + // Unsupported operations on read-only map + try { + map.clear(); + fail("Should have thrown UnsupportedOperationException"); + } catch (UnsupportedOperationException e) { + ; // expected result + } + try { + map.put("ckey3", "XXX"); + fail("Should have thrown UnsupportedOperationException"); + } catch (UnsupportedOperationException e) { + ; // expected result + } + try { + map.putAll(new HashMap()); + fail("Should have thrown UnsupportedOperationException"); + } catch (UnsupportedOperationException e) { + ; // expected result + } + try { + map.remove("ckey1"); + fail("Should have thrown UnsupportedOperationException"); + } catch (UnsupportedOperationException e) { + ; // expected result + } + + } + // Test state of newly created instance public void testPristine() { @@ -471,6 +521,7 @@ assertNotNull(swcontext.getInitParam()); assertNotNull(swcontext.getParam()); assertNotNull(swcontext.getParamValues()); + assertNotNull(swcontext.getCookies()); assertNotNull(swcontext.getRequestScope()); assertNotNull(swcontext.getSessionScope()); @@ -487,6 +538,8 @@ swcontext.get("param")); assertTrue(swcontext.getParamValues() == swcontext.get("paramValues")); + assertTrue(swcontext.getCookies() == + swcontext.get("cookies")); assertTrue(swcontext.getRequestScope() == swcontext.get("requestScope")); assertTrue(swcontext.getSessionScope() == @@ -508,6 +561,7 @@ assertNull(swcontext.getInitParam()); assertNull(swcontext.getParam()); assertNull(swcontext.getParamValues()); + assertNull(swcontext.getCookies()); assertNull(swcontext.getRequestScope()); assertNull(swcontext.getSessionScope()); @@ -518,6 +572,7 @@ assertNull(swcontext.get("initParam")); assertNull(swcontext.get("param")); assertNull(swcontext.get("paramValues")); + assertNull(swcontext.get("cookies")); assertNull(swcontext.get("requestScope")); assertNull(swcontext.get("sessionScope")); Index: test/org/apache/commons/chain/web/servlet/MockHttpServletRequest.java =================================================================== --- test/org/apache/commons/chain/web/servlet/MockHttpServletRequest.java (revision 190998) +++ test/org/apache/commons/chain/web/servlet/MockHttpServletRequest.java (working copy) @@ -1,5 +1,5 @@ /* - * Copyright 1999-2004 The Apache Software Foundation + * Copyright 1999-2005 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -65,6 +65,7 @@ protected HashMap attributes = new HashMap(); protected String contextPath = null; protected HashMap headers = new HashMap(); + protected Cookie[] cookies = new Cookie[0]; protected Locale locale = null; protected HashMap parameters = new HashMap(); protected String pathInfo = null; @@ -104,7 +105,18 @@ parameters.put(name, results); } + public void addCookie(String name, String value) { + addCookie(new Cookie(name, value)); + } + public void addCookie(Cookie cookie) { + Cookie[] newValues = new Cookie[cookies.length + 1]; + System.arraycopy(cookies, 0, newValues, 0, cookies.length); + cookies = newValues; + cookies[cookies.length - 1] = cookie; + } + + public void setHttpSession(HttpSession session) { this.session = session; } @@ -146,7 +158,7 @@ public Cookie[] getCookies() { - throw new UnsupportedOperationException(); + return cookies; } Index: java/org/apache/commons/chain/web/faces/FacesWebContext.java =================================================================== --- java/org/apache/commons/chain/web/faces/FacesWebContext.java (revision 190998) +++ java/org/apache/commons/chain/web/faces/FacesWebContext.java (working copy) @@ -1,5 +1,5 @@ /* - * Copyright 1999-2004 The Apache Software Foundation + * Copyright 1999-2005 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -156,6 +156,13 @@ } + public Map getCookies() { + + return (context.getExternalContext().getRequestCookieMap()); + + } + + public Map getRequestScope() { return (context.getExternalContext().getRequestMap()); Index: java/org/apache/commons/chain/web/WebContext.java =================================================================== --- java/org/apache/commons/chain/web/WebContext.java (revision 190998) +++ java/org/apache/commons/chain/web/WebContext.java (working copy) @@ -1,5 +1,5 @@ /* - * Copyright 1999-2004 The Apache Software Foundation + * Copyright 1999-2005 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -89,6 +89,13 @@ /** + *
Return an immutable Map that maps cookie names to
+ * the set of cookies specified in the request.
+ */
+ public abstract Map getCookies();
+
+
+ /**
*
Return a mutable Map that maps request scope
* attribute names to their values.
Private implementation of Map for servlet cookies
The lazily instantiated Map of cookies.
The lazily instantiated Map of request
* parameter name-value.