001: /*
002: * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/test/org/apache/commons/httpclient/TestRequestHeaders.java,v 1.8 2004/10/31 14:04:13 olegk Exp $
003: * $Revision: 480424 $
004: * $Date: 2006-11-29 06:56:49 +0100 (Wed, 29 Nov 2006) $
005: * ====================================================================
006: *
007: * Licensed to the Apache Software Foundation (ASF) under one or more
008: * contributor license agreements. See the NOTICE file distributed with
009: * this work for additional information regarding copyright ownership.
010: * The ASF licenses this file to You under the Apache License, Version 2.0
011: * (the "License"); you may not use this file except in compliance with
012: * the License. You may obtain a copy of the License at
013: *
014: * http://www.apache.org/licenses/LICENSE-2.0
015: *
016: * Unless required by applicable law or agreed to in writing, software
017: * distributed under the License is distributed on an "AS IS" BASIS,
018: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
019: * See the License for the specific language governing permissions and
020: * limitations under the License.
021: * ====================================================================
022: *
023: * This software consists of voluntary contributions made by many
024: * individuals on behalf of the Apache Software Foundation. For more
025: * information on the Apache Software Foundation, please see
026: * <http://www.apache.org/>.
027: *
028: * [Additional notices, if required by prior licensing conditions]
029: *
030: */
031:
032: package org.apache.commons.httpclient;
033:
034: import org.apache.commons.httpclient.protocol.Protocol;
035:
036: import junit.framework.Test;
037: import junit.framework.TestCase;
038: import junit.framework.TestSuite;
039:
040: /**
041: * Tests for reading response headers.
042: *
043: * @author <a href="mailto:jsdever@apache.org">Jeff Dever</a>
044: * @version $Id: TestRequestHeaders.java 480424 2006-11-29 05:56:49Z bayard $
045: */
046: public class TestRequestHeaders extends TestCase {
047:
048: // ------------------------------------------------------------ Constructor
049: public TestRequestHeaders(String testName) {
050: super (testName);
051: }
052:
053: // ------------------------------------------------------------------- Main
054: public static void main(String args[]) {
055: String[] testCaseName = { TestRequestHeaders.class.getName() };
056: junit.textui.TestRunner.main(testCaseName);
057: }
058:
059: // ------------------------------------------------------- TestCase Methods
060: public static Test suite() {
061: return new TestSuite(TestRequestHeaders.class);
062: }
063:
064: public void testNullHeader() throws Exception {
065: FakeHttpMethod method = new FakeHttpMethod();
066: assertEquals(null, method.getRequestHeader(null));
067: assertEquals(null, method.getRequestHeader("bogus"));
068: }
069:
070: public void testHostHeaderPortHTTP80() throws Exception {
071: HttpConnection conn = new HttpConnection("some.host.name", 80);
072: HttpState state = new HttpState();
073: FakeHttpMethod method = new FakeHttpMethod();
074: method.addRequestHeaders(state, conn);
075: assertEquals("Host: some.host.name", method.getRequestHeader(
076: "Host").toString().trim());
077: }
078:
079: public void testHostHeaderPortHTTP81() throws Exception {
080: HttpConnection conn = new HttpConnection("some.host.name", 81);
081: HttpState state = new HttpState();
082: FakeHttpMethod method = new FakeHttpMethod();
083: method.addRequestHeaders(state, conn);
084: assertEquals("Host: some.host.name:81", method
085: .getRequestHeader("Host").toString().trim());
086: }
087:
088: public void testHostHeaderPortHTTPS443() throws Exception {
089: HttpConnection conn = new HttpConnection("some.host.name", 443,
090: Protocol.getProtocol("https"));
091: HttpState state = new HttpState();
092: FakeHttpMethod method = new FakeHttpMethod();
093: method.addRequestHeaders(state, conn);
094: assertEquals("Host: some.host.name", method.getRequestHeader(
095: "Host").toString().trim());
096: }
097:
098: public void testHostHeaderPortHTTPS444() throws Exception {
099: HttpConnection conn = new HttpConnection("some.host.name", 444,
100: Protocol.getProtocol("https"));
101: HttpState state = new HttpState();
102: FakeHttpMethod method = new FakeHttpMethod();
103: method.addRequestHeaders(state, conn);
104: assertEquals("Host: some.host.name:444", method
105: .getRequestHeader("Host").toString().trim());
106: }
107:
108: public void testHeadersPreserveCaseKeyIgnoresCase()
109: throws Exception {
110: FakeHttpMethod method = new FakeHttpMethod();
111: method.addRequestHeader(new Header("NAME", "VALUE"));
112: Header upHeader = method.getRequestHeader("NAME");
113: Header loHeader = method.getRequestHeader("name");
114: Header mixHeader = method.getRequestHeader("nAmE");
115: assertEquals("NAME", upHeader.getName());
116: assertEquals("VALUE", upHeader.getValue());
117: assertEquals("NAME", loHeader.getName());
118: assertEquals("VALUE", loHeader.getValue());
119: assertEquals("NAME", mixHeader.getName());
120: assertEquals("VALUE", mixHeader.getValue());
121: }
122: }
|