hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r409983 - /jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/cookie/impl/TestCookieCompatibilitySpec.java
Date Sun, 28 May 2006 19:48:24 GMT
Author: olegk
Date: Sun May 28 12:48:24 2006
New Revision: 409983

URL: http://svn.apache.org/viewvc?rev=409983&view=rev
Log:
Ported browser compatibility test cases from the Commons HttpClient 3.x code line

Added:
    jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/cookie/impl/TestCookieCompatibilitySpec.java
      - copied, changed from r409331, jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/cookie/TestCookieCompatibilitySpec.java

Copied: jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/cookie/impl/TestCookieCompatibilitySpec.java (from r409331, jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/cookie/TestCookieCompatibilitySpec.java)
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/cookie/impl/TestCookieCompatibilitySpec.java?p2=jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/cookie/impl/TestCookieCompatibilitySpec.java&p1=jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/cookie/TestCookieCompatibilitySpec.java&r1=409331&r2=409983&rev=409983&view=diff
==============================================================================
--- jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/cookie/TestCookieCompatibilitySpec.java (original)
+++ jakarta/httpcomponents/httpclient/trunk/src/test/org/apache/http/cookie/impl/TestCookieCompatibilitySpec.java Sun May 28 12:48:24 2006
@@ -1,5 +1,5 @@
 /*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/test/org/apache/commons/httpclient/cookie/TestCookieCompatibilitySpec.java,v 1.7 2004/09/14 20:11:32 olegk Exp $
+ * $HeadURL$
  * $Revision$
  * $Date$
  * ====================================================================
@@ -26,26 +26,22 @@
  *
  */
 
-package org.apache.commons.httpclient.cookie;
+package org.apache.http.cookie.impl;
 
-import java.util.Collection;
 import java.util.Date;
 
+import org.apache.http.Header;
+import org.apache.http.cookie.Cookie;
+import org.apache.http.cookie.CookieOrigin;
+import org.apache.http.cookie.CookieSpec;
+import org.apache.http.cookie.MalformedCookieException;
+
 import junit.framework.Test;
+import junit.framework.TestCase;
 import junit.framework.TestSuite;
 
-import org.apache.commons.httpclient.Cookie;
-import org.apache.commons.httpclient.Header;
-import org.apache.commons.httpclient.HttpException;
-import org.apache.commons.httpclient.HttpState;
-import org.apache.commons.httpclient.NameValuePair;
-import org.apache.commons.httpclient.params.DefaultHttpParamsFactory;
-import org.apache.commons.httpclient.params.HttpMethodParams;
-import org.apache.commons.httpclient.params.HttpParams;
-
-
 /**
- * Test cases for Cookie
+ * Test cases for BrowserCompatSpec
  *
  * @author BC Holmes
  * @author Rod Waldhoff
@@ -55,169 +51,20 @@
  * @author <a href="mailto:oleg@ural.ru">Oleg Kalnichevski</a>
  * @version $Revision$
  */
-public class TestCookieCompatibilitySpec extends TestCookieBase {
-
+public class TestCookieCompatibilitySpec extends TestCase {
 
     // ------------------------------------------------------------ Constructor
 
-
     public TestCookieCompatibilitySpec(String name) {
         super(name);
     }
 
-
     // ------------------------------------------------------- TestCase Methods
 
-
     public static Test suite() {
         return new TestSuite(TestCookieCompatibilitySpec.class);
     }
 
-    public void testParseAttributeInvalidAttrib() throws Exception {
-        CookieSpec cookiespec = new CookieSpecBase();
-        try {
-            cookiespec.parseAttribute(null, null);
-            fail("IllegalArgumentException must have been thrown");
-        } catch (IllegalArgumentException expected) {
-        }
-    }
-
-    public void testParseAttributeInvalidCookie() throws Exception {
-        CookieSpec cookiespec = new CookieSpecBase();
-        try {
-            cookiespec.parseAttribute(new NameValuePair("name", "value"), null);
-            fail("IllegalArgumentException must have been thrown");
-        } catch (IllegalArgumentException expected) {
-        }
-    }
-
-    public void testParseAttributeNullPath() throws Exception {
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie cookie = new Cookie();
-        cookiespec.parseAttribute(new NameValuePair("path", null), cookie);
-        assertEquals("/", cookie.getPath());
-    }
-
-    public void testParseAttributeBlankPath() throws Exception {
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie cookie = new Cookie();
-        cookiespec.parseAttribute(new NameValuePair("path", "   "), cookie);
-        assertEquals("/", cookie.getPath());
-    }
-
-    public void testParseAttributeNullDomain() throws Exception {
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie cookie = new Cookie();
-        try {
-            cookiespec.parseAttribute(new NameValuePair("domain", null), cookie);
-            fail("MalformedCookieException must have been thrown");
-        } catch (MalformedCookieException expected) {
-        }
-    }
-
-    public void testParseAttributeBlankDomain() throws Exception {
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie cookie = new Cookie();
-        try {
-            cookiespec.parseAttribute(new NameValuePair("domain", "   "), cookie);
-            fail("MalformedCookieException must have been thrown");
-        } catch (MalformedCookieException expected) {
-        }
-    }
-
-    public void testParseAttributeNullMaxAge() throws Exception {
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie cookie = new Cookie();
-        try {
-            cookiespec.parseAttribute(new NameValuePair("max-age", null), cookie);
-            fail("MalformedCookieException must have been thrown");
-        } catch (MalformedCookieException expected) {
-        }
-    }
-
-    public void testParseAttributeInvalidMaxAge() throws Exception {
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie cookie = new Cookie();
-        try {
-            cookiespec.parseAttribute(new NameValuePair("max-age", "crap"), cookie);
-            fail("MalformedCookieException must have been thrown");
-        } catch (MalformedCookieException expected) {
-        }
-    }
-
-    public void testParseAttributeNullExpires() throws Exception {
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie cookie = new Cookie();
-        try {
-            cookiespec.parseAttribute(new NameValuePair("expires", null), cookie);
-            fail("MalformedCookieException must have been thrown");
-        } catch (MalformedCookieException expected) {
-        }
-    }
-
-    public void testParseAttributeUnknownValue() throws Exception {
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie cookie = new Cookie();
-        cookiespec.parseAttribute(new NameValuePair("nonsense", null), cookie);
-    }
-    
-    public void testValidateNullHost() throws Exception {
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie cookie = new Cookie();
-        try {
-            cookiespec.validate(null, 80, "/", false, cookie);
-            fail("IllegalArgumentException must have been thrown");
-        } catch (IllegalArgumentException expected) {
-        }
-    }
-
-    public void testValidateBlankHost() throws Exception {
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie cookie = new Cookie();
-        try {
-            cookiespec.validate("   ", 80, "/", false, cookie);
-            fail("IllegalArgumentException must have been thrown");
-        } catch (IllegalArgumentException expected) {
-        }
-    }
-
-    public void testValidateNullPath() throws Exception {
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie cookie = new Cookie();
-        try {
-            cookiespec.validate("host", 80, null, false, cookie);
-            fail("IllegalArgumentException must have been thrown");
-        } catch (IllegalArgumentException expected) {
-        }
-    }
-
-    public void testValidateBlankPath() throws Exception {
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie cookie = new Cookie("host", "name", "value", "/", null, false);
-        cookiespec.validate("host", 80, "   ", false, cookie);
-    }
-
-    public void testValidateInvalidPort() throws Exception {
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie cookie = new Cookie();
-        try {
-            cookiespec.validate("host", -80, "/", false, cookie);
-            fail("IllegalArgumentException must have been thrown");
-        } catch (IllegalArgumentException expected) {
-        }
-    }
-
-    public void testValidateInvalidCookieVersion() throws Exception {
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie cookie = new Cookie();
-        cookie.setVersion(-1);
-        try {
-            cookiespec.validate("host", 80, "/", false, cookie);
-            fail("MalformedCookieException must have been thrown");
-        } catch (MalformedCookieException expected) {
-        }
-    }
-
     /**
      * Tests whether domain attribute check is case-insensitive.
      */
@@ -225,8 +72,12 @@
         Header header = new Header("Set-Cookie", 
             "name=value; path=/; domain=.whatever.com");
 
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie[] parsed = cookieParse(cookiespec, "www.WhatEver.com", 80, "/", false, header);
+        CookieSpec cookiespec = new BrowserCompatSpec();
+        CookieOrigin origin = new CookieOrigin("www.WhatEver.com", 80, "/", false);
+        Cookie[] parsed = cookiespec.parse(header, origin);
+        for (int i = 0; i < parsed.length; i++) {
+            cookiespec.validate(parsed[i], origin);
+        }
         assertNotNull(parsed);
         assertEquals(1, parsed.length);
         assertEquals(".whatever.com", parsed[0].getDomain());
@@ -241,8 +92,12 @@
 
         Header header = new Header("set-cookie", headerValue);
 
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie[] cookies = cookieParse(cookiespec, "www.apache.org", 80, "/", false, header);
+        CookieSpec cookiespec = new BrowserCompatSpec();
+        CookieOrigin origin = new CookieOrigin("www.apache.org", 80, "/", false);
+        Cookie[] cookies = cookiespec.parse(header, origin);
+        for (int i = 0; i < cookies.length; i++) {
+            cookiespec.validate(cookies[i], origin);
+        }
         assertEquals(2, cookies.length);
 
         assertEquals("custno", cookies[0].getName());
@@ -251,7 +106,7 @@
         assertEquals(0, cookies[0].getVersion());
         assertEquals("www.apache.org", cookies[0].getDomain());
         assertEquals("/", cookies[0].getPath());
-        assertFalse(cookies[0].getSecure());
+        assertFalse(cookies[0].isSecure());
 
         assertEquals("name", cookies[1].getName());
         assertEquals("John", cookies[1].getValue());
@@ -259,10 +114,9 @@
         assertEquals(0, cookies[1].getVersion());
         assertEquals(".apache.org", cookies[1].getDomain());
         assertEquals("/", cookies[1].getPath());
-        assertTrue(cookies[1].getSecure());
+        assertTrue(cookies[1].isSecure());
     }
 
-
     /**
      * Test no spaces
      */
@@ -272,8 +126,12 @@
 
         Header header = new Header("set-cookie", headerValue);
 
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie[] cookies = cookieParse(cookiespec, "www.apache.org", 80, "/", false, header);
+        CookieSpec cookiespec = new BrowserCompatSpec();
+        CookieOrigin origin = new CookieOrigin("www.apache.org", 80, "/", false);
+        Cookie[] cookies = cookiespec.parse(header, origin);
+        for (int i = 0; i < cookies.length; i++) {
+            cookiespec.validate(cookies[i], origin);
+        }
 
         assertEquals(2, cookies.length);
 
@@ -283,7 +141,7 @@
         assertEquals(0, cookies[0].getVersion());
         assertEquals("www.apache.org", cookies[0].getDomain());
         assertEquals("/", cookies[0].getPath());
-        assertFalse(cookies[0].getSecure());
+        assertFalse(cookies[0].isSecure());
 
         assertEquals("name", cookies[1].getName());
         assertEquals("John", cookies[1].getValue());
@@ -291,7 +149,7 @@
         assertEquals(0, cookies[1].getVersion());
         assertEquals(".apache.org", cookies[1].getDomain());
         assertEquals("/", cookies[1].getPath());
-        assertTrue(cookies[1].getSecure());
+        assertTrue(cookies[1].isSecure());
     }
 
 
