1 /*
2 * Copyright 2008 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package net.sf.jdigg.requests;
17
18 import junit.framework.TestCase;
19
20 /**
21 * Base class for Digg request tests.
22 * <p>When you want to use (or have to use) a http proxy you can set these system properties:</p>
23 * <ul>
24 * <li>net.sf.jdigg.proxy.Host</li>
25 * <li>net.sf.jdigg.proxy.Port</li>
26 * <li>net.sf.jdigg.proxy.userName</li>
27 * <li>net.sf.jdigg.proxy.password</li>
28 * </ul>
29 * @author Philip May
30 * @since 1.0 M1
31 */
32 public abstract class ListRequestTestCase extends TestCase {
33
34 public ListRequestTestCase() {
35 }
36
37 public ListRequestTestCase(String name) {
38 super(name);
39 }
40
41 protected RequestConfig getRequestConfig() {
42 RequestConfig requestConfig = new RequestConfig();
43
44 String proxyHostProperty = System.getProperty("net.sf.jdigg.proxy.Host");
45 String proxyPortProperty = System.getProperty("net.sf.jdigg.proxy.Port");
46 String userNameProperty = System.getProperty("net.sf.jdigg.proxy.userName");
47 String passwordProperty = System.getProperty("net.sf.jdigg.proxy.password");
48
49 if (proxyHostProperty != null && proxyPortProperty != null) {
50
51 ProxyUser proxyUser = null;
52 if (userNameProperty != null && passwordProperty != null) {
53 proxyUser = new ProxyUser(userNameProperty, passwordProperty);
54 }
55
56 ProxyHost proxyHost = new ProxyHost(proxyHostProperty,
57 Integer.parseInt(proxyPortProperty), proxyUser);
58
59 requestConfig.setProxyHost(proxyHost);
60 }
61
62 return requestConfig;
63 }
64
65 }