Debian Codegraph @

src/test/java/com/github/markusbernhardt/proxy/search/kde/KdeProxySearchTest.java

raw symbols SCIP
1 package com.github.markusbernhardt.proxy.search.kde;
2
3 import static org.junit.Assert.assertEquals;
4
5 import java.net.Proxy;
6 import java.net.ProxySelector;
7 import java.net.URISyntaxException;
8 import java.util.List;
9
10 import org.junit.Ignore;
11 import org.junit.Test;
12
13 import com.github.markusbernhardt.proxy.TestUtil;
14 import com.github.markusbernhardt.proxy.search.desktop.kde.KdeProxySearchStrategy;
15 import com.github.markusbernhardt.proxy.util.ProxyException;
16
17 /*****************************************************************************
18 * Unit tests for the KDE settings search strategy. For every test the
19 * "user.home" system property is switched to the test/data folder where we
20 * provide some KDE config files prepared for the test cases.
21 *
22 * If the env tests fail you need to set the followingenvironment variables:
23 * <p>
24 * HTTP_PROXY = http://http_proxy.unit-test.invalid:8090 <br>
25 * HTTPS_PROXY = http://https_proxy.unit-test.invalid:8091 <br>
26 * FTP_PROXY = http://ftp_proxy.unit-test.invalid:8092 <br>
27 * </p>
28 *
29 * @author Markus Bernhardt, Copyright 2016
30 * @author Bernd Rosstauscher, Copyright 2009
31 ****************************************************************************/
32
33 public class KdeProxySearchTest {
34
35 /*************************************************************************
36 * Test method
37 *
38 * @throws ProxyException
39 * on proxy detection error.
40 ************************************************************************/
41 @Test
42 public void testNone() throws ProxyException {
43 TestUtil.setTestDataFolder("kde_none");
44 ProxySelector ps = new KdeProxySearchStrategy().getProxySelector();
45 List<Proxy> result = ps.select(TestUtil.HTTP_TEST_URI);
46
47 assertEquals(Proxy.NO_PROXY, result.get(0));
48 }
49
50 /*************************************************************************
51 * Test method
52 *
53 * @throws ProxyException
54 * on proxy detection error.
55 * @throws URISyntaxException
56 * on invalid URL syntax.
57 ************************************************************************/
58 @Test
59 public void testManualHttp() throws ProxyException, URISyntaxException {
60 TestUtil.setTestDataFolder("kde_manual");
61
62 ProxySelector ps = new KdeProxySearchStrategy().getProxySelector();
63
64 List<Proxy> result = ps.select(TestUtil.HTTP_TEST_URI);
65 assertEquals(TestUtil.HTTP_TEST_PROXY, result.get(0));
66 }
67
68 /*************************************************************************
69 * Test method
70 *
71 * @throws ProxyException
72 * on proxy detection error.
73 * @throws URISyntaxException
74 * on invalid URL syntax.
75 ************************************************************************/
76 @Test
77 public void testManualHttps() throws ProxyException, URISyntaxException {
78 TestUtil.setTestDataFolder("kde_manual");
79
80 ProxySelector ps = new KdeProxySearchStrategy().getProxySelector();
81
82 List<Proxy> result = ps.select(TestUtil.HTTPS_TEST_URI);
83 assertEquals(TestUtil.HTTPS_TEST_PROXY, result.get(0));
84 }
85
86 /*************************************************************************
87 * Test method
88 *
89 * @throws ProxyException
90 * on proxy detection error.
91 * @throws URISyntaxException
92 * on invalid URL syntax.
93 ************************************************************************/
94 @Test
95 public void testManualFtp() throws ProxyException, URISyntaxException {
96 TestUtil.setTestDataFolder("kde_manual");
97
98 ProxySelector ps = new KdeProxySearchStrategy().getProxySelector();
99
100 List<Proxy> result = ps.select(TestUtil.FTP_TEST_URI);
101 assertEquals(TestUtil.FTP_TEST_PROXY, result.get(0));
102 }
103
104 /*************************************************************************
105 * Test method
106 *
107 * @throws ProxyException
108 * on proxy detection error.
109 * @throws URISyntaxException
110 * on invalid URL syntax.
111 ************************************************************************/
112 @Test
113 public void testPac() throws ProxyException, URISyntaxException {
114 TestUtil.setTestDataFolder("kde_pac_script");
115
116 ProxySelector ps = new KdeProxySearchStrategy().getProxySelector();
117
118 List<Proxy> result = ps.select(TestUtil.HTTP_TEST_URI);
119 assertEquals(TestUtil.HTTP_TEST_PROXY, result.get(0));
120 }
121
122 /*************************************************************************
123 * Test method
124 *
125 * @throws ProxyException
126 * on proxy detection error.
127 * @throws URISyntaxException
128 * on invalid URL syntax.
129 ************************************************************************/
130 @Test
131 @Ignore
132 public void testEnvHttp() throws ProxyException, URISyntaxException {
133 // There is no good was to initialize environment variables in the
134 // running process.
135 // System.getenv().put("HTTP_PROXY",
136 // "http://http_proxy.unit-test.invalid:8090"); // Does not work
137 TestUtil.setTestDataFolder("kde_env");
138
139 ProxySelector ps = new KdeProxySearchStrategy().getProxySelector();
140
141 List<Proxy> result = ps.select(TestUtil.HTTP_TEST_URI);
142 assertEquals(TestUtil.HTTP_TEST_PROXY, result.get(0));
143 }
144
145 /*************************************************************************
146 * Test method
147 *
148 * @throws ProxyException
149 * on proxy detection error.
150 * @throws URISyntaxException
151 * on invalid URL syntax.
152 ************************************************************************/
153 @Test
154 @Ignore
155 public void testEnvHttps() throws ProxyException, URISyntaxException {
156 // There is no good was to initialize environment variables in the
157 // running process.
158 // System.getenv().put("HTTPS_PROXY",
159 // "http://http_proxy.unit-test.invalid:8090"); // Does not work
160 TestUtil.setTestDataFolder("kde_env");
161
162 ProxySelector ps = new KdeProxySearchStrategy().getProxySelector();
163
164 List<Proxy> result = ps.select(TestUtil.HTTPS_TEST_URI);
165 assertEquals(TestUtil.HTTPS_TEST_PROXY, result.get(0));
166 }
167
168 /*************************************************************************
169 * Test method
170 *
171 * @throws ProxyException
172 * on proxy detection error.
173 * @throws URISyntaxException
174 * on invalid URL syntax.
175 ************************************************************************/
176 @Test
177 @Ignore
178 public void testEnvFtp() throws ProxyException, URISyntaxException {
179 // there is no good was to initialize environment variables in the
180 // running process.
181 // System.getenv().put("FTP_PROXY",
182 // "http://http_proxy.unit-test.invalid:8090"); // Does not work
183 TestUtil.setTestDataFolder("kde_env");
184
185 ProxySelector ps = new KdeProxySearchStrategy().getProxySelector();
186
187 List<Proxy> result = ps.select(TestUtil.FTP_TEST_URI);
188 assertEquals(TestUtil.FTP_TEST_PROXY, result.get(0));
189 }
190
191 /*************************************************************************
192 * Test method
193 *
194 * @throws ProxyException
195 * on proxy detection error.
196 * @throws URISyntaxException
197 * on invalid URL syntax.
198 ************************************************************************/
199 @Test
200 public void testWhiteList() throws ProxyException, URISyntaxException {
201 TestUtil.setTestDataFolder("kde_white_list");
202
203 ProxySelector ps = new KdeProxySearchStrategy().getProxySelector();
204
205 List<Proxy> result = ps.select(TestUtil.NO_PROXY_TEST_URI);
206 assertEquals(Proxy.NO_PROXY, result.get(0));
207 }
208
209 }