2
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/test/org/apache/commons/httpclient/HttpClientTestBase.java,v 1.7 2004/11/07 12:31:42 olegk Exp $
4
* $Date: 2005-07-23 06:23:59 -0400 (Sat, 23 Jul 2005) $
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/>.
29
package org.apache.commons.httpclient;
31
import java.io.IOException;
33
import junit.framework.Test;
34
import junit.framework.TestCase;
35
import junit.framework.TestSuite;
37
import org.apache.commons.httpclient.protocol.Protocol;
38
import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
39
import org.apache.commons.httpclient.server.SimpleHttpServer;
40
import org.apache.commons.httpclient.server.SimplePlainSocketFactory;
41
import org.apache.commons.httpclient.server.SimpleProxy;
42
import org.apache.commons.httpclient.server.SimpleSocketFactory;
43
import org.apache.commons.httpclient.ssl.SimpleSSLSocketFactory;
44
import org.apache.commons.httpclient.ssl.SimpleSSLTestProtocolSocketFactory;
47
* Base class for test cases using
48
* {@link org.apache.commons.httpclient.server.SimpleHttpServer} based
51
* @author Oleg Kalnichevski
53
* @version $Id: HttpClientTestBase.java 224451 2005-07-23 10:23:59Z olegk $
55
public class HttpClientTestBase extends TestCase {
57
protected HttpClient client = null;
58
protected SimpleHttpServer server = null;
60
protected SimpleProxy proxy = null;
61
private boolean useProxy = false;
62
private boolean useSSL = false;
64
// ------------------------------------------------------------ Constructor
65
public HttpClientTestBase(final String testName) throws IOException {
69
// ------------------------------------------------------------------- Main
70
public static void main(String args[]) {
71
String[] testCaseName = { HttpClientTestBase.class.getName() };
72
junit.textui.TestRunner.main(testCaseName);
75
// ------------------------------------------------------- TestCase Methods
77
public static Test suite() {
78
return new TestSuite(HttpClientTestBase.class);
81
public void setUseProxy(boolean useProxy) {
82
this.useProxy = useProxy;
85
public void setUseSSL(boolean b) {
89
public boolean isUseSSL() {
93
// ------------------------------------------------- TestCase setup/shutdown
95
public void setUp() throws IOException {
96
// Configure socket factories
97
SimpleSocketFactory serversocketfactory = null;
98
Protocol testhttp = null;
100
serversocketfactory = new SimpleSSLSocketFactory();
101
testhttp = new Protocol("https",
102
(ProtocolSocketFactory)new SimpleSSLTestProtocolSocketFactory(), 443);
104
serversocketfactory = new SimplePlainSocketFactory();
105
testhttp = Protocol.getProtocol("http");
108
this.server = new SimpleHttpServer(serversocketfactory, 0); // use arbitrary port
109
this.server.setTestname(getName());
111
this.client = new HttpClient();
113
this.client.getHostConfiguration().setHost(
114
this.server.getLocalAddress(),
115
this.server.getLocalPort(),
119
this.proxy = new SimpleProxy();
120
client.getHostConfiguration().setProxy(
121
proxy.getLocalAddress(),
122
proxy.getLocalPort());
126
public void tearDown() throws IOException {
128
this.server.destroy();