1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 package org.apache.commons.httpclient;
26
27
28 import org.apache.commons.httpclient.protocol.Protocol;
29 import junit.framework.*;
30
31 /***
32 * Simple tests for {@link StatusLine}.
33 *
34 * @author <a href="mailto:oleg@ural.ru">oleg Kalnichevski</a>
35 * @version $Id: TestRequestLine.java 155418 2005-02-26 13:01:52Z dirkv $
36 */
37 public class TestRequestLine extends TestCase {
38
39 private StatusLine statusLine = null;
40
41
42 public TestRequestLine(String testName) {
43 super(testName);
44 }
45
46
47 public static void main(String args[]) {
48 String[] testCaseName = { TestRequestLine.class.getName() };
49 junit.textui.TestRunner.main(testCaseName);
50 }
51
52
53
54 public static Test suite() {
55 return new TestSuite(TestRequestLine.class);
56 }
57
58
59
60 public void testRequestLineGeneral() throws Exception {
61
62 HttpConnection conn = new HttpConnection("localhost", 80);
63 FakeHttpMethod method = new FakeHttpMethod();
64 assertEquals("Simple / HTTP/1.1\r\n", method.generateRequestLine(conn, HttpVersion.HTTP_1_1));
65
66 method = new FakeHttpMethod("stuff");
67 assertEquals("Simple stuff HTTP/1.1\r\n", method.generateRequestLine(conn, HttpVersion.HTTP_1_1));
68
69 conn = new HttpConnection("proxy", 8080, "localhost", 80, Protocol.getProtocol("http"));
70
71 method = new FakeHttpMethod();
72 assertEquals("Simple http://localhost/ HTTP/1.1\r\n", method.generateRequestLine(conn, HttpVersion.HTTP_1_1));
73
74 method = new FakeHttpMethod("stuff");
75 assertEquals("Simple http://localhost/stuff HTTP/1.1\r\n", method.generateRequestLine(conn, HttpVersion.HTTP_1_1));
76
77 conn = new HttpConnection("proxy", 8080, "localhost", -1, Protocol.getProtocol("http"));
78
79 method = new FakeHttpMethod();
80 assertEquals("Simple http://localhost/ HTTP/1.1\r\n", method.generateRequestLine(conn, HttpVersion.HTTP_1_1));
81
82 method = new FakeHttpMethod("stuff");
83 assertEquals("Simple http://localhost/stuff HTTP/1.1\r\n", method.generateRequestLine(conn, HttpVersion.HTTP_1_1));
84
85 conn = new HttpConnection("proxy", 8080, "localhost", 666, Protocol.getProtocol("http"));
86
87 method = new FakeHttpMethod();
88 assertEquals("Simple http://localhost:666/ HTTP/1.1\r\n", method.generateRequestLine(conn, HttpVersion.HTTP_1_1));
89
90 method = new FakeHttpMethod("stuff");
91 assertEquals("Simple http://localhost:666/stuff HTTP/1.1\r\n", method.generateRequestLine(conn, HttpVersion.HTTP_1_1));
92 }
93
94 public void testRequestLineQuery() throws Exception {
95 HttpConnection conn = new HttpConnection("localhost", 80);
96
97 FakeHttpMethod method = new FakeHttpMethod();
98 method.setQueryString( new NameValuePair[] {
99 new NameValuePair("param1", " !#$%&\'()*+,-./:;<=>?@[//]^_`{|}~"),
100 new NameValuePair("param2", "some stuff")
101 } );
102 assertEquals("Simple /?param1=+%21%23%24%25%26%27%28%29*%2B%2C-.%2F%3A%3B%3C%3D%3E%3F%40%5B%5C%5D%5E_%60%7B%7C%7D%7E¶m2=some+stuff HTTP/1.1\r\n",
103 method.generateRequestLine(conn, HttpVersion.HTTP_1_1));
104 }
105
106 public void testRequestLinePath() throws Exception {
107 HttpConnection conn = new HttpConnection("localhost", 80);
108
109 FakeHttpMethod method = new FakeHttpMethod();
110 method.setPath("/some%20stuff/");
111 assertEquals("Simple /some%20stuff/ HTTP/1.1\r\n",
112 method.generateRequestLine(conn, HttpVersion.HTTP_1_1));
113
114 method = new FakeHttpMethod("/some%20stuff/");
115 assertEquals("Simple /some%20stuff/ HTTP/1.1\r\n",
116 method.generateRequestLine(conn, HttpVersion.HTTP_1_1));
117 }
118 }