You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ol...@apache.org on 2006/05/04 18:12:06 UTC

svn commit: r399747 - /jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/test/org/apache/commons/httpclient/cookie/TestCookieVersionSupport.java

Author: olegk
Date: Thu May  4 09:12:04 2006
New Revision: 399747

URL: http://svn.apache.org/viewcvs?rev=399747&view=rev
Log:
Provided a test case for a section 9.1 requirement to discard Set-Cookie cookie if equivalent Set-Cookie2 cookie is present

Modified:
    jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/test/org/apache/commons/httpclient/cookie/TestCookieVersionSupport.java

Modified: jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/test/org/apache/commons/httpclient/cookie/TestCookieVersionSupport.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/test/org/apache/commons/httpclient/cookie/TestCookieVersionSupport.java?rev=399747&r1=399746&r2=399747&view=diff
==============================================================================
--- jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/test/org/apache/commons/httpclient/cookie/TestCookieVersionSupport.java (original)
+++ jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/test/org/apache/commons/httpclient/cookie/TestCookieVersionSupport.java Thu May  4 09:12:04 2006
@@ -32,8 +32,10 @@
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
+import org.apache.commons.httpclient.Cookie;
 import org.apache.commons.httpclient.Header;
 import org.apache.commons.httpclient.HttpClientTestBase;
+import org.apache.commons.httpclient.HttpState;
 import org.apache.commons.httpclient.HttpStatus;
 import org.apache.commons.httpclient.HttpVersion;
 import org.apache.commons.httpclient.methods.GetMethod;
@@ -180,5 +182,53 @@
         assertNotNull(cookiesupport);
         assertEquals("$Version=\"1\"", cookiesupport.getValue());
     }
+
+    private static class SetCookieVersionMixService implements HttpService {
+
+        public SetCookieVersionMixService() {
+            super();
+        }
+
+        public boolean process(final SimpleRequest request, final SimpleResponse response)
+            throws IOException
+        {
+            HttpVersion httpversion = request.getRequestLine().getHttpVersion();
+            response.setStatusLine(httpversion, HttpStatus.SC_OK);
+            response.addHeader(new Header("Set-Cookie", "name=wrong; Path=/test"));
+            response.addHeader(new Header("Set-Cookie2", "name=right; Path=\"/test\"; Version=\"1\""));
+            response.setBodyString("whatever");
+            return true;
+        }
+    }
+    
+    public static class TestHttpState extends HttpState {
+        
+        public synchronized void addCookie(Cookie cookie) {
+            if (cookie != null) {
+                if ("localhost.local".equals(cookie.getDomain())) {
+                    cookie.setDomain("localhost");
+                }
+                super.addCookie(cookie);
+            }
+        }
+    }
+    
+    public void testSetCookieVersionMix() throws IOException {
+        this.server.setHttpService(new SetCookieVersionMixService());
+        this.client.setState(new TestHttpState());
+        this.client.getParams().setCookiePolicy(CookiePolicy.RFC_2965);
+        GetMethod httpget1 = new GetMethod("/test/");
+        try {
+            this.client.executeMethod(httpget1);
+        } finally {
+            httpget1.releaseConnection();
+        }
+        Cookie[] cookies = this.client.getState().getCookies();
+        assertNotNull(cookies);
+        assertEquals(1, cookies.length);
+        assertEquals("right", cookies[0].getValue());
+        assertTrue(cookies[0] instanceof Cookie2);
+    }
+
     
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org