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 224451 2005-07-23 10:23:59Z olegk $
36 */
37 public class TestRequestLine extends TestCase {
38
39
40 public TestRequestLine(String testName) {
41 super(testName);
42 }
43
44
45 public static void main(String args[]) {
46 String[] testCaseName = { TestRequestLine.class.getName() };
47 junit.textui.TestRunner.main(testCaseName);
48 }
49
50
51
52 public static Test suite() {
53 return new TestSuite(TestRequestLine.class);
54 }
55
56
57
58 public void testRequestLineGeneral() throws Exception {
59
60 HttpConnection conn = new HttpConnection("localhost", 80);
61 FakeHttpMethod method = new FakeHttpMethod();
62 assertEquals("Simple / HTTP/1.1\r\n", method.generateRequestLine(conn, HttpVersion.HTTP_1_1));
63
64 method = new FakeHttpMethod("stuff");
65 assertEquals("Simple stuff HTTP/1.1\r\n", method.generateRequestLine(conn, HttpVersion.HTTP_1_1));
66
67 conn = new HttpConnection("proxy", 8080, "localhost", 80, Protocol.getProtocol("http"));
68
69 method = new FakeHttpMethod();
70 assertEquals("Simple http://localhost/ HTTP/1.1\r\n", method.generateRequestLine(conn, HttpVersion.HTTP_1_1));
71
72 method = new FakeHttpMethod("stuff");
73 assertEquals("Simple http://localhost/stuff HTTP/1.1\r\n", method.generateRequestLine(conn, HttpVersion.HTTP_1_1));
74
75 conn = new HttpConnection("proxy", 8080, "localhost", -1, Protocol.getProtocol("http"));
76
77 method = new FakeHttpMethod();
78 assertEquals("Simple http://localhost/ HTTP/1.1\r\n", method.generateRequestLine(conn, HttpVersion.HTTP_1_1));
79
80 method = new FakeHttpMethod("stuff");
81 assertEquals("Simple http://localhost/stuff HTTP/1.1\r\n", method.generateRequestLine(conn, HttpVersion.HTTP_1_1));
82
83 conn = new HttpConnection("proxy", 8080, "localhost", 666, Protocol.getProtocol("http"));
84
85 method = new FakeHttpMethod();
86 assertEquals("Simple http://localhost:666/ HTTP/1.1\r\n", method.generateRequestLine(conn, HttpVersion.HTTP_1_1));
87
88 method = new FakeHttpMethod("stuff");
89 assertEquals("Simple http://localhost:666/stuff HTTP/1.1\r\n", method.generateRequestLine(conn, HttpVersion.HTTP_1_1));
90 }
91
92 public void testRequestLineQuery() throws Exception {
93 HttpConnection conn = new HttpConnection("localhost", 80);
94
95 FakeHttpMethod method = new FakeHttpMethod();
96 method.setQueryString( new NameValuePair[] {
97 new NameValuePair("param1", " !#$%&\'()*+,-./:;<=>?@[//]^_`{|}~"),
98 new NameValuePair("param2", "some stuff")
99 } );
100 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",
101 method.generateRequestLine(conn, HttpVersion.HTTP_1_1));
102 }
103
104 public void testRequestLinePath() throws Exception {
105 HttpConnection conn = new HttpConnection("localhost", 80);
106
107 FakeHttpMethod method = new FakeHttpMethod();
108 method.setPath("/some%20stuff/");
109 assertEquals("Simple /some%20stuff/ HTTP/1.1\r\n",
110 method.generateRequestLine(conn, HttpVersion.HTTP_1_1));
111
112 method = new FakeHttpMethod("/some%20stuff/");
113 assertEquals("Simple /some%20stuff/ HTTP/1.1\r\n",
114 method.generateRequestLine(conn, HttpVersion.HTTP_1_1));
115 }
116 }