commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r399737 - in /jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src: java/org/apache/commons/httpclient/ test/org/apache/commons/httpclient/cookie/
Date Thu, 04 May 2006 15:34:04 GMT
Author: olegk
Date: Thu May  4 08:34:01 2006
New Revision: 399737

URL: http://svn.apache.org/viewcvs?rev=399737&view=rev
Log:
Improved compliance with the sections 3.3.5 amd 9.1 of the RFC 2965. More test coverage

Added:
    jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/test/org/apache/commons/httpclient/cookie/TestCookieVersionSupport.java
  (with props)
Modified:
    jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/HttpMethodBase.java
    jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/test/org/apache/commons/httpclient/cookie/TestCookieAll.java

Modified: jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/HttpMethodBase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/HttpMethodBase.java?rev=399737&r1=399736&r2=399737&view=diff
==============================================================================
--- jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/HttpMethodBase.java
(original)
+++ jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/java/org/apache/commons/httpclient/HttpMethodBase.java
Thu May  4 08:34:01 2006
@@ -1192,8 +1192,18 @@
                 }
             }
             if (matcher instanceof CookieVersionSupport) {
-                Header ver = ((CookieVersionSupport)matcher).getVersionHeader();
-                getRequestHeaderGroup().addHeader(ver);
+                CookieVersionSupport versupport = (CookieVersionSupport) matcher;
+                int ver = versupport.getVersion();
+                boolean needVersionHeader = false;
+                for (int i = 0; i < cookies.length; i++) {
+                    if (ver != cookies[i].getVersion()) {
+                        needVersionHeader = true;
+                    }
+                }
+                if (needVersionHeader) {
+                    // Advertise cookie version support
+                    getRequestHeaderGroup().addHeader(versupport.getVersionHeader());
+                }
             }
         }
     }

Modified: jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/test/org/apache/commons/httpclient/cookie/TestCookieAll.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/test/org/apache/commons/httpclient/cookie/TestCookieAll.java?rev=399737&r1=399736&r2=399737&view=diff
==============================================================================
--- jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/test/org/apache/commons/httpclient/cookie/TestCookieAll.java
(original)
+++ jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/test/org/apache/commons/httpclient/cookie/TestCookieAll.java
Thu May  4 08:34:01 2006
@@ -52,6 +52,7 @@
         suite.addTest(TestCookiePolicy.suite());
         suite.addTest(TestDateParser.suite());
         suite.addTest(TestCookiePathComparator.suite());
+        suite.addTest(TestCookieVersionSupport.suite());
         return suite;
     }
 

