2
* $HeadURL: https://svn.apache.org/repos/asf/httpcomponents/httpcore/tags/4.0.1/httpcore/src/test/java/org/apache/http/message/TestBasicLineFormatter.java $
4
* $Date: 2009-02-14 17:39:33 +0100 (Sat, 14 Feb 2009) $
5
* ====================================================================
6
* Licensed to the Apache Software Foundation (ASF) under one
7
* or more contributor license agreements. See the NOTICE file
8
* distributed with this work for additional information
9
* regarding copyright ownership. The ASF licenses this file
10
* to you under the Apache License, Version 2.0 (the
11
* "License"); you may not use this file except in compliance
12
* with the License. You may obtain a copy of the License at
14
* http://www.apache.org/licenses/LICENSE-2.0
16
* Unless required by applicable law or agreed to in writing,
17
* software distributed under the License is distributed on an
18
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19
* KIND, either express or implied. See the License for the
20
* specific language governing permissions and limitations
22
* ====================================================================
24
* This software consists of voluntary contributions made by many
25
* individuals on behalf of the Apache Software Foundation. For more
26
* information on the Apache Software Foundation, please see
27
* <http://www.apache.org/>.
31
package org.apache.http.message;
33
import junit.framework.Test;
34
import junit.framework.TestCase;
35
import junit.framework.TestSuite;
37
import org.apache.http.Header;
38
import org.apache.http.HttpStatus;
39
import org.apache.http.HttpVersion;
40
import org.apache.http.RequestLine;
41
import org.apache.http.StatusLine;
42
import org.apache.http.util.CharArrayBuffer;
45
* Tests for {@link BasicLineFormatter}.
48
* @version $Revision: 744517 $
50
public class TestBasicLineFormatter extends TestCase {
52
// ------------------------------------------------------------ Constructor
53
public TestBasicLineFormatter(String testName) {
57
// ------------------------------------------------------------------- Main
58
public static void main(String args[]) {
59
String[] testCaseName = { TestBasicLineFormatter.class.getName() };
60
junit.textui.TestRunner.main(testCaseName);
63
// ------------------------------------------------------- TestCase Methods
65
public static Test suite() {
66
return new TestSuite(TestBasicLineFormatter.class);
71
public void testHttpVersionFormatting() throws Exception {
72
String s = BasicLineFormatter.formatProtocolVersion
73
(HttpVersion.HTTP_1_1, null);
74
assertEquals("HTTP/1.1", s);
77
public void testHttpVersionFormattingInvalidInput() throws Exception {
79
BasicLineFormatter.formatProtocolVersion
80
(null, BasicLineFormatter.DEFAULT);
81
fail("IllegalArgumentException should habe been thrown");
82
} catch (IllegalArgumentException ex) {
86
BasicLineFormatter.DEFAULT.appendProtocolVersion
87
(new CharArrayBuffer(10), (HttpVersion) null);
88
fail("IllegalArgumentException should habe been thrown");
89
} catch (IllegalArgumentException ex) {
95
public void testRLFormatting() throws Exception {
96
RequestLine requestline = new BasicRequestLine("GET", "/stuff", HttpVersion.HTTP_1_1);
97
String s = BasicLineFormatter.formatRequestLine(requestline, null);
98
assertEquals("GET /stuff HTTP/1.1", s);
101
public void testRLFormattingInvalidInput() throws Exception {
103
BasicLineFormatter.formatRequestLine
104
(null, BasicLineFormatter.DEFAULT);
105
fail("IllegalArgumentException should habe been thrown");
106
} catch (IllegalArgumentException ex) {
110
BasicLineFormatter.DEFAULT.formatRequestLine
111
(new CharArrayBuffer(10), (RequestLine) null);
112
fail("IllegalArgumentException should habe been thrown");
113
} catch (IllegalArgumentException ex) {
120
public void testSLFormatting() throws Exception {
121
StatusLine statusline = new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
122
String s = BasicLineFormatter.formatStatusLine(statusline, null);
123
assertEquals("HTTP/1.1 200 OK", s);
124
statusline = new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, null);
125
s = BasicLineFormatter.formatStatusLine(statusline, null);
126
assertEquals("HTTP/1.1 200 ", s);
127
// see "testSLParseSuccess" in TestBasicLineParser:
128
// trailing space is correct
131
public void testSLFormattingInvalidInput() throws Exception {
133
BasicLineFormatter.formatStatusLine
134
(null, BasicLineFormatter.DEFAULT);
135
fail("IllegalArgumentException should habe been thrown");
136
} catch (IllegalArgumentException ex) {
140
BasicLineFormatter.DEFAULT.formatStatusLine
141
(new CharArrayBuffer(10), (StatusLine) null);
142
fail("IllegalArgumentException should habe been thrown");
143
} catch (IllegalArgumentException ex) {
149
public void testHeaderFormatting() throws Exception {
150
Header header1 = new BasicHeader("name", "value");
151
String s = BasicLineFormatter.formatHeader(header1, null);
152
assertEquals("name: value", s);
153
Header header2 = new BasicHeader("name", null);
154
s = BasicLineFormatter.formatHeader(header2, null);
155
assertEquals("name: ", s);
158
public void testHeaderFormattingInvalidInput() throws Exception {
160
BasicLineFormatter.formatHeader
161
(null, BasicLineFormatter.DEFAULT);
162
fail("IllegalArgumentException should habe been thrown");
163
} catch (IllegalArgumentException ex) {
167
BasicLineFormatter.DEFAULT.formatHeader
168
(new CharArrayBuffer(10), (Header) null);
169
fail("IllegalArgumentException should habe been thrown");
170
} catch (IllegalArgumentException ex) {