@@ -303,8 +161,12 @@
             "name=\"Doe, John\";version=1;max-age=600;secure;domain=.apache.org";
         Header header = new Header("set-cookie", headerValue);
 
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie[] cookies = cookieParse(cookiespec, "www.apache.org", 80, "/", false, header);
+        CookieSpec cookiespec = new BrowserCompatSpec();
+        CookieOrigin origin = new CookieOrigin("www.apache.org", 80, "/", false);
+        Cookie[] cookies = cookiespec.parse(header, origin);
+        for (int i = 0; i < cookies.length; i++) {
+            cookiespec.validate(cookies[i], origin);
+        }
 
         assertEquals(1, cookies.length);
 
@@ -314,7 +176,7 @@
         assertEquals(0, cookies[0].getVersion());
         assertEquals(".apache.org", cookies[0].getDomain());
         assertEquals("/", cookies[0].getPath());
-        assertTrue(cookies[0].getSecure());
+        assertTrue(cookies[0].isSecure());
     }
 
 
@@ -324,8 +186,12 @@
 
         Header header = new Header("set-cookie", headerValue);
 
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie[] cookies = cookieParse(cookiespec, "www.apache.org", 80, "/", true, header);
+        CookieSpec cookiespec = new BrowserCompatSpec();
+        CookieOrigin origin = new CookieOrigin("www.apache.org", 80, "/", true);
+        Cookie[] cookies = cookiespec.parse(header, origin);
+        for (int i = 0; i < cookies.length; i++) {
+            cookiespec.validate(cookies[i], origin);
+        }
         assertNotNull("Expected some cookies",cookies);
         assertEquals("Expected 1 cookie",1,cookies.length);
         assertNotNull("Expected cookie to have getExpiryDate",cookies[0].getExpiryDate());
@@ -336,11 +202,15 @@
             "name=John;version=1;max-age=600;secure;domain=jakarta.apache.org";
         Header header = new Header("set-cookie", headerValue);
 
-        CookieSpec cookiespec = new CookieSpecBase();
+        CookieSpec cookiespec = new BrowserCompatSpec();
+        CookieOrigin origin = new CookieOrigin("www.apache.org", 80, "/", true);
         try {
-            Cookie[] cookies = cookieParse(cookiespec, "www.apache.org", 80, "/", false, header);
-            fail("HttpException exception should have been thrown");
-        } catch (HttpException e) {
+            Cookie[] cookies = cookiespec.parse(header, origin);
+            for (int i = 0; i < cookies.length; i++) {
+                cookiespec.validate(cookies[i], origin);
+            }
+            fail("MalformedCookieException exception should have been thrown");
+        } catch (MalformedCookieException ex) {
             // expected
         }
     }