Added: 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=399737&view=auto
==============================================================================
--- jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/test/org/apache/commons/httpclient/cookie/TestCookieVersionSupport.java
(added)
+++ jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/test/org/apache/commons/httpclient/cookie/TestCookieVersionSupport.java
Thu May  4 08:34:01 2006
@@ -0,0 +1,184 @@
+/*
+ * $HeaderURL$
+ * $Revision$
+ * $Date$
+ * ====================================================================
+ *
+ *  Copyright 1999-2004 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.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+
+package org.apache.commons.httpclient.cookie;
+
+import java.io.IOException;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.commons.httpclient.Header;
+import org.apache.commons.httpclient.HttpClientTestBase;
+import org.apache.commons.httpclient.HttpStatus;
+import org.apache.commons.httpclient.HttpVersion;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.server.HttpService;
+import org.apache.commons.httpclient.server.SimpleRequest;
+import org.apache.commons.httpclient.server.SimpleResponse;
+
+/**
+ * Cookie version support tests.
+ *
+ * @author Oleg Kalnichevski
+ * 
+ * @version $Revision$
+ */
+public class TestCookieVersionSupport extends HttpClientTestBase {
+
+    // ------------------------------------------------------------ Constructor
+    public TestCookieVersionSupport(final String testName) throws IOException {
+        super(testName);
+    }
+
+    // ------------------------------------------------------------------- Main
+    public static void main(String args[]) {
+        String[] testCaseName = { TestCookieVersionSupport.class.getName() };
+        junit.textui.TestRunner.main(testCaseName);
+    }
+
+    // ------------------------------------------------------- TestCase Methods
+
+    public static Test suite() {
+        return new TestSuite(TestCookieVersionSupport.class);
+    }
+
+//    private static class CookieVer0Service implements HttpService {
+//
+//        public CookieVer0Service() {
+//            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", "name1=value1; path=/test"));
+//            response.setBodyString("whatever");
+//            return true;
+//        }
+//    }
+//    
+//    
+//    public void testCookieVersionSupportHeader1() throws IOException {
+//        this.server.setHttpService(new CookieVer0Service());
+//        this.client.getParams().setCookiePolicy(CookiePolicy.RFC_2965);
+//        GetMethod httpget1 = new GetMethod("/test/");
+//        try {
+//            this.client.executeMethod(httpget1);
+//        } finally {
+//            httpget1.releaseConnection();
+//        }
+//        GetMethod httpget2 = new GetMethod("/test/");
+//        try {
+//            this.client.executeMethod(httpget2);
+//        } finally {
+//            httpget2.releaseConnection();
+//        }
+//        Header cookiesupport = httpget2.getRequestHeader("Cookie2");
+//        assertNotNull(cookiesupport);
+//        assertEquals("$Version=\"1\"", cookiesupport.getValue());
+//    }
+//    
+//    private static class CookieVer1Service implements HttpService {
+//
+//        public CookieVer1Service() {
+//            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", "name1=value1; Path=\"/test\";
Version=\"1\""));
+//            response.addHeader(new Header("Set-Cookie2", "name2=value2; Path=\"/test\";
Version=\"1\""));
+//            response.setBodyString("whatever");
+//            return true;
+//        }
+//    }
+//    
+//    
+//    public void testCookieVersionSupportHeader2() throws IOException {
+//        this.server.setHttpService(new CookieVer1Service());
+//        this.client.getParams().setCookiePolicy(CookiePolicy.RFC_2965);
+//        GetMethod httpget1 = new GetMethod("/test/");
+//        try {
+//            this.client.executeMethod(httpget1);
+//        } finally {
+//            httpget1.releaseConnection();
+//        }
+//        GetMethod httpget2 = new GetMethod("/test/");
+//        try {
+//            this.client.executeMethod(httpget2);
+//        } finally {
+//            httpget2.releaseConnection();
+//        }
+//        Header cookiesupport = httpget2.getRequestHeader("Cookie2");
+//        assertNull(cookiesupport);
+//    }
+
+    private static class CookieVer2Service implements HttpService {
+
+        public CookieVer2Service() {
+            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-Cookie2", "name2=value2; Path=\"/test\"; Version=\"2\""));
+            response.setBodyString("whatever");
+            return true;
+        }
+    }
+    
+    
+    public void testCookieVersionSupportHeader3() throws IOException {
+        this.server.setHttpService(new CookieVer2Service());
+        this.client.getParams().setCookiePolicy(CookiePolicy.RFC_2965);
+        GetMethod httpget1 = new GetMethod("/test/");
+        try {
+            this.client.executeMethod(httpget1);
+        } finally {
+            httpget1.releaseConnection();
+        }
+        GetMethod httpget2 = new GetMethod("/test/");
+        try {
+            this.client.executeMethod(httpget2);
+        } finally {
+            httpget2.releaseConnection();
+        }
+        Header cookiesupport = httpget2.getRequestHeader("Cookie2");
+        assertNotNull(cookiesupport);
+        assertEquals("$Version=\"1\"", cookiesupport.getValue());
+    }
+    
+}

Propchange: jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/test/org/apache/commons/httpclient/cookie/TestCookieVersionSupport.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/test/org/apache/commons/httpclient/cookie/TestCookieVersionSupport.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/commons/proper/httpclient/branches/COOKIE_2_BRANCH/src/test/org/apache/commons/httpclient/cookie/TestCookieVersionSupport.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



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


Mime
View raw message