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/10/15 22:32:23 UTC
svn commit: r321483 - in
/jakarta/httpclient/trunk/http-common/src/test/org/apache/http: io/ mockup/
Author: olegk
Date: Sat Oct 15 13:32:14 2005
New Revision: 321483
URL: http://svn.apache.org/viewcvs?rev=321483&view=rev
Log:
Additional test cases for org.apache.http.io classes
Added:
jakarta/httpclient/trunk/http-common/src/test/org/apache/http/io/TestContentLengthOutputStream.java (with props)
jakarta/httpclient/trunk/http-common/src/test/org/apache/http/io/TestIdentityOutputStream.java (with props)
Modified:
jakarta/httpclient/trunk/http-common/src/test/org/apache/http/io/TestAllIO.java
jakarta/httpclient/trunk/http-common/src/test/org/apache/http/io/TestChunkCoding.java
jakarta/httpclient/trunk/http-common/src/test/org/apache/http/io/TestContentLengthInputStream.java
jakarta/httpclient/trunk/http-common/src/test/org/apache/http/io/TestHttpDataInputStream.java
jakarta/httpclient/trunk/http-common/src/test/org/apache/http/mockup/HttpDataReceiverMockup.java
Modified: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/io/TestAllIO.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/test/org/apache/http/io/TestAllIO.java?rev=321483&r1=321482&r2=321483&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/test/org/apache/http/io/TestAllIO.java (original)
+++ jakarta/httpclient/trunk/http-common/src/test/org/apache/http/io/TestAllIO.java Sat Oct 15 13:32:14 2005
@@ -42,6 +42,8 @@
suite.addTest(TestHttpDataOutputStream.suite());
suite.addTest(TestChunkCoding.suite());
suite.addTest(TestContentLengthInputStream.suite());
+ suite.addTest(TestContentLengthOutputStream.suite());
+ suite.addTest(TestIdentityOutputStream.suite());
return suite;
}
Modified: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/io/TestChunkCoding.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/test/org/apache/http/io/TestChunkCoding.java?rev=321483&r1=321482&r2=321483&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/test/org/apache/http/io/TestChunkCoding.java (original)
+++ jakarta/httpclient/trunk/http-common/src/test/org/apache/http/io/TestChunkCoding.java Sat Oct 15 13:32:14 2005
@@ -180,6 +180,25 @@
}
}
+ public void testChunkedOutputStreamClose() throws IOException {
+ ChunkedOutputStream out = new ChunkedOutputStream(
+ new HttpDataTransmitterMockup());
+ out.close();
+ out.close();
+ try {
+ out.write(new byte[] {1,2,3});
+ fail("IOException should have been thrown");
+ } catch (IOException ex) {
+ // expected
+ }
+ try {
+ out.write(1);
+ fail("IOException should have been thrown");
+ } catch (IOException ex) {
+ // expected
+ }
+ }
+
// Missing \r\n at the end of the first chunk
public void testCorruptChunkedInputStreamMissingCRLF() throws IOException {
String s = "5\r\n012345\r\n56789\r\n0\r\n";
Modified: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/io/TestContentLengthInputStream.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/test/org/apache/http/io/TestContentLengthInputStream.java?rev=321483&r1=321482&r2=321483&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/test/org/apache/http/io/TestContentLengthInputStream.java (original)
+++ jakarta/httpclient/trunk/http-common/src/test/org/apache/http/io/TestContentLengthInputStream.java Sat Oct 15 13:32:14 2005
@@ -105,7 +105,12 @@
in.read();
in.read();
assertTrue(in.skip(10) <= 0);
+ assertTrue(in.skip(-1) == 0);
assertTrue(in.read() == -1);
+
+ in = new ContentLengthInputStream(new HttpDataReceiverMockup(new byte[2]), 4L);
+ in.read();
+ assertTrue(in.skip(2) == 1);
}
public void testClose() throws IOException {
Added: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/io/TestContentLengthOutputStream.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/test/org/apache/http/io/TestContentLengthOutputStream.java?rev=321483&view=auto
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/test/org/apache/http/io/TestContentLengthOutputStream.java (added)
+++ jakarta/httpclient/trunk/http-common/src/test/org/apache/http/io/TestContentLengthOutputStream.java Sat Oct 15 13:32:14 2005
@@ -0,0 +1,116 @@
+/*
+ * $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.io;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.http.mockup.HttpDataTransmitterMockup;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class TestContentLengthOutputStream extends TestCase {
+
+ public TestContentLengthOutputStream(String testName) {
+ super(testName);
+ }
+
+ // ------------------------------------------------------- TestCase Methods
+
+ public static Test suite() {
+ return new TestSuite(TestContentLengthOutputStream.class);
+ }
+
+ // ------------------------------------------------------------------- Main
+ public static void main(String args[]) {
+ String[] testCaseName = { TestContentLengthOutputStream.class.getName() };
+ junit.textui.TestRunner.main(testCaseName);
+ }
+
+ public void testConstructors() throws Exception {
+ new ContentLengthOutputStream(new HttpDataTransmitterMockup(), 10L);
+ try {
+ new ContentLengthOutputStream(null, 10L);
+ fail("IllegalArgumentException should have been thrown");
+ } catch (IllegalArgumentException ex) {
+ // expected
+ }
+ try {
+ new ContentLengthOutputStream(new HttpDataTransmitterMockup(), -10);
+ fail("IllegalArgumentException should have been thrown");
+ } catch (IllegalArgumentException ex) {
+ // expected
+ }
+ }
+
+ public void testBasics() throws Exception {
+ ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+ HttpDataTransmitterMockup datatransmitter = new HttpDataTransmitterMockup(buffer);
+ OutputStream out = new ContentLengthOutputStream(datatransmitter, 15L);
+
+ byte[] tmp = new byte[10];
+ out.write(tmp, 0, 10);
+ out.write(1);
+ out.write(tmp, 0, 10);
+ out.write(tmp, 0, 10);
+ out.write(tmp);
+ out.write(1);
+ out.write(2);
+ out.flush();
+ out.close();
+ byte[] data = datatransmitter.getData();
+ assertEquals(15, data.length);
+ }
+
+ public void testClose() throws Exception {
+ ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+ HttpDataTransmitterMockup datatransmitter = new HttpDataTransmitterMockup(buffer);
+ OutputStream out = new ContentLengthOutputStream(datatransmitter, 15L);
+ out.close();
+ out.close();
+ byte[] tmp = new byte[10];
+ try {
+ out.write(tmp);
+ fail("IOException should have been thrown");
+ } catch (IOException ex) {
+ // expected
+ }
+ try {
+ out.write(1);
+ fail("IOException should have been thrown");
+ } catch (IOException ex) {
+ // expected
+ }
+ }
+
+}
+
Propchange: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/io/TestContentLengthOutputStream.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/io/TestContentLengthOutputStream.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/io/TestContentLengthOutputStream.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/io/TestHttpDataInputStream.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/test/org/apache/http/io/TestHttpDataInputStream.java?rev=321483&r1=321482&r2=321483&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/test/org/apache/http/io/TestHttpDataInputStream.java (original)
+++ jakarta/httpclient/trunk/http-common/src/test/org/apache/http/io/TestHttpDataInputStream.java Sat Oct 15 13:32:14 2005
@@ -100,4 +100,11 @@
assertEquals(-1, instream.read());
}
+ public void testAvailable() throws Exception {
+ byte[] input = new byte[] {'a', 'b', 'c'};
+ HttpDataReceiverMockup receiver = new HttpDataReceiverMockup(input);
+ HttpDataInputStream instream = new HttpDataInputStream(receiver);
+ assertTrue(instream.available() > 0);
+ }
+
}
Added: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/io/TestIdentityOutputStream.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/test/org/apache/http/io/TestIdentityOutputStream.java?rev=321483&view=auto
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/test/org/apache/http/io/TestIdentityOutputStream.java (added)
+++ jakarta/httpclient/trunk/http-common/src/test/org/apache/http/io/TestIdentityOutputStream.java Sat Oct 15 13:32:14 2005
@@ -0,0 +1,106 @@
+/*
+ * $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.io;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.http.mockup.HttpDataTransmitterMockup;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class TestIdentityOutputStream extends TestCase {
+
+ public TestIdentityOutputStream(String testName) {
+ super(testName);
+ }
+
+ // ------------------------------------------------------- TestCase Methods
+
+ public static Test suite() {
+ return new TestSuite(TestIdentityOutputStream.class);
+ }
+
+ // ------------------------------------------------------------------- Main
+ public static void main(String args[]) {
+ String[] testCaseName = { TestIdentityOutputStream.class.getName() };
+ junit.textui.TestRunner.main(testCaseName);
+ }
+
+ public void testConstructors() throws Exception {
+ new IdentityOutputStream(new HttpDataTransmitterMockup());
+ try {
+ new IdentityOutputStream(null);
+ fail("IllegalArgumentException should have been thrown");
+ } catch (IllegalArgumentException ex) {
+ // expected
+ }
+ }
+
+ public void testBasics() throws Exception {
+ ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+ HttpDataTransmitterMockup datatransmitter = new HttpDataTransmitterMockup(buffer);
+ OutputStream out = new IdentityOutputStream(datatransmitter);
+
+ byte[] tmp = new byte[10];
+ out.write(tmp, 0, 10);
+ out.write(tmp);
+ out.write(1);
+ out.flush();
+ out.close();
+ byte[] data = datatransmitter.getData();
+ assertEquals(21, data.length);
+ }
+
+ public void testClose() throws Exception {
+ ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+ HttpDataTransmitterMockup datatransmitter = new HttpDataTransmitterMockup(buffer);
+ OutputStream out = new IdentityOutputStream(datatransmitter);
+ out.close();
+ out.close();
+ byte[] tmp = new byte[10];
+ try {
+ out.write(tmp);
+ fail("IOException should have been thrown");
+ } catch (IOException ex) {
+ // expected
+ }
+ try {
+ out.write(1);
+ fail("IOException should have been thrown");
+ } catch (IOException ex) {
+ // expected
+ }
+ }
+
+}
+
Propchange: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/io/TestIdentityOutputStream.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/io/TestIdentityOutputStream.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/io/TestIdentityOutputStream.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/mockup/HttpDataReceiverMockup.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/test/org/apache/http/mockup/HttpDataReceiverMockup.java?rev=321483&r1=321482&r2=321483&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/test/org/apache/http/mockup/HttpDataReceiverMockup.java (original)
+++ jakarta/httpclient/trunk/http-common/src/test/org/apache/http/mockup/HttpDataReceiverMockup.java Sat Oct 15 13:32:14 2005
@@ -1,6 +1,7 @@
package org.apache.http.mockup;
import java.io.ByteArrayInputStream;
+import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
@@ -37,6 +38,10 @@
throws UnsupportedEncodingException {
this(s.getBytes(charset));
+ }
+
+ public boolean isDataAvailable(int timeout) throws IOException {
+ return true;
}
}