@@ -348,8 +218,12 @@
     public void testParseSimple() throws Exception {
         Header header = new Header("Set-Cookie","cookie-name=cookie-value");
         
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie[] parsed = cookieParse(cookiespec, "127.0.0.1", 80, "/path/path", false, header);
+        CookieSpec cookiespec = new BrowserCompatSpec();
+        CookieOrigin origin = new CookieOrigin("127.0.0.1", 80, "/path/path", false);
+        Cookie[] parsed = cookiespec.parse(header, origin);
+        for (int i = 0; i < parsed.length; i++) {
+            cookiespec.validate(parsed[i], origin);
+        }
         assertEquals("Found 1 cookie.",1,parsed.length);
         assertEquals("Name","cookie-name",parsed[0].getName());
         assertEquals("Value","cookie-value",parsed[0].getValue());
@@ -359,15 +233,19 @@
         assertTrue("isPersistent",!parsed[0].isPersistent());
         assertEquals("Domain","127.0.0.1",parsed[0].getDomain());
         assertEquals("Path","/path",parsed[0].getPath());
-        assertTrue("Secure",!parsed[0].getSecure());
+        assertTrue("Secure",!parsed[0].isSecure());
         assertEquals("Version",0,parsed[0].getVersion());
     }
  
     public void testParseSimple2() throws Exception {
         Header header = new Header("Set-Cookie", "cookie-name=cookie-value");
     
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie[] parsed = cookieParse(cookiespec, "127.0.0.1", 80, "/path", false, header);
+        CookieSpec cookiespec = new BrowserCompatSpec();
+        CookieOrigin origin = new CookieOrigin("127.0.0.1", 80, "/path", false);
+        Cookie[] parsed = cookiespec.parse(header, origin);
+        for (int i = 0; i < parsed.length; i++) {
+            cookiespec.validate(parsed[i], origin);
+        }
         assertEquals("Found 1 cookie.", 1, parsed.length);
         assertEquals("Name", "cookie-name", parsed[0].getName());
         assertEquals("Value", "cookie-value", parsed[0].getValue());
@@ -377,16 +255,20 @@
         assertTrue("isPersistent", !parsed[0].isPersistent());
         assertEquals("Domain", "127.0.0.1", parsed[0].getDomain());
         assertEquals("Path", "/", parsed[0].getPath());
-        assertTrue("Secure", !parsed[0].getSecure());
+        assertTrue("Secure", !parsed[0].isSecure());
         assertEquals("Version", 0, parsed[0].getVersion());
     }
  
     public void testParseNoName() throws Exception {
         Header header = new Header("Set-Cookie","=stuff; path=/");
 
-        CookieSpec cookiespec = new CookieSpecBase();
+        CookieSpec cookiespec = new BrowserCompatSpec();
+        CookieOrigin origin = new CookieOrigin("127.0.0.1", 80, "/", false);
         try {
-            Cookie[] parsed = cookieParse(cookiespec, "127.0.0.1", 80, "/", false, header);
+            Cookie[] parsed = cookiespec.parse(header, origin);
+            for (int i = 0; i < parsed.length; i++) {
+                cookiespec.validate(parsed[i], origin);
+            }
             fail("MalformedCookieException should have been thrown");
         } catch (MalformedCookieException ex) {
             // expected
@@ -396,8 +278,12 @@
     public void testParseNoValue() throws Exception {
         Header header = new Header("Set-Cookie","cookie-name=");
 
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie[] parsed = cookieParse(cookiespec, "127.0.0.1", 80, "/", false, header);
+        CookieSpec cookiespec = new BrowserCompatSpec();
+        CookieOrigin origin = new CookieOrigin("127.0.0.1", 80, "/", false);
+        Cookie[] parsed = cookiespec.parse(header, origin);
+        for (int i = 0; i < parsed.length; i++) {
+            cookiespec.validate(parsed[i], origin);
+        }
         assertEquals("Found 1 cookie.",1,parsed.length);
         assertEquals("Name","cookie-name",parsed[0].getName());
         assertEquals("Value", "", parsed[0].getValue());
@@ -407,21 +293,25 @@
         assertTrue("isPersistent",!parsed[0].isPersistent());
         assertEquals("Domain","127.0.0.1",parsed[0].getDomain());
         assertEquals("Path","/",parsed[0].getPath());
-        assertTrue("Secure",!parsed[0].getSecure());
+        assertTrue("Secure",!parsed[0].isSecure());
         assertEquals("Version",0,parsed[0].getVersion());
     }
 
     public void testParseWithWhiteSpace() throws Exception {
         Header header = new Header("Set-Cookie"," cookie-name  =    cookie-value  ");
 
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie[] parsed = cookieParse(cookiespec, "127.0.0.1", 80, "/", false, header);
+        CookieSpec cookiespec = new BrowserCompatSpec();
+        CookieOrigin origin = new CookieOrigin("127.0.0.1", 80, "/", false);
+        Cookie[] parsed = cookiespec.parse(header, origin);
+        for (int i = 0; i < parsed.length; i++) {
+            cookiespec.validate(parsed[i], origin);
+        }
         assertEquals("Found 1 cookie.",1,parsed.length);
         assertEquals("Name","cookie-name",parsed[0].getName());
         assertEquals("Value","cookie-value",parsed[0].getValue());
         assertEquals("Domain","127.0.0.1",parsed[0].getDomain());
         assertEquals("Path","/",parsed[0].getPath());
-        assertTrue("Secure",!parsed[0].getSecure());
+        assertTrue("Secure",!parsed[0].isSecure());
         assertTrue("ExpiryDate",null == parsed[0].getExpiryDate());
         assertTrue("Comment",null == parsed[0].getComment());
     }
@@ -429,14 +319,18 @@
     public void testParseWithQuotes() throws Exception {
         Header header = new Header("Set-Cookie"," cookie-name  =  \" cookie-value \" ;path=/");
 
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie[] parsed = cookieParse(cookiespec, "127.0.0.1",80, "/", false, header);
+        CookieSpec cookiespec = new BrowserCompatSpec();
+        CookieOrigin origin = new CookieOrigin("127.0.0.1",80, "/", false);
+        Cookie[] parsed = cookiespec.parse(header, origin);
+        for (int i = 0; i < parsed.length; i++) {
+            cookiespec.validate(parsed[i], origin);
+        }
         assertEquals("Found 1 cookie.",1,parsed.length);
         assertEquals("Name","cookie-name",parsed[0].getName());
         assertEquals("Value"," cookie-value ",parsed[0].getValue());
         assertEquals("Domain","127.0.0.1",parsed[0].getDomain());
         assertEquals("Path","/",parsed[0].getPath());
-        assertTrue("Secure",!parsed[0].getSecure());
+        assertTrue("Secure",!parsed[0].isSecure());
         assertTrue("ExpiryDate",null == parsed[0].getExpiryDate());
         assertTrue("Comment",null == parsed[0].getComment());
     }
@@ -444,14 +338,18 @@
     public void testParseWithPath() throws Exception {
         Header header = new Header("Set-Cookie","cookie-name=cookie-value; Path=/path/");
 
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie[] parsed = cookieParse(cookiespec, "127.0.0.1",80, "/path/path", false, header);
+        CookieSpec cookiespec = new BrowserCompatSpec();
+        CookieOrigin origin = new CookieOrigin("127.0.0.1", 80, "/path/path", false);
+        Cookie[] parsed = cookiespec.parse(header, origin);
+        for (int i = 0; i < parsed.length; i++) {
+            cookiespec.validate(parsed[i], origin);
+        }
         assertEquals("Found 1 cookie.",1,parsed.length);
         assertEquals("Name","cookie-name",parsed[0].getName());
         assertEquals("Value","cookie-value",parsed[0].getValue());
         assertEquals("Domain","127.0.0.1",parsed[0].getDomain());
         assertEquals("Path","/path/",parsed[0].getPath());
-        assertTrue("Secure",!parsed[0].getSecure());
+        assertTrue("Secure",!parsed[0].isSecure());
         assertTrue("ExpiryDate",null == parsed[0].getExpiryDate());
         assertTrue("Comment",null == parsed[0].getComment());
     }
@@ -459,14 +357,18 @@
     public void testParseWithDomain() throws Exception {
         Header header = new Header("Set-Cookie","cookie-name=cookie-value; Domain=127.0.0.1");
 
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie[] parsed = cookieParse(cookiespec, "127.0.0.1", 80, "/", false, header);
+        CookieSpec cookiespec = new BrowserCompatSpec();
+        CookieOrigin origin = new CookieOrigin("127.0.0.1", 80, "/", false);
+        Cookie[] parsed = cookiespec.parse(header, origin);
+        for (int i = 0; i < parsed.length; i++) {
+            cookiespec.validate(parsed[i], origin);
+        }
         assertEquals("Found 1 cookie.",1,parsed.length);
         assertEquals("Name","cookie-name",parsed[0].getName());
         assertEquals("Value","cookie-value",parsed[0].getValue());
         assertEquals("Domain","127.0.0.1",parsed[0].getDomain());
         assertEquals("Path","/",parsed[0].getPath());
-        assertTrue("Secure",!parsed[0].getSecure());
+        assertTrue("Secure",!parsed[0].isSecure());
         assertTrue("ExpiryDate",null == parsed[0].getExpiryDate());
         assertTrue("Comment",null == parsed[0].getComment());
     }
@@ -474,14 +376,18 @@
     public void testParseWithSecure() throws Exception {
         Header header = new Header("Set-Cookie","cookie-name=cookie-value; secure");
 
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie[] parsed = cookieParse(cookiespec, "127.0.0.1", 80, "/", true, header);
+        CookieSpec cookiespec = new BrowserCompatSpec();
+        CookieOrigin origin = new CookieOrigin("127.0.0.1", 80, "/", true);
+        Cookie[] parsed = cookiespec.parse(header, origin);
+        for (int i = 0; i < parsed.length; i++) {
+            cookiespec.validate(parsed[i], origin);
+        }
         assertEquals("Found 1 cookie.",1,parsed.length);
         assertEquals("Name","cookie-name",parsed[0].getName());
         assertEquals("Value","cookie-value",parsed[0].getValue());
         assertEquals("Domain","127.0.0.1",parsed[0].getDomain());
         assertEquals("Path","/",parsed[0].getPath());
-        assertTrue("Secure",parsed[0].getSecure());
+        assertTrue("Secure",parsed[0].isSecure());
         assertTrue("ExpiryDate",null == parsed[0].getExpiryDate());
         assertTrue("Comment",null == parsed[0].getComment());
     }
@@ -490,14 +396,18 @@
         Header header = new Header("Set-Cookie",
             "cookie-name=cookie-value; comment=\"This is a comment.\"");
 
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie[] parsed = cookieParse(cookiespec, "127.0.0.1", 80, "/", true, header);
+        CookieSpec cookiespec = new BrowserCompatSpec();
+        CookieOrigin origin = new CookieOrigin("127.0.0.1", 80, "/", true);
+        Cookie[] parsed = cookiespec.parse(header, origin);
+        for (int i = 0; i < parsed.length; i++) {
+            cookiespec.validate(parsed[i], origin);
+        }
         assertEquals("Found 1 cookie.",1,parsed.length);
         assertEquals("Name","cookie-name",parsed[0].getName());
         assertEquals("Value","cookie-value",parsed[0].getValue());
         assertEquals("Domain","127.0.0.1",parsed[0].getDomain());
         assertEquals("Path","/",parsed[0].getPath());
-        assertTrue("Secure",!parsed[0].getSecure());
+        assertTrue("Secure",!parsed[0].isSecure());
         assertTrue("ExpiryDate",null == parsed[0].getExpiryDate());
         assertEquals("Comment","This is a comment.",parsed[0].getComment());
     }
@@ -506,14 +416,18 @@
         Header header = new Header("Set-Cookie",
             "cookie-name=cookie-value;Expires=Thu, 01-Jan-1970 00:00:10 GMT");
 
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie[] parsed = cookieParse(cookiespec, "127.0.0.1", 80, "/", true, header);
+        CookieSpec cookiespec = new BrowserCompatSpec();
+        CookieOrigin origin = new CookieOrigin("127.0.0.1", 80, "/", true);
+        Cookie[] parsed = cookiespec.parse(header, origin);
+        for (int i = 0; i < parsed.length; i++) {
+            cookiespec.validate(parsed[i], origin);
+        }
         assertEquals("Found 1 cookie.",1,parsed.length);
         assertEquals("Name","cookie-name",parsed[0].getName());
         assertEquals("Value","cookie-value",parsed[0].getValue());
         assertEquals("Domain","127.0.0.1",parsed[0].getDomain());
         assertEquals("Path","/",parsed[0].getPath());
-        assertTrue("Secure",!parsed[0].getSecure());
+        assertTrue("Secure",!parsed[0].isSecure());
         assertEquals(new Date(10000L),parsed[0].getExpiryDate());
         assertTrue("Comment",null == parsed[0].getComment());
     }
