5
* ====================================================================
7
* Copyright 1999-2004 The Apache Software Foundation
9
* Licensed under the Apache License, Version 2.0 (the "License");
10
* you may not use this file except in compliance with the License.
11
* You may obtain a copy of the License at
13
* http://www.apache.org/licenses/LICENSE-2.0
15
* Unless required by applicable law or agreed to in writing, software
16
* distributed under the License is distributed on an "AS IS" BASIS,
17
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
* See the License for the specific language governing permissions and
19
* limitations under the License.
20
* ====================================================================
22
* This software consists of voluntary contributions made by many
23
* individuals on behalf of the Apache Software Foundation. For more
24
* information on the Apache Software Foundation, please see
25
* <http://www.apache.org/>.
27
* [Additional notices, if required by prior licensing conditions]
31
package org.apache.commons.httpclient;
33
import junit.framework.Test;
34
import junit.framework.TestSuite;
36
import org.apache.commons.httpclient.methods.TraceMethod;
40
* Simple tests of {@link TraceMethod}.
42
* @author Sean C. Sullivan
43
* @version $Id: TestGetMethodLocal.java,v 1.3 2002/02/04 15:26:43 dion Exp $
46
public class TestTraceMethodLocal extends TestLocalHostBase {
49
// ------------------------------------------------------------ Constructor
51
public TestTraceMethodLocal(String testName) {
56
// ------------------------------------------------------- TestCase Methods
59
public static Test suite() {
60
return new TestSuite(TestTraceMethodLocal.class);
64
// ------------------------------------------------------------------ Tests
68
public void testExecute() {
70
HttpClient client = createHttpClient();
72
TraceMethod method = new TraceMethod("/");
74
final String strTestHeaderName = "MyTestHeader";
76
final String strTestHeaderValue = "This-is-a-test-value.";
78
method.setRequestHeader(
83
client.executeMethod(method);
85
final int iResponseStatusCode = method.getStatusCode();
86
assertEquals(200, iResponseStatusCode);
88
Header[] requestHeaders = method.getRequestHeaders();
89
assertTrue( requestHeaders.length > 0);
91
Header[] responseHeaders = method.getResponseHeaders();
92
assertNotNull(responseHeaders);
95
// note: the reason that we convert the String's to lowercase is
96
// because some HTTP servers send a response body that contains
97
// lower request headers
99
final String strResponseBody_lowercase = method.getResponseBodyAsString().toLowerCase();
100
assertNotNull(strResponseBody_lowercase);
101
assertTrue( strResponseBody_lowercase.length() > 0);
103
assertTrue( strResponseBody_lowercase.indexOf(strTestHeaderName.toLowerCase()) != -1);
104
assertTrue( strResponseBody_lowercase.indexOf(strTestHeaderValue.toLowerCase()) != -1);
106
} catch (Throwable t) {
108
fail("Unable to execute method : " + t.toString());
112
public void testRecycle() {
113
HttpClient client = createHttpClient();
115
TraceMethod method = new TraceMethod("/");
118
client.executeMethod(method);
119
} catch (Throwable t) {
121
fail("Unable to execute method : " + t.toString());
125
String data = method.getResponseBodyAsString();
126
assertTrue("No data returned.",(data.length() > 0));
127
} catch (Throwable t) {
129
fail("Unable to execute method : " + t.toString());
136
client.executeMethod(method);
137
} catch (Throwable t) {
139
fail("Unable to execute method : " + t.toString());
143
String data = method.getResponseBodyAsString();
144
assertTrue("No data returned.",(data.length() > 0));
145
} catch (Throwable t) {
147
fail("Unable to execute method : " + t.toString());
151
public static void main(String args[]) {
152
String[] testCaseName = { TestTraceMethodLocal.class.getName() };
153
junit.textui.TestRunner.main(testCaseName);