1 27 28 package org.apache.commons.httpclient; 29 30 31 import org.apache.commons.httpclient.protocol.Protocol; 32 import junit.framework.*; 33 34 40 public class TestRequestLine extends TestCase { 41 42 private StatusLine statusLine = null; 43 44 public TestRequestLine(String testName) { 46 super(testName); 47 } 48 49 public static void main(String args[]) { 51 String [] testCaseName = { TestRequestLine.class.getName() }; 52 junit.textui.TestRunner.main(testCaseName); 53 } 54 55 57 public static Test suite() { 58 return new TestSuite(TestRequestLine.class); 59 } 60 61 63 64 66 public void testRequestLineGeneral() throws Exception { 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 { 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¶m2=some+stuff HTTP/1.1\r\n", 115 method.getTestRequestLine(conn)); 116 } 117 118 public void testRequestLinePath() throws Exception { 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 |