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 2005/04/04 20:52:51 UTC
svn commit: r160084 - in jakarta/httpclient/trunk/http-common/src:
java/org/apache/http/ java/org/apache/http/impl/ test/org/apache/http/
test/org/apache/http/impl/
Author: olegk
Date: Mon Apr 4 11:52:49 2005
New Revision: 160084
URL: http://svn.apache.org/viewcvs?view=rev&rev=160084
Log:
Extra test coverage
Added:
jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestHttpExceptions.java (with props)
jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestHttpHost.java (with props)
jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestHttpRuntime.java (with props)
jakarta/httpclient/trunk/http-common/src/test/org/apache/http/impl/TestDefaultConnectionReuseStrategy.java (with props)
Modified:
jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpHost.java
jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpRuntime.java
jakarta/httpclient/trunk/http-common/src/java/org/apache/http/NoHttpResponseException.java
jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/BasicHttpResponse.java
jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestAll.java
jakarta/httpclient/trunk/http-common/src/test/org/apache/http/impl/TestAllImpl.java
Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpHost.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpHost.java?view=diff&r1=160083&r2=160084
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpHost.java (original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpHost.java Mon Apr 4 11:52:49 2005
@@ -148,10 +148,8 @@
*/
public String toURI() {
StringBuffer buffer = new StringBuffer(50);
- if (this.protocol != null) {
- buffer.append(this.protocol.getScheme());
- buffer.append("://");
- }
+ buffer.append(this.protocol.getScheme());
+ buffer.append("://");
buffer.append(this.hostname);
if (this.port != this.protocol.getDefaultPort()) {
buffer.append(':');
@@ -164,9 +162,7 @@
* @see java.lang.Object#toString()
*/
public String toString() {
- StringBuffer buffer = new StringBuffer(50);
- buffer.append(toURI());
- return buffer.toString();
+ return toURI();
}
/**
@@ -190,7 +186,7 @@
*/
public int hashCode() {
int hash = LangUtils.HASH_SEED;
- hash = LangUtils.hashCode(hash, this.hostname);
+ hash = LangUtils.hashCode(hash, this.hostname.toUpperCase());
hash = LangUtils.hashCode(hash, this.port);
hash = LangUtils.hashCode(hash, this.protocol);
return hash;
Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpRuntime.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpRuntime.java?view=diff&r1=160083&r2=160084
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpRuntime.java (original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpRuntime.java Mon Apr 4 11:52:49 2005
@@ -64,7 +64,7 @@
throw new FatalError("Invalid Java specification major version: " + verstr);
}
try {
- JAVA_MINOR_VER = Integer.parseInt(verstr.substring(i - 1));
+ JAVA_MINOR_VER = Integer.parseInt(verstr.substring(i + 1));
} catch (NumberFormatException ex) {
throw new FatalError("Invalid Java specification minor version: " + verstr);
}
Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/NoHttpResponseException.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/NoHttpResponseException.java?view=diff&r1=160083&r2=160084
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/NoHttpResponseException.java (original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/NoHttpResponseException.java Mon Apr 4 11:52:49 2005
@@ -43,13 +43,6 @@
public class NoHttpResponseException extends IOException {
/**
- * Creates a new NoHttpResponseException with a <tt>null</tt> detail message.
- */
- public NoHttpResponseException() {
- super();
- }
-
- /**
* Creates a new NoHttpResponseException with the specified detail message.
*
* @param message exception message
Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/BasicHttpResponse.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/BasicHttpResponse.java?view=diff&r1=160083&r2=160084
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/BasicHttpResponse.java (original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/BasicHttpResponse.java Mon Apr 4 11:52:49 2005
@@ -45,6 +45,7 @@
public class BasicHttpResponse extends BasicHttpMessage implements HttpMutableResponse {
private StatusLine statusline = null;
+ private HttpEntity entity = null;
public BasicHttpResponse() {
super();
@@ -67,10 +68,11 @@
}
public HttpEntity getEntity() {
- return null;
+ return this.entity;
}
public void setEntity(final HttpEntity entity) {
+ this.entity = entity;
}
}
Modified: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestAll.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestAll.java?view=diff&r1=160083&r2=160084
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestAll.java (original)
+++ jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestAll.java Mon Apr 4 11:52:49 2005
@@ -45,6 +45,7 @@
suite.addTest(TestAllUtil.suite());
+ suite.addTest(TestHttpExceptions.suite());
suite.addTest(TestNameValuePair.suite());
suite.addTest(TestHeader.suite());
suite.addTest(TestHeaderElement.suite());
@@ -52,6 +53,8 @@
suite.addTest(TestHttpVersion.suite());
suite.addTest(TestStatusLine.suite());
suite.addTest(TestRequestLine.suite());
+ suite.addTest(TestHttpHost.suite());
+ suite.addTest(TestHttpRuntime.suite());
suite.addTest(TestAllIO.suite());
Added: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestHttpExceptions.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestHttpExceptions.java?view=auto&rev=160084
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestHttpExceptions.java (added)
+++ jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestHttpExceptions.java Mon Apr 4 11:52:49 2005
@@ -0,0 +1,72 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ * ====================================================================
+ *
+ * Copyright 1999-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http;
+
+import junit.framework.*;
+
+/**
+ * Simple tests for various HTTP exception classes.
+ *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @version $Revision$
+ */
+public class TestHttpExceptions extends TestCase {
+
+ // ------------------------------------------------------------ Constructor
+ public TestHttpExceptions(String testName) {
+ super(testName);
+ }
+
+ // ------------------------------------------------------------------- Main
+ public static void main(String args[]) {
+ String[] testCaseName = { TestHttpExceptions.class.getName() };
+ junit.textui.TestRunner.main(testCaseName);
+ }
+
+ // ------------------------------------------------------- TestCase Methods
+
+ public static Test suite() {
+ return new TestSuite(TestHttpExceptions.class);
+ }
+
+ public void testConstructor() {
+ Throwable cause = new Exception();
+ new HttpException();
+ new HttpException("Oppsie");
+ new HttpException("Oppsie", cause);
+ new ProtocolException();
+ new ProtocolException("Oppsie");
+ new ProtocolException("Oppsie", cause);
+ new NoHttpResponseException("Oppsie");
+ new ConnectTimeoutException();
+ new ConnectTimeoutException("Oppsie");
+ }
+
+}
Propchange: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestHttpExceptions.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestHttpExceptions.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestHttpExceptions.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestHttpHost.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestHttpHost.java?view=auto&rev=160084
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestHttpHost.java (added)
+++ jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestHttpHost.java Mon Apr 4 11:52:49 2005
@@ -0,0 +1,153 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ *
+ * Copyright 1999-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http;
+
+import org.apache.http.impl.NIOProtocolSocketFactory;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Unit tests for {@link HttpHost}.
+ *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ */
+public class TestHttpHost extends TestCase {
+
+ public TestHttpHost(String testName) {
+ super(testName);
+ }
+
+ public static void main(String args[]) {
+ String[] testCaseName = { TestHttpHost.class.getName() };
+ junit.textui.TestRunner.main(testCaseName);
+ }
+
+ public static Test suite() {
+ return new TestSuite(TestHttpHost.class);
+ }
+
+ public void testConstructor() {
+ Protocol http = Protocol.getProtocol("http");
+ HttpHost host1 = new HttpHost("somehost");
+ assertEquals("somehost", host1.getHostName());
+ assertEquals(http.getDefaultPort(), host1.getPort());
+ assertEquals(http, host1.getProtocol());
+ HttpHost host2 = new HttpHost("somehost", 8080);
+ assertEquals("somehost", host2.getHostName());
+ assertEquals(8080, host2.getPort());
+ assertEquals(http, host2.getProtocol());
+ HttpHost host3 = new HttpHost("somehost", -1);
+ assertEquals("somehost", host3.getHostName());
+ assertEquals(http.getDefaultPort(), host3.getPort());
+ assertEquals(http, host3.getProtocol());
+ HttpHost host4 = new HttpHost("somehost", 8080, http);
+ assertEquals("somehost", host4.getHostName());
+ assertEquals(8080, host4.getPort());
+ assertEquals(http, host4.getProtocol());
+ try {
+ HttpHost host = new HttpHost(null, -1, null);
+ fail("IllegalArgumentException should have been thrown");
+ } catch (IllegalArgumentException ex) {
+ //expected
+ }
+ try {
+ HttpHost host = new HttpHost("somehost", -1, null);
+ fail("IllegalArgumentException should have been thrown");
+ } catch (IllegalArgumentException ex) {
+ //expected
+ }
+ }
+
+ public void testHashCode() {
+ Protocol http = Protocol.getProtocol("http");
+ Protocol myhttp = new Protocol("myhttp",
+ NIOProtocolSocketFactory.getSocketFactory(), 8080);
+ HttpHost host1 = new HttpHost("somehost", 8080, http);
+ HttpHost host2 = new HttpHost("somehost", 80, http);
+ HttpHost host3 = new HttpHost("someotherhost", 8080, http);
+ HttpHost host4 = new HttpHost("somehost", 80, http);
+ HttpHost host5 = new HttpHost("SomeHost", 80, http);
+ HttpHost host6 = new HttpHost("SomeHost", 80, myhttp);
+
+ assertTrue(host1.hashCode() == host1.hashCode());
+ assertTrue(host1.hashCode() != host2.hashCode());
+ assertTrue(host1.hashCode() != host3.hashCode());
+ assertTrue(host2.hashCode() == host4.hashCode());
+ assertTrue(host2.hashCode() == host5.hashCode());
+ assertTrue(host5.hashCode() != host6.hashCode());
+ }
+
+ public void testEquals() {
+ Protocol http = Protocol.getProtocol("http");
+ Protocol myhttp = new Protocol("myhttp",
+ NIOProtocolSocketFactory.getSocketFactory(), 8080);
+ HttpHost host1 = new HttpHost("somehost", 8080, http);
+ HttpHost host2 = new HttpHost("somehost", 80, http);
+ HttpHost host3 = new HttpHost("someotherhost", 8080, http);
+ HttpHost host4 = new HttpHost("somehost", 80, http);
+ HttpHost host5 = new HttpHost("SomeHost", 80, http);
+ HttpHost host6 = new HttpHost("SomeHost", 80, myhttp);
+
+ assertTrue(host1.equals(host1));
+ assertFalse(host1.equals(host2));
+ assertFalse(host1.equals(host3));
+ assertTrue(host2.equals(host4));
+ assertTrue(host2.equals(host5));
+ assertFalse(host5.equals(host6));
+ assertFalse(host1.equals(null));
+ assertFalse(host1.equals("http://somehost"));
+ }
+
+ public void testToString() {
+ Protocol http = Protocol.getProtocol("http");
+ Protocol myhttp = new Protocol("myhttp",
+ NIOProtocolSocketFactory.getSocketFactory(), 8080);
+ HttpHost host1 = new HttpHost("somehost");
+ assertEquals("http://somehost", host1.toString());
+ HttpHost host2 = new HttpHost("somehost", http.getDefaultPort());
+ assertEquals("http://somehost", host2.toString());
+ HttpHost host3 = new HttpHost("somehost", -1);
+ assertEquals("http://somehost", host3.toString());
+ HttpHost host4 = new HttpHost("somehost", 8888);
+ assertEquals("http://somehost:8888", host4.toString());
+ HttpHost host5 = new HttpHost("somehost", -1, myhttp);
+ assertEquals("myhttp://somehost", host5.toString());
+ HttpHost host6 = new HttpHost("somehost", 80, myhttp);
+ assertEquals("myhttp://somehost:80", host6.toString());
+ }
+
+ public void testClone() {
+ HttpHost host1 = new HttpHost("somehost", 8888, Protocol.getProtocol("http"));
+ HttpHost host2 = (HttpHost) host1.clone();
+ assertEquals(host1, host2);
+ }
+}
Propchange: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestHttpHost.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestHttpHost.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestHttpHost.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestHttpRuntime.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestHttpRuntime.java?view=auto&rev=160084
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestHttpRuntime.java (added)
+++ jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestHttpRuntime.java Mon Apr 4 11:52:49 2005
@@ -0,0 +1,82 @@
+/*
+ * $HeadURL:
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ *
+ * Copyright 1999-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Unit tests for {@link HttpRuntime}.
+ *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ */
+public class TestHttpRuntime extends TestCase {
+
+ public TestHttpRuntime(String testName) {
+ super(testName);
+ }
+
+ public static void main(String args[]) {
+ String[] testCaseName = { TestHttpRuntime.class.getName() };
+ junit.textui.TestRunner.main(testCaseName);
+ }
+
+ public static Test suite() {
+ return new TestSuite(TestHttpRuntime.class);
+ }
+
+ public void testJavaVersion() {
+ String verstr = (String) System.getProperty("java.specification.version");
+ assertEquals(verstr, HttpRuntime.JAVA_MAJOR_VER + "." + HttpRuntime.JAVA_MINOR_VER);
+ }
+
+ public void testIOCapabilities() {
+ if (HttpRuntime.JAVA_MAJOR_VER == 1 && HttpRuntime.JAVA_MINOR_VER < 4) {
+ assertFalse(HttpRuntime.isNIOCapable());
+ }
+ if (HttpRuntime.JAVA_MAJOR_VER > 1 ||
+ (HttpRuntime.JAVA_MAJOR_VER == 1 && HttpRuntime.JAVA_MINOR_VER >= 4)) {
+ assertTrue(HttpRuntime.isNIOCapable());
+ }
+ if (HttpRuntime.JAVA_MAJOR_VER == 1 && HttpRuntime.JAVA_MINOR_VER < 5) {
+ assertFalse(HttpRuntime.isSSLNIOCapable());
+ }
+ if (HttpRuntime.JAVA_MAJOR_VER > 1 ||
+ (HttpRuntime.JAVA_MAJOR_VER == 1 && HttpRuntime.JAVA_MINOR_VER >= 5)) {
+ assertTrue(HttpRuntime.isSSLNIOCapable());
+ }
+ }
+
+ public void testFatalErrorConstructor() {
+ new HttpRuntime.FatalError("Oopsie");
+ new HttpRuntime.FatalError("Oopsie", new Exception());
+ }
+}
Propchange: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestHttpRuntime.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestHttpRuntime.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestHttpRuntime.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/impl/TestAllImpl.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/test/org/apache/http/impl/TestAllImpl.java?view=diff&r1=160083&r2=160084
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/test/org/apache/http/impl/TestAllImpl.java (original)
+++ jakarta/httpclient/trunk/http-common/src/test/org/apache/http/impl/TestAllImpl.java Mon Apr 4 11:52:49 2005
@@ -40,6 +40,8 @@
TestSuite suite = new TestSuite();
suite.addTest(TestHeaderGroup.suite());
suite.addTest(TestNIOHttpTransmitterAndReceiver.suite());
+ suite.addTest(TestAutoCloseInputStream.suite());
+ suite.addTest(TestDefaultConnectionReuseStrategy.suite());
return suite;
}
Added: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/impl/TestDefaultConnectionReuseStrategy.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/test/org/apache/http/impl/TestDefaultConnectionReuseStrategy.java?view=auto&rev=160084
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/test/org/apache/http/impl/TestDefaultConnectionReuseStrategy.java (added)
+++ jakarta/httpclient/trunk/http-common/src/test/org/apache/http/impl/TestDefaultConnectionReuseStrategy.java Mon Apr 4 11:52:49 2005
@@ -0,0 +1,161 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ * ====================================================================
+ *
+ * Copyright 2002-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.impl;
+
+import org.apache.http.Header;
+import org.apache.http.HttpMutableEntity;
+import org.apache.http.HttpMutableResponse;
+import org.apache.http.HttpVersion;
+import org.apache.http.StatusLine;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class TestDefaultConnectionReuseStrategy extends TestCase {
+
+ public TestDefaultConnectionReuseStrategy(String testName) {
+ super(testName);
+ }
+
+ // ------------------------------------------------------- TestCase Methods
+
+ public static Test suite() {
+ return new TestSuite(TestDefaultConnectionReuseStrategy.class);
+ }
+
+ // ------------------------------------------------------------------- Main
+ public static void main(String args[]) {
+ String[] testCaseName = { TestDefaultConnectionReuseStrategy.class.getName() };
+ junit.textui.TestRunner.main(testCaseName);
+ }
+
+ public void testIllegalResponseArg() throws Exception {
+ ConnectionReuseStrategy s = new DefaultConnectionReuseStrategy();
+ try {
+ s.keepAlive(null);
+ fail("IllegalArgumentException should have been thrown");
+ } catch (IllegalArgumentException ex) {
+ // expected
+ }
+ }
+
+ public void testNoContentLengthResponse() throws Exception {
+ HttpMutableEntity entity = new BasicHttpEntity();
+ entity.setChunked(false);
+ entity.setContentLength(-1);
+ HttpMutableResponse response = new BasicHttpResponse();
+ response.setStatusLine(new StatusLine(HttpVersion.HTTP_1_0, 200, "OK"));
+ response.setParams(new DefaultHttpParams(null));
+ response.setEntity(entity);
+
+ ConnectionReuseStrategy s = new DefaultConnectionReuseStrategy();
+ assertFalse(s.keepAlive(response));
+ }
+
+ public void testExplicitClose() throws Exception {
+ HttpMutableEntity entity = new BasicHttpEntity();
+ entity.setChunked(true);
+ entity.setContentLength(-1);
+ HttpMutableResponse response = new BasicHttpResponse();
+ // Use HTTP 1.1
+ response.setStatusLine(new StatusLine(HttpVersion.HTTP_1_1, 200, "OK"));
+ response.setParams(new DefaultHttpParams(null));
+ response.addHeader(new Header("Connection", "close"));
+ response.setEntity(entity);
+
+ ConnectionReuseStrategy s = new DefaultConnectionReuseStrategy();
+ assertFalse(s.keepAlive(response));
+ }
+
+ public void testExplicitKeepAlive() throws Exception {
+ HttpMutableEntity entity = new BasicHttpEntity();
+ entity.setChunked(false);
+ entity.setContentLength(10);
+ HttpMutableResponse response = new BasicHttpResponse();
+ // Use HTTP 1.0
+ response.setStatusLine(new StatusLine(HttpVersion.HTTP_1_0, 200, "OK"));
+ response.setParams(new DefaultHttpParams(null));
+ response.addHeader(new Header("Connection", "keep-alive"));
+ response.setEntity(entity);
+
+ ConnectionReuseStrategy s = new DefaultConnectionReuseStrategy();
+ assertTrue(s.keepAlive(response));
+ }
+
+ public void testHTTP10Default() throws Exception {
+ HttpMutableResponse response = new BasicHttpResponse();
+ response.setStatusLine(new StatusLine(HttpVersion.HTTP_1_0, 200, "OK"));
+ response.setParams(new DefaultHttpParams(null));
+
+ ConnectionReuseStrategy s = new DefaultConnectionReuseStrategy();
+ assertFalse(s.keepAlive(response));
+ }
+
+ public void testHTTP11Default() throws Exception {
+ HttpMutableResponse response = new BasicHttpResponse();
+ response.setStatusLine(new StatusLine(HttpVersion.HTTP_1_1, 200, "OK"));
+ response.setParams(new DefaultHttpParams(null));
+
+ ConnectionReuseStrategy s = new DefaultConnectionReuseStrategy();
+ assertTrue(s.keepAlive(response));
+ }
+
+ public void testFutureHTTP() throws Exception {
+ HttpMutableResponse response = new BasicHttpResponse();
+ response.setStatusLine(new StatusLine(new HttpVersion(3, 45), 200, "OK"));
+ response.setParams(new DefaultHttpParams(null));
+
+ ConnectionReuseStrategy s = new DefaultConnectionReuseStrategy();
+ assertTrue(s.keepAlive(response));
+ }
+
+ public void testBrokenConnectionDirective1() throws Exception {
+ HttpMutableResponse response = new BasicHttpResponse();
+ // Use HTTP 1.0
+ response.setStatusLine(new StatusLine(HttpVersion.HTTP_1_0, 200, "OK"));
+ response.setParams(new DefaultHttpParams(null));
+ response.addHeader(new Header("Connection", "keep--alive"));
+
+ ConnectionReuseStrategy s = new DefaultConnectionReuseStrategy();
+ assertFalse(s.keepAlive(response));
+ }
+
+ public void testBrokenConnectionDirective2() throws Exception {
+ HttpMutableResponse response = new BasicHttpResponse();
+ // Use HTTP 1.0
+ response.setStatusLine(new StatusLine(HttpVersion.HTTP_1_0, 200, "OK"));
+ response.setParams(new DefaultHttpParams(null));
+ response.addHeader(new Header("Connection", null));
+
+ ConnectionReuseStrategy s = new DefaultConnectionReuseStrategy();
+ assertFalse(s.keepAlive(response));
+ }
+}
+
Propchange: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/impl/TestDefaultConnectionReuseStrategy.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/impl/TestDefaultConnectionReuseStrategy.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/impl/TestDefaultConnectionReuseStrategy.java
------------------------------------------------------------------------------
svn:mime-type = text/plain