2
* $Header: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestLocalHostBase.java,v 1.4.2.1 2004/02/22 18:21:16 olegk Exp $
4
* $Date: 2004/02/22 18:21:16 $
5
* ====================================================================
7
* Copyright 2002-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]
30
package org.apache.commons.httpclient;
32
import junit.framework.TestCase;
35
* The base class for all tests that need to connection to the localhost
38
* @author Michael Becke
40
public abstract class TestLocalHostBase extends TestCase {
42
private final String protocol = System.getProperty(
43
"httpclient.test.localHost.protocol",
46
private final String host = System.getProperty("httpclient.test.localHost","localhost");
47
private final int port;
48
private final String proxyHost = System.getProperty("httpclient.test.proxy.host");
49
private final int proxyPort;
52
* Constructor for TestLocalHostBase.
55
public TestLocalHostBase(String testName) {
57
String portString = System.getProperty("httpclient.test.localPort","8080");
60
tempPort = Integer.parseInt(portString);
61
} catch(Exception e) {
65
String proxyPortString = System.getProperty("httpclient.test.proxy.port","3128");
66
int tempProxyPort = 3128;
68
tempProxyPort = Integer.parseInt(proxyPortString);
69
} catch(Exception e) {
72
proxyPort = tempProxyPort;
76
* Gets a new HttpClient instance. This instance has been configured
77
* with all appropriate host/proxy values.
79
* @return a new HttpClient instance
81
public HttpClient createHttpClient() {
82
return createHttpClient(null);
86
* Gets a new HttpClient instance that uses the given connection manager.
87
* This instance has been configured with all appropriate host/proxy values.
89
* @param connectionManager the connection manager to use or <code>null</code>
91
* @return a new HttpClient instance
93
public HttpClient createHttpClient(HttpConnectionManager connectionManager) {
95
HttpClient client = null;
97
if (connectionManager == null) {
98
client = new HttpClient();
100
client = new HttpClient(connectionManager);
103
client.getHostConfiguration().setHost(host, port, protocol);
104
if (proxyHost != null) {
105
client.getHostConfiguration().setProxy(proxyHost, proxyPort);
114
public String getHost() {
121
public int getPort() {
128
public String getProtocol() {