1 27 package org.apache.commons.httpclient; 28 29 import junit.framework.*; 30 import org.apache.commons.httpclient.methods.*; 31 32 39 40 public class TestWebappNoncompliant extends TestWebappBase 41 { 42 public TestWebappNoncompliant(String s) 43 { 44 super(s); 45 } 46 47 public static Test suite() { 48 TestSuite suite = new TestSuite(TestWebappNoncompliant.class); 49 return suite; 50 } 51 52 public static void main(String args[]) { 53 String [] testCaseName = { TestWebappNoncompliant.class.getName() }; 54 junit.textui.TestRunner.main(testCaseName); 55 } 56 57 64 public void testNoncompliantPostMethodString() 65 { 66 HttpClient client = createHttpClient(); 67 NoncompliantPostMethod method = new NoncompliantPostMethod("/" + getWebappContext() + "/body"); 68 method.setUseExpectHeader(true); 69 method.setRequestBody("This is data to be sent in the body of an HTTP POST."); 70 try { 71 client.executeMethod(method); 72 } catch (Exception e) { 73 e.printStackTrace(); 74 fail("Unexpected exception: " + e.toString()); 75 } 76 assertEquals(200,method.getStatusCode()); 77 } 78 79 81 public void testNoncompliantStatusLine() 82 { 83 HttpClient client = createHttpClient(); 84 GetMethod method = new GetMethod("/" + getWebappContext() + "/statusline"); 85 method.setRequestHeader("Set-StatusCode", 444+""); 86 method.setRequestHeader("Set-StatusMessage", "This status message contains\n" 87 + " a newline and a\r" 88 + " carrage return but that should be OK."); 89 try { 90 client.executeMethod(method); 91 } catch (Exception e) { 92 e.printStackTrace(); 93 fail("Unexpected exception: " + e.toString()); 94 } 95 assertEquals(444, method.getStatusCode()); 96 } 97 98 99 103 104 public void testNoncompliantHeadWithResponseBody() 105 throws Exception { 106 HttpClient client = createHttpClient(); 107 HeadMethod method = new NoncompliantHeadMethod("/" + getWebappContext() + "/redirect"); 108 method.setBodyCheckTimeout(50); 109 client.executeMethod(method); 110 assertEquals(200,method.getStatusCode()); 111 method.releaseConnection(); 112 } 113 114 118 119 public void testNoncompliantHeadStrictMode() 120 throws Exception { 121 HttpClient client = createHttpClient(); 122 client.setStrictMode(true); 123 HeadMethod method = new NoncompliantHeadMethod("/" + getWebappContext() + "/body"); 124 method.setBodyCheckTimeout(50); 125 try { 126 client.executeMethod(method); 127 fail("HttpException should have been thrown"); 128 } catch(HttpException e) { 129 } 131 method.releaseConnection(); 132 } 133 134 } 135 | Popular Tags |