1 30 31 package org.apache.commons.httpclient; 32 33 import junit.framework.Test; 34 import junit.framework.TestSuite; 35 36 import org.apache.commons.httpclient.methods.TraceMethod; 37 38 46 public class TestTraceMethodLocal extends TestLocalHostBase { 47 48 49 51 public TestTraceMethodLocal(String testName) { 52 super(testName); 53 } 54 55 56 58 59 public static Test suite() { 60 return new TestSuite(TestTraceMethodLocal.class); 61 } 62 63 64 66 67 68 public void testExecute() { 69 70 HttpClient client = createHttpClient(); 71 72 TraceMethod method = new TraceMethod("/"); 73 74 final String strTestHeaderName = "MyTestHeader"; 75 76 final String strTestHeaderValue = "This-is-a-test-value."; 77 78 method.setRequestHeader( 79 strTestHeaderName, 80 strTestHeaderValue); 81 82 try { 83 client.executeMethod(method); 84 85 final int iResponseStatusCode = method.getStatusCode(); 86 assertEquals(200, iResponseStatusCode); 87 88 Header[] requestHeaders = method.getRequestHeaders(); 89 assertTrue( requestHeaders.length > 0); 90 91 Header[] responseHeaders = method.getResponseHeaders(); 92 assertNotNull(responseHeaders); 93 94 final String strResponseBody_lowercase = method.getResponseBodyAsString().toLowerCase(); 100 assertNotNull(strResponseBody_lowercase); 101 assertTrue( strResponseBody_lowercase.length() > 0); 102 103 assertTrue( strResponseBody_lowercase.indexOf(strTestHeaderName.toLowerCase()) != -1); 104 assertTrue( strResponseBody_lowercase.indexOf(strTestHeaderValue.toLowerCase()) != -1); 105 106 } catch (Throwable t) { 107 t.printStackTrace(); 108 fail("Unable to execute method : " + t.toString()); 109 } 110 } 111 112 public void testRecycle() { 113 HttpClient client = createHttpClient(); 114 115 TraceMethod method = new TraceMethod("/"); 116 117 try { 118 client.executeMethod(method); 119 } catch (Throwable t) { 120 t.printStackTrace(); 121 fail("Unable to execute method : " + t.toString()); 122 } 123 124 try { 125 String data = method.getResponseBodyAsString(); 126 assertTrue("No data returned.",(data.length() > 0)); 127 } catch (Throwable t) { 128 t.printStackTrace(); 129 fail("Unable to execute method : " + t.toString()); 130 } 131 132 method.recycle(); 133 method.setPath("/"); 134 135 try { 136 client.executeMethod(method); 137 } catch (Throwable t) { 138 t.printStackTrace(); 139 fail("Unable to execute method : " + t.toString()); 140 } 141 142 try { 143 String data = method.getResponseBodyAsString(); 144 assertTrue("No data returned.",(data.length() > 0)); 145 } catch (Throwable t) { 146 t.printStackTrace(); 147 fail("Unable to execute method : " + t.toString()); 148 } 149 } 150 151 public static void main(String args[]) { 152 String [] testCaseName = { TestTraceMethodLocal.class.getName() }; 153 junit.textui.TestRunner.main(testCaseName); 154 } 155 156 157 } 158 | Popular Tags |