KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > httpclient > TestRequestLine


1 /*
2  * ====================================================================
3  *
4  * Copyright 1999-2004 The Apache Software Foundation
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  * ====================================================================
18  *
19  * This software consists of voluntary contributions made by many
20  * individuals on behalf of the Apache Software Foundation. For more
21  * information on the Apache Software Foundation, please see
22  * <http://www.apache.org/>.
23  *
24  * [Additional notices, if required by prior licensing conditions]
25  *
26  */

27
28 package org.apache.commons.httpclient;
29
30
31 import org.apache.commons.httpclient.protocol.Protocol;
32 import junit.framework.*;
33
34 /**
35  * Simple tests for {@link StatusLine}.
36  *
37  * @author <a HREF="mailto:oleg@ural.ru">oleg Kalnichevski</a>
38  * @version $Id: TestRequestLine.java,v 1.3.2.1 2004/02/22 18:21:16 olegk Exp $
39  */

40 public class TestRequestLine extends TestCase {
41
42     private StatusLine statusLine = null;
43
44     // ------------------------------------------------------------ Constructor
45
public TestRequestLine(String JavaDoc testName) {
46         super(testName);
47     }
48
49     // ------------------------------------------------------------------- Main
50
public static void main(String JavaDoc args[]) {
51         String JavaDoc[] testCaseName = { TestRequestLine.class.getName() };
52         junit.textui.TestRunner.main(testCaseName);
53     }
54
55     // ------------------------------------------------------- TestCase Methods
56

57     public static Test suite() {
58         return new TestSuite(TestRequestLine.class);
59     }
60
61     // ------------------------------------------------------ Protected Methods
62

63
64     // ----------------------------------------------------------- Test Methods
65

66     public void testRequestLineGeneral() throws Exception JavaDoc {
67         SimpleHttpConnection conn = null;
68         SimpleHttpMethod method = null;
69                 
70         conn = new SimpleHttpConnection(null, -1, "localhost", null, 80, Protocol.getProtocol("http"));
71
72         method = new SimpleHttpMethod();
73         assertEquals("Simple / HTTP/1.1\r\n", method.getTestRequestLine(conn));
74
75         method = new SimpleHttpMethod("stuff");
76         assertEquals("Simple stuff HTTP/1.1\r\n", method.getTestRequestLine(conn));
77
78         conn = new SimpleHttpConnection("proxy", 8080, "localhost", null, 80, Protocol.getProtocol("http"));
79
80         method = new SimpleHttpMethod();
81         assertEquals("Simple http://localhost/ HTTP/1.1\r\n", method.getTestRequestLine(conn));
82
83         method = new SimpleHttpMethod("stuff");
84         assertEquals("Simple http://localhost/stuff HTTP/1.1\r\n", method.getTestRequestLine(conn));
85
86         conn = new SimpleHttpConnection("proxy", 8080, "localhost", null, -1, Protocol.getProtocol("http"));
87
88         method = new SimpleHttpMethod();
89         assertEquals("Simple http://localhost/ HTTP/1.1\r\n", method.getTestRequestLine(conn));
90
91         method = new SimpleHttpMethod("stuff");
92         assertEquals("Simple http://localhost/stuff HTTP/1.1\r\n", method.getTestRequestLine(conn));
93
94         conn = new SimpleHttpConnection("proxy", 8080, "localhost", null, 666, Protocol.getProtocol("http"));
95
96         method = new SimpleHttpMethod();
97         assertEquals("Simple http://localhost:666/ HTTP/1.1\r\n", method.getTestRequestLine(conn));
98
99         method = new SimpleHttpMethod("stuff");
100         assertEquals("Simple http://localhost:666/stuff HTTP/1.1\r\n", method.getTestRequestLine(conn));
101     }
102
103     public void testRequestLineQuery() throws Exception JavaDoc {
104         SimpleHttpConnection conn = null;
105         SimpleHttpMethod method = null;
106                 
107         conn = new SimpleHttpConnection(null, -1, "localhost", null, 80, Protocol.getProtocol("http"));
108
109         method = new SimpleHttpMethod();
110         method.setQueryString( new NameValuePair[] {
111             new NameValuePair("param1", " !#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~"),
112             new NameValuePair("param2", "some stuff")
113           } );
114         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&param2=some+stuff HTTP/1.1\r\n",
115           method.getTestRequestLine(conn));
116     }
117
118     public void testRequestLinePath() throws Exception JavaDoc {
119         SimpleHttpConnection conn = null;
120         SimpleHttpMethod method = null;
121                 
122         conn = new SimpleHttpConnection(null, -1, "localhost", null, 80, Protocol.getProtocol("http"));
123
124         method = new SimpleHttpMethod();
125         method.setPath("/some%20stuff/");
126         assertEquals("Simple /some%20stuff/ HTTP/1.1\r\n",
127           method.getTestRequestLine(conn));
128
129         method = new SimpleHttpMethod("/some%20stuff/");
130         assertEquals("Simple /some%20stuff/ HTTP/1.1\r\n",
131           method.getTestRequestLine(conn));
132     }
133 }
134
Popular Tags