summaryrefslogtreecommitdiffstats
path: root/src/test/java/com/btr/proxy/search/kde/KdeProxySearchTest.java
blob: d600aa26f304b6c90197873d5d3c805093ba778e (plain) (blame)
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
package com.btr.proxy.search.kde;

import static org.junit.Assert.assertEquals;

import java.net.Proxy;
import java.net.ProxySelector;
import java.net.URISyntaxException;
import java.util.List;

import org.junit.Ignore;
import org.junit.Test;

import com.btr.proxy.TestUtil;
import com.btr.proxy.search.desktop.kde.KdeProxySearchStrategy;
import com.btr.proxy.util.ProxyException;


/*****************************************************************************
 * Unit tests for the KDE settings search strategy.
 * For every test the "user.home" system property is switched to the test/data
 * folder where we provide some KDE config files prepared for the test cases. 
 * 
 * If the env tests fail you need to set the followingenvironment variables:
 * <p>
 * HTTP_PROXY = http://http_proxy.unit-test.invalid:8090 <br/>
 * HTTPS_PROXY = http://https_proxy.unit-test.invalid:8091 <br/>
 * FTP_PROXY = http://ftp_proxy.unit-test.invalid:8092 <br/>
 * </p>
 * 
 * @author Bernd Rosstauscher (proxyvole@rosstauscher.de) Copyright 2009
 ****************************************************************************/
@Ignore
public class KdeProxySearchTest {
	
	/*************************************************************************
	 * Test method
	 * @throws ProxyException on proxy detection error.
	 ************************************************************************/
	@Test
	public void testNone() throws ProxyException {
		TestUtil.setTestDataFolder("kde_none");
		ProxySelector ps = new KdeProxySearchStrategy().getProxySelector();
		List<Proxy> result = ps.select(TestUtil.HTTP_TEST_URI);
		
		assertEquals(Proxy.NO_PROXY, result.get(0));
	}
	
	/*************************************************************************
	 * Test method
	 * @throws ProxyException on proxy detection error.
	 * @throws URISyntaxException on invalid URL syntax.
	 ************************************************************************/
	@Test
	public void testManualHttp() throws ProxyException, URISyntaxException {
		TestUtil.setTestDataFolder("kde_manual");
		
		ProxySelector ps = new KdeProxySearchStrategy().getProxySelector();

		List<Proxy> result = ps.select(TestUtil.HTTP_TEST_URI);
		assertEquals(TestUtil.HTTP_TEST_PROXY, result.get(0));
	}
	
	/*************************************************************************
	 * Test method
	 * @throws ProxyException on proxy detection error.
	 * @throws URISyntaxException on invalid URL syntax.
	 ************************************************************************/
	@Test
	public void testManualHttps() throws ProxyException, URISyntaxException {
		TestUtil.setTestDataFolder("kde_manual");
		
		ProxySelector ps = new KdeProxySearchStrategy().getProxySelector();

		List<Proxy> result = ps.select(TestUtil.HTTPS_TEST_URI);
		assertEquals(TestUtil.HTTPS_TEST_PROXY, result.get(0));
	}
	
	/*************************************************************************
	 * Test method
	 * @throws ProxyException on proxy detection error.
	 * @throws URISyntaxException on invalid URL syntax.
	 ************************************************************************/
	@Test
	public void testManualFtp() throws ProxyException, URISyntaxException {
		TestUtil.setTestDataFolder("kde_manual");
		
		ProxySelector ps = new KdeProxySearchStrategy().getProxySelector();

		List<Proxy> result = ps.select(TestUtil.FTP_TEST_URI);
		assertEquals(TestUtil.FTP_TEST_PROXY, result.get(0));
	}

	/*************************************************************************
	 * Test method
	 * @throws ProxyException on proxy detection error.
	 * @throws URISyntaxException on invalid URL syntax.
	 ************************************************************************/
	@Test
	public void testPac() throws ProxyException, URISyntaxException {
		TestUtil.setTestDataFolder("kde_pac_script");
		
		ProxySelector ps = new KdeProxySearchStrategy().getProxySelector();

		List<Proxy> result = ps.select(TestUtil.HTTP_TEST_URI);
		assertEquals(TestUtil.HTTP_TEST_PROXY, result.get(0));
	}

	/*************************************************************************
	 * Test method
	 * @throws ProxyException on proxy detection error.
	 * @throws URISyntaxException on invalid URL syntax.
	 ************************************************************************/
	@Test
	@Ignore
	public void testEnvHttp() throws ProxyException, URISyntaxException {
		// There is no good was to initialize environment variables in the running process.
		//System.getenv().put("HTTP_PROXY", "http://http_proxy.unit-test.invalid:8090"); // Does not work
		TestUtil.setTestDataFolder("kde_env");
		
		ProxySelector ps = new KdeProxySearchStrategy().getProxySelector();

		List<Proxy> result = ps.select(TestUtil.HTTP_TEST_URI);
		assertEquals(TestUtil.HTTP_TEST_PROXY, result.get(0));
	}
	
	/*************************************************************************
	 * Test method
	 * @throws ProxyException on proxy detection error.
	 * @throws URISyntaxException on invalid URL syntax.
	 ************************************************************************/
	@Test
	@Ignore
	public void testEnvHttps() throws ProxyException, URISyntaxException {
		// There is no good was to initialize environment variables in the running process.
		// System.getenv().put("HTTPS_PROXY", "http://http_proxy.unit-test.invalid:8090"); // Does not work
		TestUtil.setTestDataFolder("kde_env");
		
		ProxySelector ps = new KdeProxySearchStrategy().getProxySelector();

		List<Proxy> result = ps.select(TestUtil.HTTPS_TEST_URI);
		assertEquals(TestUtil.HTTPS_TEST_PROXY, result.get(0));
	}

	/*************************************************************************
	 * Test method
	 * @throws ProxyException on proxy detection error.
	 * @throws URISyntaxException on invalid URL syntax.
	 ************************************************************************/
	@Test
	@Ignore
	public void testEnvFtp() throws ProxyException, URISyntaxException {
		// there is no good was to initialize environment variables in the running process.
		//System.getenv().put("FTP_PROXY", "http://http_proxy.unit-test.invalid:8090"); // Does not work
		TestUtil.setTestDataFolder("kde_env");
		
		ProxySelector ps = new KdeProxySearchStrategy().getProxySelector();

		List<Proxy> result = ps.select(TestUtil.FTP_TEST_URI);
		assertEquals(TestUtil.FTP_TEST_PROXY, result.get(0));
	}
	
	/*************************************************************************
	 * Test method
	 * @throws ProxyException on proxy detection error.
	 * @throws URISyntaxException on invalid URL syntax.
	 ************************************************************************/
	@Test
	public void testWhiteList() throws ProxyException, URISyntaxException {
		TestUtil.setTestDataFolder("kde_white_list");
		
		ProxySelector ps = new KdeProxySearchStrategy().getProxySelector();

		List<Proxy> result = ps.select(TestUtil.NO_PROXY_TEST_URI);
		assertEquals(Proxy.NO_PROXY, result.get(0));
	}

}