001: /*
002: * ====================================================================
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one or more
005: * contributor license agreements. See the NOTICE file distributed with
006: * this work for additional information regarding copyright ownership.
007: * The ASF licenses this file to You under the Apache License, Version 2.0
008: * (the "License"); you may not use this file except in compliance with
009: * the License. You may obtain a copy of the License at
010: *
011: * http://www.apache.org/licenses/LICENSE-2.0
012: *
013: * Unless required by applicable law or agreed to in writing, software
014: * distributed under the License is distributed on an "AS IS" BASIS,
015: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016: * See the License for the specific language governing permissions and
017: * limitations under the License.
018: * ====================================================================
019: *
020: * This software consists of voluntary contributions made by many
021: * individuals on behalf of the Apache Software Foundation. For more
022: * information on the Apache Software Foundation, please see
023: * <http://www.apache.org/>.
024: */
025:
026: package org.apache.commons.httpclient;
027:
028: import org.apache.commons.httpclient.protocol.Protocol;
029: import junit.framework.*;
030:
031: /**
032: * Simple tests for {@link StatusLine}.
033: *
034: * @author <a href="mailto:oleg@ural.ru">oleg Kalnichevski</a>
035: * @version $Id: TestRequestLine.java 480424 2006-11-29 05:56:49Z bayard $
036: */
037: public class TestRequestLine extends TestCase {
038:
039: // ------------------------------------------------------------ Constructor
040: public TestRequestLine(String testName) {
041: super (testName);
042: }
043:
044: // ------------------------------------------------------------------- Main
045: public static void main(String args[]) {
046: String[] testCaseName = { TestRequestLine.class.getName() };
047: junit.textui.TestRunner.main(testCaseName);
048: }
049:
050: // ------------------------------------------------------- TestCase Methods
051:
052: public static Test suite() {
053: return new TestSuite(TestRequestLine.class);
054: }
055:
056: // ----------------------------------------------------------- Test Methods
057:
058: public void testRequestLineGeneral() throws Exception {
059:
060: HttpConnection conn = new HttpConnection("localhost", 80);
061: FakeHttpMethod method = new FakeHttpMethod();
062: assertEquals("Simple / HTTP/1.1\r\n", method
063: .generateRequestLine(conn, HttpVersion.HTTP_1_1));
064:
065: method = new FakeHttpMethod("stuff");
066: assertEquals("Simple stuff HTTP/1.1\r\n", method
067: .generateRequestLine(conn, HttpVersion.HTTP_1_1));
068:
069: conn = new HttpConnection("proxy", 8080, "localhost", 80,
070: Protocol.getProtocol("http"));
071:
072: method = new FakeHttpMethod();
073: assertEquals("Simple http://localhost/ HTTP/1.1\r\n", method
074: .generateRequestLine(conn, HttpVersion.HTTP_1_1));
075:
076: method = new FakeHttpMethod("stuff");
077: assertEquals("Simple http://localhost/stuff HTTP/1.1\r\n",
078: method.generateRequestLine(conn, HttpVersion.HTTP_1_1));
079:
080: conn = new HttpConnection("proxy", 8080, "localhost", -1,
081: Protocol.getProtocol("http"));
082:
083: method = new FakeHttpMethod();
084: assertEquals("Simple http://localhost/ HTTP/1.1\r\n", method
085: .generateRequestLine(conn, HttpVersion.HTTP_1_1));
086:
087: method = new FakeHttpMethod("stuff");
088: assertEquals("Simple http://localhost/stuff HTTP/1.1\r\n",
089: method.generateRequestLine(conn, HttpVersion.HTTP_1_1));
090:
091: conn = new HttpConnection("proxy", 8080, "localhost", 666,
092: Protocol.getProtocol("http"));
093:
094: method = new FakeHttpMethod();
095: assertEquals("Simple http://localhost:666/ HTTP/1.1\r\n",
096: method.generateRequestLine(conn, HttpVersion.HTTP_1_1));
097:
098: method = new FakeHttpMethod("stuff");
099: assertEquals("Simple http://localhost:666/stuff HTTP/1.1\r\n",
100: method.generateRequestLine(conn, HttpVersion.HTTP_1_1));
101: }
102:
103: public void testRequestLineQuery() throws Exception {
104: HttpConnection conn = new HttpConnection("localhost", 80);
105:
106: FakeHttpMethod method = new FakeHttpMethod();
107: method.setQueryString(new NameValuePair[] {
108: new NameValuePair("param1",
109: " !#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~"),
110: new NameValuePair("param2", "some stuff") });
111: assertEquals(
112: "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",
113: method.generateRequestLine(conn, HttpVersion.HTTP_1_1));
114: }
115:
116: public void testRequestLinePath() throws Exception {
117: HttpConnection conn = new HttpConnection("localhost", 80);
118:
119: FakeHttpMethod method = new FakeHttpMethod();
120: method.setPath("/some%20stuff/");
121: assertEquals("Simple /some%20stuff/ HTTP/1.1\r\n", method
122: .generateRequestLine(conn, HttpVersion.HTTP_1_1));
123:
124: method = new FakeHttpMethod("/some%20stuff/");
125: assertEquals("Simple /some%20stuff/ HTTP/1.1\r\n", method
126: .generateRequestLine(conn, HttpVersion.HTTP_1_1));
127: }
128: }
|