1 30 31 package org.apache.commons.httpclient; 32 33 import junit.framework.Test; 34 import junit.framework.TestCase; 35 import junit.framework.TestSuite; 36 37 43 public class TestRequestHeaders extends TestCase { 44 45 HttpState state = null; 46 SimpleHttpMethod method = null; 47 HttpConnection conn = null; 48 49 public TestRequestHeaders(String testName) { 51 super(testName); 52 } 53 54 public static void main(String args[]) { 56 String [] testCaseName = {TestRequestHeaders.class.getName()}; 57 junit.textui.TestRunner.main(testCaseName); 58 } 59 60 public static Test suite() { 62 return new TestSuite(TestRequestHeaders.class); 63 } 64 65 public void setUp() { 66 state = new HttpState(); 67 method = new SimpleHttpMethod("/some/absolute/path/"); 68 } 70 71 public void tearDown() { 72 state = null; 73 method = null; 74 conn = null; 75 } 76 77 public void testNullHeader() throws Exception { 78 conn = new SimpleHttpConnection("some.host.name", 80, "http"); 79 assertEquals(null, method.getRequestHeader(null)); 80 assertEquals(null, method.getRequestHeader("bogus")); 81 } 82 83 public void testHostHeaderPortHTTP80() throws Exception { 84 conn = new SimpleHttpConnection("some.host.name", 80, "http"); 85 method.addRequestHeaders(state, conn); 86 assertEquals("Host: some.host.name", method.getRequestHeader("Host").toString().trim()); 87 } 88 89 public void testHostHeaderPortHTTP81() throws Exception { 90 conn = new SimpleHttpConnection("some.host.name", 81, "http"); 91 method.addRequestHeaders(state, conn); 92 assertEquals("Host: some.host.name:81", method.getRequestHeader("Host").toString().trim()); 93 } 94 95 public void testHostHeaderPortHTTPS443() throws Exception { 96 conn = new SimpleHttpConnection("some.host.name", 443, "https"); 97 method.addRequestHeaders(state, conn); 98 assertEquals("Host: some.host.name", method.getRequestHeader("Host").toString().trim()); 99 } 100 101 public void testHostHeaderPortHTTPS444() throws Exception { 102 conn = new SimpleHttpConnection("some.host.name", 444, "https"); 103 method.addRequestHeaders(state, conn); 104 assertEquals("Host: some.host.name:444", method.getRequestHeader("Host").toString().trim()); 105 } 106 107 public void testHeadersPreserveCaseKeyIgnoresCase() throws Exception { 108 method.addRequestHeader(new Header("NAME", "VALUE")); 109 Header upHeader = method.getRequestHeader("NAME"); 110 Header loHeader = method.getRequestHeader("name"); 111 Header mixHeader = method.getRequestHeader("nAmE"); 112 assertEquals("NAME", upHeader.getName()); 113 assertEquals("VALUE", upHeader.getValue()); 114 assertEquals("NAME", loHeader.getName()); 115 assertEquals("VALUE", loHeader.getValue()); 116 assertEquals("NAME", mixHeader.getName()); 117 assertEquals("VALUE", mixHeader.getValue()); 118 } 119 } 120 | Popular Tags |