@@ -523,14 +437,18 @@
             "cookie-name=cookie-value;Version=1;Path=/commons;Domain=.apache.org;" + 
             "Comment=This is a comment.;secure;Expires=Thu, 01-Jan-1970 00:00:10 GMT");
 
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie[] parsed = cookieParse(cookiespec, ".apache.org", 80, "/commons/httpclient", true, header);
+        CookieSpec cookiespec = new BrowserCompatSpec();
+        CookieOrigin origin = new CookieOrigin("www.apache.org", 80, "/commons/httpclient", true);
+        Cookie[] parsed = cookiespec.parse(header, origin);
+        for (int i = 0; i < parsed.length; i++) {
+            cookiespec.validate(parsed[i], origin);
+        }
         assertEquals("Found 1 cookie.",1,parsed.length);
         assertEquals("Name","cookie-name",parsed[0].getName());
         assertEquals("Value","cookie-value",parsed[0].getValue());
         assertEquals("Domain",".apache.org",parsed[0].getDomain());
         assertEquals("Path","/commons",parsed[0].getPath());
-        assertTrue("Secure",parsed[0].getSecure());
+        assertTrue("Secure",parsed[0].isSecure());
         assertEquals(new Date(10000L),parsed[0].getExpiryDate());
         assertEquals("Comment","This is a comment.",parsed[0].getComment());
         assertEquals("Version",0,parsed[0].getVersion());
