You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2010/02/26 13:19:06 UTC
svn commit: r916658 - in /httpcomponents/httpclient/trunk: ./
httpclient/src/main/java/org/apache/http/auth/
httpclient/src/main/java/org/apache/http/impl/client/
httpclient/src/main/java/org/apache/http/impl/cookie/
httpclient/src/test/java/org/apache...
Author: olegk
Date: Fri Feb 26 12:19:06 2010
New Revision: 916658
URL: http://svn.apache.org/viewvc?rev=916658&view=rev
Log:
HTTPCLIENT-916: UsernamePasswordCredentials, NTUserPrincipal, BasicClientCookie, BasicClientCookie2 and BasicCookieStore made Serializable
Added:
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestBasicCookieStore.java (with props)
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/cookie/TestBasicClientCookie.java (with props)
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/cookie/TestBasicClientCookie2.java (with props)
Modified:
httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/auth/BasicUserPrincipal.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/auth/NTCredentials.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/auth/NTUserPrincipal.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/auth/UsernamePasswordCredentials.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/BasicCookieStore.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/cookie/BasicClientCookie.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/cookie/BasicClientCookie2.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/auth/TestCredentials.java
Modified: httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/RELEASE_NOTES.txt?rev=916658&r1=916657&r2=916658&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpclient/trunk/RELEASE_NOTES.txt Fri Feb 26 12:19:06 2010
@@ -1,6 +1,10 @@
Changes since 4.1 ALPHA1
-------------------
+* [HTTPCLIENT-916] UsernamePasswordCredentials, NTUserPrincipal,
+ BasicClientCookie, BasicClientCookie2 and BasicCookieStore made Serializable.
+ Contributed by Oleg Kalnichevski <olegk at apache.org>
+
* [HTTPCLIENT-914] Upgraded Commons Codec dependency to version 1.4
Contributed by Oleg Kalnichevski <olegk at apache.org>
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/auth/BasicUserPrincipal.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/auth/BasicUserPrincipal.java?rev=916658&r1=916657&r2=916658&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/auth/BasicUserPrincipal.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/auth/BasicUserPrincipal.java Fri Feb 26 12:19:06 2010
@@ -26,6 +26,7 @@
package org.apache.http.auth;
+import java.io.Serializable;
import java.security.Principal;
import org.apache.http.annotation.Immutable;
@@ -34,12 +35,13 @@
/**
* Basic user principal used for HTTP authentication
- *
*
* @since 4.0
*/
@Immutable
-public final class BasicUserPrincipal implements Principal {
+public final class BasicUserPrincipal implements Principal, Serializable {
+
+ private static final long serialVersionUID = -2266305184969850467L;
private final String username;
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/auth/NTCredentials.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/auth/NTCredentials.java?rev=916658&r1=916657&r2=916658&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/auth/NTCredentials.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/auth/NTCredentials.java Fri Feb 26 12:19:06 2010
@@ -26,6 +26,7 @@
package org.apache.http.auth;
+import java.io.Serializable;
import java.security.Principal;
import java.util.Locale;
@@ -40,7 +41,9 @@
* @since 4.0
*/
@Immutable
-public class NTCredentials implements Credentials {
+public class NTCredentials implements Credentials, Serializable {
+
+ private static final long serialVersionUID = -7385699315228907265L;
/** The user principal */
private final NTUserPrincipal principal;
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/auth/NTUserPrincipal.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/auth/NTUserPrincipal.java?rev=916658&r1=916657&r2=916658&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/auth/NTUserPrincipal.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/auth/NTUserPrincipal.java Fri Feb 26 12:19:06 2010
@@ -26,6 +26,7 @@
package org.apache.http.auth;
+import java.io.Serializable;
import java.security.Principal;
import java.util.Locale;
@@ -39,8 +40,10 @@
* @since 4.0
*/
@Immutable
-public class NTUserPrincipal implements Principal {
+public class NTUserPrincipal implements Principal, Serializable {
+ private static final long serialVersionUID = -6870169797924406894L;
+
private final String username;
private final String domain;
private final String ntname;
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/auth/UsernamePasswordCredentials.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/auth/UsernamePasswordCredentials.java?rev=916658&r1=916657&r2=916658&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/auth/UsernamePasswordCredentials.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/auth/UsernamePasswordCredentials.java Fri Feb 26 12:19:06 2010
@@ -26,6 +26,7 @@
package org.apache.http.auth;
+import java.io.Serializable;
import java.security.Principal;
import org.apache.http.annotation.Immutable;
@@ -39,7 +40,9 @@
* @since 4.0
*/
@Immutable
-public class UsernamePasswordCredentials implements Credentials {
+public class UsernamePasswordCredentials implements Credentials, Serializable {
+
+ private static final long serialVersionUID = 243343858802739403L;
private final BasicUserPrincipal principal;
private final String password;
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/BasicCookieStore.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/BasicCookieStore.java?rev=916658&r1=916657&r2=916658&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/BasicCookieStore.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/BasicCookieStore.java Fri Feb 26 12:19:06 2010
@@ -26,6 +26,7 @@
package org.apache.http.impl.client;
+import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
@@ -47,7 +48,9 @@
* @since 4.0
*/
@ThreadSafe
-public class BasicCookieStore implements CookieStore {
+public class BasicCookieStore implements CookieStore, Serializable {
+
+ private static final long serialVersionUID = -1113466491038527240L;
@GuardedBy("this")
private final ArrayList<Cookie> cookies;
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/cookie/BasicClientCookie.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/cookie/BasicClientCookie.java?rev=916658&r1=916657&r2=916658&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/cookie/BasicClientCookie.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/cookie/BasicClientCookie.java Fri Feb 26 12:19:06 2010
@@ -27,6 +27,7 @@
package org.apache.http.impl.cookie;
+import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
@@ -43,7 +44,9 @@
* @since 4.0
*/
@NotThreadSafe
-public class BasicClientCookie implements SetCookie, ClientCookie, Cloneable {
+public class BasicClientCookie implements SetCookie, ClientCookie, Cloneable, Serializable {
+
+ private static final long serialVersionUID = -3869795591041535538L;
/**
* Default Constructor taking a name and a value. The value may be null.
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/cookie/BasicClientCookie2.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/cookie/BasicClientCookie2.java?rev=916658&r1=916657&r2=916658&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/cookie/BasicClientCookie2.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/cookie/BasicClientCookie2.java Fri Feb 26 12:19:06 2010
@@ -27,6 +27,7 @@
package org.apache.http.impl.cookie;
+import java.io.Serializable;
import java.util.Date;
import org.apache.http.annotation.NotThreadSafe;
@@ -39,8 +40,10 @@
* @since 4.0
*/
@NotThreadSafe
-public class BasicClientCookie2 extends BasicClientCookie implements SetCookie2 {
+public class BasicClientCookie2 extends BasicClientCookie implements SetCookie2, Serializable {
+ private static final long serialVersionUID = -7744598295706617057L;
+
private String commentURL;
private int[] ports;
private boolean discard;
Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/auth/TestCredentials.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/auth/TestCredentials.java?rev=916658&r1=916657&r2=916658&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/auth/TestCredentials.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/auth/TestCredentials.java Fri Feb 26 12:19:06 2010
@@ -27,6 +27,11 @@
package org.apache.http.auth;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
@@ -205,4 +210,31 @@
assertTrue(creds9.equals(creds7));
}
+
+ public void testUsernamePasswordCredentialsSerialization() throws Exception {
+ UsernamePasswordCredentials orig = new UsernamePasswordCredentials("name", "pwd");
+ ByteArrayOutputStream outbuffer = new ByteArrayOutputStream();
+ ObjectOutputStream outstream = new ObjectOutputStream(outbuffer);
+ outstream.writeObject(orig);
+ outstream.close();
+ byte[] raw = outbuffer.toByteArray();
+ ByteArrayInputStream inbuffer = new ByteArrayInputStream(raw);
+ ObjectInputStream instream = new ObjectInputStream(inbuffer);
+ UsernamePasswordCredentials clone = (UsernamePasswordCredentials) instream.readObject();
+ assertEquals(orig, clone);
+ }
+
+ public void testNTCredentialsSerialization() throws Exception {
+ NTCredentials orig = new NTCredentials("name", "pwd", "somehost", "domain");
+ ByteArrayOutputStream outbuffer = new ByteArrayOutputStream();
+ ObjectOutputStream outstream = new ObjectOutputStream(outbuffer);
+ outstream.writeObject(orig);
+ outstream.close();
+ byte[] raw = outbuffer.toByteArray();
+ ByteArrayInputStream inbuffer = new ByteArrayInputStream(raw);
+ ObjectInputStream instream = new ObjectInputStream(inbuffer);
+ NTCredentials clone = (NTCredentials) instream.readObject();
+ assertEquals(orig, clone);
+ }
+
}
Added: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestBasicCookieStore.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestBasicCookieStore.java?rev=916658&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestBasicCookieStore.java (added)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestBasicCookieStore.java Fri Feb 26 12:19:06 2010
@@ -0,0 +1,113 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.impl.client;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.Calendar;
+import java.util.List;
+
+import org.apache.http.cookie.Cookie;
+import org.apache.http.impl.cookie.BasicClientCookie;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Unit tests for {@link BasicCookieStore}.
+ */
+public class TestBasicCookieStore extends TestCase {
+
+ public TestBasicCookieStore(String testName) {
+ super(testName);
+ }
+
+ public static void main(String args[]) {
+ String[] testCaseName = { TestBasicCookieStore.class.getName() };
+ junit.textui.TestRunner.main(testCaseName);
+ }
+
+ public static Test suite() {
+ return new TestSuite(TestBasicCookieStore.class);
+ }
+
+ public void testBasics() throws Exception {
+ BasicCookieStore store = new BasicCookieStore();
+ store.addCookie(new BasicClientCookie("name1", "value1"));
+ store.addCookies(new BasicClientCookie[] {new BasicClientCookie("name2", "value2")});
+ List<Cookie> l = store.getCookies();
+ assertNotNull(l);
+ assertEquals(2, l.size());
+ assertEquals("name1", l.get(0).getName());
+ assertEquals("name2", l.get(1).getName());
+ store.clear();
+ l = store.getCookies();
+ assertNotNull(l);
+ assertEquals(0, l.size());
+ }
+
+ public void testExpiredCookie() throws Exception {
+ BasicCookieStore store = new BasicCookieStore();
+ BasicClientCookie cookie = new BasicClientCookie("name1", "value1");
+
+ Calendar c = Calendar.getInstance();
+ c.add(Calendar.DAY_OF_YEAR, -10);
+ cookie.setExpiryDate(c.getTime());
+ store.addCookie(cookie);
+ List<Cookie> l = store.getCookies();
+ assertNotNull(l);
+ assertEquals(0, l.size());
+ }
+
+ public void testSerialization() throws Exception {
+ BasicCookieStore orig = new BasicCookieStore();
+ orig.addCookie(new BasicClientCookie("name1", "value1"));
+ orig.addCookie(new BasicClientCookie("name2", "value2"));
+ ByteArrayOutputStream outbuffer = new ByteArrayOutputStream();
+ ObjectOutputStream outstream = new ObjectOutputStream(outbuffer);
+ outstream.writeObject(orig);
+ outstream.close();
+ byte[] raw = outbuffer.toByteArray();
+ ByteArrayInputStream inbuffer = new ByteArrayInputStream(raw);
+ ObjectInputStream instream = new ObjectInputStream(inbuffer);
+ BasicCookieStore clone = (BasicCookieStore) instream.readObject();
+ List<Cookie> expected = orig.getCookies();
+ List<Cookie> clones = clone.getCookies();
+ assertNotNull(expected);
+ assertNotNull(clones);
+ assertEquals(expected.size(), clones.size());
+ for (int i = 0; i < expected.size(); i++) {
+ assertEquals(expected.get(i).getName(), clones.get(i).getName());
+ assertEquals(expected.get(i).getValue(), clones.get(i).getValue());
+ }
+ }
+
+}
Propchange: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestBasicCookieStore.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestBasicCookieStore.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/cookie/TestBasicClientCookie.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/cookie/TestBasicClientCookie.java?rev=916658&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/cookie/TestBasicClientCookie.java (added)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/cookie/TestBasicClientCookie.java Fri Feb 26 12:19:06 2010
@@ -0,0 +1,102 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.impl.cookie;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Unit tests for {@link BasicClientCookie}.
+ */
+public class TestBasicClientCookie extends TestCase {
+
+ public TestBasicClientCookie(String testName) {
+ super(testName);
+ }
+
+ public static void main(String args[]) {
+ String[] testCaseName = { TestBasicClientCookie.class.getName() };
+ junit.textui.TestRunner.main(testCaseName);
+ }
+
+ public static Test suite() {
+ return new TestSuite(TestBasicClientCookie.class);
+ }
+
+ public void testConstructor() {
+ BasicClientCookie cookie = new BasicClientCookie("name", "value");
+ assertEquals("name", cookie.getName());
+ assertEquals("value", cookie.getValue());
+ try {
+ new BasicClientCookie(null, null);
+ fail("IllegalArgumentException should have been thrown");
+ } catch (IllegalArgumentException ex) {
+ //expected
+ }
+ }
+
+ public void testCloning() throws Exception {
+ BasicClientCookie orig = new BasicClientCookie("name", "value");
+ orig.setDomain("domain");
+ orig.setPath("/");
+ orig.setAttribute("attrib", "stuff");
+ BasicClientCookie clone = (BasicClientCookie) orig.clone();
+ assertEquals(orig.getName(), clone.getName());
+ assertEquals(orig.getValue(), clone.getValue());
+ assertEquals(orig.getDomain(), clone.getDomain());
+ assertEquals(orig.getPath(), clone.getPath());
+ assertEquals(orig.getAttribute("attrib"), clone.getAttribute("attrib"));
+ }
+
+ public void testSerialization() throws Exception {
+ BasicClientCookie orig = new BasicClientCookie("name", "value");
+ orig.setDomain("domain");
+ orig.setPath("/");
+ orig.setAttribute("attrib", "stuff");
+ ByteArrayOutputStream outbuffer = new ByteArrayOutputStream();
+ ObjectOutputStream outstream = new ObjectOutputStream(outbuffer);
+ outstream.writeObject(orig);
+ outstream.close();
+ byte[] raw = outbuffer.toByteArray();
+ ByteArrayInputStream inbuffer = new ByteArrayInputStream(raw);
+ ObjectInputStream instream = new ObjectInputStream(inbuffer);
+ BasicClientCookie clone = (BasicClientCookie) instream.readObject();
+ assertEquals(orig.getName(), clone.getName());
+ assertEquals(orig.getValue(), clone.getValue());
+ assertEquals(orig.getDomain(), clone.getDomain());
+ assertEquals(orig.getPath(), clone.getPath());
+ assertEquals(orig.getAttribute("attrib"), clone.getAttribute("attrib"));
+ }
+
+}
Propchange: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/cookie/TestBasicClientCookie.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/cookie/TestBasicClientCookie.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/cookie/TestBasicClientCookie2.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/cookie/TestBasicClientCookie2.java?rev=916658&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/cookie/TestBasicClientCookie2.java (added)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/cookie/TestBasicClientCookie2.java Fri Feb 26 12:19:06 2010
@@ -0,0 +1,115 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.impl.cookie;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Unit tests for {@link BasicClientCookie2}.
+ */
+public class TestBasicClientCookie2 extends TestCase {
+
+ public TestBasicClientCookie2(String testName) {
+ super(testName);
+ }
+
+ public static void main(String args[]) {
+ String[] testCaseName = { TestBasicClientCookie2.class.getName() };
+ junit.textui.TestRunner.main(testCaseName);
+ }
+
+ public static Test suite() {
+ return new TestSuite(TestBasicClientCookie2.class);
+ }
+
+ public void testConstructor() {
+ BasicClientCookie2 cookie = new BasicClientCookie2("name", "value");
+ assertEquals("name", cookie.getName());
+ assertEquals("value", cookie.getValue());
+ try {
+ new BasicClientCookie2(null, null);
+ fail("IllegalArgumentException should have been thrown");
+ } catch (IllegalArgumentException ex) {
+ //expected
+ }
+ }
+
+ public void testCloning() throws Exception {
+ BasicClientCookie2 orig = new BasicClientCookie2("name", "value");
+ orig.setDomain("domain");
+ orig.setPath("/");
+ orig.setAttribute("attrib", "stuff");
+ orig.setPorts(new int[] {80, 8080});
+ BasicClientCookie2 clone = (BasicClientCookie2) orig.clone();
+ assertEquals(orig.getName(), clone.getName());
+ assertEquals(orig.getValue(), clone.getValue());
+ assertEquals(orig.getDomain(), clone.getDomain());
+ assertEquals(orig.getPath(), clone.getPath());
+ assertEquals(orig.getAttribute("attrib"), clone.getAttribute("attrib"));
+ assertEquals(orig.getPorts().length, clone.getPorts().length);
+ assertEquals(orig.getPorts()[0], clone.getPorts()[0]);
+ assertEquals(orig.getPorts()[1], clone.getPorts()[1]);
+ }
+
+ public void testSerialization() throws Exception {
+ BasicClientCookie2 orig = new BasicClientCookie2("name", "value");
+ orig.setDomain("domain");
+ orig.setPath("/");
+ orig.setAttribute("attrib", "stuff");
+ orig.setPorts(new int[] {80, 8080});
+ ByteArrayOutputStream outbuffer = new ByteArrayOutputStream();
+ ObjectOutputStream outstream = new ObjectOutputStream(outbuffer);
+ outstream.writeObject(orig);
+ outstream.close();
+ byte[] raw = outbuffer.toByteArray();
+ ByteArrayInputStream inbuffer = new ByteArrayInputStream(raw);
+ ObjectInputStream instream = new ObjectInputStream(inbuffer);
+ BasicClientCookie2 clone = (BasicClientCookie2) instream.readObject();
+ assertEquals(orig.getName(), clone.getName());
+ assertEquals(orig.getValue(), clone.getValue());
+ assertEquals(orig.getDomain(), clone.getDomain());
+ assertEquals(orig.getPath(), clone.getPath());
+ assertEquals(orig.getAttribute("attrib"), clone.getAttribute("attrib"));
+ int[] expected = orig.getPorts();
+ int[] clones = clone.getPorts();
+ assertNotNull(expected);
+ assertNotNull(clones);
+ assertEquals(expected.length, clones.length);
+ for (int i = 0; i < expected.length; i++) {
+ assertEquals(expected[i], clones[i]);
+ }
+ }
+
+}
Propchange: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/cookie/TestBasicClientCookie2.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/cookie/TestBasicClientCookie2.java
------------------------------------------------------------------------------
svn:keywords = Rev Date