1 /*
2 * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/test/org/apache/commons/httpclient/TestHttpParser.java,v 1.3 2004/02/22 18:08:49 olegk Exp $
3 * $Revision: 155418 $
4 * $Date: 2005-02-26 08:01:52 -0500 (Sat, 26 Feb 2005) $
5 * ====================================================================
6 *
7 * Copyright 1999-2004 The Apache Software Foundation
8 *
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ====================================================================
21 *
22 * This software consists of voluntary contributions made by many
23 * individuals on behalf of the Apache Software Foundation. For more
24 * information on the Apache Software Foundation, please see
25 * <http://www.apache.org/>.
26 *
27 * [Additional notices, if required by prior licensing conditions]
28 *
29 */
30
31 package org.apache.commons.httpclient;
32
33 import java.io.ByteArrayInputStream;
34 import java.io.InputStream;
35
36 import junit.framework.*;
37
38 /***
39 * Simple tests for {@link HttpParser}.
40 *
41 * @author Oleg Kalnichevski
42 * @version $Id: TestHttpParser.java 155418 2005-02-26 13:01:52Z dirkv $
43 */
44 public class TestHttpParser extends TestCase {
45
46 private static final String HTTP_ELEMENT_CHARSET = "US-ASCII";
47
48 // ------------------------------------------------------------ Constructor
49 public TestHttpParser(String testName) {
50 super(testName);
51 }
52
53 // ------------------------------------------------------------------- Main
54 public static void main(String args[]) {
55 String[] testCaseName = { TestHeader.class.getName() };
56 junit.textui.TestRunner.main(testCaseName);
57 }
58
59 // ------------------------------------------------------- TestCase Methods
60
61 public static Test suite() {
62 return new TestSuite(TestHttpParser.class);
63 }
64
65 public void testReadHttpLine() throws Exception {
66 InputStream instream = new ByteArrayInputStream(
67 "\r\r\nstuff\r\n".getBytes(HTTP_ELEMENT_CHARSET));
68 assertEquals("\r", HttpParser.readLine(instream, HTTP_ELEMENT_CHARSET));
69 assertEquals("stuff", HttpParser.readLine(instream, HTTP_ELEMENT_CHARSET));
70 assertEquals(null, HttpParser.readLine(instream, HTTP_ELEMENT_CHARSET));
71
72 instream = new ByteArrayInputStream(
73 "\n\r\nstuff\r\n".getBytes("US-ASCII"));
74 assertEquals("", HttpParser.readLine(instream, HTTP_ELEMENT_CHARSET));
75 assertEquals("", HttpParser.readLine(instream, HTTP_ELEMENT_CHARSET));
76 assertEquals("stuff", HttpParser.readLine(instream, HTTP_ELEMENT_CHARSET));
77 assertEquals(null, HttpParser.readLine(instream, HTTP_ELEMENT_CHARSET));
78 }
79 }