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/03/25 17:26:03 UTC
svn commit: r159036 - in
jakarta/httpclient/trunk/http-common/src/test/org/apache/http: TestAll.java
impl/TestAllImpl.java impl/TestNIOHttpTransmitterAndReceiver.java
Author: olegk
Date: Fri Mar 25 08:26:03 2005
New Revision: 159036
URL: http://svn.apache.org/viewcvs?view=rev&rev=159036
Log:
More test coverage
Added:
jakarta/httpclient/trunk/http-common/src/test/org/apache/http/impl/TestAllImpl.java (with props)
Modified:
jakarta/httpclient/trunk/http-common/src/test/org/apache/http/TestAll.java
jakarta/httpclient/trunk/http-common/src/test/org/apache/http/impl/TestNIOHttpTransmitterAndReceiver.java
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=159035&r2=159036
==============================================================================
--- 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 Fri Mar 25 08:26:03 2005
@@ -28,6 +28,7 @@
package org.apache.http;
+import org.apache.http.impl.TestAllImpl;
import org.apache.http.util.TestAllUtil;
import junit.framework.*;
@@ -40,7 +41,9 @@
public static Test suite() {
TestSuite suite = new TestSuite();
+
suite.addTest(TestAllUtil.suite());
+
suite.addTest(TestNameValuePair.suite());
suite.addTest(TestHeader.suite());
suite.addTest(TestHeaderElement.suite());
@@ -49,6 +52,9 @@
suite.addTest(TestHttpVersion.suite());
suite.addTest(TestStatusLine.suite());
suite.addTest(TestRequestLine.suite());
+
+ suite.addTest(TestAllImpl.suite());
+
return suite;
}
Added: 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=auto&rev=159036
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/test/org/apache/http/impl/TestAllImpl.java (added)
+++ jakarta/httpclient/trunk/http-common/src/test/org/apache/http/impl/TestAllImpl.java Fri Mar 25 08:26:03 2005
@@ -0,0 +1,50 @@
+/*
+ * $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.impl;
+
+import junit.framework.*;
+
+public class TestAllImpl extends TestCase {
+
+ public TestAllImpl(String testName) {
+ super(testName);
+ }
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite();
+ suite.addTest(TestNIOHttpTransmitterAndReceiver.suite());
+ return suite;
+ }
+
+ public static void main(String args[]) {
+ String[] testCaseName = { TestAllImpl.class.getName() };
+ junit.textui.TestRunner.main(testCaseName);
+ }
+
+}
Propchange: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/impl/TestAllImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/impl/TestAllImpl.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/impl/TestAllImpl.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/impl/TestNIOHttpTransmitterAndReceiver.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/test/org/apache/http/impl/TestNIOHttpTransmitterAndReceiver.java?view=diff&r1=159035&r2=159036
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/test/org/apache/http/impl/TestNIOHttpTransmitterAndReceiver.java (original)
+++ jakarta/httpclient/trunk/http-common/src/test/org/apache/http/impl/TestNIOHttpTransmitterAndReceiver.java Fri Mar 25 08:26:03 2005
@@ -62,6 +62,31 @@
public static Test suite() {
return new TestSuite(TestNIOHttpTransmitterAndReceiver.class);
}
+
+ public void testConstructor() throws Exception {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ HttpDataTransmitter transmitter1 =
+ new NIOHttpDataTransmitter(Channels.newChannel(out), -10);
+ HttpDataTransmitter transmitter2 =
+ new NIOHttpDataTransmitter(Channels.newChannel(out), 200000000);
+ try {
+ HttpDataTransmitter transmitter3 = new NIOHttpDataTransmitter(null, 1024);
+ fail("IllegalArgumentException should have been thrown");
+ } catch (IllegalArgumentException ex) {
+ //expected
+ }
+ ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
+ HttpDataReceiver receiver1 =
+ new NIOHttpDataReceiver(Channels.newChannel(in), -10);
+ HttpDataReceiver receiver2 =
+ new NIOHttpDataReceiver(Channels.newChannel(in), 200000000);
+ try {
+ HttpDataReceiver receiver3 = new NIOHttpDataReceiver(null, 1024);
+ fail("IllegalArgumentException should have been thrown");
+ } catch (IllegalArgumentException ex) {
+ //expected
+ }
+ }
public void testBasicReadWriteLine() throws Exception {
@@ -84,12 +109,16 @@
for (int i = 0; i < teststrs.length; i++) {
transmitter.writeLine(teststrs[i]);
}
+ //this write operation should have no effect
+ transmitter.writeLine(null);
transmitter.flush();
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
HttpDataReceiver receiver =
new NIOHttpDataReceiver(Channels.newChannel(in), 16);
+ assertTrue(receiver.isDataAvailable(0));
+
for (int i = 0; i < teststrs.length; i++) {
assertEquals(teststrs[i], receiver.readLine());
}
@@ -105,6 +134,10 @@
transmitter.write(new byte[] {'\r', '\n'});
transmitter.write(new byte[] {'\r', '\r', '\n'});
transmitter.write(new byte[] {'\n'});
+ //these write operations should have no effect
+ transmitter.write(null);
+ transmitter.write(null, 0, 12);
+
transmitter.flush();
StringBuffer buffer = new StringBuffer();
@@ -151,5 +184,64 @@
assertEquals("a", receiver.readLine());
assertNull(receiver.readLine());
assertNull(receiver.readLine());
+ }
+
+ public void testReadWriteBytes() throws Exception {
+ // make the buffer larger than that of transmitter
+ byte[] out = new byte[40];
+ for (int i = 0; i < out.length; i++) {
+ out[i] = (byte)('0' + i);
+ }
+ ByteArrayOutputStream outstream = new ByteArrayOutputStream();
+ HttpDataTransmitter transmitter =
+ new NIOHttpDataTransmitter(Channels.newChannel(outstream), 16);
+ int off = 0;
+ int remaining = out.length;
+ while (remaining > 0) {
+ int chunk = 10;
+ if (chunk > remaining) {
+ chunk = remaining;
+ }
+ transmitter.write(out, off, chunk);
+ off += chunk;
+ remaining -= chunk;
+ }
+ transmitter.flush();
+
+ byte[] tmp = outstream.toByteArray();
+ assertEquals(out.length, tmp.length);
+ for (int i = 0; i < out.length; i++) {
+ assertEquals(out[i], tmp[i]);
+ }
+
+ ByteArrayInputStream instream = new ByteArrayInputStream(tmp);
+ HttpDataReceiver receiver =
+ new NIOHttpDataReceiver(Channels.newChannel(instream), 16);
+
+ // these read operations will have no effect
+ assertEquals(0, receiver.read(null, 0, 10));
+ assertEquals(0, receiver.read(null));
+
+ byte[] in = new byte[40];
+ int noRead = 0;
+ off = 0;
+ remaining = in.length;
+ while (remaining > 0) {
+ int chunk = 10;
+ if (chunk > remaining) {
+ chunk = remaining;
+ }
+ int l = receiver.read(in, off, chunk);
+ if (l == -1) {
+ break;
+ }
+ off += l;
+ remaining -= l;
+ }
+ for (int i = 0; i < out.length; i++) {
+ assertEquals(out[i], in[i]);
+ }
+ assertEquals(-1, receiver.read(tmp));
+ assertEquals(-1, receiver.read(tmp));
}
}