diff --git a/module-client/pom.xml b/module-client/pom.xml
index f04a6f746..311be9f34 100644
--- a/module-client/pom.xml
+++ b/module-client/pom.xml
@@ -84,8 +84,8 @@
- 1.4
- 1.4
+ 1.5
+ 1.5
true
true
diff --git a/module-client/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java b/module-client/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java
index 99c1e4845..3884fe0a3 100644
--- a/module-client/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java
+++ b/module-client/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java
@@ -159,11 +159,10 @@ public class RequestAddCookies implements HttpRequestInterceptor {
}
}
// Generate Cookie request headers
- cookies = matchedCookies.toArray(new Cookie[matchedCookies.size()]);
if (cookies.length > 0) {
- Header[] headers = cookieSpec.formatCookies(cookies);
- for (int i = 0; i < headers.length; i++) {
- request.addHeader(headers[i]);
+ List headers = cookieSpec.formatCookies(matchedCookies);
+ for (int i = 0; i < headers.size(); i++) {
+ request.addHeader(headers.get(i));
}
}
diff --git a/module-client/src/main/java/org/apache/http/client/protocol/ResponseProcessCookies.java b/module-client/src/main/java/org/apache/http/client/protocol/ResponseProcessCookies.java
index 7b9280ffd..d54aa8021 100644
--- a/module-client/src/main/java/org/apache/http/client/protocol/ResponseProcessCookies.java
+++ b/module-client/src/main/java/org/apache/http/client/protocol/ResponseProcessCookies.java
@@ -32,6 +32,7 @@
package org.apache.http.client.protocol;
import java.io.IOException;
+import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -116,9 +117,9 @@ public class ResponseProcessCookies implements HttpResponseInterceptor {
while (iterator.hasNext()) {
Header header = iterator.nextHeader();
try {
- Cookie[] cookies = cookieSpec.parse(header, cookieOrigin);
- for (int c = 0; c < cookies.length; c++) {
- Cookie cookie = cookies[c];
+ List cookies = cookieSpec.parse(header, cookieOrigin);
+ for (int c = 0; c < cookies.size(); c++) {
+ Cookie cookie = cookies.get(c);
try {
cookieSpec.validate(cookie, cookieOrigin);
cookieStore.addCookie(cookie);
diff --git a/module-client/src/main/java/org/apache/http/cookie/CookieSpec.java b/module-client/src/main/java/org/apache/http/cookie/CookieSpec.java
index 527a61d1c..435fb8cfe 100644
--- a/module-client/src/main/java/org/apache/http/cookie/CookieSpec.java
+++ b/module-client/src/main/java/org/apache/http/cookie/CookieSpec.java
@@ -31,6 +31,8 @@
package org.apache.http.cookie;
+import java.util.List;
+
import org.apache.http.Header;
/**
@@ -71,7 +73,7 @@ public interface CookieSpec {
* @return an array of Cookies parsed from the header
* @throws MalformedCookieException if an exception occurs during parsing
*/
- Cookie[] parse(Header header, CookieOrigin origin) throws MalformedCookieException;
+ List parse(Header header, CookieOrigin origin) throws MalformedCookieException;
/**
* Validate the cookie according to validation rules defined by the
@@ -101,7 +103,7 @@ public interface CookieSpec {
* @return a Header for the given Cookies.
* @throws IllegalArgumentException if an input parameter is illegal
*/
- Header[] formatCookies(Cookie[] cookies);
+ List formatCookies(List cookies);
/**
* Returns a request header identifying what version of the state management
diff --git a/module-client/src/main/java/org/apache/http/impl/cookie/AbstractCookieSpec.java b/module-client/src/main/java/org/apache/http/impl/cookie/AbstractCookieSpec.java
index 003debf84..61bf8b55e 100644
--- a/module-client/src/main/java/org/apache/http/impl/cookie/AbstractCookieSpec.java
+++ b/module-client/src/main/java/org/apache/http/impl/cookie/AbstractCookieSpec.java
@@ -31,8 +31,8 @@
package org.apache.http.impl.cookie;
+import java.util.Collection;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.Map;
import org.apache.http.cookie.CookieAttributeHandler;
@@ -52,14 +52,14 @@ public abstract class AbstractCookieSpec implements CookieSpec {
/**
* Stores attribute name -> attribute handler mappings
*/
- private final Map attribHandlerMap;
+ private final Map attribHandlerMap;
/**
* Default constructor
* */
public AbstractCookieSpec() {
super();
- this.attribHandlerMap = new HashMap(10);
+ this.attribHandlerMap = new HashMap(10);
}
public void registerAttribHandler(
@@ -103,8 +103,8 @@ public abstract class AbstractCookieSpec implements CookieSpec {
}
}
- protected Iterator getAttribHandlerIterator() {
- return this.attribHandlerMap.values().iterator();
+ protected Collection getAttribHandlers() {
+ return this.attribHandlerMap.values();
}
}
diff --git a/module-client/src/main/java/org/apache/http/impl/cookie/BasicClientCookie.java b/module-client/src/main/java/org/apache/http/impl/cookie/BasicClientCookie.java
index 7168ff67c..133f3e3dd 100644
--- a/module-client/src/main/java/org/apache/http/impl/cookie/BasicClientCookie.java
+++ b/module-client/src/main/java/org/apache/http/impl/cookie/BasicClientCookie.java
@@ -71,7 +71,7 @@ public class BasicClientCookie implements SetCookie, ClientCookie {
throw new IllegalArgumentException("Name may not be null");
}
this.name = name;
- this.attribs = new HashMap();
+ this.attribs = new HashMap();
this.value = value;
}
@@ -305,7 +305,7 @@ public class BasicClientCookie implements SetCookie, ClientCookie {
}
public String getAttribute(final String name) {
- return (String) this.attribs.get(name);
+ return this.attribs.get(name);
}
public boolean containsAttribute(final String name) {
@@ -341,7 +341,7 @@ public class BasicClientCookie implements SetCookie, ClientCookie {
private final String name;
/** Cookie attributes as specified by the origin server */
- private final Map attribs;
+ private final Map attribs;
/** Cookie value */
private String value;
diff --git a/module-client/src/main/java/org/apache/http/impl/cookie/BrowserCompatSpec.java b/module-client/src/main/java/org/apache/http/impl/cookie/BrowserCompatSpec.java
index 0297835c2..edf040db6 100644
--- a/module-client/src/main/java/org/apache/http/impl/cookie/BrowserCompatSpec.java
+++ b/module-client/src/main/java/org/apache/http/impl/cookie/BrowserCompatSpec.java
@@ -31,6 +31,9 @@
package org.apache.http.impl.cookie;
+import java.util.ArrayList;
+import java.util.List;
+
import org.apache.http.FormattedHeader;
import org.apache.http.Header;
import org.apache.http.HeaderElement;
@@ -96,7 +99,7 @@ public class BrowserCompatSpec extends CookieSpecBase {
this(null);
}
- public Cookie[] parse(final Header header, final CookieOrigin origin)
+ public List parse(final Header header, final CookieOrigin origin)
throws MalformedCookieException {
if (header == null) {
throw new IllegalArgumentException("Header may not be null");
@@ -146,18 +149,18 @@ public class BrowserCompatSpec extends CookieSpecBase {
return parse(elems, origin);
}
- public Header[] formatCookies(final Cookie[] cookies) {
+ public List formatCookies(final List cookies) {
if (cookies == null) {
- throw new IllegalArgumentException("Cookie array may not be null");
+ throw new IllegalArgumentException("List of cookies may not be null");
}
- if (cookies.length == 0) {
- throw new IllegalArgumentException("Cookie array may not be empty");
+ if (cookies.isEmpty()) {
+ throw new IllegalArgumentException("List of cookies may not be empty");
}
- CharArrayBuffer buffer = new CharArrayBuffer(20 * cookies.length);
+ CharArrayBuffer buffer = new CharArrayBuffer(20 * cookies.size());
buffer.append(SM.COOKIE);
buffer.append(": ");
- for (int i = 0; i < cookies.length; i++) {
- Cookie cookie = cookies[i];
+ for (int i = 0; i < cookies.size(); i++) {
+ Cookie cookie = cookies.get(i);
if (i > 0) {
buffer.append("; ");
}
@@ -168,7 +171,9 @@ public class BrowserCompatSpec extends CookieSpecBase {
buffer.append(s);
}
}
- return new Header[] { new BufferedHeader(buffer) };
+ List headers = new ArrayList(1);
+ headers.add(new BufferedHeader(buffer));
+ return headers;
}
public int getVersion() {
diff --git a/module-client/src/main/java/org/apache/http/impl/cookie/CookieSpecBase.java b/module-client/src/main/java/org/apache/http/impl/cookie/CookieSpecBase.java
index 754bd9051..91f64665c 100644
--- a/module-client/src/main/java/org/apache/http/impl/cookie/CookieSpecBase.java
+++ b/module-client/src/main/java/org/apache/http/impl/cookie/CookieSpecBase.java
@@ -31,7 +31,8 @@
package org.apache.http.impl.cookie;
-import java.util.Iterator;
+import java.util.ArrayList;
+import java.util.List;
import org.apache.http.HeaderElement;
import org.apache.http.NameValuePair;
@@ -66,9 +67,9 @@ public abstract class CookieSpecBase extends AbstractCookieSpec {
return origin.getHost();
}
- protected Cookie[] parse(final HeaderElement[] elems, final CookieOrigin origin)
+ protected List parse(final HeaderElement[] elems, final CookieOrigin origin)
throws MalformedCookieException {
- Cookie[] cookies = new Cookie[elems.length];
+ List cookies = new ArrayList(elems.length);
for (int i = 0; i < elems.length; i++) {
HeaderElement headerelement = elems[i];
@@ -95,7 +96,7 @@ public abstract class CookieSpecBase extends AbstractCookieSpec {
handler.parse(cookie, attrib.getValue());
}
}
- cookies[i] = cookie;
+ cookies.add(cookie);
}
return cookies;
}
@@ -108,8 +109,7 @@ public abstract class CookieSpecBase extends AbstractCookieSpec {
if (origin == null) {
throw new IllegalArgumentException("Cookie origin may not be null");
}
- for (Iterator i = getAttribHandlerIterator(); i.hasNext();) {
- CookieAttributeHandler handler = (CookieAttributeHandler) i.next();
+ for (CookieAttributeHandler handler: getAttribHandlers()) {
handler.validate(cookie, origin);
}
}
@@ -121,8 +121,7 @@ public abstract class CookieSpecBase extends AbstractCookieSpec {
if (origin == null) {
throw new IllegalArgumentException("Cookie origin may not be null");
}
- for (Iterator i = getAttribHandlerIterator(); i.hasNext();) {
- CookieAttributeHandler handler = (CookieAttributeHandler) i.next();
+ for (CookieAttributeHandler handler: getAttribHandlers()) {
if (!handler.match(cookie, origin)) {
return false;
}
diff --git a/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDraftHeaderParser.java b/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDraftHeaderParser.java
index fce91a567..cd29367b4 100644
--- a/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDraftHeaderParser.java
+++ b/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDraftHeaderParser.java
@@ -65,14 +65,14 @@ public class NetscapeDraftHeaderParser {
throw new IllegalArgumentException("Parser cursor may not be null");
}
NameValuePair nvp = this.nvpParser.parseNameValuePair(buffer, cursor, DELIMITERS);
- List params = new ArrayList();
+ List params = new ArrayList();
while (!cursor.atEnd()) {
NameValuePair param = this.nvpParser.parseNameValuePair(buffer, cursor, DELIMITERS);
params.add(param);
}
return new BasicHeaderElement(
nvp.getName(),
- nvp.getValue(), (NameValuePair[]) params.toArray(new NameValuePair[params.size()]));
+ nvp.getValue(), params.toArray(new NameValuePair[params.size()]));
}
}
diff --git a/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDraftSpec.java b/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDraftSpec.java
index e9f64b45c..391b869f5 100644
--- a/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDraftSpec.java
+++ b/module-client/src/main/java/org/apache/http/impl/cookie/NetscapeDraftSpec.java
@@ -31,6 +31,9 @@
package org.apache.http.impl.cookie;
+import java.util.ArrayList;
+import java.util.List;
+
import org.apache.http.FormattedHeader;
import org.apache.http.Header;
import org.apache.http.HeaderElement;
@@ -98,7 +101,7 @@ public class NetscapeDraftSpec extends CookieSpecBase {
* @return an array of Cookies parsed from the Set-Cookie value
* @throws MalformedCookieException if an exception occurs during parsing
*/
- public Cookie[] parse(final Header header, final CookieOrigin origin)
+ public List parse(final Header header, final CookieOrigin origin)
throws MalformedCookieException {
if (header == null) {
throw new IllegalArgumentException("Header may not be null");
@@ -126,18 +129,18 @@ public class NetscapeDraftSpec extends CookieSpecBase {
return parse(new HeaderElement[] { parser.parseHeader(buffer, cursor) }, origin);
}
- public Header[] formatCookies(final Cookie[] cookies) {
+ public List formatCookies(final List cookies) {
if (cookies == null) {
- throw new IllegalArgumentException("Cookie array may not be null");
+ throw new IllegalArgumentException("List of cookies may not be null");
}
- if (cookies.length == 0) {
- throw new IllegalArgumentException("Cookie array may not be empty");
+ if (cookies.isEmpty()) {
+ throw new IllegalArgumentException("List of cookies may not be empty");
}
- CharArrayBuffer buffer = new CharArrayBuffer(20 * cookies.length);
+ CharArrayBuffer buffer = new CharArrayBuffer(20 * cookies.size());
buffer.append(SM.COOKIE);
buffer.append(": ");
- for (int i = 0; i < cookies.length; i++) {
- Cookie cookie = cookies[i];
+ for (int i = 0; i < cookies.size(); i++) {
+ Cookie cookie = cookies.get(i);
if (i > 0) {
buffer.append("; ");
}
@@ -148,7 +151,9 @@ public class NetscapeDraftSpec extends CookieSpecBase {
buffer.append(s);
}
}
- return new Header[] { new BufferedHeader(buffer) };
+ List headers = new ArrayList(1);
+ headers.add(new BufferedHeader(buffer));
+ return headers;
}
public int getVersion() {
diff --git a/module-client/src/main/java/org/apache/http/impl/cookie/RFC2109Spec.java b/module-client/src/main/java/org/apache/http/impl/cookie/RFC2109Spec.java
index 94af25e38..a3e17013c 100644
--- a/module-client/src/main/java/org/apache/http/impl/cookie/RFC2109Spec.java
+++ b/module-client/src/main/java/org/apache/http/impl/cookie/RFC2109Spec.java
@@ -31,7 +31,9 @@
package org.apache.http.impl.cookie;
-import java.util.Arrays;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
import org.apache.http.Header;
import org.apache.http.HeaderElement;
@@ -98,7 +100,7 @@ public class RFC2109Spec extends CookieSpecBase {
this(null, false);
}
- public Cookie[] parse(final Header header, final CookieOrigin origin)
+ public List parse(final Header header, final CookieOrigin origin)
throws MalformedCookieException {
if (header == null) {
throw new IllegalArgumentException("Header may not be null");
@@ -125,14 +127,14 @@ public class RFC2109Spec extends CookieSpecBase {
super.validate(cookie, origin);
}
- public Header[] formatCookies(final Cookie[] cookies) {
+ public List formatCookies(final List cookies) {
if (cookies == null) {
- throw new IllegalArgumentException("Cookie array may not be null");
+ throw new IllegalArgumentException("List of cookies may not be null");
}
- if (cookies.length == 0) {
- throw new IllegalArgumentException("Cookie array may not be empty");
+ if (cookies.isEmpty()) {
+ throw new IllegalArgumentException("List of cookies may not be empty");
}
- Arrays.sort(cookies, PATH_COMPARATOR);
+ Collections.sort(cookies, PATH_COMPARATOR);
if (this.oneHeader) {
return doFormatOneHeader(cookies);
} else {
@@ -140,40 +142,42 @@ public class RFC2109Spec extends CookieSpecBase {
}
}
- private Header[] doFormatOneHeader(final Cookie[] cookies) {
+ private List doFormatOneHeader(final List cookies) {
int version = Integer.MAX_VALUE;
// Pick the lowest common denominator
- for (int i = 0; i < cookies.length; i++) {
- Cookie cookie = cookies[i];
+ for (int i = 0; i < cookies.size(); i++) {
+ Cookie cookie = cookies.get(i);
if (cookie.getVersion() < version) {
version = cookie.getVersion();
}
}
- CharArrayBuffer buffer = new CharArrayBuffer(40 * cookies.length);
+ CharArrayBuffer buffer = new CharArrayBuffer(40 * cookies.size());
buffer.append(SM.COOKIE);
buffer.append(": ");
buffer.append("$Version=");
buffer.append(Integer.toString(version));
- for (int i = 0; i < cookies.length; i++) {
+ for (int i = 0; i < cookies.size(); i++) {
buffer.append("; ");
- Cookie cookie = cookies[i];
+ Cookie cookie = cookies.get(i);
formatCookieAsVer(buffer, cookie, version);
}
- return new Header[] { new BufferedHeader(buffer) };
+ List headers = new ArrayList(1);
+ headers.add(new BufferedHeader(buffer));
+ return headers;
}
- private Header[] doFormatManyHeaders(final Cookie[] cookies) {
- Header[] headers = new Header[cookies.length];
- for (int i = 0; i < cookies.length; i++) {
- Cookie cookie = cookies[i];
+ private List doFormatManyHeaders(final List cookies) {
+ List headers = new ArrayList(cookies.size());
+ for (int i = 0; i < cookies.size(); i++) {
+ Cookie cookie = cookies.get(i);
int version = cookie.getVersion();
CharArrayBuffer buffer = new CharArrayBuffer(40);
buffer.append("Cookie: ");
buffer.append("$Version=");
buffer.append(Integer.toString(version));
buffer.append("; ");
- formatCookieAsVer(buffer, cookies[i], version);
- headers[i] = new BufferedHeader(buffer);
+ formatCookieAsVer(buffer, cookie, version);
+ headers.add(new BufferedHeader(buffer));
}
return headers;
}
diff --git a/module-client/src/main/java/org/apache/http/impl/cookie/RFC2965Spec.java b/module-client/src/main/java/org/apache/http/impl/cookie/RFC2965Spec.java
index 67eee1b52..2e654e6fe 100644
--- a/module-client/src/main/java/org/apache/http/impl/cookie/RFC2965Spec.java
+++ b/module-client/src/main/java/org/apache/http/impl/cookie/RFC2965Spec.java
@@ -30,8 +30,9 @@
package org.apache.http.impl.cookie;
+import java.util.ArrayList;
import java.util.HashMap;
-import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import org.apache.http.Header;
@@ -90,7 +91,7 @@ public class RFC2965Spec extends RFC2109Spec {
return cookie;
}
- public Cookie[] parse(
+ public List parse(
final Header header,
CookieOrigin origin) throws MalformedCookieException {
if (header == null) {
@@ -104,7 +105,7 @@ public class RFC2965Spec extends RFC2109Spec {
HeaderElement[] elems = header.getElements();
- Cookie[] cookies = new Cookie[elems.length];
+ List cookies = new ArrayList(elems.length);
for (int i = 0; i < elems.length; i++) {
HeaderElement headerelement = elems[i];
@@ -126,14 +127,14 @@ public class RFC2965Spec extends RFC2109Spec {
// Eliminate duplicate attributes. The first occurrence takes precedence
// See RFC2965: 3.2 Origin Server Role
- Map attribmap = new HashMap(attribs.length);
+ Map attribmap =
+ new HashMap(attribs.length);
for (int j = attribs.length - 1; j >= 0; j--) {
NameValuePair param = attribs[j];
attribmap.put(param.getName().toLowerCase(), param);
}
- for (Iterator it = attribmap.entrySet().iterator(); it.hasNext(); ) {
- Map.Entry entry = (Map.Entry) it.next();
- NameValuePair attrib = (NameValuePair) entry.getValue();
+ for (Map.Entry entry: attribmap.entrySet()) {
+ NameValuePair attrib = entry.getValue();
String s = attrib.getName().toLowerCase();
cookie.setAttribute(s, attrib.getValue());
@@ -143,7 +144,7 @@ public class RFC2965Spec extends RFC2109Spec {
handler.parse(cookie, attrib.getValue());
}
}
- cookies[i] = cookie;
+ cookies.add(cookie);
}
return cookies;
}
diff --git a/module-client/src/test/java/org/apache/http/impl/cookie/TestAbstractCookieSpec.java b/module-client/src/test/java/org/apache/http/impl/cookie/TestAbstractCookieSpec.java
index e27f70d00..37d7a155b 100644
--- a/module-client/src/test/java/org/apache/http/impl/cookie/TestAbstractCookieSpec.java
+++ b/module-client/src/test/java/org/apache/http/impl/cookie/TestAbstractCookieSpec.java
@@ -32,6 +32,7 @@ package org.apache.http.impl.cookie;
import java.io.IOException;
import java.util.Iterator;
+import java.util.List;
import junit.framework.Test;
import junit.framework.TestCase;
@@ -62,7 +63,7 @@ public class TestAbstractCookieSpec extends TestCase {
private static class DummyCookieSpec extends AbstractCookieSpec {
- public Header[] formatCookies(Cookie[] cookies) {
+ public List formatCookies(List cookies) {
return null;
}
@@ -70,7 +71,7 @@ public class TestAbstractCookieSpec extends TestCase {
return true;
}
- public Cookie[] parse(Header header, CookieOrigin origin) throws MalformedCookieException {
+ public List parse(Header header, CookieOrigin origin) throws MalformedCookieException {
return null;
}
@@ -116,7 +117,7 @@ public class TestAbstractCookieSpec extends TestCase {
assertTrue(h1 == cookiespec.getAttribHandler("thistoo"));
assertTrue(h2 == cookiespec.getAttribHandler("thattoo"));
- Iterator it = cookiespec.getAttribHandlerIterator();
+ Iterator it = cookiespec.getAttribHandlers().iterator();
assertNotNull(it.next());
assertNotNull(it.next());
assertNotNull(it.next());
diff --git a/module-client/src/test/java/org/apache/http/impl/cookie/TestBrowserCompatSpec.java b/module-client/src/test/java/org/apache/http/impl/cookie/TestBrowserCompatSpec.java
index 7158b6b74..f670ab291 100644
--- a/module-client/src/test/java/org/apache/http/impl/cookie/TestBrowserCompatSpec.java
+++ b/module-client/src/test/java/org/apache/http/impl/cookie/TestBrowserCompatSpec.java
@@ -30,7 +30,9 @@
package org.apache.http.impl.cookie;
+import java.util.ArrayList;
import java.util.Date;
+import java.util.List;
import junit.framework.Test;
import junit.framework.TestCase;
@@ -85,13 +87,13 @@ public class TestBrowserCompatSpec extends TestCase {
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);
+ List cookies = cookiespec.parse(header, origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(i), origin);
}
- assertNotNull(parsed);
- assertEquals(1, parsed.length);
- assertEquals(".whatever.com", parsed[0].getDomain());
+ assertNotNull(cookies);
+ assertEquals(1, cookies.size());
+ assertEquals(".whatever.com", cookies.get(0).getDomain());
}
/**
@@ -105,27 +107,27 @@ public class TestBrowserCompatSpec extends TestCase {
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);
+ List cookies = cookiespec.parse(header, origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(i), origin);
}
- assertEquals(2, cookies.length);
+ assertEquals(2, cookies.size());
- assertEquals("custno", cookies[0].getName());
- assertEquals("12345", cookies[0].getValue());
- assertEquals("test", cookies[0].getComment());
- assertEquals(0, cookies[0].getVersion());
- assertEquals("www.apache.org", cookies[0].getDomain());
- assertEquals("/", cookies[0].getPath());
- assertFalse(cookies[0].isSecure());
+ assertEquals("custno", cookies.get(0).getName());
+ assertEquals("12345", cookies.get(0).getValue());
+ assertEquals("test", cookies.get(0).getComment());
+ assertEquals(0, cookies.get(0).getVersion());
+ assertEquals("www.apache.org", cookies.get(0).getDomain());
+ assertEquals("/", cookies.get(0).getPath());
+ assertFalse(cookies.get(0).isSecure());
- assertEquals("name", cookies[1].getName());
- assertEquals("John", cookies[1].getValue());
- assertEquals(null, cookies[1].getComment());
- assertEquals(0, cookies[1].getVersion());
- assertEquals(".apache.org", cookies[1].getDomain());
- assertEquals("/", cookies[1].getPath());
- assertTrue(cookies[1].isSecure());
+ assertEquals("name", cookies.get(1).getName());
+ assertEquals("John", cookies.get(1).getValue());
+ assertEquals(null, cookies.get(1).getComment());
+ assertEquals(0, cookies.get(1).getVersion());
+ assertEquals(".apache.org", cookies.get(1).getDomain());
+ assertEquals("/", cookies.get(1).getPath());
+ assertTrue(cookies.get(1).isSecure());
}
/**
@@ -139,28 +141,28 @@ public class TestBrowserCompatSpec extends TestCase {
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);
+ List cookies = cookiespec.parse(header, origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(i), origin);
}
- assertEquals(2, cookies.length);
+ assertEquals(2, cookies.size());
- assertEquals("custno", cookies[0].getName());
- assertEquals("12345", cookies[0].getValue());
- assertEquals("test", cookies[0].getComment());
- assertEquals(0, cookies[0].getVersion());
- assertEquals("www.apache.org", cookies[0].getDomain());
- assertEquals("/", cookies[0].getPath());
- assertFalse(cookies[0].isSecure());
+ assertEquals("custno", cookies.get(0).getName());
+ assertEquals("12345", cookies.get(0).getValue());
+ assertEquals("test", cookies.get(0).getComment());
+ assertEquals(0, cookies.get(0).getVersion());
+ assertEquals("www.apache.org", cookies.get(0).getDomain());
+ assertEquals("/", cookies.get(0).getPath());
+ assertFalse(cookies.get(0).isSecure());
- assertEquals("name", cookies[1].getName());
- assertEquals("John", cookies[1].getValue());
- assertEquals(null, cookies[1].getComment());
- assertEquals(0, cookies[1].getVersion());
- assertEquals(".apache.org", cookies[1].getDomain());
- assertEquals("/", cookies[1].getPath());
- assertTrue(cookies[1].isSecure());
+ assertEquals("name", cookies.get(1).getName());
+ assertEquals("John", cookies.get(1).getValue());
+ assertEquals(null, cookies.get(1).getComment());
+ assertEquals(0, cookies.get(1).getVersion());
+ assertEquals(".apache.org", cookies.get(1).getDomain());
+ assertEquals("/", cookies.get(1).getPath());
+ assertTrue(cookies.get(1).isSecure());
}
@@ -174,20 +176,20 @@ public class TestBrowserCompatSpec extends TestCase {
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);
+ List cookies = cookiespec.parse(header, origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(i), origin);
}
- assertEquals(1, cookies.length);
+ assertEquals(1, cookies.size());
- assertEquals("name", cookies[0].getName());
- assertEquals("Doe, John", cookies[0].getValue());
- assertEquals(null, cookies[0].getComment());
- assertEquals(0, cookies[0].getVersion());
- assertEquals(".apache.org", cookies[0].getDomain());
- assertEquals("/", cookies[0].getPath());
- assertTrue(cookies[0].isSecure());
+ assertEquals("name", cookies.get(0).getName());
+ assertEquals("Doe, John", cookies.get(0).getValue());
+ assertEquals(null, cookies.get(0).getComment());
+ assertEquals(0, cookies.get(0).getVersion());
+ assertEquals(".apache.org", cookies.get(0).getDomain());
+ assertEquals("/", cookies.get(0).getPath());
+ assertTrue(cookies.get(0).isSecure());
}
@@ -199,13 +201,13 @@ public class TestBrowserCompatSpec extends TestCase {
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);
+ List cookies = cookiespec.parse(header, origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(i), origin);
}
assertNotNull("Expected some cookies",cookies);
- assertEquals("Expected 1 cookie",1,cookies.length);
- assertNotNull("Expected cookie to have getExpiryDate",cookies[0].getExpiryDate());
+ assertEquals("Expected 1 cookie",1,cookies.size());
+ assertNotNull("Expected cookie to have getExpiryDate",cookies.get(0).getExpiryDate());
}
public void testSecurityError() throws Exception {
@@ -216,9 +218,9 @@ public class TestBrowserCompatSpec extends TestCase {
CookieSpec cookiespec = new BrowserCompatSpec();
CookieOrigin origin = new CookieOrigin("www.apache.org", 80, "/", true);
try {
- Cookie[] cookies = cookiespec.parse(header, origin);
- for (int i = 0; i < cookies.length; i++) {
- cookiespec.validate(cookies[i], origin);
+ List cookies = cookiespec.parse(header, origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(i), origin);
}
fail("MalformedCookieException exception should have been thrown");
} catch (MalformedCookieException ex) {
@@ -231,21 +233,21 @@ public class TestBrowserCompatSpec extends TestCase {
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);
+ List cookies = cookiespec.parse(header, origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(i), origin);
}
- assertEquals("Found 1 cookie.",1,parsed.length);
- assertEquals("Name","cookie-name",parsed[0].getName());
- assertEquals("Value","cookie-value",parsed[0].getValue());
- assertTrue("Comment",null == parsed[0].getComment());
- assertTrue("ExpiryDate",null == parsed[0].getExpiryDate());
- //assertTrue("isToBeDiscarded",parsed[0].isToBeDiscarded());
- assertTrue("isPersistent",!parsed[0].isPersistent());
- assertEquals("Domain","127.0.0.1",parsed[0].getDomain());
- assertEquals("Path","/path",parsed[0].getPath());
- assertTrue("Secure",!parsed[0].isSecure());
- assertEquals("Version",0,parsed[0].getVersion());
+ assertEquals("Found 1 cookie.",1,cookies.size());
+ assertEquals("Name","cookie-name",cookies.get(0).getName());
+ assertEquals("Value","cookie-value",cookies.get(0).getValue());
+ assertTrue("Comment",null == cookies.get(0).getComment());
+ assertTrue("ExpiryDate",null == cookies.get(0).getExpiryDate());
+ //assertTrue("isToBeDiscarded",cookies.get(0).isToBeDiscarded());
+ assertTrue("isPersistent",!cookies.get(0).isPersistent());
+ assertEquals("Domain","127.0.0.1",cookies.get(0).getDomain());
+ assertEquals("Path","/path",cookies.get(0).getPath());
+ assertTrue("Secure",!cookies.get(0).isSecure());
+ assertEquals("Version",0,cookies.get(0).getVersion());
}
public void testParseSimple2() throws Exception {
@@ -253,21 +255,21 @@ public class TestBrowserCompatSpec extends TestCase {
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);
+ List cookies = cookiespec.parse(header, origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(i), origin);
}
- assertEquals("Found 1 cookie.", 1, parsed.length);
- assertEquals("Name", "cookie-name", parsed[0].getName());
- assertEquals("Value", "cookie-value", parsed[0].getValue());
- assertTrue("Comment", null == parsed[0].getComment());
- assertTrue("ExpiryDate", null == parsed[0].getExpiryDate());
- //assertTrue("isToBeDiscarded",parsed[0].isToBeDiscarded());
- assertTrue("isPersistent", !parsed[0].isPersistent());
- assertEquals("Domain", "127.0.0.1", parsed[0].getDomain());
- assertEquals("Path", "/", parsed[0].getPath());
- assertTrue("Secure", !parsed[0].isSecure());
- assertEquals("Version", 0, parsed[0].getVersion());
+ assertEquals("Found 1 cookie.", 1, cookies.size());
+ assertEquals("Name", "cookie-name", cookies.get(0).getName());
+ assertEquals("Value", "cookie-value", cookies.get(0).getValue());
+ assertTrue("Comment", null == cookies.get(0).getComment());
+ assertTrue("ExpiryDate", null == cookies.get(0).getExpiryDate());
+ //assertTrue("isToBeDiscarded",cookies.get(0).isToBeDiscarded());
+ assertTrue("isPersistent", !cookies.get(0).isPersistent());
+ assertEquals("Domain", "127.0.0.1", cookies.get(0).getDomain());
+ assertEquals("Path", "/", cookies.get(0).getPath());
+ assertTrue("Secure", !cookies.get(0).isSecure());
+ assertEquals("Version", 0, cookies.get(0).getVersion());
}
public void testParseNoName() throws Exception {
@@ -276,9 +278,9 @@ public class TestBrowserCompatSpec extends TestCase {
CookieSpec cookiespec = new BrowserCompatSpec();
CookieOrigin origin = new CookieOrigin("127.0.0.1", 80, "/", false);
try {
- Cookie[] parsed = cookiespec.parse(header, origin);
- for (int i = 0; i < parsed.length; i++) {
- cookiespec.validate(parsed[i], origin);
+ List cookies = cookiespec.parse(header, origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(i), origin);
}
fail("MalformedCookieException should have been thrown");
} catch (MalformedCookieException ex) {
@@ -291,21 +293,21 @@ public class TestBrowserCompatSpec extends TestCase {
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);
+ List cookies = cookiespec.parse(header, origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(i), origin);
}
- assertEquals("Found 1 cookie.",1,parsed.length);
- assertEquals("Name","cookie-name",parsed[0].getName());
- assertEquals("Value", "", parsed[0].getValue());
- assertTrue("Comment",null == parsed[0].getComment());
- assertTrue("ExpiryDate",null == parsed[0].getExpiryDate());
- //assertTrue("isToBeDiscarded",parsed[0].isToBeDiscarded());
- assertTrue("isPersistent",!parsed[0].isPersistent());
- assertEquals("Domain","127.0.0.1",parsed[0].getDomain());
- assertEquals("Path","/",parsed[0].getPath());
- assertTrue("Secure",!parsed[0].isSecure());
- assertEquals("Version",0,parsed[0].getVersion());
+ assertEquals("Found 1 cookie.",1,cookies.size());
+ assertEquals("Name","cookie-name",cookies.get(0).getName());
+ assertEquals("Value", "", cookies.get(0).getValue());
+ assertTrue("Comment",null == cookies.get(0).getComment());
+ assertTrue("ExpiryDate",null == cookies.get(0).getExpiryDate());
+ //assertTrue("isToBeDiscarded",cookies.get(0).isToBeDiscarded());
+ assertTrue("isPersistent",!cookies.get(0).isPersistent());
+ assertEquals("Domain","127.0.0.1",cookies.get(0).getDomain());
+ assertEquals("Path","/",cookies.get(0).getPath());
+ assertTrue("Secure",!cookies.get(0).isSecure());
+ assertEquals("Version",0,cookies.get(0).getVersion());
}
public void testParseWithWhiteSpace() throws Exception {
@@ -313,18 +315,18 @@ public class TestBrowserCompatSpec extends TestCase {
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);
+ List cookies = cookiespec.parse(header, origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(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].isSecure());
- assertTrue("ExpiryDate",null == parsed[0].getExpiryDate());
- assertTrue("Comment",null == parsed[0].getComment());
+ assertEquals("Found 1 cookie.",1,cookies.size());
+ assertEquals("Name","cookie-name",cookies.get(0).getName());
+ assertEquals("Value","cookie-value",cookies.get(0).getValue());
+ assertEquals("Domain","127.0.0.1",cookies.get(0).getDomain());
+ assertEquals("Path","/",cookies.get(0).getPath());
+ assertTrue("Secure",!cookies.get(0).isSecure());
+ assertTrue("ExpiryDate",null == cookies.get(0).getExpiryDate());
+ assertTrue("Comment",null == cookies.get(0).getComment());
}
public void testParseWithQuotes() throws Exception {
@@ -332,18 +334,18 @@ public class TestBrowserCompatSpec extends TestCase {
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);
+ List cookies = cookiespec.parse(header, origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(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].isSecure());
- assertTrue("ExpiryDate",null == parsed[0].getExpiryDate());
- assertTrue("Comment",null == parsed[0].getComment());
+ assertEquals("Found 1 cookie.",1,cookies.size());
+ assertEquals("Name","cookie-name",cookies.get(0).getName());
+ assertEquals("Value"," cookie-value ",cookies.get(0).getValue());
+ assertEquals("Domain","127.0.0.1",cookies.get(0).getDomain());
+ assertEquals("Path","/",cookies.get(0).getPath());
+ assertTrue("Secure",!cookies.get(0).isSecure());
+ assertTrue("ExpiryDate",null == cookies.get(0).getExpiryDate());
+ assertTrue("Comment",null == cookies.get(0).getComment());
}
public void testParseWithPath() throws Exception {
@@ -351,18 +353,18 @@ public class TestBrowserCompatSpec extends TestCase {
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);
+ List cookies = cookiespec.parse(header, origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(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].isSecure());
- assertTrue("ExpiryDate",null == parsed[0].getExpiryDate());
- assertTrue("Comment",null == parsed[0].getComment());
+ assertEquals("Found 1 cookie.",1,cookies.size());
+ assertEquals("Name","cookie-name",cookies.get(0).getName());
+ assertEquals("Value","cookie-value",cookies.get(0).getValue());
+ assertEquals("Domain","127.0.0.1",cookies.get(0).getDomain());
+ assertEquals("Path","/path/",cookies.get(0).getPath());
+ assertTrue("Secure",!cookies.get(0).isSecure());
+ assertTrue("ExpiryDate",null == cookies.get(0).getExpiryDate());
+ assertTrue("Comment",null == cookies.get(0).getComment());
}
public void testParseWithDomain() throws Exception {
@@ -370,18 +372,18 @@ public class TestBrowserCompatSpec extends TestCase {
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);
+ List cookies = cookiespec.parse(header, origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(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].isSecure());
- assertTrue("ExpiryDate",null == parsed[0].getExpiryDate());
- assertTrue("Comment",null == parsed[0].getComment());
+ assertEquals("Found 1 cookie.",1,cookies.size());
+ assertEquals("Name","cookie-name",cookies.get(0).getName());
+ assertEquals("Value","cookie-value",cookies.get(0).getValue());
+ assertEquals("Domain","127.0.0.1",cookies.get(0).getDomain());
+ assertEquals("Path","/",cookies.get(0).getPath());
+ assertTrue("Secure",!cookies.get(0).isSecure());
+ assertTrue("ExpiryDate",null == cookies.get(0).getExpiryDate());
+ assertTrue("Comment",null == cookies.get(0).getComment());
}
public void testParseWithSecure() throws Exception {
@@ -389,18 +391,18 @@ public class TestBrowserCompatSpec extends TestCase {
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);
+ List cookies = cookiespec.parse(header, origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(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].isSecure());
- assertTrue("ExpiryDate",null == parsed[0].getExpiryDate());
- assertTrue("Comment",null == parsed[0].getComment());
+ assertEquals("Found 1 cookie.",1,cookies.size());
+ assertEquals("Name","cookie-name",cookies.get(0).getName());
+ assertEquals("Value","cookie-value",cookies.get(0).getValue());
+ assertEquals("Domain","127.0.0.1",cookies.get(0).getDomain());
+ assertEquals("Path","/",cookies.get(0).getPath());
+ assertTrue("Secure",cookies.get(0).isSecure());
+ assertTrue("ExpiryDate",null == cookies.get(0).getExpiryDate());
+ assertTrue("Comment",null == cookies.get(0).getComment());
}
public void testParseWithComment() throws Exception {
@@ -409,18 +411,18 @@ public class TestBrowserCompatSpec extends TestCase {
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);
+ List cookies = cookiespec.parse(header, origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(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].isSecure());
- assertTrue("ExpiryDate",null == parsed[0].getExpiryDate());
- assertEquals("Comment","This is a comment.",parsed[0].getComment());
+ assertEquals("Found 1 cookie.",1,cookies.size());
+ assertEquals("Name","cookie-name",cookies.get(0).getName());
+ assertEquals("Value","cookie-value",cookies.get(0).getValue());
+ assertEquals("Domain","127.0.0.1",cookies.get(0).getDomain());
+ assertEquals("Path","/",cookies.get(0).getPath());
+ assertTrue("Secure",!cookies.get(0).isSecure());
+ assertTrue("ExpiryDate",null == cookies.get(0).getExpiryDate());
+ assertEquals("Comment","This is a comment.",cookies.get(0).getComment());
}
public void testParseWithExpires() throws Exception {
@@ -429,18 +431,18 @@ public class TestBrowserCompatSpec extends TestCase {
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);
+ List cookies = cookiespec.parse(header, origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(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].isSecure());
- assertEquals(new Date(10000L),parsed[0].getExpiryDate());
- assertTrue("Comment",null == parsed[0].getComment());
+ assertEquals("Found 1 cookie.",1,cookies.size());
+ assertEquals("Name","cookie-name",cookies.get(0).getName());
+ assertEquals("Value","cookie-value",cookies.get(0).getValue());
+ assertEquals("Domain","127.0.0.1",cookies.get(0).getDomain());
+ assertEquals("Path","/",cookies.get(0).getPath());
+ assertTrue("Secure",!cookies.get(0).isSecure());
+ assertEquals(new Date(10000L),cookies.get(0).getExpiryDate());
+ assertTrue("Comment",null == cookies.get(0).getComment());
}
public void testParseWithAll() throws Exception {
@@ -450,19 +452,19 @@ public class TestBrowserCompatSpec extends TestCase {
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);
+ List cookies = cookiespec.parse(header, origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(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].isSecure());
- assertEquals(new Date(10000L),parsed[0].getExpiryDate());
- assertEquals("Comment","This is a comment.",parsed[0].getComment());
- assertEquals("Version",0,parsed[0].getVersion());
+ assertEquals("Found 1 cookie.",1,cookies.size());
+ assertEquals("Name","cookie-name",cookies.get(0).getName());
+ assertEquals("Value","cookie-value",cookies.get(0).getValue());
+ assertEquals("Domain",".apache.org",cookies.get(0).getDomain());
+ assertEquals("Path","/commons",cookies.get(0).getPath());
+ assertTrue("Secure",cookies.get(0).isSecure());
+ assertEquals(new Date(10000L),cookies.get(0).getExpiryDate());
+ assertEquals("Comment","This is a comment.",cookies.get(0).getComment());
+ assertEquals("Version",0,cookies.get(0).getVersion());
}
public void testParseMultipleDifferentPaths() throws Exception {
@@ -472,15 +474,15 @@ public class TestBrowserCompatSpec extends TestCase {
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);
+ List cookies = cookiespec.parse(header, origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(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());
+ assertEquals("Wrong number of cookies.",2,cookies.size());
+ assertEquals("Name","name1",cookies.get(0).getName());
+ assertEquals("Value","value1",cookies.get(0).getValue());
+ assertEquals("Name","name1",cookies.get(1).getName());
+ assertEquals("Value","value2",cookies.get(1).getValue());
}
public void testParseRelativePath() throws Exception {
@@ -488,14 +490,14 @@ public class TestBrowserCompatSpec extends TestCase {
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);
+ List cookies = cookiespec.parse(header, origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(i), origin);
}
- assertEquals("Found 1 cookies.",1,parsed.length);
- assertEquals("Name","name1",parsed[0].getName());
- assertEquals("Value","value1",parsed[0].getValue());
- assertEquals("Path","whatever",parsed[0].getPath());
+ assertEquals("Found 1 cookies.",1,cookies.size());
+ assertEquals("Name","name1",cookies.get(0).getName());
+ assertEquals("Value","value1",cookies.get(0).getValue());
+ assertEquals("Path","whatever",cookies.get(0).getPath());
}
public void testParseWithWrongDomain() throws Exception {
@@ -505,9 +507,9 @@ public class TestBrowserCompatSpec extends TestCase {
CookieSpec cookiespec = new BrowserCompatSpec();
CookieOrigin origin = new CookieOrigin("127.0.0.2", 80, "/", false);
try {
- Cookie[] parsed = cookiespec.parse(header, origin);
- for (int i = 0; i < parsed.length; i++) {
- cookiespec.validate(parsed[i], origin);
+ List cookies = cookiespec.parse(header, origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(i), origin);
}
fail("MalformedCookieException exception should have been thrown");
} catch (MalformedCookieException ex) {
@@ -522,9 +524,9 @@ public class TestBrowserCompatSpec extends TestCase {
CookieSpec cookiespec = new BrowserCompatSpec();
CookieOrigin origin = new CookieOrigin("127.0.0.1", 80, "/path", false);
try {
- Cookie[] parsed = cookiespec.parse(header, origin);
- for (int i = 0; i < parsed.length; i++) {
- cookiespec.validate(parsed[i], origin);
+ List cookies = cookiespec.parse(header, origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(i), origin);
}
fail("MalformedCookieException should have been thrown.");
} catch (MalformedCookieException e) {
@@ -539,9 +541,9 @@ public class TestBrowserCompatSpec extends TestCase {
CookieSpec cookiespec = new BrowserCompatSpec();
CookieOrigin origin = new CookieOrigin("127.0.0.1", 80, "/foo", false);
try {
- Cookie[] parsed = cookiespec.parse(header, origin);
- for (int i = 0; i < parsed.length; i++) {
- cookiespec.validate(parsed[i], origin);
+ List cookies = cookiespec.parse(header, origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(i), origin);
}
fail("MalformedCookieException should have been thrown.");
} catch (MalformedCookieException e) {
@@ -556,12 +558,12 @@ public class TestBrowserCompatSpec extends TestCase {
Header header = new BasicHeader("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);
+ List cookies = cookiespec.parse(header, origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(i), origin);
}
- assertNotNull(parsed);
- assertEquals(1, parsed.length);
+ assertNotNull(cookies);
+ assertEquals(1, cookies.size());
}
/**
@@ -572,9 +574,9 @@ public class TestBrowserCompatSpec extends TestCase {
CookieSpec cookiespec = new BrowserCompatSpec();
CookieOrigin origin = new CookieOrigin("127.0.0.1", 80, "/", false);
try {
- Cookie[] parsed = cookiespec.parse(header, origin);
- for (int i = 0; i < parsed.length; i++) {
- cookiespec.validate(parsed[i], origin);
+ List cookies = cookiespec.parse(header, origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(i), origin);
}
fail("MalformedCookieException should have been thrown");
} catch (MalformedCookieException expected) {
@@ -588,17 +590,17 @@ public class TestBrowserCompatSpec extends TestCase {
Header header = new BasicHeader("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);
+ List cookies = cookiespec.parse(header, origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(i), origin);
}
- assertNotNull(parsed);
- assertEquals(1, parsed.length);
+ assertNotNull(cookies);
+ assertEquals(1, cookies.size());
}
/**
- * Tests if malformatted expires attribute is parsed correctly.
+ * Tests if malformatted expires attribute is cookies correctly.
*/
public void testCookieWithComma() throws Exception {
Header header = new BasicHeader("Set-Cookie", "name=value; expires=\"Thu, 01-Jan-1970 00:00:00 GMT");
@@ -606,9 +608,9 @@ public class TestBrowserCompatSpec extends TestCase {
CookieSpec cookiespec = new BrowserCompatSpec();
CookieOrigin origin = new CookieOrigin("localhost", 80, "/", false);
try {
- Cookie[] parsed = cookiespec.parse(header, origin);
- for (int i = 0; i < parsed.length; i++) {
- cookiespec.validate(parsed[i], origin);
+ List cookies = cookiespec.parse(header, origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(i), origin);
}
fail("MalformedCookieException should have been thrown");
} catch (MalformedCookieException expected) {
@@ -648,9 +650,9 @@ public class TestBrowserCompatSpec extends TestCase {
Header header = new BasicHeader("Set-Cookie", "custno=12345;Expires='"+date+"';");
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);
+ List cookies = cookiespec.parse(header, origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(i), origin);
}
}
@@ -867,12 +869,12 @@ public class TestBrowserCompatSpec extends TestCase {
"name=value; path=/; domain=.mydomain.com");
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);
+ List cookies = cookiespec.parse(header, origin);
+ cookiespec.validate(cookies.get(0), origin);
+ List headers = cookiespec.formatCookies(cookies);
assertNotNull(headers);
- assertEquals(1, headers.length);
- assertEquals("name=value", headers[0].getValue());
+ assertEquals(1, headers.size());
+ assertEquals("name=value", headers.get(0).getValue());
}
/**
@@ -886,10 +888,12 @@ public class TestBrowserCompatSpec extends TestCase {
cookie.setAttribute(ClientCookie.PATH_ATTR, cookie.getPath());
CookieSpec cookiespec = new BrowserCompatSpec();
- Header[] headers = cookiespec.formatCookies(new Cookie[]{ cookie });
+ List cookies = new ArrayList(1);
+ cookies.add(cookie);
+ List headers = cookiespec.formatCookies(cookies);
assertNotNull(headers);
- assertEquals(1, headers.length);
- assertEquals("name=", headers[0].getValue());
+ assertEquals(1, headers.size());
+ assertEquals("name=", headers.get(0).getValue());
}
/**
@@ -900,11 +904,11 @@ public class TestBrowserCompatSpec extends TestCase {
"name1=value1; path=/; domain=.mydomain.com, name2 = value2 ; path=/; domain=.mydomain.com");
CookieSpec cookiespec = new BrowserCompatSpec();
CookieOrigin origin = new CookieOrigin("myhost.mydomain.com", 80, "/", false);
- Cookie[] cookies = cookiespec.parse(header, origin);
- Header[] headers = cookiespec.formatCookies(cookies);
+ List cookies = cookiespec.parse(header, origin);
+ List headers = cookiespec.formatCookies(cookies);
assertNotNull(headers);
- assertEquals(1, headers.length);
- assertEquals("name1=value1; name2=value2", headers[0].getValue());
+ assertEquals(1, headers.size());
+ assertEquals("name1=value1; name2=value2", headers.get(0).getValue());
}
public void testKeepCloverHappy() throws Exception {
@@ -958,7 +962,8 @@ public class TestBrowserCompatSpec extends TestCase {
// expected
}
try {
- cookiespec.formatCookies(new BasicClientCookie[] {});
+ List cookies = new ArrayList();
+ cookiespec.formatCookies(cookies);
fail("IllegalArgumentException must have been thrown");
} catch (IllegalArgumentException ex) {
// expected
diff --git a/module-client/src/test/java/org/apache/http/impl/cookie/TestCookieNetscapeDraft.java b/module-client/src/test/java/org/apache/http/impl/cookie/TestCookieNetscapeDraft.java
index 370c9559d..ed4edc029 100644
--- a/module-client/src/test/java/org/apache/http/impl/cookie/TestCookieNetscapeDraft.java
+++ b/module-client/src/test/java/org/apache/http/impl/cookie/TestCookieNetscapeDraft.java
@@ -30,6 +30,9 @@
package org.apache.http.impl.cookie;
+import java.util.ArrayList;
+import java.util.List;
+
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
@@ -68,15 +71,15 @@ public class TestCookieNetscapeDraft extends TestCase {
CookieSpec cookiespec = new NetscapeDraftSpec();
CookieOrigin origin = new CookieOrigin("host", 80, "/path/", true);
- Cookie[] parsed = cookiespec.parse(header, origin);
- for (int i = 0; i < parsed.length; i++) {
- cookiespec.validate(parsed[i], origin);
+ List cookies = cookiespec.parse(header, origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(i), origin);
}
- assertEquals("Found 1 cookies.",1,parsed.length);
- assertEquals("Name","name1",parsed[0].getName());
- assertEquals("Value","value1",parsed[0].getValue());
- assertEquals("Domain","host",parsed[0].getDomain());
- assertEquals("Path","/path/",parsed[0].getPath());
+ assertEquals("Found 1 cookies.",1,cookies.size());
+ assertEquals("Name","name1",cookies.get(0).getName());
+ assertEquals("Value","value1",cookies.get(0).getValue());
+ assertEquals("Domain","host",cookies.get(0).getDomain());
+ assertEquals("Path","/path/",cookies.get(0).getPath());
}
public void testParseAbsPath2() throws Exception {
@@ -84,15 +87,15 @@ public class TestCookieNetscapeDraft extends TestCase {
CookieSpec cookiespec = new NetscapeDraftSpec();
CookieOrigin origin = new CookieOrigin("host", 80, "/", true);
- Cookie[] parsed = cookiespec.parse(header, origin);
- for (int i = 0; i < parsed.length; i++) {
- cookiespec.validate(parsed[i], origin);
+ List cookies = cookiespec.parse(header, origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(i), origin);
}
- assertEquals("Found 1 cookies.",1,parsed.length);
- assertEquals("Name","name1",parsed[0].getName());
- assertEquals("Value","value1",parsed[0].getValue());
- assertEquals("Domain","host",parsed[0].getDomain());
- assertEquals("Path","/",parsed[0].getPath());
+ assertEquals("Found 1 cookies.",1,cookies.size());
+ assertEquals("Name","name1",cookies.get(0).getName());
+ assertEquals("Value","value1",cookies.get(0).getValue());
+ assertEquals("Domain","host",cookies.get(0).getDomain());
+ assertEquals("Path","/",cookies.get(0).getPath());
}
public void testParseRelativePath() throws Exception {
@@ -100,15 +103,15 @@ public class TestCookieNetscapeDraft extends TestCase {
CookieSpec cookiespec = new NetscapeDraftSpec();
CookieOrigin origin = new CookieOrigin("host", 80, "whatever", true);
- Cookie[] parsed = cookiespec.parse(header, origin);
- for (int i = 0; i < parsed.length; i++) {
- cookiespec.validate(parsed[i], origin);
+ List cookies = cookiespec.parse(header, origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(i), origin);
}
- assertEquals("Found 1 cookies.",1,parsed.length);
- assertEquals("Name","name1",parsed[0].getName());
- assertEquals("Value","value1",parsed[0].getValue());
- assertEquals("Domain","host",parsed[0].getDomain());
- assertEquals("Path","whatever",parsed[0].getPath());
+ assertEquals("Found 1 cookies.",1,cookies.size());
+ assertEquals("Name","name1",cookies.get(0).getName());
+ assertEquals("Value","value1",cookies.get(0).getValue());
+ assertEquals("Domain","host",cookies.get(0).getDomain());
+ assertEquals("Path","whatever",cookies.get(0).getPath());
}
public void testParseWithIllegalNetscapeDomain1() throws Exception {
@@ -117,9 +120,9 @@ public class TestCookieNetscapeDraft extends TestCase {
CookieSpec cookiespec = new NetscapeDraftSpec();
try {
CookieOrigin origin = new CookieOrigin("a.com", 80, "/", false);
- Cookie[] parsed = cookiespec.parse(header, origin);
- for (int i = 0; i < parsed.length; i++) {
- cookiespec.validate(parsed[i], origin);
+ List cookies = cookiespec.parse(header, origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(i), origin);
}
fail("MalformedCookieException exception should have been thrown");
} catch (MalformedCookieException e) {
@@ -133,9 +136,9 @@ public class TestCookieNetscapeDraft extends TestCase {
CookieSpec cookiespec = new NetscapeDraftSpec();
try {
CookieOrigin origin = new CookieOrigin("x.y.z", 80, "/", false);
- Cookie[] parsed = cookiespec.parse(header, origin);
- for (int i = 0; i < parsed.length; i++) {
- cookiespec.validate(parsed[i], origin);
+ List cookies = cookiespec.parse(header, origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(i), origin);
}
fail("MalformedCookieException exception should have been thrown");
} catch (MalformedCookieException e) {
@@ -151,11 +154,11 @@ public class TestCookieNetscapeDraft extends TestCase {
"Set-Cookie", "name=value; path=/; domain=.mydomain.com");
CookieSpec cookiespec = new NetscapeDraftSpec();
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);
- assertEquals(1, headers.length);
- assertEquals("name=value", headers[0].getValue());
+ List cookies = cookiespec.parse(header, origin);
+ cookiespec.validate(cookies.get(0), origin);
+ List headers = cookiespec.formatCookies(cookies);
+ assertEquals(1, headers.size());
+ assertEquals("name=value", headers.get(0).getValue());
}
/**
@@ -166,13 +169,13 @@ public class TestCookieNetscapeDraft extends TestCase {
Header header = new BasicHeader("Set-Cookie",
"name=value; path=/; domain=.mydomain.com; expires=Thu, 01-Jan-2070 00:00:10 GMT; comment=no_comment");
CookieOrigin origin = new CookieOrigin("myhost.mydomain.com", 80, "/", false);
- Cookie[] cookies = cookiespec.parse(header, origin);
- cookiespec.validate(cookies[0], origin);
+ List cookies = cookiespec.parse(header, origin);
+ cookiespec.validate(cookies.get(0), origin);
header = new BasicHeader("Set-Cookie",
"name=value; path=/; domain=.mydomain.com; expires=Thu 01-Jan-2070 00:00:10 GMT; comment=no_comment");
try {
cookies = cookiespec.parse(header, origin);
- cookiespec.validate(cookies[0], origin);
+ cookiespec.validate(cookies.get(0), origin);
fail("MalformedCookieException exception should have been thrown");
} catch (MalformedCookieException e) {
// expected
@@ -203,10 +206,10 @@ public class TestCookieNetscapeDraft extends TestCase {
CookieSpec cookiespec = new NetscapeDraftSpec();
CookieOrigin origin = new CookieOrigin("localhost", 80, "/", false);
- Cookie[] cookies = cookiespec.parse(header, origin);
- assertEquals("number of cookies", 1, cookies.length);
- assertEquals("a", cookies[0].getName());
- assertEquals("b,c", cookies[0].getValue());
+ List cookies = cookiespec.parse(header, origin);
+ assertEquals("number of cookies", 1, cookies.size());
+ assertEquals("a", cookies.get(0).getName());
+ assertEquals("b,c", cookies.get(0).getValue());
}
public void testFormatCookies() throws Exception {
@@ -220,10 +223,14 @@ public class TestCookieNetscapeDraft extends TestCase {
Cookie c3 = new BasicClientCookie("name3", null);
CookieSpec cookiespec = new NetscapeDraftSpec();
- Header[] headers = cookiespec.formatCookies(new Cookie[] {c1, c2, c3});
+ List cookies = new ArrayList();
+ cookies.add(c1);
+ cookies.add(c2);
+ cookies.add(c3);
+ List headers = cookiespec.formatCookies(cookies);
assertNotNull(headers);
- assertEquals(1, headers.length);
- assertEquals("name1=value1; name2=value2; name3", headers[0].getValue());
+ assertEquals(1, headers.size());
+ assertEquals("name1=value1; name2=value2; name3", headers.get(0).getValue());
}
public void testInvalidInput() throws Exception {
@@ -247,7 +254,8 @@ public class TestCookieNetscapeDraft extends TestCase {
// expected
}
try {
- cookiespec.formatCookies(new BasicClientCookie[] {});
+ List cookies = new ArrayList();
+ cookiespec.formatCookies(cookies);
fail("IllegalArgumentException must have been thrown");
} catch (IllegalArgumentException ex) {
// expected
diff --git a/module-client/src/test/java/org/apache/http/impl/cookie/TestCookieRFC2109Spec.java b/module-client/src/test/java/org/apache/http/impl/cookie/TestCookieRFC2109Spec.java
index 4de8e78f2..1bd912208 100644
--- a/module-client/src/test/java/org/apache/http/impl/cookie/TestCookieRFC2109Spec.java
+++ b/module-client/src/test/java/org/apache/http/impl/cookie/TestCookieRFC2109Spec.java
@@ -30,6 +30,9 @@
package org.apache.http.impl.cookie;
+import java.util.ArrayList;
+import java.util.List;
+
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
@@ -76,32 +79,32 @@ public class TestCookieRFC2109Spec extends TestCase {
CookieSpec cookiespec = new RFC2109Spec();
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);
+ List cookies = cookiespec.parse(header, origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(i), origin);
}
- assertEquals("Found 1 cookie.",1,parsed.length);
- assertEquals("Name","cookie-name",parsed[0].getName());
- assertEquals("Value","cookie-value",parsed[0].getValue());
- assertEquals("Version",1,parsed[0].getVersion());
+ assertEquals("Found 1 cookie.",1,cookies.size());
+ assertEquals("Name","cookie-name",cookies.get(0).getName());
+ assertEquals("Value","cookie-value",cookies.get(0).getValue());
+ assertEquals("Version",1,cookies.get(0).getVersion());
}
/**
* Test domain equals host
*/
- public void testParseDomainEqualsHost() throws Exception {
+ public void testcookiesomainEqualsHost() throws Exception {
Header header = new BasicHeader("Set-Cookie",
"cookie-name=cookie-value; domain=www.b.com; version=1");
CookieSpec cookiespec = new RFC2109Spec();
CookieOrigin origin = new CookieOrigin("www.b.com", 80, "/", false);
- Cookie[] parsed = cookiespec.parse(header, origin);
- for (int i = 0; i < parsed.length; i++) {
- cookiespec.validate(parsed[i], origin);
+ List cookies = cookiespec.parse(header, origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(i), origin);
}
- assertNotNull(parsed);
- assertEquals(1, parsed.length);
- assertEquals("www.b.com", parsed[0].getDomain());
+ assertNotNull(cookies);
+ assertEquals(1, cookies.size());
+ assertEquals("www.b.com", cookies.get(0).getDomain());
}
/**
@@ -114,9 +117,9 @@ public class TestCookieRFC2109Spec extends TestCase {
CookieSpec cookiespec = new RFC2109Spec();
CookieOrigin origin = new CookieOrigin("www.a.b.com", 80, "/", false);
try {
- Cookie[] parsed = cookiespec.parse(header, origin);
- for (int i = 0; i < parsed.length; i++) {
- cookiespec.validate(parsed[i], origin);
+ List cookies = cookiespec.parse(header, origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(i), origin);
}
fail("MalformedCookieException should have been thrown");
} catch (MalformedCookieException e) {
@@ -134,9 +137,9 @@ public class TestCookieRFC2109Spec extends TestCase {
CookieSpec cookiespec = new RFC2109Spec();
CookieOrigin origin = new CookieOrigin("b.com", 80, "/", false);
try {
- Cookie[] parsed = cookiespec.parse(header, origin);
- for (int i = 0; i < parsed.length; i++) {
- cookiespec.validate(parsed[i], origin);
+ List cookies = cookiespec.parse(header, origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(i), origin);
}
fail("MalformedCookieException should have been thrown");
} catch (MalformedCookieException e) {
@@ -154,9 +157,9 @@ public class TestCookieRFC2109Spec extends TestCase {
CookieSpec cookiespec = new RFC2109Spec();
CookieOrigin origin = new CookieOrigin("a.b.c.com", 80, "/", false);
try {
- Cookie[] parsed = cookiespec.parse(header, origin);
- for (int i = 0; i < parsed.length; i++) {
- cookiespec.validate(parsed[i], origin);
+ List cookies = cookiespec.parse(header, origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(i), origin);
}
fail("MalformedCookieException should have been thrown");
} catch (MalformedCookieException e) {
@@ -205,9 +208,9 @@ public class TestCookieRFC2109Spec extends TestCase {
CookieSpec cookiespec = new RFC2109Spec();
CookieOrigin origin = new CookieOrigin("127.0.0.1", 80, "/", false);
try {
- Cookie[] parsed = cookiespec.parse(header, origin);
- for (int i = 0; i < parsed.length; i++) {
- cookiespec.validate(parsed[i], origin);
+ List cookies = cookiespec.parse(header, origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(i), origin);
}
fail("MalformedCookieException exception should have been thrown");
} catch (MalformedCookieException e) {
@@ -223,9 +226,9 @@ public class TestCookieRFC2109Spec extends TestCase {
CookieSpec cookiespec = new RFC2109Spec();
CookieOrigin origin = new CookieOrigin("127.0.0.1", 80, "/", false);
try {
- Cookie[] parsed = cookiespec.parse(setcookie, origin);
- for (int i = 0; i < parsed.length; i++) {
- cookiespec.validate(parsed[i], origin);
+ List cookies = cookiespec.parse(setcookie, origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(i), origin);
}
fail("MalformedCookieException exception should have been thrown");
} catch (MalformedCookieException e) {
@@ -241,9 +244,9 @@ public class TestCookieRFC2109Spec extends TestCase {
CookieSpec cookiespec = new RFC2109Spec();
CookieOrigin origin = new CookieOrigin("127.0.0.1", 80, "/", false);
try {
- Cookie[] parsed = cookiespec.parse(setcookie, origin);
- for (int i = 0; i < parsed.length; i++) {
- cookiespec.validate(parsed[i], origin);
+ List cookies = cookiespec.parse(setcookie, origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(i), origin);
}
fail("MalformedCookieException exception should have been thrown");
} catch (MalformedCookieException e) {
@@ -260,9 +263,9 @@ public class TestCookieRFC2109Spec extends TestCase {
Header header = new BasicHeader("Set-Cookie",
"name=\"value\"; version=\"1\"; path=\"/\"; domain=\".mydomain.com\"");
CookieOrigin origin1 = new CookieOrigin("host", 80, "/", false);
- Cookie[]cookies = cookiespec.parse(header, origin1);
+ List cookies = cookiespec.parse(header, origin1);
try {
- cookiespec.validate(cookies[0], origin1);
+ cookiespec.validate(cookies.get(0), origin1);
fail("MalformedCookieException must have thrown");
}
catch(MalformedCookieException expected) {
@@ -272,7 +275,7 @@ public class TestCookieRFC2109Spec extends TestCase {
"name=\"value\"; version=\"1\"; path=\"/\"; domain=\"host1\"");
cookies = cookiespec.parse(header, origin2);
try {
- cookiespec.validate(cookies[0], origin2);
+ cookiespec.validate(cookies.get(0), origin2);
fail("MalformedCookieException must have thrown");
}
catch(MalformedCookieException expected) {
@@ -287,12 +290,12 @@ public class TestCookieRFC2109Spec extends TestCase {
CookieSpec cookiespec = new RFC2109Spec();
CookieOrigin origin = new CookieOrigin("localhost", 80, "/", false);
- Cookie[] cookies = cookiespec.parse(header, origin);
- assertEquals("number of cookies", 2, cookies.length);
- assertEquals("a", cookies[0].getName());
- assertEquals("b", cookies[0].getValue());
- assertEquals("c", cookies[1].getName());
- assertEquals(null, cookies[1].getValue());
+ List cookies = cookiespec.parse(header, origin);
+ assertEquals("number of cookies", 2, cookies.size());
+ assertEquals("a", cookies.get(0).getName());
+ assertEquals("b", cookies.get(0).getValue());
+ assertEquals("c", cookies.get(1).getName());
+ assertEquals(null, cookies.get(1).getValue());
}
/**
@@ -303,23 +306,23 @@ public class TestCookieRFC2109Spec extends TestCase {
Header header = new BasicHeader("Set-Cookie",
"name=\"value\"; version=1; path=\"/\"; domain=\".mydomain.com\"");
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);
+ List cookies = cookiespec.parse(header, origin);
+ cookiespec.validate(cookies.get(0), origin);
+ List headers = cookiespec.formatCookies(cookies);
assertNotNull(headers);
- assertEquals(1, headers.length);
+ assertEquals(1, headers.size());
assertEquals("$Version=1; name=\"value\"; $Path=\"/\"; $Domain=\".mydomain.com\"",
- headers[0].getValue());
+ headers.get(0).getValue());
header = new BasicHeader( "Set-Cookie",
"name=value; path=/; domain=.mydomain.com");
cookies = cookiespec.parse(header, origin);
- cookiespec.validate(cookies[0], origin);
+ cookiespec.validate(cookies.get(0), origin);
headers = cookiespec.formatCookies(cookies);
assertNotNull(headers);
- assertEquals(1, headers.length);
+ assertEquals(1, headers.size());
assertEquals("$Version=0; name=value; $Path=/; $Domain=.mydomain.com",
- headers[0].getValue());
+ headers.get(0).getValue());
}
public void testRFC2109CookiesFormatting() throws Exception {
@@ -328,34 +331,34 @@ public class TestCookieRFC2109Spec extends TestCase {
"name1=value1; path=/; domain=.mydomain.com, " +
"name2=\"value2\"; version=\"1\"; path=\"/\"; domain=\".mydomain.com\"");
CookieOrigin origin = new CookieOrigin("myhost.mydomain.com", 80, "/", false);
- Cookie[] cookies = cookiespec.parse(header, origin);
- for (int i = 0; i < cookies.length; i++) {
- cookiespec.validate(cookies[i], origin);
+ List cookies = cookiespec.parse(header, origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(i), origin);
}
assertNotNull(cookies);
- assertEquals(2, cookies.length);
- Header[] headers = cookiespec.formatCookies(cookies);
+ assertEquals(2, cookies.size());
+ List headers = cookiespec.formatCookies(cookies);
assertNotNull(headers);
- assertEquals(1, headers.length);
+ assertEquals(1, headers.size());
assertEquals(
"$Version=0; name1=value1; $Path=/; $Domain=.mydomain.com; " +
"name2=value2; $Path=/; $Domain=.mydomain.com",
- headers[0].getValue());
+ headers.get(0).getValue());
header = new BasicHeader("Set-Cookie",
"name1=value1; version=1; path=/; domain=.mydomain.com, " +
"name2=\"value2\"; version=\"1\"; path=\"/\"; domain=\".mydomain.com\"");
cookies = cookiespec.parse(header, origin);
- for (int i = 0; i < cookies.length; i++) {
- cookiespec.validate(cookies[i], origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(i), origin);
}
assertNotNull(cookies);
- assertEquals(2, cookies.length);
+ assertEquals(2, cookies.size());
headers = cookiespec.formatCookies(cookies);
assertEquals(
"$Version=1; name1=\"value1\"; $Path=\"/\"; $Domain=\".mydomain.com\"; " +
"name2=\"value2\"; $Path=\"/\"; $Domain=\".mydomain.com\"",
- headers[0].getValue());
+ headers.get(0).getValue());
}
/**
@@ -369,18 +372,22 @@ public class TestCookieRFC2109Spec extends TestCase {
cookie.setAttribute(ClientCookie.PATH_ATTR, cookie.getPath());
CookieSpec cookiespec = new RFC2109Spec();
- Header[] headers = cookiespec.formatCookies(new Cookie[] { cookie });
+ List cookies = new ArrayList();
+ cookies.add(cookie);
+ List headers = cookiespec.formatCookies(cookies);
assertNotNull(headers);
- assertEquals(1, headers.length);
+ assertEquals(1, headers.size());
assertEquals("$Version=0; name=; $Path=/; $Domain=.whatever.com",
- headers[0].getValue());
+ headers.get(0).getValue());
cookie.setVersion(1);
- headers = cookiespec.formatCookies(new Cookie[] { cookie });
+ cookies = new ArrayList();
+ cookies.add(cookie);
+ headers = cookiespec.formatCookies(cookies);
assertNotNull(headers);
- assertEquals(1, headers.length);
+ assertEquals(1, headers.size());
assertEquals("$Version=1; name=; $Path=\"/\"; $Domain=\".whatever.com\"",
- headers[0].getValue());
+ headers.get(0).getValue());
}
public void testCookieNullDomainNullPathFormatting() {
@@ -389,17 +396,21 @@ public class TestCookieRFC2109Spec extends TestCase {
cookie.setAttribute(ClientCookie.PATH_ATTR, cookie.getPath());
CookieSpec cookiespec = new RFC2109Spec();
- Header[] headers = cookiespec.formatCookies(new Cookie[] { cookie });
+ List cookies = new ArrayList();
+ cookies.add(cookie);
+ List headers = cookiespec.formatCookies(cookies);
assertNotNull(headers);
- assertEquals(1, headers.length);
- assertEquals("$Version=0; name=; $Path=/", headers[0].getValue());
+ assertEquals(1, headers.size());
+ assertEquals("$Version=0; name=; $Path=/", headers.get(0).getValue());
cookie.setAttribute(ClientCookie.DOMAIN_ATTR, null);
cookie.setAttribute(ClientCookie.PATH_ATTR, null);
- headers = cookiespec.formatCookies(new Cookie[] { cookie });
+ cookies = new ArrayList();
+ cookies.add(cookie);
+ headers = cookiespec.formatCookies(cookies);
assertNotNull(headers);
- assertEquals(1, headers.length);
- assertEquals("$Version=0; name=", headers[0].getValue());
+ assertEquals(1, headers.size());
+ assertEquals("$Version=0; name=", headers.get(0).getValue());
}
public void testCookieOrderingByPath() {
@@ -417,13 +428,18 @@ public class TestCookieRFC2109Spec extends TestCase {
c4.setAttribute(ClientCookie.PATH_ATTR, c4.getPath());
CookieSpec cookiespec = new RFC2109Spec(null, true);
- Header[] headers = cookiespec.formatCookies(new Cookie[] { c2, c4, c1, c3 });
+ List cookies = new ArrayList();
+ cookies.add(c2);
+ cookies.add(c4);
+ cookies.add(c1);
+ cookies.add(c3);
+ List headers = cookiespec.formatCookies(cookies);
assertNotNull(headers);
- assertEquals(1, headers.length);
+ assertEquals(1, headers.size());
assertEquals("$Version=0; name1=value1; $Path=/a/b/c; " +
"name2=value2; $Path=/a/b; " +
"name3=value3; $Path=/a; " +
- "name4=value4; $Path=/", headers[0].getValue());
+ "name4=value4; $Path=/", headers.get(0).getValue());
}
public void testInvalidInput() throws Exception {
@@ -453,7 +469,8 @@ public class TestCookieRFC2109Spec extends TestCase {
// expected
}
try {
- cookiespec.formatCookies(new BasicClientCookie[] {});
+ List cookies = new ArrayList();
+ cookiespec.formatCookies(cookies);
fail("IllegalArgumentException must have been thrown");
} catch (IllegalArgumentException ex) {
// expected
diff --git a/module-client/src/test/java/org/apache/http/impl/cookie/TestCookieRFC2965Spec.java b/module-client/src/test/java/org/apache/http/impl/cookie/TestCookieRFC2965Spec.java
index 008519ece..33e2ff640 100644
--- a/module-client/src/test/java/org/apache/http/impl/cookie/TestCookieRFC2965Spec.java
+++ b/module-client/src/test/java/org/apache/http/impl/cookie/TestCookieRFC2965Spec.java
@@ -33,7 +33,9 @@ import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
+import java.util.ArrayList;
import java.util.Date;
+import java.util.List;
import org.apache.http.Header;
import org.apache.http.cookie.ClientCookie;
@@ -71,11 +73,11 @@ public class TestCookieRFC2965Spec extends TestCase {
CookieSpec cookiespec = new RFC2965Spec();
CookieOrigin origin = new CookieOrigin("www.domain.com", 80, "/", false);
Header header = new BasicHeader("Set-Cookie2", "name=value;Path=/;Version=1;Path=");
- Cookie[] parsed = cookiespec.parse(header, origin);
- assertNotNull(parsed);
- assertEquals(1, parsed.length);
+ List cookies = cookiespec.parse(header, origin);
+ assertNotNull(cookies);
+ assertEquals(1, cookies.size());
// only the first occurrence of path attribute is considered, others ignored
- ClientCookie cookie = (ClientCookie) parsed[0];
+ ClientCookie cookie = (ClientCookie) cookies.get(0);
assertEquals("/", cookie.getPath());
assertTrue(cookie.containsAttribute(ClientCookie.PATH_ATTR));
}
@@ -85,10 +87,10 @@ public class TestCookieRFC2965Spec extends TestCase {
CookieOrigin origin = new CookieOrigin("www.domain.com", 80, "/path/", false);
// Path is OPTIONAL, defaults to the request path
Header header = new BasicHeader("Set-Cookie2", "name=value;Version=1");
- Cookie[] parsed = cookiespec.parse(header, origin);
- assertNotNull(parsed);
- assertEquals(1, parsed.length);
- ClientCookie cookie = (ClientCookie) parsed[0];
+ List cookies = cookiespec.parse(header, origin);
+ assertNotNull(cookies);
+ assertEquals(1, cookies.size());
+ ClientCookie cookie = (ClientCookie) cookies.get(0);
assertEquals("/path", cookie.getPath());
assertFalse(cookie.containsAttribute(ClientCookie.PATH_ATTR));
}
@@ -97,10 +99,10 @@ public class TestCookieRFC2965Spec extends TestCase {
CookieSpec cookiespec = new RFC2965Spec();
CookieOrigin origin = new CookieOrigin("www.domain.com", 80, "/", false);
Header header = new BasicHeader("Set-Cookie2", "name=value;Path=;Version=1");
- Cookie[] parsed = cookiespec.parse(header, origin);
- assertNotNull(parsed);
- assertEquals(1, parsed.length);
- ClientCookie cookie = (ClientCookie) parsed[0];
+ List cookies = cookiespec.parse(header, origin);
+ assertNotNull(cookies);
+ assertEquals(1, cookies.size());
+ ClientCookie cookie = (ClientCookie) cookies.get(0);
assertEquals("/", cookie.getPath());
assertTrue(cookie.containsAttribute(ClientCookie.PATH_ATTR));
}
@@ -109,10 +111,10 @@ public class TestCookieRFC2965Spec extends TestCase {
CookieSpec cookiespec = new RFC2965Spec();
CookieOrigin origin = new CookieOrigin("www.domain.com", 80, "/", false);
Header header = new BasicHeader("Set-Cookie2", "name=value;Path=\" \";Version=1");
- Cookie[] parsed = cookiespec.parse(header, origin);
- assertNotNull(parsed);
- assertEquals(1, parsed.length);
- ClientCookie cookie = (ClientCookie) parsed[0];
+ List cookies = cookiespec.parse(header, origin);
+ assertNotNull(cookies);
+ assertEquals(1, cookies.size());
+ ClientCookie cookie = (ClientCookie) cookies.get(0);
assertEquals("/", cookie.getPath());
assertTrue(cookie.containsAttribute(ClientCookie.PATH_ATTR));
}
@@ -120,36 +122,36 @@ public class TestCookieRFC2965Spec extends TestCase {
/**
* Test parsing cookie "Domain" attribute.
*/
- public void testParseDomain() throws Exception {
+ public void testcookiesomain() throws Exception {
CookieSpec cookiespec = new RFC2965Spec();
CookieOrigin origin = new CookieOrigin("www.domain.com", 80, "/", false);
Header header = new BasicHeader("Set-Cookie2", "name=value;Domain=.domain.com;Version=1;Domain=");
- Cookie[] parsed = cookiespec.parse(header, origin);
- assertNotNull(parsed);
- assertEquals(1, parsed.length);
+ List cookies = cookiespec.parse(header, origin);
+ assertNotNull(cookies);
+ assertEquals(1, cookies.size());
// only the first occurrence of domain attribute is considered, others ignored
- ClientCookie cookie = (ClientCookie) parsed[0];
+ ClientCookie cookie = (ClientCookie) cookies.get(0);
assertEquals(".domain.com", cookie.getDomain());
assertTrue(cookie.containsAttribute(ClientCookie.DOMAIN_ATTR));
// should put a leading dot if there is no dot in front of domain
header = new BasicHeader("Set-Cookie2", "name=value;Domain=domain.com;Version=1");
- parsed = cookiespec.parse(header, origin);
- assertNotNull(parsed);
- assertEquals(1, parsed.length);
- cookie = (ClientCookie) parsed[0];
+ cookies = cookiespec.parse(header, origin);
+ assertNotNull(cookies);
+ assertEquals(1, cookies.size());
+ cookie = (ClientCookie) cookies.get(0);
assertEquals(".domain.com", cookie.getDomain());
}
- public void testParseDomainDefault() throws Exception {
+ public void testcookiesomainDefault() throws Exception {
CookieSpec cookiespec = new RFC2965Spec();
CookieOrigin origin = new CookieOrigin("www.domain.com", 80, "/", false);
// Domain is OPTIONAL, defaults to the request host
Header header = new BasicHeader("Set-Cookie2", "name=value;Version=1");
- Cookie[] parsed = cookiespec.parse(header, origin);
- assertNotNull(parsed);
- assertEquals(1, parsed.length);
- ClientCookie cookie = (ClientCookie) parsed[0];
+ List cookies = cookiespec.parse(header, origin);
+ assertNotNull(cookies);
+ assertEquals(1, cookies.size());
+ ClientCookie cookie = (ClientCookie) cookies.get(0);
assertEquals("www.domain.com", cookie.getDomain());
assertFalse(cookie.containsAttribute(ClientCookie.DOMAIN_ATTR));
}
@@ -186,11 +188,11 @@ public class TestCookieRFC2965Spec extends TestCase {
CookieSpec cookiespec = new RFC2965Spec();
CookieOrigin origin = new CookieOrigin("www.domain.com", 80, "/", false);
Header header = new BasicHeader("Set-Cookie2", "name=value;Port=\"80,800,8000\";Version=1;Port=nonsense");
- Cookie[] parsed = cookiespec.parse(header, origin);
- assertNotNull(parsed);
- assertEquals(1, parsed.length);
+ List cookies = cookiespec.parse(header, origin);
+ assertNotNull(cookies);
+ assertEquals(1, cookies.size());
// only the first occurrence of port attribute is considered, others ignored
- ClientCookie cookie = (ClientCookie) parsed[0];
+ ClientCookie cookie = (ClientCookie) cookies.get(0);
int[] ports = cookie.getPorts();
assertNotNull(ports);
assertEquals(3, ports.length);
@@ -205,10 +207,10 @@ public class TestCookieRFC2965Spec extends TestCase {
CookieOrigin origin = new CookieOrigin("www.domain.com", 80, "/", false);
// Port is OPTIONAL, cookie can be accepted from any port
Header header = new BasicHeader("Set-Cookie2", "name=value;Version=1");
- Cookie[] parsed = cookiespec.parse(header, origin);
- assertNotNull(parsed);
- assertEquals(1, parsed.length);
- ClientCookie cookie = (ClientCookie) parsed[0];
+ List cookies = cookiespec.parse(header, origin);
+ assertNotNull(cookies);
+ assertEquals(1, cookies.size());
+ ClientCookie cookie = (ClientCookie) cookies.get(0);
assertFalse(cookie.containsAttribute(ClientCookie.PORT_ATTR));
}
@@ -217,10 +219,10 @@ public class TestCookieRFC2965Spec extends TestCase {
CookieOrigin origin = new CookieOrigin("www.domain.com", 80, "/", false);
// null port defaults to request port
Header header = new BasicHeader("Set-Cookie2", "name=value;Port=;Version=1");
- Cookie[] parsed = cookiespec.parse(header, origin);
- assertNotNull(parsed);
- assertEquals(1, parsed.length);
- ClientCookie cookie = (ClientCookie) parsed[0];
+ List cookies = cookiespec.parse(header, origin);
+ assertNotNull(cookies);
+ assertEquals(1, cookies.size());
+ ClientCookie cookie = (ClientCookie) cookies.get(0);
int[] ports = cookie.getPorts();
assertNotNull(ports);
assertEquals(1, ports.length);
@@ -233,10 +235,10 @@ public class TestCookieRFC2965Spec extends TestCase {
CookieOrigin origin = new CookieOrigin("www.domain.com", 80, "/", false);
// blank port defaults to request port
Header header = new BasicHeader("Set-Cookie2", "name=value;Port=\" \";Version=1");
- Cookie[] parsed = cookiespec.parse(header, origin);
- assertNotNull(parsed);
- assertEquals(1, parsed.length);
- ClientCookie cookie = (ClientCookie) parsed[0];
+ List cookies = cookiespec.parse(header, origin);
+ assertNotNull(cookies);
+ assertEquals(1, cookies.size());
+ ClientCookie cookie = (ClientCookie) cookies.get(0);
int[] ports = cookie.getPorts();
assertNotNull(ports);
assertEquals(1, ports.length);
@@ -275,10 +277,10 @@ public class TestCookieRFC2965Spec extends TestCase {
CookieSpec cookiespec = new RFC2965Spec();
CookieOrigin origin = new CookieOrigin("www.domain.com", 80, "/", false);
Header header = new BasicHeader("Set-Cookie2", "name=value;Version=1;");
- Cookie[] parsed = cookiespec.parse(header, origin);
- assertNotNull(parsed);
- assertEquals(1, parsed.length);
- ClientCookie cookie = (ClientCookie) parsed[0];
+ List cookies = cookiespec.parse(header, origin);
+ assertNotNull(cookies);
+ assertEquals(1, cookies.size());
+ ClientCookie cookie = (ClientCookie) cookies.get(0);
assertEquals("name", cookie.getName());
assertEquals("value", cookie.getValue());
}
@@ -290,10 +292,10 @@ public class TestCookieRFC2965Spec extends TestCase {
CookieSpec cookiespec = new RFC2965Spec();
CookieOrigin origin = new CookieOrigin("www.domain.com", 80, "/", false);
Header header = new BasicHeader("Set-Cookie2", "name=value;Version=1;");
- Cookie[] parsed = cookiespec.parse(header, origin);
- assertNotNull(parsed);
- assertEquals(1, parsed.length);
- ClientCookie cookie = (ClientCookie) parsed[0];
+ List cookies = cookiespec.parse(header, origin);
+ assertNotNull(cookies);
+ assertEquals(1, cookies.size());
+ ClientCookie cookie = (ClientCookie) cookies.get(0);
assertEquals(1, cookie.getVersion());
assertTrue(cookie.containsAttribute(ClientCookie.VERSION_ATTR));
}
@@ -329,11 +331,11 @@ public class TestCookieRFC2965Spec extends TestCase {
CookieSpec cookiespec = new RFC2965Spec();
CookieOrigin origin = new CookieOrigin("www.domain.com", 80, "/", false);
Header header = new BasicHeader("Set-Cookie2", "name=value;Max-age=3600;Version=1;Max-age=nonsense");
- Cookie[] parsed = cookiespec.parse(header, origin);
- assertNotNull(parsed);
- assertEquals(1, parsed.length);
+ List cookies = cookiespec.parse(header, origin);
+ assertNotNull(cookies);
+ assertEquals(1, cookies.size());
// only the first occurence of max-age attribute is considered, others ignored
- ClientCookie cookie = (ClientCookie) parsed[0];
+ ClientCookie cookie = (ClientCookie) cookies.get(0);
assertFalse(cookie.isExpired(new Date()));
}
@@ -342,10 +344,10 @@ public class TestCookieRFC2965Spec extends TestCase {
CookieOrigin origin = new CookieOrigin("www.domain.com", 80, "/", false);
// Max-age is OPTIONAL, defaults to session cookie
Header header = new BasicHeader("Set-Cookie2", "name=value;Version=1");
- Cookie[] parsed = cookiespec.parse(header, origin);
- assertNotNull(parsed);
- assertEquals(1, parsed.length);
- ClientCookie cookie = (ClientCookie) parsed[0];
+ List cookies = cookiespec.parse(header, origin);
+ assertNotNull(cookies);
+ assertEquals(1, cookies.size());
+ ClientCookie cookie = (ClientCookie) cookies.get(0);
assertFalse(cookie.isPersistent());
}
@@ -380,33 +382,33 @@ public class TestCookieRFC2965Spec extends TestCase {
CookieSpec cookiespec = new RFC2965Spec();
CookieOrigin origin = new CookieOrigin("www.domain.com", 80, "/", false);
Header header = new BasicHeader("Set-Cookie2", "name=value;Secure;Version=1");
- Cookie[] parsed = cookiespec.parse(header, origin);
- assertNotNull(parsed);
- assertEquals(1, parsed.length);
- ClientCookie cookie = (ClientCookie) parsed[0];
+ List cookies = cookiespec.parse(header, origin);
+ assertNotNull(cookies);
+ assertEquals(1, cookies.size());
+ ClientCookie cookie = (ClientCookie) cookies.get(0);
assertTrue(cookie.isSecure());
}
/**
* test parsing "Discard" attribute.
*/
- public void testParseDiscard() throws Exception {
+ public void testcookiesiscard() throws Exception {
CookieSpec cookiespec = new RFC2965Spec();
CookieOrigin origin = new CookieOrigin("www.domain.com", 80, "/", false);
Header header = new BasicHeader("Set-Cookie2", "name=value;Discard;Max-age=36000;Version=1");
- Cookie[] parsed = cookiespec.parse(header, origin);
- assertNotNull(parsed);
- assertEquals(1, parsed.length);
- ClientCookie cookie = (ClientCookie) parsed[0];
+ List cookies = cookiespec.parse(header, origin);
+ assertNotNull(cookies);
+ assertEquals(1, cookies.size());
+ ClientCookie cookie = (ClientCookie) cookies.get(0);
// discard overrides max-age
assertFalse(cookie.isPersistent());
// Discard is OPTIONAL, default behavior is dictated by max-age
header = new BasicHeader("Set-Cookie2", "name=value;Max-age=36000;Version=1");
- parsed = cookiespec.parse(header, origin);
- assertNotNull(parsed);
- assertEquals(1, parsed.length);
- cookie = (ClientCookie) parsed[0];
+ cookies = cookiespec.parse(header, origin);
+ assertNotNull(cookies);
+ assertEquals(1, cookies.size());
+ cookie = (ClientCookie) cookies.get(0);
assertTrue(cookie.isPersistent());
}
@@ -419,20 +421,20 @@ public class TestCookieRFC2965Spec extends TestCase {
CookieOrigin origin = new CookieOrigin("www.domain.com", 80, "/", false);
Header header = new BasicHeader("Set-Cookie2", "name=value;Comment=\"good cookie\";" +
"CommentURL=\"www.domain.com/goodcookie/\";Secure;Version=1");
- Cookie[] parsed = cookiespec.parse(header, origin);
- assertNotNull(parsed);
- assertEquals(1, parsed.length);
- ClientCookie cookie = (ClientCookie) parsed[0];
+ List cookies = cookiespec.parse(header, origin);
+ assertNotNull(cookies);
+ assertEquals(1, cookies.size());
+ ClientCookie cookie = (ClientCookie) cookies.get(0);
assertEquals("good cookie", cookie.getComment());
assertEquals("www.domain.com/goodcookie/", cookie.getCommentURL());
assertTrue(cookie.isSecure());
// Comment, CommentURL, Secure are OPTIONAL
header = new BasicHeader("Set-Cookie2", "name=value;Version=1");
- parsed = cookiespec.parse(header, origin);
- assertNotNull(parsed);
- assertEquals(1, parsed.length);
- cookie = (ClientCookie) parsed[0];
+ cookies = cookiespec.parse(header, origin);
+ assertNotNull(cookies);
+ assertEquals(1, cookies.size());
+ cookie = (ClientCookie) cookies.get(0);
assertFalse(cookie.isSecure());
}
@@ -443,13 +445,13 @@ public class TestCookieRFC2965Spec extends TestCase {
CookieSpec cookiespec = new RFC2965Spec();
CookieOrigin origin = new CookieOrigin("www.domain.com", 80, "/", false);
Header header = new BasicHeader("Set-Cookie2", "a=b,c");
- Cookie[] parsed = cookiespec.parse(header, origin);
- assertNotNull(parsed);
- assertEquals(2, parsed.length);
- assertEquals("a", parsed[0].getName());
- assertEquals("b", parsed[0].getValue());
- assertEquals("c", parsed[1].getName());
- assertEquals(null, parsed[1].getValue());
+ List cookies = cookiespec.parse(header, origin);
+ assertNotNull(cookies);
+ assertEquals(2, cookies.size());
+ assertEquals("a", cookies.get(0).getName());
+ assertEquals("b", cookies.get(0).getValue());
+ assertEquals("c", cookies.get(1).getName());
+ assertEquals(null, cookies.get(1).getValue());
}
// ------------------------------------------------------- Test Cookie Validation
@@ -462,13 +464,13 @@ public class TestCookieRFC2965Spec extends TestCase {
CookieSpec cookiespec = new RFC2965Spec();
CookieOrigin origin = new CookieOrigin("www.domain.com", 80, "/", false);
Header header = new BasicHeader("Set-Cookie2", "name=value;Version=1");
- Cookie[] parsed = cookiespec.parse(header, origin);
- for (int i = 0; i < parsed.length; i++) {
- cookiespec.validate(parsed[i], origin);
+ List cookies = cookiespec.parse(header, origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(i), origin);
}
- assertNotNull(parsed);
- assertEquals(1, parsed.length);
- ClientCookie cookie = (ClientCookie) parsed[0];
+ assertNotNull(cookies);
+ assertEquals(1, cookies.size());
+ ClientCookie cookie = (ClientCookie) cookies.get(0);
// cookie domain must string match request host
assertEquals("www.domain.com", cookie.getDomain());
}
@@ -481,13 +483,13 @@ public class TestCookieRFC2965Spec extends TestCase {
CookieSpec cookiespec = new RFC2965Spec();
CookieOrigin origin = new CookieOrigin("www.domain.com", 80, "/", false);
Header header = new BasicHeader("Set-Cookie2", "name=value;Domain=domain.com;Version=1");
- Cookie[] parsed = cookiespec.parse(header, origin);
- for (int i = 0; i < parsed.length; i++) {
- cookiespec.validate(parsed[i], origin);
+ List cookies = cookiespec.parse(header, origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(i), origin);
}
- assertNotNull(parsed);
- assertEquals(1, parsed.length);
- ClientCookie cookie = (ClientCookie) parsed[0];
+ assertNotNull(cookies);
+ assertEquals(1, cookies.size());
+ ClientCookie cookie = (ClientCookie) cookies.get(0);
assertEquals(".domain.com", cookie.getDomain());
}
@@ -499,21 +501,21 @@ public class TestCookieRFC2965Spec extends TestCase {
CookieOrigin origin = new CookieOrigin("b.com", 80, "/", false);
Header header = new BasicHeader("Set-Cookie2", "name=value; domain=.com; version=1");
try {
- Cookie[] parsed = cookiespec.parse(header, origin);
- for (int i = 0; i < parsed.length; i++) {
- cookiespec.validate(parsed[i], origin);
+ List cookies = cookiespec.parse(header, origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(i), origin);
}
fail("MalformedCookieException should have been thrown");
} catch (MalformedCookieException expected) {}
origin = new CookieOrigin("www.domain.com", 80, "/", false);
header = new BasicHeader("Set-Cookie2", "name=value;Domain=domain.com;Version=1");
- Cookie[] parsed = cookiespec.parse(header, origin);
- for (int i = 0; i < parsed.length; i++) {
- cookiespec.validate(parsed[i], origin);
+ List cookies = cookiespec.parse(header, origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(i), origin);
}
- assertNotNull(parsed);
- assertEquals(1, parsed.length);
+ assertNotNull(cookies);
+ assertEquals(1, cookies.size());
}
/**
@@ -526,22 +528,22 @@ public class TestCookieRFC2965Spec extends TestCase {
CookieOrigin origin = new CookieOrigin("simplehost", 80, "/", false);
// when domain is specified as .local, simple host names are valid
Header header = new BasicHeader("Set-Cookie2", "name=value; domain=.local; version=1");
- Cookie[] parsed = cookiespec.parse(header, origin);
- for (int i = 0; i < parsed.length; i++) {
- cookiespec.validate(parsed[i], origin);
+ List cookies = cookiespec.parse(header, origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(i), origin);
}
- assertNotNull(parsed);
- assertEquals(1, parsed.length);
- ClientCookie cookie = (ClientCookie) parsed[0];
+ assertNotNull(cookies);
+ assertEquals(1, cookies.size());
+ ClientCookie cookie = (ClientCookie) cookies.get(0);
assertEquals(".local", cookie.getDomain());
// when domain is NOT specified as .local, simple host names are invalid
header = new BasicHeader("Set-Cookie2", "name=value; domain=domain.com; version=1");
try {
// since domain is not .local, this must fail
- parsed = cookiespec.parse(header, origin);
- for (int i = 0; i < parsed.length; i++) {
- cookiespec.validate(parsed[i], origin);
+ cookies = cookiespec.parse(header, origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(i), origin);
}
fail("MalformedCookieException should have been thrown");
} catch (MalformedCookieException expected) {}
@@ -559,9 +561,9 @@ public class TestCookieRFC2965Spec extends TestCase {
Header header = new BasicHeader("Set-Cookie2", "name=value; domain=.domain.com; version=1");
try {
CookieOrigin origin = new CookieOrigin("www.domain.org", 80, "/", false);
- Cookie[] parsed = cookiespec.parse(header, origin);
- for (int i = 0; i < parsed.length; i++) {
- cookiespec.validate(parsed[i], origin);
+ List cookies = cookiespec.parse(header, origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(i), origin);
}
fail("MalformedCookieException should have been thrown");
} catch (MalformedCookieException expected) {}
@@ -569,12 +571,12 @@ public class TestCookieRFC2965Spec extends TestCase {
CookieOrigin origin = new CookieOrigin("www.domain.com", 80, "/", false);
// cookie domain domain-matches request host
header = new BasicHeader("Set-Cookie2", "name=value; domain=.domain.com; version=1");
- Cookie[] parsed = cookiespec.parse(header, origin);
- for (int i = 0; i < parsed.length; i++) {
- cookiespec.validate(parsed[i], origin);
+ List cookies = cookiespec.parse(header, origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(i), origin);
}
- assertNotNull(parsed);
- assertEquals(1, parsed.length);
+ assertNotNull(cookies);
+ assertEquals(1, cookies.size());
}
/**
@@ -586,9 +588,9 @@ public class TestCookieRFC2965Spec extends TestCase {
CookieOrigin origin = new CookieOrigin("a.b.domain.com", 80, "/", false);
Header header = new BasicHeader("Set-Cookie2", "name=value; domain=.domain.com; version=1");
try {
- Cookie[] parsed = cookiespec.parse(header, origin);
- for (int i = 0; i < parsed.length; i++) {
- cookiespec.validate(parsed[i], origin);
+ List cookies = cookiespec.parse(header, origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(i), origin);
}
fail("MalformedCookieException should have been thrown");
} catch (MalformedCookieException expected) {}
@@ -603,9 +605,9 @@ public class TestCookieRFC2965Spec extends TestCase {
Header header = new BasicHeader("Set-Cookie2", "name=value;path=/path;version=1");
try {
CookieOrigin origin = new CookieOrigin("www.domain.com", 80, "/", false);
- Cookie[] parsed = cookiespec.parse(header, origin);
- for (int i = 0; i < parsed.length; i++) {
- cookiespec.validate(parsed[i], origin);
+ List cookies = cookiespec.parse(header, origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(i), origin);
}
fail("MalformedCookieException exception should have been thrown");
} catch (MalformedCookieException expected) {}
@@ -614,22 +616,22 @@ public class TestCookieRFC2965Spec extends TestCase {
header = new BasicHeader("Set-Cookie2", "name=value;path=/Path;version=1");
try {
CookieOrigin origin = new CookieOrigin("www.domain.com", 80, "/path", false);
- Cookie[] parsed = cookiespec.parse(header, origin);
- for (int i = 0; i < parsed.length; i++) {
- cookiespec.validate(parsed[i], origin);
+ List cookies = cookiespec.parse(header, origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(i), origin);
}
fail("MalformedCookieException exception should have been thrown");
} catch (MalformedCookieException expected) {}
CookieOrigin origin = new CookieOrigin("www.domain.com", 80, "/path/path1", false);
header = new BasicHeader("Set-Cookie2", "name=value;path=/path;version=1");
- Cookie[] parsed = cookiespec.parse(header, origin);
- for (int i = 0; i < parsed.length; i++) {
- cookiespec.validate(parsed[i], origin);
+ List cookies = cookiespec.parse(header, origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(i), origin);
}
- assertNotNull(parsed);
- assertEquals(1, parsed.length);
- assertEquals("/path", parsed[0].getPath());
+ assertNotNull(cookies);
+ assertEquals(1, cookies.size());
+ assertEquals("/path", cookies.get(0).getPath());
}
/**
@@ -641,9 +643,9 @@ public class TestCookieRFC2965Spec extends TestCase {
// cookie name must not contain blanks
Header header = new BasicHeader("Set-Cookie2", "invalid name=value; version=1");
try {
- Cookie[] parsed = cookiespec.parse(header, origin);
- for (int i = 0; i < parsed.length; i++) {
- cookiespec.validate(parsed[i], origin);
+ List cookies = cookiespec.parse(header, origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(i), origin);
}
fail("MalformedCookieException exception should have been thrown");
} catch (MalformedCookieException expected) {}
@@ -651,19 +653,19 @@ public class TestCookieRFC2965Spec extends TestCase {
// cookie name must not start with '$'.
header = new BasicHeader("Set-Cookie2", "$invalid_name=value; version=1");
try {
- Cookie[] parsed = cookiespec.parse(header, origin);
- for (int i = 0; i < parsed.length; i++) {
- cookiespec.validate(parsed[i], origin);
+ List cookies = cookiespec.parse(header, origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(i), origin);
}
fail("MalformedCookieException exception should have been thrown");
} catch (MalformedCookieException expected) {}
// valid name
header = new BasicHeader("Set-Cookie2", "name=value; version=1");
- Cookie[] parsed = cookiespec.parse(header, origin);
- assertNotNull(parsed);
- assertEquals(1, parsed.length);
- ClientCookie cookie = (ClientCookie) parsed[0];
+ List cookies = cookiespec.parse(header, origin);
+ assertNotNull(cookies);
+ assertEquals(1, cookies.size());
+ ClientCookie cookie = (ClientCookie) cookies.get(0);
assertEquals("name", cookie.getName());
assertEquals("value", cookie.getValue());
}
@@ -677,22 +679,22 @@ public class TestCookieRFC2965Spec extends TestCase {
CookieSpec cookiespec = new RFC2965Spec();
try {
CookieOrigin origin = new CookieOrigin("www.domain.com", 8000, "/", false);
- Cookie[] parsed = cookiespec.parse(header, origin);
- for (int i = 0; i < parsed.length; i++) {
- cookiespec.validate(parsed[i], origin);
+ List cookies = cookiespec.parse(header, origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(i), origin);
}
fail("MalformedCookieException should have been thrown");
} catch (MalformedCookieException e) {}
// valid port list
CookieOrigin origin = new CookieOrigin("www.domain.com", 80, "/", false);
- Cookie[] parsed = cookiespec.parse(header, origin);
- for (int i = 0; i < parsed.length; i++) {
- cookiespec.validate(parsed[i], origin);
+ List cookies = cookiespec.parse(header, origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(i), origin);
}
- assertNotNull(parsed);
- assertEquals(1, parsed.length);
- ClientCookie cookie = (ClientCookie) parsed[0];
+ assertNotNull(cookies);
+ assertEquals(1, cookies.size());
+ ClientCookie cookie = (ClientCookie) cookies.get(0);
int[] ports = cookie.getPorts();
assertNotNull(ports);
assertEquals(2, ports.length);
@@ -709,9 +711,9 @@ public class TestCookieRFC2965Spec extends TestCase {
Header header = new BasicHeader("Set-Cookie2", "name=value");
try {
CookieOrigin origin = new CookieOrigin("www.domain.com", 8000, "/", false);
- Cookie[] parsed = cookiespec.parse(header, origin);
- for (int i = 0; i < parsed.length; i++) {
- cookiespec.validate(parsed[i], origin);
+ List cookies = cookiespec.parse(header, origin);
+ for (int i = 0; i < cookies.size(); i++) {
+ cookiespec.validate(cookies.get(i), origin);
}
fail("MalformedCookieException should have been thrown");
} catch (MalformedCookieException e) {}
@@ -861,11 +863,13 @@ public class TestCookieRFC2965Spec extends TestCase {
cookie1.setAttribute(ClientCookie.PATH_ATTR, "/");
cookie1.setAttribute(ClientCookie.PORT_ATTR, "80,8080");
- Header[] headers = cookiespec.formatCookies(new Cookie[] {cookie1});
+ List cookies = new ArrayList();
+ cookies.add(cookie1);
+ List headers = cookiespec.formatCookies(cookies);
assertNotNull(headers);
- assertEquals(1, headers.length);
+ assertEquals(1, headers.size());
assertEquals("$Version=1; name1=\"value\"; $Path=\"/\"; $Domain=\".domain.com\"; $Port=\"80,8080\"",
- headers[0].getValue());
+ headers.get(0).getValue());
BasicClientCookie2 cookie2 = new BasicClientCookie2("name2", "value");
@@ -877,11 +881,13 @@ public class TestCookieRFC2965Spec extends TestCase {
cookie2.setAttribute(ClientCookie.DOMAIN_ATTR, ".domain.com");
cookie2.setAttribute(ClientCookie.PATH_ATTR, "/a/");
- headers = cookiespec.formatCookies(new Cookie[] {cookie2});
+ cookies = new ArrayList();
+ cookies.add(cookie2);
+ headers = cookiespec.formatCookies(cookies);
assertNotNull(headers);
- assertEquals(1, headers.length);
+ assertEquals(1, headers.size());
assertEquals("$Version=2; name2=\"value\"; $Path=\"/a/\"; $Domain=\".domain.com\"",
- headers[0].getValue());
+ headers.get(0).getValue());
BasicClientCookie2 cookie3 = new BasicClientCookie2("name3", "value");
cookie3.setDomain(".domain.com");
@@ -892,20 +898,26 @@ public class TestCookieRFC2965Spec extends TestCase {
cookie3.setAttribute(ClientCookie.PATH_ATTR, "/a/b/");
cookie3.setAttribute(ClientCookie.PORT_ATTR, " ");
- headers = cookiespec.formatCookies(new Cookie[] {cookie3});
+ cookies = new ArrayList();
+ cookies.add(cookie3);
+ headers = cookiespec.formatCookies(cookies);
assertNotNull(headers);
- assertEquals(1, headers.length);
+ assertEquals(1, headers.size());
assertEquals("$Version=1; name3=\"value\"; $Path=\"/a/b/\"; $Port=\"\"",
- headers[0].getValue());
+ headers.get(0).getValue());
- headers = cookiespec.formatCookies(new Cookie[] {cookie3, cookie2, cookie1});
+ cookies = new ArrayList();
+ cookies.add(cookie3);
+ cookies.add(cookie2);
+ cookies.add(cookie1);
+ headers = cookiespec.formatCookies(cookies);
assertNotNull(headers);
- assertEquals(1, headers.length);
+ assertEquals(1, headers.size());
assertEquals("$Version=1; " +
"name3=\"value\"; $Path=\"/a/b/\"; $Port=\"\"; " +
"name2=\"value\"; $Path=\"/a/\"; $Domain=\".domain.com\"; " +
"name1=\"value\"; $Path=\"/\"; $Domain=\".domain.com\"; $Port=\"80,8080\"",
- headers[0].getValue());
+ headers.get(0).getValue());
}
/**
@@ -932,13 +944,16 @@ public class TestCookieRFC2965Spec extends TestCase {
cookie2.setAttribute(ClientCookie.DOMAIN_ATTR, ".domain.com");
cookie2.setAttribute(ClientCookie.PATH_ATTR, "/");
- Header[] headers = cookiespec.formatCookies(new Cookie[] {cookie1, cookie2});
+ List cookies = new ArrayList();
+ cookies.add(cookie1);
+ cookies.add(cookie2);
+ List headers = cookiespec.formatCookies(cookies);
assertNotNull(headers);
- assertEquals(1, headers.length);
+ assertEquals(1, headers.size());
assertEquals("$Version=1; name1=\"value1\"; $Path=\"/\"; $Domain=\".domain.com\"; $Port=\"80,8080\"; " +
"name2=\"\"; $Path=\"/\"; $Domain=\".domain.com\"",
- headers[0].getValue());
+ headers.get(0).getValue());
}
// ------------------------------------------------------- Backward compatibility tests
@@ -950,13 +965,13 @@ public class TestCookieRFC2965Spec extends TestCase {
CookieSpec cookiespec = new RFC2965Spec();
CookieOrigin origin = new CookieOrigin("www.domain.com", 80, "/", false);
Header header = new BasicHeader("Set-Cookie", "name=value; domain=.domain.com; version=1");
- Cookie[] parsed = cookiespec.parse(header, origin);
- assertNotNull(parsed);
- assertEquals(1, parsed.length);
- assertEquals("name", parsed[0].getName());
- assertEquals("value", parsed[0].getValue());
- assertEquals(".domain.com", parsed[0].getDomain());
- assertEquals("/", parsed[0].getPath());
+ List cookies = cookiespec.parse(header, origin);
+ assertNotNull(cookies);
+ assertEquals(1, cookies.size());
+ assertEquals("name", cookies.get(0).getName());
+ assertEquals("value", cookies.get(0).getValue());
+ assertEquals(".domain.com", cookies.get(0).getDomain());
+ assertEquals("/", cookies.get(0).getPath());
}
}