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/31 20:20:19 UTC
svn commit: r159616 - in jakarta/httpclient/trunk/http-common/src:
java/org/apache/http/impl/ java/org/apache/http/io/
java/org/apache/http/util/ test/org/apache/http/ test/org/apache/http/impl/
test/org/apache/http/io/ test/org/apache/http/mockup/
test/org/apache/http/util/
Author: olegk
Date: Thu Mar 31 10:20:14 2005
New Revision: 159616
URL: http://svn.apache.org/viewcvs?view=rev&rev=159616
Log:
Added HeadersParser util class, HttpDataInputStream and HttpDataOutputStream classes with accompanying test cases
Added:
jakarta/httpclient/trunk/http-common/src/java/org/apache/http/io/
jakarta/httpclient/trunk/http-common/src/java/org/apache/http/io/HttpDataInputStream.java (with props)
jakarta/httpclient/trunk/http-common/src/java/org/apache/http/io/HttpDataOutputStream.java (with props)
jakarta/httpclient/trunk/http-common/src/java/org/apache/http/util/HeadersParser.java (with props)
jakarta/httpclient/trunk/http-common/src/test/org/apache/http/io/
jakarta/httpclient/trunk/http-common/src/test/org/apache/http/io/TestAllIO.java (with props)
jakarta/httpclient/trunk/http-common/src/test/org/apache/http/io/TestHttpDataInputStream.java (with props)
jakarta/httpclient/trunk/http-common/src/test/org/apache/http/io/TestHttpDataOutputStream.java (with props)
jakarta/httpclient/trunk/http-common/src/test/org/apache/http/mockup/
jakarta/httpclient/trunk/http-common/src/test/org/apache/http/mockup/HttpDataReceiverMockup.java (with props)
jakarta/httpclient/trunk/http-common/src/test/org/apache/http/mockup/HttpDataTransmitterMockup.java (with props)
jakarta/httpclient/trunk/http-common/src/test/org/apache/http/util/TestHeadersParser.java (with props)
Modified:
jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/BasicHttpResponse.java
jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/NIOHttpDataReceiver.java
jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/NIOHttpDataTransmitter.java
jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/NIOSocketHttpDataReceiver.java
jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/NIOSocketHttpDataTransmitter.java
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
jakarta/httpclient/trunk/http-common/src/test/org/apache/http/util/TestAllUtil.java
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=159615&r2=159616
==============================================================================
--- 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 Thu Mar 31 10:20:14 2005
@@ -46,7 +46,11 @@
private StatusLine statusline = null;
- protected BasicHttpResponse(final StatusLine statusline) {
+ public BasicHttpResponse() {
+ super();
+ }
+
+ public BasicHttpResponse(final StatusLine statusline) {
super();
setStatusLine(statusline);
}
Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/NIOHttpDataReceiver.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/NIOHttpDataReceiver.java?view=diff&r1=159615&r2=159616
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/NIOHttpDataReceiver.java (original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/NIOHttpDataReceiver.java Thu Mar 31 10:20:14 2005
@@ -50,17 +50,17 @@
*
* @since 4.0
*/
-public class NIOHttpDataReceiver implements HttpDataReceiver {
+public abstract class NIOHttpDataReceiver implements HttpDataReceiver {
private static final int CR = 13;
private static final int LF = 10;
- private final ReadableByteChannel channel;
- private final ByteBuffer buffer;
+ private ReadableByteChannel channel = null;
+ private ByteBuffer buffer = null;
private Charset charset = null;
- protected NIOHttpDataReceiver(final ReadableByteChannel channel, int buffersize) {
+ protected void init(final ReadableByteChannel channel, int buffersize) {
if (channel == null) {
throw new IllegalArgumentException("Channel may not be null");
}
Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/NIOHttpDataTransmitter.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/NIOHttpDataTransmitter.java?view=diff&r1=159615&r2=159616
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/NIOHttpDataTransmitter.java (original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/NIOHttpDataTransmitter.java Thu Mar 31 10:20:14 2005
@@ -51,19 +51,18 @@
*
* @since 4.0
*/
-public class NIOHttpDataTransmitter implements HttpDataTransmitter {
+public abstract class NIOHttpDataTransmitter implements HttpDataTransmitter {
private static final int CR = 13;
private static final int LF = 10;
private static final byte[] CRLF = new byte[] {CR, LF};
- private final WritableByteChannel channel;
- private final ByteBuffer buffer;
+ private WritableByteChannel channel = null;
+ private ByteBuffer buffer = null;
private Charset charset = null;
- protected NIOHttpDataTransmitter(final WritableByteChannel channel, int buffersize) {
- super();
+ protected void init(final WritableByteChannel channel, int buffersize) {
if (channel == null) {
throw new IllegalArgumentException("Channel may not be null");
}
Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/NIOSocketHttpDataReceiver.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/NIOSocketHttpDataReceiver.java?view=diff&r1=159615&r2=159616
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/NIOSocketHttpDataReceiver.java (original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/NIOSocketHttpDataReceiver.java Thu Mar 31 10:20:14 2005
@@ -47,18 +47,15 @@
private final Socket socket;
- private static Socket validate(final Socket socket) {
+ protected NIOSocketHttpDataReceiver(final Socket socket) throws SocketException {
+ super();
if (socket == null) {
throw new IllegalArgumentException("Socket may not be null");
}
if (socket.getChannel() == null) {
throw new IllegalArgumentException("Socket does not implement NIO channel");
}
- return socket;
- }
-
- protected NIOSocketHttpDataReceiver(final Socket socket) throws SocketException {
- super(validate(socket).getChannel(), socket.getReceiveBufferSize());
+ init(socket.getChannel(), socket.getReceiveBufferSize());
this.socket = socket;
}
Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/NIOSocketHttpDataTransmitter.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/NIOSocketHttpDataTransmitter.java?view=diff&r1=159615&r2=159616
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/NIOSocketHttpDataTransmitter.java (original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/NIOSocketHttpDataTransmitter.java Thu Mar 31 10:20:14 2005
@@ -45,18 +45,15 @@
private final Socket socket;
- private static Socket validate(final Socket socket) {
+ protected NIOSocketHttpDataTransmitter(final Socket socket) throws SocketException {
+ super();
if (socket == null) {
throw new IllegalArgumentException("Socket may not be null");
}
if (socket.getChannel() == null) {
throw new IllegalArgumentException("Socket does not implement NIO channel");
}
- return socket;
- }
-
- protected NIOSocketHttpDataTransmitter(final Socket socket) throws SocketException {
- super(validate(socket).getChannel(), socket.getSendBufferSize());
+ init(socket.getChannel(), socket.getSendBufferSize());
this.socket = socket;
}
Added: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/io/HttpDataInputStream.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/io/HttpDataInputStream.java?view=auto&rev=159616
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/io/HttpDataInputStream.java (added)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/io/HttpDataInputStream.java Thu Mar 31 10:20:14 2005
@@ -0,0 +1,88 @@
+/*
+ * $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.io;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.http.HttpDataReceiver;
+
+/**
+ * <p>
+ * </p>
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @version $Revision$
+ *
+ * @since 4.0
+ */
+public class HttpDataInputStream extends InputStream {
+
+ private final HttpDataReceiver datareceiver;
+
+ private boolean closed = false;
+
+ public HttpDataInputStream(final HttpDataReceiver datareceiver) {
+ super();
+ if (datareceiver == null) {
+ throw new IllegalArgumentException("HTTP data receiver may not be null");
+ }
+ this.datareceiver = datareceiver;
+ }
+
+ public int available() throws IOException {
+ if (!this.closed && this.datareceiver.isDataAvailable(10)) {
+ return 1;
+ } else {
+ return 0;
+ }
+ }
+
+ public void close() throws IOException {
+ this.closed = true;
+ }
+
+ public int read() throws IOException {
+ if (this.closed) {
+ return -1;
+ } else {
+ return this.datareceiver.read();
+ }
+ }
+
+ public int read(final byte[] b, int off, int len) throws IOException {
+ if (this.closed) {
+ return -1;
+ } else {
+ return this.datareceiver.read(b, off, len);
+ }
+ }
+
+}
Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/io/HttpDataInputStream.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/io/HttpDataInputStream.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/io/HttpDataInputStream.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/io/HttpDataOutputStream.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/io/HttpDataOutputStream.java?view=auto&rev=159616
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/io/HttpDataOutputStream.java (added)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/io/HttpDataOutputStream.java Thu Mar 31 10:20:14 2005
@@ -0,0 +1,87 @@
+/*
+ * $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.io;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.http.HttpDataTransmitter;
+
+/**
+ * <p>
+ * </p>
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @version $Revision$
+ *
+ * @since 4.0
+ */
+public class HttpDataOutputStream extends OutputStream {
+
+ private final HttpDataTransmitter datatransmitter;
+
+ private boolean closed = false;
+
+ public HttpDataOutputStream(final HttpDataTransmitter datatransmitter) {
+ super();
+ if (datatransmitter == null) {
+ throw new IllegalArgumentException("HTTP data transmitter may not be null");
+ }
+ this.datatransmitter = datatransmitter;
+ }
+
+ public void close() throws IOException {
+ if (!this.closed) {
+ this.closed = true;
+ this.datatransmitter.flush();
+ }
+ }
+
+ private void assertNotClosed() {
+ if (this.closed) {
+ throw new IllegalStateException("Stream closed");
+ }
+ }
+
+ public void flush() throws IOException {
+ assertNotClosed();
+ this.datatransmitter.flush();
+ }
+
+ public void write(final byte[] b, int off, int len) throws IOException {
+ assertNotClosed();
+ this.datatransmitter.write(b, off, len);
+ }
+
+ public void write(int b) throws IOException {
+ assertNotClosed();
+ this.datatransmitter.write(b);
+ }
+}
Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/io/HttpDataOutputStream.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/io/HttpDataOutputStream.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/io/HttpDataOutputStream.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/util/HeadersParser.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/util/HeadersParser.java?view=auto&rev=159616
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/util/HeadersParser.java (added)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/util/HeadersParser.java Thu Mar 31 10:20:14 2005
@@ -0,0 +1,88 @@
+/*
+ * $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.util;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
+import org.apache.http.Header;
+import org.apache.http.HttpDataReceiver;
+import org.apache.http.HttpException;
+
+/**
+ * A utility class for parsing http header values according to
+ * RFC-2616 Section 4 and 19.3.
+ *
+ * @author Michael Becke
+ * @author <a href="mailto:oleg@ural.ru">Oleg Kalnichevski</a>
+ *
+ * @version $Revision$
+ *
+ * @since 4.0
+ */
+public class HeadersParser {
+
+ private HeadersParser() {
+ super();
+ }
+
+ public static Header[] processHeaders(final HttpDataReceiver datareceiver)
+ throws HttpException, IOException {
+ ArrayList headerLines = new ArrayList();
+ for (;;) {
+ String line = datareceiver.readLine();
+ if ((line == null) || (line.length() < 1)) {
+ break;
+ }
+ // Parse the header name and value
+ // Check for folded headers first
+ // Detect LWS-char see HTTP/1.0 or HTTP/1.1 Section 2.2
+ // discussion on folded headers
+ if ((line.charAt(0) == ' ' || line.charAt(0) == '\t') && !headerLines.isEmpty()) {
+ // we have continuation folded header
+ // so append value
+ String previousLine = (String) headerLines.remove(headerLines.size() - 1);
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(previousLine);
+ buffer.append(' ');
+ buffer.append(line.trim());
+ headerLines.add(buffer.toString());
+ } else {
+ headerLines.add(line.trim());
+ }
+ }
+ Header[] headers = new Header[headerLines.size()];
+ for (int i = 0; i < headerLines.size(); i++) {
+ headers[i] = Header.parse((String) headerLines.get(i));
+ }
+ return headers;
+ }
+
+}
Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/util/HeadersParser.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/util/HeadersParser.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/util/HeadersParser.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
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=159615&r2=159616
==============================================================================
--- 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 Thu Mar 31 10:20:14 2005
@@ -29,6 +29,7 @@
package org.apache.http;
import org.apache.http.impl.TestAllImpl;
+import org.apache.http.io.TestAllIO;
import org.apache.http.util.TestAllUtil;
import junit.framework.*;
@@ -51,6 +52,8 @@
suite.addTest(TestHttpVersion.suite());
suite.addTest(TestStatusLine.suite());
suite.addTest(TestRequestLine.suite());
+
+ suite.addTest(TestAllIO.suite());
suite.addTest(TestAllImpl.suite());
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=159615&r2=159616
==============================================================================
--- 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 Thu Mar 31 10:20:14 2005
@@ -34,6 +34,8 @@
import org.apache.http.HttpDataReceiver;
import org.apache.http.HttpDataTransmitter;
+import org.apache.http.mockup.HttpDataReceiverMockup;
+import org.apache.http.mockup.HttpDataTransmitterMockup;
import org.apache.http.params.HttpParams;
import org.apache.http.params.HttpProtocolParams;
@@ -65,25 +67,25 @@
return new TestSuite(TestNIOHttpTransmitterAndReceiver.class);
}
- public void testConstructor() throws Exception {
+ public void testInit() throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
HttpDataTransmitter transmitter1 =
- new NIOHttpDataTransmitter(Channels.newChannel(out), -10);
+ new HttpDataTransmitterMockup(Channels.newChannel(out), -10);
HttpDataTransmitter transmitter2 =
- new NIOHttpDataTransmitter(Channels.newChannel(out), 200000000);
+ new HttpDataTransmitterMockup(Channels.newChannel(out), 200000000);
try {
- HttpDataTransmitter transmitter3 = new NIOHttpDataTransmitter(null, 1024);
+ HttpDataTransmitter transmitter3 = new HttpDataTransmitterMockup(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);
+ new HttpDataReceiverMockup(Channels.newChannel(in), -10);
HttpDataReceiver receiver2 =
- new NIOHttpDataReceiver(Channels.newChannel(in), 200000000);
+ new HttpDataReceiverMockup (Channels.newChannel(in), 200000000);
try {
- HttpDataReceiver receiver3 = new NIOHttpDataReceiver(null, 1024);
+ HttpDataReceiver receiver3 = new HttpDataReceiverMockup(null, 1024);
fail("IllegalArgumentException should have been thrown");
} catch (IllegalArgumentException ex) {
//expected
@@ -105,9 +107,7 @@
teststrs[3] = "";
teststrs[4] = "And goodbye";
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- HttpDataTransmitter transmitter =
- new NIOHttpDataTransmitter(Channels.newChannel(out), 16);
+ HttpDataTransmitterMockup transmitter = new HttpDataTransmitterMockup();
for (int i = 0; i < teststrs.length; i++) {
transmitter.writeLine(teststrs[i]);
}
@@ -115,9 +115,7 @@
transmitter.writeLine(null);
transmitter.flush();
- ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
- HttpDataReceiver receiver =
- new NIOHttpDataReceiver(Channels.newChannel(in), 16);
+ HttpDataReceiverMockup receiver = new HttpDataReceiverMockup(transmitter.getData());
assertTrue(receiver.isDataAvailable(0));
@@ -129,9 +127,7 @@
}
public void testComplexReadWriteLine() throws Exception {
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- HttpDataTransmitter transmitter =
- new NIOHttpDataTransmitter(Channels.newChannel(out), 16);
+ HttpDataTransmitterMockup transmitter = new HttpDataTransmitterMockup();
transmitter.write(new byte[] {'a', '\n'});
transmitter.write(new byte[] {'\r', '\n'});
transmitter.write(new byte[] {'\r', '\r', '\n'});
@@ -172,9 +168,7 @@
transmitter.write(new byte[] {'a'});
transmitter.flush();
- ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
- HttpDataReceiver receiver =
- new NIOHttpDataReceiver(Channels.newChannel(in), 16);
+ HttpDataReceiverMockup receiver = new HttpDataReceiverMockup(transmitter.getData());
assertEquals("a", receiver.readLine());
assertEquals("", receiver.readLine());
@@ -194,9 +188,7 @@
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);
+ HttpDataTransmitterMockup transmitter = new HttpDataTransmitterMockup();
int off = 0;
int remaining = out.length;
while (remaining > 0) {
@@ -210,15 +202,13 @@
}
transmitter.flush();
- byte[] tmp = outstream.toByteArray();
+ byte[] tmp = transmitter.getData();
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);
+ HttpDataReceiverMockup receiver = new HttpDataReceiverMockup(tmp);
// these read operations will have no effect
assertEquals(0, receiver.read(null, 0, 10));
@@ -253,23 +243,19 @@
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);
+ HttpDataTransmitterMockup transmitter = new HttpDataTransmitterMockup();
for (int i = 0; i < out.length; i++) {
transmitter.write(out[i]);
}
transmitter.flush();
- byte[] tmp = outstream.toByteArray();
+ byte[] tmp = transmitter.getData();
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);
+ HttpDataReceiverMockup receiver = new HttpDataReceiverMockup(tmp);
byte[] in = new byte[40];
for (int i = 0; i < in.length; i++) {
@@ -309,9 +295,7 @@
HttpParams params = new DefaultHttpParams(null);
new HttpProtocolParams(params).setHttpElementCharset("UTF-8");
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- HttpDataTransmitter transmitter =
- new NIOHttpDataTransmitter(Channels.newChannel(out), 16);
+ HttpDataTransmitterMockup transmitter = new HttpDataTransmitterMockup();
transmitter.reset(params);
for (int i = 0; i < 10; i++) {
@@ -321,9 +305,7 @@
}
transmitter.flush();
- ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
- HttpDataReceiver receiver =
- new NIOHttpDataReceiver(Channels.newChannel(in), 16);
+ HttpDataReceiverMockup receiver = new HttpDataReceiverMockup(transmitter.getData());
receiver.reset(params);
assertTrue(receiver.isDataAvailable(0));
Added: 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?view=auto&rev=159616
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/test/org/apache/http/io/TestAllIO.java (added)
+++ jakarta/httpclient/trunk/http-common/src/test/org/apache/http/io/TestAllIO.java Thu Mar 31 10:20:14 2005
@@ -0,0 +1,51 @@
+/*
+ * $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.io;
+
+import junit.framework.*;
+
+public class TestAllIO extends TestCase {
+
+ public TestAllIO(String testName) {
+ super(testName);
+ }
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite();
+ suite.addTest(TestHttpDataInputStream.suite());
+ suite.addTest(TestHttpDataOutputStream.suite());
+ return suite;
+ }
+
+ public static void main(String args[]) {
+ String[] testCaseName = { TestAllIO.class.getName() };
+ junit.textui.TestRunner.main(testCaseName);
+ }
+
+}
Propchange: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/io/TestAllIO.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/io/TestAllIO.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/io/TestAllIO.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: 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?view=auto&rev=159616
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/test/org/apache/http/io/TestHttpDataInputStream.java (added)
+++ jakarta/httpclient/trunk/http-common/src/test/org/apache/http/io/TestHttpDataInputStream.java Thu Mar 31 10:20:14 2005
@@ -0,0 +1,105 @@
+/*
+ * $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.io;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.http.HttpDataReceiver;
+import org.apache.http.mockup.HttpDataReceiverMockup;
+
+/**
+ * Simple tests for {@link HttpDataInputStream}.
+ *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ */
+public class TestHttpDataInputStream extends TestCase {
+
+ // ------------------------------------------------------------ Constructor
+ public TestHttpDataInputStream(String testName) {
+ super(testName);
+ }
+
+ // ------------------------------------------------------------------- Main
+ public static void main(String args[]) {
+ String[] testCaseName = { TestHttpDataInputStream.class.getName() };
+ junit.textui.TestRunner.main(testCaseName);
+ }
+
+ // ------------------------------------------------------- TestCase Methods
+
+ public static Test suite() {
+ return new TestSuite(TestHttpDataInputStream.class);
+ }
+
+ public void testConstructor() throws Exception {
+ HttpDataReceiver receiver = new HttpDataReceiverMockup(new byte[] {});
+ HttpDataInputStream instream1 = new HttpDataInputStream(receiver);
+ try {
+ HttpDataInputStream instream2 = new HttpDataInputStream(null);
+ fail("IllegalArgumentException should have been thrown");
+ } catch (IllegalArgumentException ex) {
+ //expected
+ }
+ }
+
+ public void testBasicRead() throws Exception {
+ byte[] input = new byte[] {'a', 'b', 'c'};
+ HttpDataReceiverMockup receiver = new HttpDataReceiverMockup(input);
+ HttpDataInputStream instream = new HttpDataInputStream(receiver);
+ assertTrue(instream.available() > 0);
+ byte[] tmp = new byte[2];
+ assertEquals(2, instream.read(tmp, 0, tmp.length));
+ assertEquals('a', tmp[0]);
+ assertEquals('b', tmp[1]);
+ assertEquals('c', instream.read());
+ assertEquals(-1, instream.read(tmp, 0, tmp.length));
+ assertEquals(-1, instream.read());
+ assertEquals(-1, instream.read(tmp, 0, tmp.length));
+ assertEquals(-1, instream.read());
+ }
+
+ public void testClosedCondition() throws Exception {
+ byte[] input = new byte[] {'a', 'b', 'c'};
+ HttpDataReceiverMockup receiver = new HttpDataReceiverMockup(input);
+ HttpDataInputStream instream = new HttpDataInputStream(receiver);
+
+ instream.close();
+ instream.close();
+
+ assertTrue(instream.available() == 0);
+ byte[] tmp = new byte[2];
+ assertEquals(-1, instream.read(tmp, 0, tmp.length));
+ assertEquals(-1, instream.read());
+ assertEquals(-1, instream.read(tmp, 0, tmp.length));
+ assertEquals(-1, instream.read());
+ }
+
+}
Propchange: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/io/TestHttpDataInputStream.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/io/TestHttpDataInputStream.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/io/TestHttpDataInputStream.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/io/TestHttpDataOutputStream.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/test/org/apache/http/io/TestHttpDataOutputStream.java?view=auto&rev=159616
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/test/org/apache/http/io/TestHttpDataOutputStream.java (added)
+++ jakarta/httpclient/trunk/http-common/src/test/org/apache/http/io/TestHttpDataOutputStream.java Thu Mar 31 10:20:14 2005
@@ -0,0 +1,116 @@
+/*
+ * $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.io;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.http.mockup.HttpDataTransmitterMockup;
+
+/**
+ * Simple tests for {@link HttpDataOutputStream}.
+ *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ */
+public class TestHttpDataOutputStream extends TestCase {
+
+ // ------------------------------------------------------------ Constructor
+ public TestHttpDataOutputStream(String testName) {
+ super(testName);
+ }
+
+ // ------------------------------------------------------------------- Main
+ public static void main(String args[]) {
+ String[] testCaseName = { TestHttpDataOutputStream.class.getName() };
+ junit.textui.TestRunner.main(testCaseName);
+ }
+
+ // ------------------------------------------------------- TestCase Methods
+
+ public static Test suite() {
+ return new TestSuite(TestHttpDataOutputStream.class);
+ }
+
+ public void testConstructor() throws Exception {
+ HttpDataTransmitterMockup transmitter = new HttpDataTransmitterMockup();
+ HttpDataOutputStream outstream1 = new HttpDataOutputStream(transmitter);
+ try {
+ HttpDataOutputStream outstream2 = new HttpDataOutputStream(null);
+ fail("IllegalArgumentException should have been thrown");
+ } catch (IllegalArgumentException ex) {
+ //expected
+ }
+ }
+
+ public void testBasicWrite() throws Exception {
+ HttpDataTransmitterMockup transmitter = new HttpDataTransmitterMockup();
+ HttpDataOutputStream outstream = new HttpDataOutputStream(transmitter);
+ outstream.write(new byte[] {'a', 'b'}, 0, 2);
+ outstream.write('c');
+ outstream.flush();
+
+ byte[] input = transmitter.getData();
+
+ assertNotNull(input);
+ byte[] expected = new byte[] {'a', 'b', 'c'};
+ assertEquals(expected.length, input.length);
+ for (int i = 0; i < expected.length; i++) {
+ assertEquals(expected[i], input[i]);
+ }
+ }
+
+ public void testClosedCondition() throws Exception {
+ HttpDataTransmitterMockup transmitter = new HttpDataTransmitterMockup();
+ HttpDataOutputStream outstream = new HttpDataOutputStream(transmitter);
+ outstream.close();
+ outstream.close();
+
+ try {
+ byte[] tmp = new byte[2];
+ outstream.write(tmp, 0, tmp.length);
+ fail("IllegalStateException should have been thrown");
+ } catch (IllegalStateException e) {
+ //expected
+ }
+ try {
+ outstream.write('a');
+ fail("IllegalStateException should have been thrown");
+ } catch (IllegalStateException e) {
+ //expected
+ }
+ try {
+ outstream.flush();
+ fail("IllegalStateException should have been thrown");
+ } catch (IllegalStateException e) {
+ //expected
+ }
+ }
+
+}
Propchange: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/io/TestHttpDataOutputStream.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/io/TestHttpDataOutputStream.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/io/TestHttpDataOutputStream.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: 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?view=auto&rev=159616
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/test/org/apache/http/mockup/HttpDataReceiverMockup.java (added)
+++ jakarta/httpclient/trunk/http-common/src/test/org/apache/http/mockup/HttpDataReceiverMockup.java Thu Mar 31 10:20:14 2005
@@ -0,0 +1,36 @@
+package org.apache.http.mockup;
+
+import java.io.ByteArrayInputStream;
+import java.io.UnsupportedEncodingException;
+import java.nio.channels.Channels;
+import java.nio.channels.ReadableByteChannel;
+
+import org.apache.http.impl.NIOHttpDataReceiver;
+
+/**
+ * {@link HttpDataInputStream} mockup implementation.
+ *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ */
+public class HttpDataReceiverMockup extends NIOHttpDataReceiver {
+
+ public static int BUFFER_SIZE = 16;
+
+ public HttpDataReceiverMockup(final ReadableByteChannel channel, int buffersize) {
+ super();
+ init(channel, buffersize);
+ }
+
+ public HttpDataReceiverMockup(final byte[] bytes) {
+ super();
+ init(Channels.newChannel(
+ new ByteArrayInputStream(bytes)),
+ BUFFER_SIZE);
+ }
+
+ public HttpDataReceiverMockup(final String s, final String charset)
+ throws UnsupportedEncodingException {
+ this(s.getBytes(charset));
+ }
+
+}
Propchange: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/mockup/HttpDataReceiverMockup.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/mockup/HttpDataReceiverMockup.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/mockup/HttpDataReceiverMockup.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/mockup/HttpDataTransmitterMockup.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/test/org/apache/http/mockup/HttpDataTransmitterMockup.java?view=auto&rev=159616
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/test/org/apache/http/mockup/HttpDataTransmitterMockup.java (added)
+++ jakarta/httpclient/trunk/http-common/src/test/org/apache/http/mockup/HttpDataTransmitterMockup.java Thu Mar 31 10:20:14 2005
@@ -0,0 +1,34 @@
+package org.apache.http.mockup;
+
+import java.io.ByteArrayOutputStream;
+import java.nio.channels.Channels;
+import java.nio.channels.WritableByteChannel;
+
+import org.apache.http.impl.NIOHttpDataTransmitter;
+
+/**
+ * {@link HttpDataTransmitter} mockup implementation.
+ *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ */
+public class HttpDataTransmitterMockup extends NIOHttpDataTransmitter {
+
+ public static int BUFFER_SIZE = 16;
+
+ private final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+
+ public HttpDataTransmitterMockup(final WritableByteChannel channel, int buffersize) {
+ super();
+ init(channel, buffersize);
+ }
+
+ public HttpDataTransmitterMockup() {
+ super();
+ init(Channels.newChannel(this.buffer), BUFFER_SIZE);
+ }
+
+ public byte[] getData() {
+ return this.buffer.toByteArray();
+ }
+
+}
Propchange: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/mockup/HttpDataTransmitterMockup.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/mockup/HttpDataTransmitterMockup.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/mockup/HttpDataTransmitterMockup.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/util/TestAllUtil.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/test/org/apache/http/util/TestAllUtil.java?view=diff&r1=159615&r2=159616
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/test/org/apache/http/util/TestAllUtil.java (original)
+++ jakarta/httpclient/trunk/http-common/src/test/org/apache/http/util/TestAllUtil.java Thu Mar 31 10:20:14 2005
@@ -38,8 +38,9 @@
public static Test suite() {
TestSuite suite = new TestSuite();
- suite.addTest(TestParameterParser.suite());
suite.addTest(TestLangUtils.suite());
+ suite.addTest(TestParameterParser.suite());
+ suite.addTest(TestHeadersParser.suite());
return suite;
}
Added: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/util/TestHeadersParser.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/test/org/apache/http/util/TestHeadersParser.java?view=auto&rev=159616
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/test/org/apache/http/util/TestHeadersParser.java (added)
+++ jakarta/httpclient/trunk/http-common/src/test/org/apache/http/util/TestHeadersParser.java Thu Mar 31 10:20:14 2005
@@ -0,0 +1,102 @@
+/*
+ * $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.util;
+
+import org.apache.http.Header;
+import org.apache.http.HttpDataReceiver;
+import org.apache.http.mockup.HttpDataReceiverMockup;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Unit tests for {@link HeadersParser}.
+ *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ */
+public class TestHeadersParser extends TestCase {
+
+ public TestHeadersParser(String testName) {
+ super(testName);
+ }
+
+ public static void main(String args[]) {
+ String[] testCaseName = { TestHeadersParser.class.getName() };
+ junit.textui.TestRunner.main(testCaseName);
+ }
+
+ public static Test suite() {
+ return new TestSuite(TestHeadersParser.class);
+ }
+
+ public void testSimpleHeaders() throws Exception {
+ String s =
+ "header1: stuff\r\n" +
+ "header2 : stuff \r\n" +
+ "header3: stuff\r\n" +
+ " and more stuff\r\n" +
+ "\t and even more stuff\r\n" +
+ "\r\n";
+ HttpDataReceiver receiver = new HttpDataReceiverMockup(s, "US-ASCII");
+ Header[] headers = HeadersParser.processHeaders(receiver);
+ assertNotNull(headers);
+ assertEquals(3, headers.length);
+ assertEquals("header1", headers[0].getName());
+ assertEquals("stuff", headers[0].getValue());
+ assertEquals("header2", headers[1].getName());
+ assertEquals("stuff", headers[1].getValue());
+ assertEquals("header3", headers[2].getName());
+ assertEquals("stuff and more stuff and even more stuff", headers[2].getValue());
+ }
+
+ public void testMalformedFirstHeader() throws Exception {
+ String s =
+ " header1: stuff\r\n" +
+ "header2 : stuff \r\n";
+ HttpDataReceiver receiver = new HttpDataReceiverMockup(s, "US-ASCII");
+ Header[] headers = HeadersParser.processHeaders(receiver);
+ assertNotNull(headers);
+ assertEquals(2, headers.length);
+ assertEquals("header1", headers[0].getName());
+ assertEquals("stuff", headers[0].getValue());
+ assertEquals("header2", headers[1].getName());
+ assertEquals("stuff", headers[1].getValue());
+ }
+
+ public void testEmptyDataStream() throws Exception {
+ String s = "";
+ HttpDataReceiver receiver = new HttpDataReceiverMockup(s, "US-ASCII");
+ Header[] headers = HeadersParser.processHeaders(receiver);
+ assertNotNull(headers);
+ assertEquals(0, headers.length);
+ }
+
+}
\ No newline at end of file
Propchange: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/util/TestHeadersParser.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/util/TestHeadersParser.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/util/TestHeadersParser.java
------------------------------------------------------------------------------
svn:mime-type = text/plain