@@ -541,37 +459,28 @@
             "name1=value1;Version=1;Path=/commons,name1=value2;Version=1;" +
             "Path=/commons/httpclient;Version=1");
 
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie[] parsed = cookieParse(cookiespec, ".apache.org", 80, "/commons/httpclient", true, header);
-        HttpState state = new HttpState();
-        state.addCookies(parsed);
-        Cookie[] cookies = state.getCookies();
-        assertEquals("Wrong number of cookies.",2,cookies.length);
-        assertEquals("Name","name1",cookies[0].getName());
-        assertEquals("Value","value1",cookies[0].getValue());
-        assertEquals("Name","name1",cookies[1].getName());
-        assertEquals("Value","value2",cookies[1].getValue());
-    }
-
-    public void testParseMultipleSamePaths() throws Exception {
-        Header header = new Header("Set-Cookie",
-            "name1=value1;Version=1;Path=/commons,name1=value2;Version=1;Path=/commons");
-
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie[] parsed = cookieParse(cookiespec, ".apache.org", 80, "/commons/httpclient", true, header);
-        HttpState state = new HttpState();
-        state.addCookies(parsed);
-        Cookie[] cookies = state.getCookies();
-        assertEquals("Found 1 cookies.",1,cookies.length);
-        assertEquals("Name","name1",cookies[0].getName());
-        assertEquals("Value","value2",cookies[0].getValue());
+        CookieSpec cookiespec = new BrowserCompatSpec();
+        CookieOrigin origin = new CookieOrigin("www.apache.org", 80, "/commons/httpclient", true);
+        Cookie[] parsed = cookiespec.parse(header, origin);
+        for (int i = 0; i < parsed.length; i++) {
+            cookiespec.validate(parsed[i], origin);
+        }
+        assertEquals("Wrong number of cookies.",2,parsed.length);
+        assertEquals("Name","name1",parsed[0].getName());
+        assertEquals("Value","value1",parsed[0].getValue());
+        assertEquals("Name","name1",parsed[1].getName());
+        assertEquals("Value","value2",parsed[1].getValue());
     }
 
     public void testParseRelativePath() throws Exception {
         Header header = new Header("Set-Cookie", "name1=value1;Path=whatever");
 
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie[] parsed = cookieParse(cookiespec, ".apache.org", 80, "whatever", true, header);
+        CookieSpec cookiespec = new BrowserCompatSpec();
+        CookieOrigin origin = new CookieOrigin("www.apache.org", 80, "whatever", true);
+        Cookie[] parsed = cookiespec.parse(header, origin);
+        for (int i = 0; i < parsed.length; i++) {
+            cookiespec.validate(parsed[i], origin);
+        }
         assertEquals("Found 1 cookies.",1,parsed.length);
         assertEquals("Name","name1",parsed[0].getName());
         assertEquals("Value","value1",parsed[0].getValue());
@@ -582,87 +491,15 @@
         Header header = new Header("Set-Cookie",
             "cookie-name=cookie-value; domain=127.0.0.1; version=1");
 
-        CookieSpec cookiespec = new CookieSpecBase();
+        CookieSpec cookiespec = new BrowserCompatSpec();
+        CookieOrigin origin = new CookieOrigin("127.0.0.2", 80, "/", false);
         try {
-            Cookie[] parsed = cookieParse(cookiespec, "127.0.0.2", 80, "/", false, header);
-            fail("HttpException exception should have been thrown");
-        } catch (HttpException e) {
-            // expected
-        }
-    }
-
-    public void testParseWithNullHost() throws Exception {
-        Header header = new Header("Set-Cookie",
-            "cookie-name=cookie-value; domain=127.0.0.1; path=/; secure");
-
-        CookieSpec cookiespec = new CookieSpecBase();
-        try {
-            Cookie[] parsed = cookieParse(cookiespec, null, 80, "/", false, header);
-            fail("IllegalArgumentException should have been thrown");
-        } catch (IllegalArgumentException e) {
-            // expected
-        }
-    }
-
-    public void testParseWithBlankHost() throws Exception {
-        Header header = new Header("Set-Cookie",
-            "cookie-name=cookie-value; domain=127.0.0.1; path=/; secure");
-
-        CookieSpec cookiespec = new CookieSpecBase();
-        try {
-            Cookie[] parsed = cookieParse(cookiespec, "  ", 80, "/", false, header);
-            fail("IllegalArgumentException should have been thrown");
-        } catch (IllegalArgumentException e) {
-            // expected
-        }
-    }
-
-    public void testParseWithNullPath() throws Exception {
-        Header header = new Header("Set-Cookie",
-            "cookie-name=cookie-value; domain=127.0.0.1; path=/; secure");
-
-        CookieSpec cookiespec = new CookieSpecBase();
-        try {
-            Cookie[] parsed = cookieParse(cookiespec, "127.0.0.1", 80, null, false, header);
-            fail("IllegalArgumentException should have been thrown");
-        } catch (IllegalArgumentException e) {
-            // expected
-        }
-    }
-
-    public void testParseWithBlankPath() throws Exception {
-        Header header = new Header("Set-Cookie",
-            "cookie-name=cookie-value; domain=127.0.0.1; path=/; secure");
-
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie[] parsed = cookieParse(cookiespec, "127.0.0.1", 80, "  ", false, header);
-        assertNotNull(parsed);
-        assertEquals(1, parsed.length);
-        assertEquals("/", parsed[0].getPath());
-    }
-
-    public void testParseWithNegativePort() throws Exception {
-        Header header = new Header("Set-Cookie",
-            "cookie-name=cookie-value; domain=127.0.0.1; path=/; secure");
-
-        CookieSpec cookiespec = new CookieSpecBase();
-        try {
-            Cookie[] parsed = cookieParse(cookiespec, "127.0.0.1", -80, null, false, header);
-            fail("IllegalArgumentException should have been thrown");
-        } catch (IllegalArgumentException e) {
-            // expected
-        }
-    }
-
-    public void testParseWithNullHostAndPath() throws Exception {
-        Header header = new Header("Set-Cookie",
-            "cookie-name=cookie-value; domain=127.0.0.1; path=/; secure");
-
-        CookieSpec cookiespec = new CookieSpecBase();
-        try {
-            Cookie[] parsed = cookieParse(cookiespec, null, 80, null, false, header);
-            fail("IllegalArgumentException should have been thrown");
-        } catch (IllegalArgumentException e) {
+            Cookie[] parsed = cookiespec.parse(header, origin);
+            for (int i = 0; i < parsed.length; i++) {
+                cookiespec.validate(parsed[i], origin);
+            }
+            fail("MalformedCookieException exception should have been thrown");
+        } catch (MalformedCookieException ex) {
             // expected
         }
     }
@@ -671,9 +508,13 @@
         Header header = new Header("Set-Cookie",
             "cookie-name=cookie-value; path=/path/path/path");
 
-        CookieSpec cookiespec = new CookieSpecBase();
+        CookieSpec cookiespec = new BrowserCompatSpec();
+        CookieOrigin origin = new CookieOrigin("127.0.0.1", 80, "/path", false);
         try {
-            Cookie[] parsed = cookieParse(cookiespec, "127.0.0.1", 80, "/path", false, header);
+            Cookie[] parsed = cookiespec.parse(header, origin);
+            for (int i = 0; i < parsed.length; i++) {
+                cookiespec.validate(parsed[i], origin);
+            }
             fail("MalformedCookieException should have been thrown.");
         } catch (MalformedCookieException e) {
             // expected
@@ -684,55 +525,45 @@
         Header header = new Header("Set-Cookie",
             "cookie-name=cookie-value; path=/foobar");
 
-        CookieSpec cookiespec = new CookieSpecBase();
+        CookieSpec cookiespec = new BrowserCompatSpec();
+        CookieOrigin origin = new CookieOrigin("127.0.0.1", 80, "/foo", false);
         try {
-            Cookie[] parsed = cookieParse(cookiespec, "127.0.0.1", 80, "/foo", false, header);
+            Cookie[] parsed = cookiespec.parse(header, origin);
+            for (int i = 0; i < parsed.length; i++) {
+                cookiespec.validate(parsed[i], origin);
+            }
             fail("MalformedCookieException should have been thrown.");
         } catch (MalformedCookieException e) {
             // expected
         }
     }
 
-
-    public void testParseWithInvalidHeader1() throws Exception {
-        CookieSpec cookiespec = new CookieSpecBase();
-        try {
-            Cookie[] parsed = cookiespec.parse("127.0.0.1", 80, "/foo", false, (Header)null);
-            fail("IllegalArgumentException should have been thrown.");
-        } catch (IllegalArgumentException e) {
-            // expected
-        }
-    }
-
-    public void testParseWithInvalidHeader2() throws Exception {
-        CookieSpec cookiespec = new CookieSpecBase();
-        try {
-            Cookie[] parsed = cookiespec.parse("127.0.0.1", 80, "/foo", false, (String)null);
-            fail("IllegalArgumentException should have been thrown.");
-        } catch (IllegalArgumentException e) {
-            // expected
-        }
-    }
-
     /**
      * Tests if cookie constructor rejects cookie name containing blanks.
      */
     public void testCookieNameWithBlanks() throws Exception {
-        Header setcookie = new Header("Set-Cookie", "invalid name=");
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie[] parsed = cookieParse(cookiespec, "127.0.0.1", 80, "/", false, setcookie);
+        Header header = new Header("Set-Cookie", "invalid name=");
+        CookieSpec cookiespec = new BrowserCompatSpec();
+        CookieOrigin origin = new CookieOrigin("127.0.0.1", 80, "/", false);
+        Cookie[] parsed = cookiespec.parse(header, origin);
+        for (int i = 0; i < parsed.length; i++) {
+            cookiespec.validate(parsed[i], origin);
+        }
         assertNotNull(parsed);
         assertEquals(1, parsed.length);
     }
 
-
     /**
      * Tests if cookie constructor rejects cookie name starting with $.
      */
     public void testCookieNameStartingWithDollarSign() throws Exception {
-        Header setcookie = new Header("Set-Cookie", "$invalid_name=");
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie[] parsed = cookieParse(cookiespec, "127.0.0.1", 80, "/", false, setcookie);
+        Header header = new Header("Set-Cookie", "$invalid_name=");
+        CookieSpec cookiespec = new BrowserCompatSpec();
+        CookieOrigin origin = new CookieOrigin("127.0.0.1", 80, "/", false);
+        Cookie[] parsed = cookiespec.parse(header, origin);
+        for (int i = 0; i < parsed.length; i++) {
+            cookiespec.validate(parsed[i], origin);
+        }
         assertNotNull(parsed);
         assertEquals(1, parsed.length);
     }
