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