1 /* 2 * $Header: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestRequestHeaders.java,v 1.5 2003/01/25 12:52:07 olegk Exp $ 3 * $Revision: 1.5 $ 4 * $Date: 2003/01/25 12:52:07 $ 5 * ==================================================================== 6 * 7 * The Apache Software License, Version 1.1 8 * 9 * Copyright (c) 1999-2003 The Apache Software Foundation. All rights 10 * reserved. 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 15 * 16 * 1. Redistributions of source code must retain the above copyright 17 * notice, this list of conditions and the following disclaimer. 18 * 19 * 2. Redistributions in binary form must reproduce the above copyright 20 * notice, this list of conditions and the following disclaimer in 21 * the documentation and/or other materials provided with the 22 * distribution. 23 * 24 * 3. The end-user documentation included with the redistribution, if 25 * any, must include the following acknowlegement: 26 * "This product includes software developed by the 27 * Apache Software Foundation (http://www.apache.org/)." 28 * Alternately, this acknowlegement may appear in the software itself, 29 * if and wherever such third-party acknowlegements normally appear. 30 * 31 * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software 32 * Foundation" must not be used to endorse or promote products derived 33 * from this software without prior written permission. For written 34 * permission, please contact apache@apache.org. 35 * 36 * 5. Products derived from this software may not be called "Apache" 37 * nor may "Apache" appear in their names without prior written 38 * permission of the Apache Group. 39 * 40 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 41 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 42 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 43 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR 44 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 45 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 46 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 47 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 48 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 49 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 50 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51 * SUCH DAMAGE. 52 * ==================================================================== 53 * 54 * This software consists of voluntary contributions made by many 55 * individuals on behalf of the Apache Software Foundation. For more 56 * information on the Apache Software Foundation, please see 57 * <http://www.apache.org/>. 58 * 59 * [Additional notices, if required by prior licensing conditions] 60 * 61 */ 62 63 package org.apache.commons.httpclient; 64 65 import junit.framework.Test; 66 import junit.framework.TestCase; 67 import junit.framework.TestSuite; 68 69 /*** 70 * Tests for reading response headers. 71 * 72 * @author <a href="mailto:jsdever@apache.org">Jeff Dever</a> 73 * @version $Id: TestRequestHeaders.java,v 1.5 2003/01/25 12:52:07 olegk Exp $ 74 */ 75 public class TestRequestHeaders extends TestCase { 76 77 HttpState state = null; 78 SimpleHttpMethod method = null; 79 HttpConnection conn = null; 80 81 // ------------------------------------------------------------ Constructor 82 public TestRequestHeaders(String testName) { 83 super(testName); 84 } 85 86 // ------------------------------------------------------------------- Main 87 public static void main(String args[]) { 88 String[] testCaseName = {TestRequestHeaders.class.getName()}; 89 junit.textui.TestRunner.main(testCaseName); 90 } 91 92 // ------------------------------------------------------- TestCase Methods 93 public static Test suite() { 94 return new TestSuite(TestRequestHeaders.class); 95 } 96 97 public void setUp() { 98 state = new HttpState(); 99 method = new SimpleHttpMethod("/some/absolute/path/"); 100 //assign conn in test case 101 } 102 103 public void tearDown() { 104 state = null; 105 method = null; 106 conn = null; 107 } 108 109 public void testNullHeader() throws Exception { 110 conn = new SimpleHttpConnection("some.host.name", 80, "http"); 111 assertEquals(null, method.getRequestHeader(null)); 112 assertEquals(null, method.getRequestHeader("bogus")); 113 } 114 115 public void testHostHeaderPortHTTP80() throws Exception { 116 conn = new SimpleHttpConnection("some.host.name", 80, "http"); 117 method.addRequestHeaders(state, conn); 118 assertEquals("Host: some.host.name", method.getRequestHeader("Host").toString().trim()); 119 } 120 121 public void testHostHeaderPortHTTP81() throws Exception { 122 conn = new SimpleHttpConnection("some.host.name", 81, "http"); 123 method.addRequestHeaders(state, conn); 124 assertEquals("Host: some.host.name:81", method.getRequestHeader("Host").toString().trim()); 125 } 126 127 public void testHostHeaderPortHTTPS443() throws Exception { 128 conn = new SimpleHttpConnection("some.host.name", 443, "https"); 129 method.addRequestHeaders(state, conn); 130 assertEquals("Host: some.host.name", method.getRequestHeader("Host").toString().trim()); 131 } 132 133 public void testHostHeaderPortHTTPS444() throws Exception { 134 conn = new SimpleHttpConnection("some.host.name", 444, "https"); 135 method.addRequestHeaders(state, conn); 136 assertEquals("Host: some.host.name:444", method.getRequestHeader("Host").toString().trim()); 137 } 138 139 public void testHeadersPreserveCaseKeyIgnoresCase() throws Exception { 140 method.addRequestHeader(new Header("NAME", "VALUE")); 141 Header upHeader = method.getRequestHeader("NAME"); 142 Header loHeader = method.getRequestHeader("name"); 143 Header mixHeader = method.getRequestHeader("nAmE"); 144 assertEquals("NAME", upHeader.getName()); 145 assertEquals("VALUE", upHeader.getValue()); 146 assertEquals("NAME", loHeader.getName()); 147 assertEquals("VALUE", loHeader.getValue()); 148 assertEquals("NAME", mixHeader.getName()); 149 assertEquals("VALUE", mixHeader.getValue()); 150 } 151 }

This page was automatically generated by Maven