Lines 1-26
Link Here
|
1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2007 IBM Corporation and others. |
2 |
* Copyright (c) 2007 IBM Corporation and others. All rights reserved. This |
3 |
* All rights reserved. This program and the accompanying materials |
3 |
* program and the accompanying materials are made available under the terms of |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* the Eclipse Public License v1.0 which accompanies this distribution, and is |
5 |
* which accompanies this distribution, and is available at |
5 |
* available at http://www.eclipse.org/legal/epl-v10.html |
6 |
* http://www.eclipse.org/legal/epl-v10.html |
6 |
* |
7 |
* |
7 |
* Contributors: IBM Corporation - initial API and implementation |
8 |
* Contributors: |
8 |
******************************************************************************/ |
9 |
* IBM Corporation - initial API and implementation |
|
|
10 |
*******************************************************************************/ |
11 |
package org.eclipse.core.tests.net; |
9 |
package org.eclipse.core.tests.net; |
12 |
|
10 |
|
13 |
import java.util.*; |
11 |
import java.net.URI; |
14 |
|
12 |
import java.net.URISyntaxException; |
15 |
import junit.framework.*; |
13 |
import java.util.HashMap; |
|
|
14 |
import java.util.Map; |
15 |
import java.util.Properties; |
16 |
|
17 |
import junit.framework.Test; |
18 |
import junit.framework.TestCase; |
19 |
import junit.framework.TestSuite; |
16 |
|
20 |
|
|
|
21 |
import org.eclipse.core.internal.net.AbstractProxyProvider; |
17 |
import org.eclipse.core.internal.net.ProxyType; |
22 |
import org.eclipse.core.internal.net.ProxyType; |
|
|
23 |
import org.eclipse.core.internal.net.UnixProxyProvider; |
24 |
import org.eclipse.core.internal.net.WindowsProxyProvider; |
18 |
import org.eclipse.core.net.proxy.IProxyData; |
25 |
import org.eclipse.core.net.proxy.IProxyData; |
19 |
import org.eclipse.core.net.proxy.IProxyService; |
26 |
import org.eclipse.core.net.proxy.IProxyService; |
20 |
import org.eclipse.core.runtime.CoreException; |
27 |
import org.eclipse.core.runtime.CoreException; |
21 |
|
28 |
|
22 |
public class NetTest extends TestCase { |
29 |
public class NetTest extends TestCase { |
23 |
|
30 |
|
24 |
private boolean isSetEnabled; |
31 |
private boolean isSetEnabled; |
25 |
private Map dataCache = new HashMap(); |
32 |
private Map dataCache = new HashMap(); |
26 |
|
33 |
|
Lines 31-37
Link Here
|
31 |
public NetTest(String name) { |
38 |
public NetTest(String name) { |
32 |
super(name); |
39 |
super(name); |
33 |
} |
40 |
} |
34 |
|
41 |
|
35 |
public static Test suite() { |
42 |
public static Test suite() { |
36 |
return new TestSuite(NetTest.class); |
43 |
return new TestSuite(NetTest.class); |
37 |
} |
44 |
} |
Lines 43-49
Link Here
|
43 |
dataCache.clear(); |
50 |
dataCache.clear(); |
44 |
ProxyType.socksSystemPropertySetting = ProxyType.ALWAYS_SET; |
51 |
ProxyType.socksSystemPropertySetting = ProxyType.ALWAYS_SET; |
45 |
} |
52 |
} |
46 |
|
53 |
|
47 |
protected void tearDown() throws Exception { |
54 |
protected void tearDown() throws Exception { |
48 |
super.tearDown(); |
55 |
super.tearDown(); |
49 |
setProxiesEnabled(false); |
56 |
setProxiesEnabled(false); |
Lines 54-75
Link Here
|
54 |
} |
61 |
} |
55 |
getProxyManager().setProxyData(data); |
62 |
getProxyManager().setProxyData(data); |
56 |
} |
63 |
} |
57 |
|
64 |
|
58 |
private IProxyService getProxyManager() { |
65 |
private IProxyService getProxyManager() { |
59 |
return Activator.getDefault().getProxyService(); |
66 |
return Activator.getDefault().getProxyService(); |
60 |
} |
67 |
} |
61 |
|
68 |
|
62 |
private void assertProxyDataEqual(IProxyData expectedData) { |
69 |
private void assertProxyDataEqual(IProxyData expectedData) { |
63 |
IProxyData data = getProxyManager().getProxyData(expectedData.getType()); |
70 |
IProxyData data = getProxyManager() |
|
|
71 |
.getProxyData(expectedData.getType()); |
64 |
assertEquals(expectedData.getType(), data.getType()); |
72 |
assertEquals(expectedData.getType(), data.getType()); |
65 |
assertEquals(expectedData.getHost(), data.getHost()); |
73 |
assertEquals(expectedData.getHost(), data.getHost()); |
66 |
assertEquals(expectedData.getPort(), data.getPort()); |
74 |
assertEquals(expectedData.getPort(), data.getPort()); |
67 |
assertEquals(expectedData.getUserId(), data.getUserId()); |
75 |
assertEquals(expectedData.getUserId(), data.getUserId()); |
68 |
assertEquals(expectedData.getPassword(), data.getPassword()); |
76 |
assertEquals(expectedData.getPassword(), data.getPassword()); |
69 |
assertEquals(expectedData.isRequiresAuthentication(), data.isRequiresAuthentication()); |
77 |
assertEquals(expectedData.isRequiresAuthentication(), data |
|
|
78 |
.isRequiresAuthentication()); |
70 |
assertSystemPropertiesMatch(data); |
79 |
assertSystemPropertiesMatch(data); |
71 |
} |
80 |
} |
72 |
|
81 |
|
73 |
public void assertSystemPropertiesMatch(IProxyData proxyData) { |
82 |
public void assertSystemPropertiesMatch(IProxyData proxyData) { |
74 |
if (proxyData.getType().equals(IProxyData.HTTP_PROXY_TYPE)) { |
83 |
if (proxyData.getType().equals(IProxyData.HTTP_PROXY_TYPE)) { |
75 |
assertHttpSystemProperties(proxyData, "http"); |
84 |
assertHttpSystemProperties(proxyData, "http"); |
Lines 80-104
Link Here
|
80 |
} |
89 |
} |
81 |
} |
90 |
} |
82 |
|
91 |
|
83 |
private void assertHttpSystemProperties(IProxyData proxyData, String keyPrefix) { |
92 |
private void assertHttpSystemProperties(IProxyData proxyData, |
|
|
93 |
String keyPrefix) { |
84 |
Properties sysProps = System.getProperties(); |
94 |
Properties sysProps = System.getProperties(); |
85 |
|
95 |
|
86 |
if (this.getProxyManager().isProxiesEnabled()) { |
96 |
if (this.getProxyManager().isProxiesEnabled()) { |
87 |
boolean isSet = Boolean.getBoolean(keyPrefix + ".proxySet"); |
97 |
boolean isSet = Boolean.getBoolean(keyPrefix + ".proxySet"); |
88 |
assertEquals(proxyData.getHost() != null, isSet); //$NON-NLS-1$ |
98 |
assertEquals(proxyData.getHost() != null, isSet); //$NON-NLS-1$ |
89 |
assertEquals(proxyData.getHost(), sysProps.get(keyPrefix + ".proxyHost")); //$NON-NLS-1$ |
99 |
assertEquals(proxyData.getHost(), sysProps.get(keyPrefix |
90 |
String portString = (String)sysProps.get(keyPrefix + ".proxyPort"); //$NON-NLS-1$ |
100 |
+ ".proxyHost")); //$NON-NLS-1$ |
|
|
101 |
String portString = (String) sysProps.get(keyPrefix + ".proxyPort"); //$NON-NLS-1$ |
91 |
int port = -1; |
102 |
int port = -1; |
92 |
if (portString != null) |
103 |
if (portString != null) |
93 |
port = Integer.parseInt(portString); |
104 |
port = Integer.parseInt(portString); |
94 |
assertEquals(proxyData.getPort(), port); |
105 |
assertEquals(proxyData.getPort(), port); |
95 |
if (isSet) |
106 |
if (isSet) |
96 |
assertEquals(ProxyType.convertHostsToPropertyString(this.getProxyManager().getNonProxiedHosts()), sysProps.get(keyPrefix + ".nonProxyHosts")); //$NON-NLS-1$ |
107 |
assertEquals(ProxyType.convertHostsToPropertyString(this |
97 |
else |
108 |
.getProxyManager().getNonProxiedHosts()), sysProps |
|
|
109 |
.get(keyPrefix + ".nonProxyHosts")); //$NON-NLS-1$ |
110 |
else |
98 |
assertNull(sysProps.get(keyPrefix + ".nonProxyHosts")); |
111 |
assertNull(sysProps.get(keyPrefix + ".nonProxyHosts")); |
99 |
assertEquals(proxyData.getUserId(), sysProps.get(keyPrefix + ".proxyUser")); //$NON-NLS-1$ |
112 |
assertEquals(proxyData.getUserId(), sysProps.get(keyPrefix |
100 |
assertEquals(proxyData.getUserId(), sysProps.get(keyPrefix + ".proxyUserName")); //$NON-NLS-1$ |
113 |
+ ".proxyUser")); //$NON-NLS-1$ |
101 |
assertEquals(proxyData.getPassword(), sysProps.get(keyPrefix + ".proxyPassword")); //$NON-NLS-1$ |
114 |
assertEquals(proxyData.getUserId(), sysProps.get(keyPrefix |
|
|
115 |
+ ".proxyUserName")); //$NON-NLS-1$ |
116 |
assertEquals(proxyData.getPassword(), sysProps.get(keyPrefix |
117 |
+ ".proxyPassword")); //$NON-NLS-1$ |
102 |
} else { |
118 |
} else { |
103 |
assertNull(sysProps.get(keyPrefix + ".proxySet")); |
119 |
assertNull(sysProps.get(keyPrefix + ".proxySet")); |
104 |
assertNull(sysProps.get(keyPrefix + ".proxyHost")); |
120 |
assertNull(sysProps.get(keyPrefix + ".proxyHost")); |
Lines 114-120
Link Here
|
114 |
Properties sysProps = System.getProperties(); |
130 |
Properties sysProps = System.getProperties(); |
115 |
if (this.getProxyManager().isProxiesEnabled()) { |
131 |
if (this.getProxyManager().isProxiesEnabled()) { |
116 |
assertEquals(proxyData.getHost(), sysProps.get("socksProxyHost")); //$NON-NLS-1$ |
132 |
assertEquals(proxyData.getHost(), sysProps.get("socksProxyHost")); //$NON-NLS-1$ |
117 |
String portString = (String)sysProps.get("socksProxyPort"); //$NON-NLS-1$ |
133 |
String portString = (String) sysProps.get("socksProxyPort"); //$NON-NLS-1$ |
118 |
int port = -1; |
134 |
int port = -1; |
119 |
if (portString != null) |
135 |
if (portString != null) |
120 |
port = Integer.parseInt(portString); |
136 |
port = Integer.parseInt(portString); |
Lines 124-139
Link Here
|
124 |
assertNull(sysProps.get("socksProxyPort")); |
140 |
assertNull(sysProps.get("socksProxyPort")); |
125 |
} |
141 |
} |
126 |
} |
142 |
} |
127 |
|
143 |
|
128 |
private IProxyData getProxyData(String type) { |
144 |
private IProxyData getProxyData(String type) { |
129 |
IProxyData data = (IProxyData)dataCache.get(type); |
145 |
IProxyData data = (IProxyData) dataCache.get(type); |
130 |
if (data == null) { |
146 |
if (data == null) { |
131 |
data = this.getProxyManager().getProxyData(type); |
147 |
data = this.getProxyManager().getProxyData(type); |
132 |
assertProxyDataEqual(data); |
148 |
assertProxyDataEqual(data); |
133 |
} |
149 |
} |
134 |
return data; |
150 |
return data; |
135 |
} |
151 |
} |
136 |
|
152 |
|
137 |
private void setProxyData(IProxyData data) throws CoreException { |
153 |
private void setProxyData(IProxyData data) throws CoreException { |
138 |
if (isSetEnabled) { |
154 |
if (isSetEnabled) { |
139 |
this.getProxyManager().setProxyData(new IProxyData[] { data }); |
155 |
this.getProxyManager().setProxyData(new IProxyData[] { data }); |
Lines 142-153
Link Here
|
142 |
dataCache.put(data.getType(), data); |
158 |
dataCache.put(data.getType(), data); |
143 |
} |
159 |
} |
144 |
} |
160 |
} |
145 |
|
161 |
|
146 |
private void disableProxy(IProxyData proxyData) throws CoreException { |
162 |
private void disableProxy(IProxyData proxyData) throws CoreException { |
147 |
proxyData.disable(); |
163 |
proxyData.disable(); |
148 |
setProxyData(proxyData); |
164 |
setProxyData(proxyData); |
149 |
} |
165 |
} |
150 |
|
166 |
|
151 |
private void changeProxyData(IProxyData oldData, IProxyData data) |
167 |
private void changeProxyData(IProxyData oldData, IProxyData data) |
152 |
throws CoreException { |
168 |
throws CoreException { |
153 |
// Make sure that setting the host doesn't change the persisted settings |
169 |
// Make sure that setting the host doesn't change the persisted settings |
Lines 156-162
Link Here
|
156 |
// Now set it in the manager and assert that it is set |
172 |
// Now set it in the manager and assert that it is set |
157 |
setProxyData(data); |
173 |
setProxyData(data); |
158 |
} |
174 |
} |
159 |
|
175 |
|
160 |
private void setHost(String type) throws CoreException { |
176 |
private void setHost(String type) throws CoreException { |
161 |
String host = "www.eclipse.org"; |
177 |
String host = "www.eclipse.org"; |
162 |
setHost(type, host); |
178 |
setHost(type, host); |
Lines 168-206
Link Here
|
168 |
data.setHost(host); |
184 |
data.setHost(host); |
169 |
changeProxyData(oldData, data); |
185 |
changeProxyData(oldData, data); |
170 |
} |
186 |
} |
171 |
|
187 |
|
172 |
private void setPort(String type, int port) throws CoreException { |
188 |
private void setPort(String type, int port) throws CoreException { |
173 |
IProxyData data = getProxyData(type); |
189 |
IProxyData data = getProxyData(type); |
174 |
IProxyData oldData = getProxyData(type); |
190 |
IProxyData oldData = getProxyData(type); |
175 |
data.setPort(port); |
191 |
data.setPort(port); |
176 |
changeProxyData(oldData, data); |
192 |
changeProxyData(oldData, data); |
177 |
} |
193 |
} |
178 |
|
194 |
|
179 |
private void setUser(String type, String user, String password) throws CoreException { |
195 |
private void setUser(String type, String user, String password) |
|
|
196 |
throws CoreException { |
180 |
IProxyData data = getProxyData(type); |
197 |
IProxyData data = getProxyData(type); |
181 |
IProxyData oldData = getProxyData(type); |
198 |
IProxyData oldData = getProxyData(type); |
182 |
data.setUserid(user); |
199 |
data.setUserid(user); |
183 |
data.setPassword(password); |
200 |
data.setPassword(password); |
184 |
changeProxyData(oldData, data); |
201 |
changeProxyData(oldData, data); |
185 |
} |
202 |
} |
186 |
|
203 |
|
187 |
private void setDataTest(String type) throws CoreException { |
204 |
private void setDataTest(String type) throws CoreException { |
188 |
setHost(type, "www.eclipse.org"); |
205 |
setHost(type, "www.eclipse.org"); |
189 |
setPort(type, 1024); |
206 |
setPort(type, 1024); |
190 |
setUser(type, "me", "passw0rd"); |
207 |
setUser(type, "me", "passw0rd"); |
191 |
} |
208 |
} |
192 |
|
209 |
|
193 |
private void setProxiesEnabled(boolean enabled) { |
210 |
private void setProxiesEnabled(boolean enabled) { |
194 |
this.getProxyManager().setProxiesEnabled(enabled); |
211 |
this.getProxyManager().setProxiesEnabled(enabled); |
195 |
assertEquals(enabled, this.getProxyManager().isProxiesEnabled()); |
212 |
assertEquals(enabled, this.getProxyManager().isProxiesEnabled()); |
196 |
} |
213 |
} |
197 |
|
214 |
|
198 |
private void delaySettingData() { |
215 |
private void delaySettingData() { |
199 |
isSetEnabled = false; |
216 |
isSetEnabled = false; |
200 |
} |
217 |
} |
201 |
|
218 |
|
202 |
private void performSettingData() throws CoreException { |
219 |
private void performSettingData() throws CoreException { |
203 |
IProxyData[] data = (IProxyData[]) dataCache.values().toArray(new IProxyData[dataCache.size()]); |
220 |
IProxyData[] data = (IProxyData[]) dataCache.values().toArray( |
|
|
221 |
new IProxyData[dataCache.size()]); |
204 |
this.getProxyManager().setProxyData(data); |
222 |
this.getProxyManager().setProxyData(data); |
205 |
for (int i = 0; i < data.length; i++) { |
223 |
for (int i = 0; i < data.length; i++) { |
206 |
IProxyData proxyData = data[i]; |
224 |
IProxyData proxyData = data[i]; |
Lines 209-215
Link Here
|
209 |
isSetEnabled = true; |
227 |
isSetEnabled = true; |
210 |
dataCache.clear(); |
228 |
dataCache.clear(); |
211 |
} |
229 |
} |
212 |
|
230 |
|
213 |
public void testIndividualSetAndClear() throws CoreException { |
231 |
public void testIndividualSetAndClear() throws CoreException { |
214 |
setDataTest(IProxyData.HTTP_PROXY_TYPE); |
232 |
setDataTest(IProxyData.HTTP_PROXY_TYPE); |
215 |
setDataTest(IProxyData.HTTPS_PROXY_TYPE); |
233 |
setDataTest(IProxyData.HTTPS_PROXY_TYPE); |
Lines 220-233
Link Here
|
220 |
disableProxy(proxyData); |
238 |
disableProxy(proxyData); |
221 |
} |
239 |
} |
222 |
} |
240 |
} |
223 |
|
241 |
|
224 |
public void testAllSetAndClear() throws CoreException { |
242 |
public void testAllSetAndClear() throws CoreException { |
225 |
delaySettingData(); |
243 |
delaySettingData(); |
226 |
setDataTest(IProxyData.HTTP_PROXY_TYPE); |
244 |
setDataTest(IProxyData.HTTP_PROXY_TYPE); |
227 |
setDataTest(IProxyData.HTTPS_PROXY_TYPE); |
245 |
setDataTest(IProxyData.HTTPS_PROXY_TYPE); |
228 |
setDataTest(IProxyData.SOCKS_PROXY_TYPE); |
246 |
setDataTest(IProxyData.SOCKS_PROXY_TYPE); |
229 |
performSettingData(); |
247 |
performSettingData(); |
230 |
|
248 |
|
231 |
delaySettingData(); |
249 |
delaySettingData(); |
232 |
IProxyData[] data = this.getProxyManager().getProxyData(); |
250 |
IProxyData[] data = this.getProxyManager().getProxyData(); |
233 |
for (int i = 0; i < data.length; i++) { |
251 |
for (int i = 0; i < data.length; i++) { |
Lines 250-301
Link Here
|
250 |
setProxiesEnabled(false); |
268 |
setProxiesEnabled(false); |
251 |
assertProxyDataEqual(data); |
269 |
assertProxyDataEqual(data); |
252 |
} |
270 |
} |
253 |
|
271 |
|
254 |
public void testSimpleHost() throws CoreException { |
272 |
public void testSimpleHost() throws CoreException { |
255 |
setDataTest(IProxyData.HTTP_PROXY_TYPE); |
273 |
setDataTest(IProxyData.HTTP_PROXY_TYPE); |
256 |
setDataTest(IProxyData.HTTPS_PROXY_TYPE); |
274 |
setDataTest(IProxyData.HTTPS_PROXY_TYPE); |
257 |
setDataTest(IProxyData.SOCKS_PROXY_TYPE); |
275 |
setDataTest(IProxyData.SOCKS_PROXY_TYPE); |
258 |
|
276 |
|
259 |
IProxyData[] allData = this.getProxyManager().getProxyDataForHost("www.randomhot.com"); |
277 |
IProxyData[] allData = this.getProxyManager().getProxyDataForHost( |
|
|
278 |
"www.randomhot.com"); |
260 |
assertEquals(3, allData.length); |
279 |
assertEquals(3, allData.length); |
261 |
|
280 |
|
262 |
IProxyData data = this.getProxyManager().getProxyDataForHost("www.randomhot.com", IProxyData.HTTP_PROXY_TYPE); |
281 |
IProxyData data = this.getProxyManager().getProxyDataForHost( |
|
|
282 |
"www.randomhot.com", IProxyData.HTTP_PROXY_TYPE); |
263 |
assertNotNull(data); |
283 |
assertNotNull(data); |
264 |
|
284 |
|
265 |
allData = this.getProxyManager().getProxyDataForHost("localhost"); |
285 |
allData = this.getProxyManager().getProxyDataForHost("localhost"); |
266 |
assertEquals(0, allData.length); |
286 |
assertEquals(0, allData.length); |
267 |
|
287 |
|
268 |
data = this.getProxyManager().getProxyDataForHost("localhost", IProxyData.HTTP_PROXY_TYPE); |
288 |
data = this.getProxyManager().getProxyDataForHost("localhost", |
|
|
289 |
IProxyData.HTTP_PROXY_TYPE); |
269 |
assertNull(data); |
290 |
assertNull(data); |
270 |
} |
291 |
} |
271 |
|
292 |
|
272 |
public void testHostPattern() throws CoreException { |
293 |
public void testHostPattern() throws CoreException { |
273 |
setDataTest(IProxyData.HTTP_PROXY_TYPE); |
294 |
setDataTest(IProxyData.HTTP_PROXY_TYPE); |
274 |
setDataTest(IProxyData.HTTPS_PROXY_TYPE); |
295 |
setDataTest(IProxyData.HTTPS_PROXY_TYPE); |
275 |
setDataTest(IProxyData.SOCKS_PROXY_TYPE); |
296 |
setDataTest(IProxyData.SOCKS_PROXY_TYPE); |
276 |
|
297 |
|
277 |
String[] oldHosts = this.getProxyManager().getNonProxiedHosts(); |
298 |
String[] oldHosts = this.getProxyManager().getNonProxiedHosts(); |
278 |
this.getProxyManager().setNonProxiedHosts(new String[] { "*ignore.com" }); |
299 |
this.getProxyManager().setNonProxiedHosts( |
279 |
|
300 |
new String[] { "*ignore.com" }); |
280 |
IProxyData[] allData = this.getProxyManager().getProxyDataForHost("www.randomhot.com"); |
301 |
|
|
|
302 |
IProxyData[] allData = this.getProxyManager().getProxyDataForHost( |
303 |
"www.randomhot.com"); |
281 |
assertEquals(3, allData.length); |
304 |
assertEquals(3, allData.length); |
282 |
|
305 |
|
283 |
IProxyData data = this.getProxyManager().getProxyDataForHost("www.randomhot.com", IProxyData.HTTP_PROXY_TYPE); |
306 |
IProxyData data = this.getProxyManager().getProxyDataForHost( |
|
|
307 |
"www.randomhot.com", IProxyData.HTTP_PROXY_TYPE); |
284 |
assertNotNull(data); |
308 |
assertNotNull(data); |
285 |
|
309 |
|
286 |
allData = this.getProxyManager().getProxyDataForHost("www.ignore.com"); |
310 |
allData = this.getProxyManager().getProxyDataForHost("www.ignore.com"); |
287 |
assertEquals(0, allData.length); |
311 |
assertEquals(0, allData.length); |
288 |
|
312 |
|
289 |
data = this.getProxyManager().getProxyDataForHost("www.ignore.com", IProxyData.HTTP_PROXY_TYPE); |
313 |
data = this.getProxyManager().getProxyDataForHost("www.ignore.com", |
|
|
314 |
IProxyData.HTTP_PROXY_TYPE); |
290 |
assertNull(data); |
315 |
assertNull(data); |
291 |
|
316 |
|
292 |
allData = this.getProxyManager().getProxyDataForHost("ignore.com"); |
317 |
allData = this.getProxyManager().getProxyDataForHost("ignore.com"); |
293 |
assertEquals(0, allData.length); |
318 |
assertEquals(0, allData.length); |
294 |
|
319 |
|
295 |
data = this.getProxyManager().getProxyDataForHost("ignore.com", IProxyData.HTTP_PROXY_TYPE); |
320 |
data = this.getProxyManager().getProxyDataForHost("ignore.com", |
|
|
321 |
IProxyData.HTTP_PROXY_TYPE); |
296 |
assertNull(data); |
322 |
assertNull(data); |
297 |
|
323 |
|
298 |
this.getProxyManager().setNonProxiedHosts(oldHosts); |
324 |
this.getProxyManager().setNonProxiedHosts(oldHosts); |
299 |
} |
325 |
} |
300 |
|
326 |
|
|
|
327 |
// This test case has to be manually setup and run because it depends on |
328 |
// whether the proxy is set in the native environment. It is here as |
329 |
// a convenience to test the native support. |
330 |
public void testNativeLinux() throws Exception { |
331 |
|
332 |
// Leave this test off for the automatic test runs so we don't |
333 |
// get confused by the settings that happen to be on the test machine |
334 |
if (true) |
335 |
return; |
336 |
|
337 |
AbstractProxyProvider pp = new UnixProxyProvider(); |
338 |
|
339 |
IProxyData[] pd; |
340 |
|
341 |
// Test the following cases |
342 |
// 1) No proxy set anywhere |
343 |
// 2) http_proxy environment variable (use proxyIsSet) |
344 |
// 3) gconf-edit proxy (use proxyIsSet and proxyAuthIsSet) |
345 |
// 4) KDE proxy (use proxyIsSet and proxyAuthIsSet) |
346 |
|
347 |
// Toggle this if you have the proxy set up in the native environment |
348 |
boolean proxyIsSet = true; |
349 |
|
350 |
// Toggle this if you have the proxy authentication information setup |
351 |
boolean proxyAuthIsSet = true; |
352 |
|
353 |
String proxyHost = null; |
354 |
String proxyUser = null; |
355 |
String proxyPassword = null; |
356 |
boolean proxyReqAuth = false; |
357 |
int proxyPort = 0; |
358 |
|
359 |
if (proxyIsSet) { |
360 |
proxyHost = "berlioz"; |
361 |
proxyPort = 3128; |
362 |
if (proxyAuthIsSet) { |
363 |
proxyUser = "user"; |
364 |
proxyPassword = "password"; |
365 |
proxyReqAuth = true; |
366 |
} |
367 |
} |
368 |
|
369 |
// Test HTTP |
370 |
pd = pp.select(new URI("http://bbc.com")); |
371 |
if (proxyIsSet) { |
372 |
assertEquals(1, pd.length); |
373 |
assertEquals(proxyHost, pd[0].getHost()); |
374 |
assertEquals(proxyPort, pd[0].getPort()); |
375 |
if (proxyAuthIsSet) { |
376 |
assertEquals(proxyUser, pd[0].getUserId()); |
377 |
assertEquals(proxyPassword, pd[0].getPassword()); |
378 |
assertEquals(proxyReqAuth, pd[0].isRequiresAuthentication()); |
379 |
} |
380 |
|
381 |
} else { |
382 |
assertEquals(0, pd.length); |
383 |
} |
384 |
|
385 |
// Test HTTPS |
386 |
pd = pp.select(new URI("https://bbc.com")); |
387 |
if (proxyIsSet) { |
388 |
assertEquals(1, pd.length); |
389 |
assertEquals("https_" + proxyHost, pd[0].getHost()); |
390 |
assertEquals(1 + proxyPort, pd[0].getPort()); |
391 |
} else { |
392 |
assertEquals(0, pd.length); |
393 |
} |
394 |
|
395 |
// Test SOCKS |
396 |
pd = pp.select(new URI("SOCKS://bbc.com")); |
397 |
if (proxyIsSet) { |
398 |
assertEquals(1, pd.length); |
399 |
assertEquals("socks_" + proxyHost, pd[0].getHost()); |
400 |
assertEquals(2 + proxyPort, pd[0].getPort()); |
401 |
} else { |
402 |
assertEquals(0, pd.length); |
403 |
} |
404 |
|
405 |
// Test FTP |
406 |
pd = pp.select(new URI("FTP://bbc.com")); |
407 |
if (proxyIsSet) { |
408 |
assertEquals(1, pd.length); |
409 |
assertEquals("ftp_" + proxyHost, pd[0].getHost()); |
410 |
assertEquals(3 + proxyPort, pd[0].getPort()); |
411 |
} else { |
412 |
assertEquals(0, pd.length); |
413 |
} |
414 |
|
415 |
// Assume that localhost is a non-proxy host |
416 |
pd = pp.select(new URI("http://localhost")); |
417 |
assertEquals(0, pd.length); |
418 |
} |
419 |
|
420 |
// This test case has to be manually setup and run because it depends on |
421 |
// whether the proxy is set in the native environment. It is here as |
422 |
// a convenience to test the native support. |
423 |
public void testNativeWin32() throws Exception { |
424 |
|
425 |
// Leave this test off for the automatic test runs so we don't |
426 |
// get confused by the settings that happen to be on the test machine |
427 |
if (false) |
428 |
return; |
429 |
|
430 |
AbstractProxyProvider pp = new WindowsProxyProvider(); |
431 |
|
432 |
// loop here - while looping play with the internet options ;-) |
433 |
while (true) { |
434 |
proxiesFor(pp,"http://www.eclipse.org"); |
435 |
proxiesFor(pp,"https://www.eclipse.org"); |
436 |
proxiesFor(pp,"ftp://www.eclipse.org"); |
437 |
proxiesFor(pp,"socks://www.eclipse.org"); |
438 |
} |
439 |
} |
440 |
|
441 |
public void proxiesFor( AbstractProxyProvider pp,String url ) throws URISyntaxException{ |
442 |
IProxyData[] pd = pp.select(new URI(url)); |
443 |
System.out.println("Url: "+ url + ":"); |
444 |
for (int i = 0; i < pd.length; i++) { |
445 |
System.out.println("\t"+pd[i]); |
446 |
} |
447 |
} |
301 |
} |
448 |
} |