@@ -744,9 +575,13 @@
     public void testCookieWithComma() throws Exception {
         Header header = new Header("Set-Cookie", "name=value; expires=\"Thu, 01-Jan-1970 00:00:00 GMT");
 
-        CookieSpec cookiespec = new CookieSpecBase();
+        CookieSpec cookiespec = new BrowserCompatSpec();
+        CookieOrigin origin = new CookieOrigin("localhost", 80, "/", false);
         try {
-            Cookie[] cookies = cookiespec.parse("localhost", 80, "/", false, header);
+            Cookie[] parsed = cookiespec.parse(header, origin);
+            for (int i = 0; i < parsed.length; i++) {
+                cookiespec.validate(parsed[i], origin);
+            }
             fail("MalformedCookieException should have been thrown");
         } catch (MalformedCookieException expected) {
         }
@@ -783,11 +618,12 @@
 
     private void checkDate(String date) throws Exception {
         Header header = new Header("Set-Cookie", "custno=12345;Expires='"+date+"';");
-        HttpParams params = new DefaultHttpParamsFactory().getDefaultParams();
-        CookieSpec cookiespec = new CookieSpecBase();
-        cookiespec.setValidDateFormats(
-        		(Collection)params.getParameter(HttpMethodParams.DATE_PATTERNS));
-        cookieParse(cookiespec, "localhost", 80, "/", false, header);
+        CookieSpec cookiespec = new BrowserCompatSpec();
+        CookieOrigin origin = new CookieOrigin("localhost", 80, "/", false);
+        Cookie[] parsed = cookiespec.parse(header, origin);
+        for (int i = 0; i < parsed.length; i++) {
+            cookiespec.validate(parsed[i], origin);
+        }
     }
 
     /**
@@ -795,314 +631,258 @@
      * browser compatibility mode.
      */
     public void testSecondDomainLevelCookie() throws Exception {
-        Cookie cookie = new Cookie(".sourceforge.net", "name", null, "/", null, false); 
+        Cookie cookie = new Cookie("name", null);
+        cookie.setDomain(".sourceforge.net");
         cookie.setDomainAttributeSpecified(true);
+        cookie.setPath("/");
         cookie.setPathAttributeSpecified(true);
 
-        CookieSpec cookiespec = new CookieSpecBase();
-        cookiespec.validate("sourceforge.net", 80, "/", false, cookie);
+        CookieSpec cookiespec = new BrowserCompatSpec();
+        CookieOrigin origin = new CookieOrigin("sourceforge.net", 80, "/", false);
+        cookiespec.validate(cookie, origin);
     }
 
     public void testSecondDomainLevelCookieMatch1() throws Exception {
-        Cookie cookie = new Cookie(".sourceforge.net", "name", null, "/", null, false); 
+        Cookie cookie = new Cookie("name", null);
+        cookie.setDomain(".sourceforge.net");
         cookie.setDomainAttributeSpecified(true);
+        cookie.setPath("/");
         cookie.setPathAttributeSpecified(true);
 
-        CookieSpec cookiespec = new CookieSpecBase();
-        assertTrue(cookiespec.match("sourceforge.net", 80, "/", false, cookie));
+        CookieSpec cookiespec = new BrowserCompatSpec();
+        CookieOrigin origin = new CookieOrigin("sourceforge.net", 80, "/", false);
+        assertTrue(cookiespec.match(cookie, origin));
     }
 
     public void testSecondDomainLevelCookieMatch2() throws Exception {
-        Cookie cookie = new Cookie("sourceforge.net", "name", null, "/", null, false); 
+        Cookie cookie = new Cookie("name", null);
+        cookie.setDomain("sourceforge.net");
         cookie.setDomainAttributeSpecified(true);
+        cookie.setPath("/");
         cookie.setPathAttributeSpecified(true);
 
-        CookieSpec cookiespec = new CookieSpecBase();
-        assertTrue(cookiespec.match("www.sourceforge.net", 80, "/", false, cookie));
+        CookieSpec cookiespec = new BrowserCompatSpec();
+        CookieOrigin origin = new CookieOrigin("www.sourceforge.net", 80, "/", false);
+        assertTrue(cookiespec.match(cookie, origin));
     }
 
     public void testSecondDomainLevelCookieMatch3() throws Exception {
-        Cookie cookie = new Cookie(".sourceforge.net", "name", null, "/", null, false); 
-         cookie.setDomainAttributeSpecified(true);
-         cookie.setPathAttributeSpecified(true);
+        Cookie cookie = new Cookie("name", null);
+        cookie.setDomain(".sourceforge.net");
+        cookie.setDomainAttributeSpecified(true);
+        cookie.setPath("/");
+        cookie.setPathAttributeSpecified(true);
 
-         CookieSpec cookiespec = new CookieSpecBase();
-         assertTrue(cookiespec.match("www.sourceforge.net", 80, "/", false, cookie));
+         CookieSpec cookiespec = new BrowserCompatSpec();
+         CookieOrigin origin = new CookieOrigin("www.sourceforge.net", 80, "/", false);
+         assertTrue(cookiespec.match(cookie, origin));
     }
          
     public void testInvalidSecondDomainLevelCookieMatch1() throws Exception {
-        Cookie cookie = new Cookie(".sourceforge.net", "name", null, "/", null, false); 
+        Cookie cookie = new Cookie("name", null);
+        cookie.setDomain(".sourceforge.net");
         cookie.setDomainAttributeSpecified(true);
+        cookie.setPath("/");
         cookie.setPathAttributeSpecified(true);
 
-        CookieSpec cookiespec = new CookieSpecBase();
-        assertFalse(cookiespec.match("antisourceforge.net", 80, "/", false, cookie));
+        CookieSpec cookiespec = new BrowserCompatSpec();
+        CookieOrigin origin = new CookieOrigin("antisourceforge.net", 80, "/", false);
+        assertFalse(cookiespec.match(cookie, origin));
     }
 
     public void testInvalidSecondDomainLevelCookieMatch2() throws Exception {
-        Cookie cookie = new Cookie("sourceforge.net", "name", null, "/", null, false); 
+        Cookie cookie = new Cookie("name", null);
+        cookie.setDomain("sourceforge.net");
         cookie.setDomainAttributeSpecified(true);
+        cookie.setPath("/");
         cookie.setPathAttributeSpecified(true);
 
-        CookieSpec cookiespec = new CookieSpecBase();
-        assertFalse(cookiespec.match("antisourceforge.net", 80, "/", false, cookie));
-    }
-
-    public void testMatchNullHost() throws Exception {
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie cookie = new Cookie();
-        try {
-            cookiespec.match(null, 80, "/", false, cookie);
-            fail("IllegalArgumentException must have been thrown");
-        } catch (IllegalArgumentException expected) {
-        }
-    }
-
-    public void testMatchBlankHost() throws Exception {
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie cookie = new Cookie();
-        try {
-            cookiespec.match("   ", 80, "/", false, cookie);
-            fail("IllegalArgumentException must have been thrown");
-        } catch (IllegalArgumentException expected) {
-        }
-    }
-
-    public void testMatchInvalidPort() throws Exception {
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie cookie = new Cookie();
-        try {
-            cookiespec.match("host", -80, "/", false, cookie);
-            fail("IllegalArgumentException must have been thrown");
-        } catch (IllegalArgumentException expected) {
-        }
-    }
-
-    public void testMatchNullPath() throws Exception {
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie cookie = new Cookie();
-        try {
-            cookiespec.match("host", 80, null, false, cookie);
-            fail("IllegalArgumentException must have been thrown");
-        } catch (IllegalArgumentException expected) {
-        }
+        CookieSpec cookiespec = new BrowserCompatSpec();
+        CookieOrigin origin = new CookieOrigin("antisourceforge.net", 80, "/", false);
+        assertFalse(cookiespec.match(cookie, origin));
     }
 
     public void testMatchBlankPath() throws Exception {
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie cookie = new Cookie("host", "name", "value", "/", null, false);
-        assertTrue(cookiespec.match("host", 80, "  ", false, cookie));
-    }
-
-    public void testMatchNullCookie() throws Exception {
-        CookieSpec cookiespec = new CookieSpecBase();
-        try {
-            cookiespec.match("host", 80, "/", false, (Cookie)null);
-            fail("IllegalArgumentException must have been thrown");
-        } catch (IllegalArgumentException expected) {
-        }
+        CookieSpec cookiespec = new BrowserCompatSpec();
+        Cookie cookie = new Cookie("name", "value");
+        cookie.setDomain("host");
+        cookie.setPath("/");
+        CookieOrigin origin = new CookieOrigin("host", 80, "  ", false);
+        assertTrue(cookiespec.match(cookie, origin));
     }
 
     public void testMatchNullCookieDomain() throws Exception {
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie cookie = new Cookie(null, "name", "value", "/", null, false);
-        assertFalse(cookiespec.match("host", 80, "/", false, cookie));
+        CookieSpec cookiespec = new BrowserCompatSpec();
+        Cookie cookie = new Cookie("name", "value");
+        cookie.setPath("/");
+        CookieOrigin origin = new CookieOrigin("host", 80, "/", false);
+        assertFalse(cookiespec.match(cookie, origin));
     }
 
     public void testMatchNullCookiePath() throws Exception {
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie cookie = new Cookie("host", "name", "value", null, null, false);
-        assertFalse(cookiespec.match("host", 80, "/", false, cookie));
+        CookieSpec cookiespec = new BrowserCompatSpec();
+        Cookie cookie = new Cookie("name", "value");
+        cookie.setDomain("host");
+        CookieOrigin origin = new CookieOrigin("host", 80, "/", false);
+        assertTrue(cookiespec.match(cookie, origin));
     }
     
     public void testCookieMatch1() throws Exception {
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie cookie = new Cookie("host", "name", "value", "/", null, false);
-        assertTrue(cookiespec.match("host", 80, "/", false, cookie));
+        CookieSpec cookiespec = new BrowserCompatSpec();
+        Cookie cookie = new Cookie("name", "value");
+        cookie.setDomain("host");
+        cookie.setPath("/");
+        CookieOrigin origin = new CookieOrigin("host", 80, "/", false);
+        assertTrue(cookiespec.match(cookie, origin));
     }
     
     public void testCookieMatch2() throws Exception {
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie cookie = new Cookie(".whatever.com", "name", "value", "/", null, false);
-        assertTrue(cookiespec.match(".whatever.com", 80, "/", false, cookie));
+        CookieSpec cookiespec = new BrowserCompatSpec();
+        Cookie cookie = new Cookie("name", "value");
+        cookie.setDomain(".whatever.com");
+        cookie.setPath("/");
+        CookieOrigin origin = new CookieOrigin(".whatever.com", 80, "/", false);
+        assertTrue(cookiespec.match(cookie, origin));
     }
     
     public void testCookieMatch3() throws Exception {
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie cookie = new Cookie(".whatever.com", "name", "value", "/", null, false);
-        assertTrue(cookiespec.match(".really.whatever.com", 80, "/", false, cookie));
+        CookieSpec cookiespec = new BrowserCompatSpec();
+        Cookie cookie = new Cookie("name", "value");
+        cookie.setDomain(".whatever.com");
+        cookie.setPath("/");
+        CookieOrigin origin = new CookieOrigin(".really.whatever.com", 80, "/", false);
+        assertTrue(cookiespec.match(cookie, origin));
     }
     
     public void testCookieMatch4() throws Exception {
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie cookie = new Cookie("host", "name", "value", "/", null, false);
-        assertTrue(cookiespec.match("host", 80, "/foobar", false, cookie));
+        CookieSpec cookiespec = new BrowserCompatSpec();
+        Cookie cookie = new Cookie("name", "value");
+        cookie.setDomain("host");
+        cookie.setPath("/");
+        CookieOrigin origin = new CookieOrigin("host", 80, "/foobar", false);
+        assertTrue(cookiespec.match(cookie, origin));
     }
     
     public void testCookieMismatch1() throws Exception {
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie cookie = new Cookie("host1", "name", "value", "/", null, false);
-        assertFalse(cookiespec.match("host2", 80, "/", false, cookie));
+        CookieSpec cookiespec = new BrowserCompatSpec();
+        Cookie cookie = new Cookie("name", "value");
+        cookie.setDomain("host1");
+        cookie.setPath("/");
+        CookieOrigin origin = new CookieOrigin("host2", 80, "/", false);
+        assertFalse(cookiespec.match(cookie, origin));
     }
     
     public void testCookieMismatch2() throws Exception {
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie cookie = new Cookie(".aaaaaaaaa.com", "name", "value", "/", null, false);
-        assertFalse(cookiespec.match(".bbbbbbbb.com", 80, "/", false, cookie));
+        CookieSpec cookiespec = new BrowserCompatSpec();
+        Cookie cookie = new Cookie("name", "value");
+        cookie.setDomain(".aaaaaaaaa.com");
+        cookie.setPath("/");
+        CookieOrigin origin = new CookieOrigin(".bbbbbbbb.com", 80, "/", false);
+        assertFalse(cookiespec.match(cookie, origin));
     }
     
     public void testCookieMismatch3() throws Exception {
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie cookie = new Cookie("host", "name", "value", "/foobar", null, false);
-        assertFalse(cookiespec.match("host", 80, "/foo", false, cookie));
+        CookieSpec cookiespec = new BrowserCompatSpec();
+        Cookie cookie = new Cookie("name", "value");
+        cookie.setDomain("host");
+        cookie.setPath("/foobar");
+        CookieOrigin origin = new CookieOrigin("host", 80, "/foo", false);
+        assertFalse(cookiespec.match(cookie, origin));
     }
     
     public void testCookieMismatch4() throws Exception {
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie cookie = new Cookie("host", "name", "value", "/foobar", null, true);
-        assertFalse(cookiespec.match("host", 80, "/foobar/", false, cookie));
+        CookieSpec cookiespec = new BrowserCompatSpec();
+        Cookie cookie = new Cookie("name", "value");
+        cookie.setDomain("host");
+        cookie.setPath("/foobar");
+        CookieOrigin origin = new CookieOrigin("host", 80, "/foobar/", false);
+        assertTrue(cookiespec.match(cookie, origin));
     }
     
     public void testCookieMatch5() throws Exception {
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie cookie = new Cookie("host", "name", "value", "/foobar/r", null, false);
-        assertFalse(cookiespec.match("host", 80, "/foobar/", false, cookie));
+        CookieSpec cookiespec = new BrowserCompatSpec();
+        Cookie cookie = new Cookie("name", "value");
+        cookie.setDomain("host");
+        cookie.setPath("/foobar/r");
+        CookieOrigin origin = new CookieOrigin("host", 80, "/foobar/", false);
+        assertFalse(cookiespec.match(cookie, origin));
     }
     
     public void testCookieMismatch6() throws Exception {
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie cookie = new Cookie("host", "name", "value", "/foobar", null, true);
-        assertFalse(cookiespec.match("host", 80, "/foobar", false, cookie));
-    }
-    
-    public void testMatchNullCookies() throws Exception {
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie[] matched = cookiespec.match("host", 80, "/foobar", false, (Cookie[])null);
-        assertNull(matched);
+        CookieSpec cookiespec = new BrowserCompatSpec();
+        Cookie cookie = new Cookie("name", "value");
+        cookie.setDomain("host");
+        cookie.setPath("/foobar");
+        cookie.setSecure(true);
+        CookieOrigin origin = new CookieOrigin("host", 80, "/foobar", false);
+        assertFalse(cookiespec.match(cookie, origin));
     }
     
-    public void testMatchedCookiesOrder() throws Exception {
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie[] cookies = {
-            new Cookie("host", "nomatch", "value", "/noway", null, false),
-            new Cookie("host", "name2", "value", "/foobar/yada", null, false),
-            new Cookie("host", "name3", "value", "/foobar", null, false),
-            new Cookie("host", "name1", "value", "/foobar/yada/yada", null, false)};
-        Cookie[] matched = cookiespec.match("host", 80, "/foobar/yada/yada", false, cookies);
-        assertNotNull(matched);
-        assertEquals(3, matched.length);
-        assertEquals("name1", matched[0].getName());
-        assertEquals("name2", matched[1].getName());
-        assertEquals("name3", matched[2].getName());
-    }
-
     public void testInvalidMatchDomain() throws Exception {
-        Cookie cookie = new Cookie("beta.gamma.com", "name", null, "/", null, false); 
+        Cookie cookie = new Cookie("name", null); 
+        cookie.setDomain("beta.gamma.com");
         cookie.setDomainAttributeSpecified(true);
+        cookie.setPath("/");
         cookie.setPathAttributeSpecified(true);
 
-        CookieSpec cookiespec = new CookieSpecBase();
-        cookiespec.validate("alpha.beta.gamma.com", 80, "/", false, cookie);
-        assertTrue(cookiespec.match("alpha.beta.gamma.com", 80, "/", false, cookie));
+        CookieSpec cookiespec = new BrowserCompatSpec();
+        CookieOrigin origin = new CookieOrigin("alpha.beta.gamma.com", 80, "/", false); 
+        cookiespec.validate(cookie, origin);
+        assertTrue(cookiespec.match(cookie, origin));
     }
 
-    public void testFormatInvalidCookie() throws Exception {
-        CookieSpec cookiespec = new CookieSpecBase();
-        try {
-            String s = cookiespec.formatCookie(null);
-            fail("IllegalArgumentException nust have been thrown");
-        } catch (IllegalArgumentException expected) {
-        }
-    }    
-
     /**
      * Tests generic cookie formatting.
      */
     public void testGenericCookieFormatting() throws Exception {
         Header header = new Header("Set-Cookie", 
             "name=value; path=/; domain=.mydomain.com");
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie[] cookies = cookiespec.parse("myhost.mydomain.com", 80, "/", false, header);
-        cookiespec.validate("myhost.mydomain.com", 80, "/", false, cookies[0]);
-        String s = cookiespec.formatCookie(cookies[0]);
-        assertEquals("name=value", s);
-    }    
-
-    public void testGenericCookieFormattingAsHeader() throws Exception {
-        Header header = new Header("Set-Cookie", 
-            "name=value; path=/; domain=.mydomain.com");
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie[] cookies = cookiespec.parse("myhost.mydomain.com", 80, "/", false, header);
-        cookiespec.validate("myhost.mydomain.com", 80, "/", false, cookies[0]);
-        Header cookieheader = cookiespec.formatCookieHeader(cookies[0]);
-        assertEquals("name=value", cookieheader.getValue());
+        CookieSpec cookiespec = new BrowserCompatSpec();
+        CookieOrigin origin = new CookieOrigin("myhost.mydomain.com", 80, "/", false); 
+        Cookie[] cookies = cookiespec.parse(header, origin);
+        cookiespec.validate(cookies[0], origin);
+        Header[] headers = cookiespec.formatCookies(cookies);
+        assertNotNull(headers);
+        assertEquals(1, headers.length);
+        assertEquals("name=value", headers[0].getValue());
     }    
 
     /**
      * Tests if null cookie values are handled correctly.
      */
     public void testNullCookieValueFormatting() {
-        Cookie cookie = new Cookie(".whatever.com", "name", null, "/", null, false); 
+        Cookie cookie = new Cookie("name", null);
+        cookie.setDomain(".whatever.com");
         cookie.setDomainAttributeSpecified(true);
+        cookie.setPath("/");
         cookie.setPathAttributeSpecified(true);
 
-        CookieSpec cookiespec = new CookieSpecBase();
-        String s = cookiespec.formatCookie(cookie);
-        assertEquals("name=", s);
+        CookieSpec cookiespec = new BrowserCompatSpec();
+        Header[] headers = cookiespec.formatCookies(new Cookie[]{cookie});
+        assertNotNull(headers);
+        assertEquals(1, headers.length);
+        assertEquals("name=", headers[0].getValue());
     }
 
-    public void testFormatInvalidCookies() throws Exception {
-        CookieSpec cookiespec = new CookieSpecBase();
-        try {
-            String s = cookiespec.formatCookies(null);
-            fail("IllegalArgumentException nust have been thrown");
-        } catch (IllegalArgumentException expected) {
-        }
-    }    
-
-    public void testFormatZeroCookies() throws Exception {
-        CookieSpec cookiespec = new CookieSpecBase();
-        try {
-            String s = cookiespec.formatCookies(new Cookie[] {});
-            fail("IllegalArgumentException nust have been thrown");
-        } catch (IllegalArgumentException expected) {
-        }
-    }    
-
     /**
      * Tests generic cookie formatting.
      */
     public void testFormatSeveralCookies() throws Exception {
         Header header = new Header("Set-Cookie", 
             "name1=value1; path=/; domain=.mydomain.com, name2 = value2 ; path=/; domain=.mydomain.com");
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie[] cookies = cookiespec.parse("myhost.mydomain.com", 80, "/", false, header);
-        String s = cookiespec.formatCookies(cookies);
-        assertEquals("name1=value1; name2=value2", s);
-    }    
-
-    public void testFormatOneCookie() throws Exception {
-        Header header = new Header("Set-Cookie", 
-            "name1=value1; path=/; domain=.mydomain.com;");
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie[] cookies = cookiespec.parse("myhost.mydomain.com", 80, "/", false, header);
-        String s = cookiespec.formatCookies(cookies);
-        assertEquals("name1=value1", s);
-    }    
-
-    public void testFormatSeveralCookiesAsHeader() throws Exception {
-        Header header = new Header("Set-Cookie", 
-            "name1=value1; path=/; domain=.mydomain.com, name2 = value2 ; path=/; domain=.mydomain.com");
-        CookieSpec cookiespec = new CookieSpecBase();
-        Cookie[] cookies = cookiespec.parse("myhost.mydomain.com", 80, "/", false, header);
-        Header cookieheader = cookiespec.formatCookieHeader(cookies);
-        assertEquals("name1=value1; name2=value2", cookieheader.getValue());
+        CookieSpec cookiespec = new BrowserCompatSpec();
+        CookieOrigin origin = new CookieOrigin("myhost.mydomain.com", 80, "/", false); 
+        Cookie[] cookies = cookiespec.parse(header, origin);
+        Header[] headers = cookiespec.formatCookies(cookies);
+        assertNotNull(headers);
+        assertEquals(1, headers.length);
+        assertEquals("name1=value1; name2=value2", headers[0].getValue());
     }    
 
     public void testKeepCloverHappy() throws Exception {
-        MalformedCookieException ex1 = new MalformedCookieException(); 
-        MalformedCookieException ex2 = new MalformedCookieException("whatever"); 
-        MalformedCookieException ex3 = new MalformedCookieException("whatever", null); 
+        new MalformedCookieException(); 
+        new MalformedCookieException("whatever"); 
+        new MalformedCookieException("whatever", null); 
     }
 
 }



Mime
View raw message