1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 package org.apache.commons.httpclient;
30
31 import java.util.Enumeration;
32
33 import junit.extensions.TestSetup;
34 import junit.framework.Test;
35 import junit.framework.TestSuite;
36
37
38 /***
39 * A TestDecorator that configures instances of HttpClientTestBase to use
40 * a proxy server.
41 */
42 public class ProxyTestDecorator extends TestSetup {
43
44 /***
45 * Iterates through all test cases included in the suite and adds
46 * copies of them modified to use a proxy server.
47 * @param suite
48 */
49 public static void addTests(TestSuite suite) {
50 TestSuite ts2 = new TestSuite();
51 addTest(ts2, suite);
52 suite.addTest(ts2);
53 }
54
55 private static void addTest(TestSuite suite, Test t) {
56 if (t instanceof HttpClientTestBase) {
57 suite.addTest(new ProxyTestDecorator((HttpClientTestBase) t));
58 } else if (t instanceof TestSuite) {
59 Enumeration en = ((TestSuite) t).tests();
60 while (en.hasMoreElements()) {
61 addTest(suite, (Test) en.nextElement());
62 }
63 }
64 }
65
66 public ProxyTestDecorator(HttpClientTestBase test) {
67 super(test);
68 }
69
70 protected void setUp() throws Exception {
71 HttpClientTestBase base = (HttpClientTestBase) fTest;
72 base.setUseProxy(true);
73 }
74 }