1 /* 2 * $Header: $ 3 * $Revision: $ 4 * $Date: $ 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.TestSuite; 67 68 import org.apache.commons.httpclient.methods.TraceMethod; 69 70 /*** 71 * 72 * Simple tests of {@link TraceMethod}. 73 * 74 * @author Sean C. Sullivan 75 * @version $Id: TestGetMethodLocal.java,v 1.3 2002/02/04 15:26:43 dion Exp $ 76 * 77 */ 78 public class TestTraceMethodLocal extends TestLocalHostBase { 79 80 81 // ------------------------------------------------------------ Constructor 82 83 public TestTraceMethodLocal(String testName) { 84 super(testName); 85 } 86 87 88 // ------------------------------------------------------- TestCase Methods 89 90 91 public static Test suite() { 92 return new TestSuite(TestTraceMethodLocal.class); 93 } 94 95 96 // ------------------------------------------------------------------ Tests 97 98 99 100 public void testExecute() { 101 102 HttpClient client = createHttpClient(); 103 104 TraceMethod method = new TraceMethod("/"); 105 106 final String strTestHeaderName = "MyTestHeader"; 107 108 final String strTestHeaderValue = "This-is-a-test-value."; 109 110 method.setRequestHeader( 111 strTestHeaderName, 112 strTestHeaderValue); 113 114 try { 115 client.executeMethod(method); 116 117 final int iResponseStatusCode = method.getStatusCode(); 118 assertEquals(200, iResponseStatusCode); 119 120 Header[] requestHeaders = method.getRequestHeaders(); 121 assertTrue( requestHeaders.length > 0); 122 123 Header[] responseHeaders = method.getResponseHeaders(); 124 assertNotNull(responseHeaders); 125 126 // 127 // note: the reason that we convert the String's to lowercase is 128 // because some HTTP servers send a response body that contains 129 // lower request headers 130 // 131 final String strResponseBody_lowercase = method.getResponseBodyAsString().toLowerCase(); 132 assertNotNull(strResponseBody_lowercase); 133 assertTrue( strResponseBody_lowercase.length() > 0); 134 135 assertTrue( strResponseBody_lowercase.indexOf(strTestHeaderName.toLowerCase()) != -1); 136 assertTrue( strResponseBody_lowercase.indexOf(strTestHeaderValue.toLowerCase()) != -1); 137 138 } catch (Throwable t) { 139 t.printStackTrace(); 140 fail("Unable to execute method : " + t.toString()); 141 } 142 } 143 144 public void testRecycle() { 145 HttpClient client = createHttpClient(); 146 147 TraceMethod method = new TraceMethod("/"); 148 149 try { 150 client.executeMethod(method); 151 } catch (Throwable t) { 152 t.printStackTrace(); 153 fail("Unable to execute method : " + t.toString()); 154 } 155 156 try { 157 String data = method.getResponseBodyAsString(); 158 assertTrue("No data returned.",(data.length() > 0)); 159 } catch (Throwable t) { 160 t.printStackTrace(); 161 fail("Unable to execute method : " + t.toString()); 162 } 163 164 method.recycle(); 165 method.setPath("/"); 166 167 try { 168 client.executeMethod(method); 169 } catch (Throwable t) { 170 t.printStackTrace(); 171 fail("Unable to execute method : " + t.toString()); 172 } 173 174 try { 175 String data = method.getResponseBodyAsString(); 176 assertTrue("No data returned.",(data.length() > 0)); 177 } catch (Throwable t) { 178 t.printStackTrace(); 179 fail("Unable to execute method : " + t.toString()); 180 } 181 } 182 183 public static void main(String args[]) { 184 String[] testCaseName = { TestTraceMethodLocal.class.getName() }; 185 junit.textui.TestRunner.main(testCaseName); 186 } 187 188 189 }

This page was automatically generated by Maven