Debian Codegraph @

src/test/java/com/github/markusbernhardt/proxy/search/gnome/GnomeProxySearchTest.java

raw symbols SCIP
1 package com.github.markusbernhardt.proxy.search.gnome;
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.Test;
11
12 import com.github.markusbernhardt.proxy.TestUtil;
13 import com.github.markusbernhardt.proxy.search.desktop.gnome.GnomeProxySearchStrategy;
14 import com.github.markusbernhardt.proxy.util.ProxyException;
15
16 /*****************************************************************************
17 * Unit tests for the Gnome settings search strategy. For every test the
18 * "user.home" system property is switched to the test/data folder where we
19 * provide some Gnome config files prepared for the test cases.
20 *
21 * @author Markus Bernhardt, Copyright 2016
22 * @author Bernd Rosstauscher, Copyright 2009
23 ****************************************************************************/
24
25 public class GnomeProxySearchTest {
26
27 /*************************************************************************
28 * Test method
29 *
30 * @throws ProxyException
31 * on proxy detection error.
32 ************************************************************************/
33 @Test
34 public void testNone() throws ProxyException {
35 TestUtil.setTestDataFolder("gnome_none");
36 ProxySelector ps = new GnomeProxySearchStrategy().getProxySelector();
37 List<Proxy> result = ps.select(TestUtil.HTTP_TEST_URI);
38
39 assertEquals(Proxy.NO_PROXY, result.get(0));
40 }
41
42 /*************************************************************************
43 * Test method
44 *
45 * @throws ProxyException
46 * on proxy detection error.
47 * @throws URISyntaxException
48 * on invalid URL syntax.
49 ************************************************************************/
50 @Test
51 public void testManualHttp() throws ProxyException, URISyntaxException {
52 TestUtil.setTestDataFolder("gnome_manual");
53
54 ProxySelector ps = new GnomeProxySearchStrategy().getProxySelector();
55
56 List<Proxy> result = ps.select(TestUtil.HTTP_TEST_URI);
57 assertEquals(TestUtil.HTTP_TEST_PROXY, result.get(0));
58 }
59
60 /*************************************************************************
61 * Test method
62 *
63 * @throws ProxyException
64 * on proxy detection error.
65 * @throws URISyntaxException
66 * on invalid URL syntax.
67 ************************************************************************/
68 @Test
69 public void testManualHttps() throws ProxyException, URISyntaxException {
70 TestUtil.setTestDataFolder("gnome_manual");
71
72 ProxySelector ps = new GnomeProxySearchStrategy().getProxySelector();
73
74 List<Proxy> result = ps.select(TestUtil.HTTPS_TEST_URI);
75 assertEquals(TestUtil.HTTPS_TEST_PROXY, result.get(0));
76 }
77
78 /*************************************************************************
79 * Test method
80 *
81 * @throws ProxyException
82 * on proxy detection error.
83 * @throws URISyntaxException
84 * on invalid URL syntax.
85 ************************************************************************/
86 @Test
87 public void testManualFtp() throws ProxyException, URISyntaxException {
88 TestUtil.setTestDataFolder("gnome_manual");
89
90 ProxySelector ps = new GnomeProxySearchStrategy().getProxySelector();
91
92 List<Proxy> result = ps.select(TestUtil.FTP_TEST_URI);
93 assertEquals(TestUtil.FTP_TEST_PROXY, result.get(0));
94 }
95
96 /*************************************************************************
97 * Test method
98 *
99 * @throws ProxyException
100 * on proxy detection error.
101 * @throws URISyntaxException
102 * on invalid URL syntax.
103 ************************************************************************/
104 @Test
105 public void testPac() throws ProxyException, URISyntaxException {
106 TestUtil.setTestDataFolder("gnome_pac_script");
107
108 ProxySelector ps = new GnomeProxySearchStrategy().getProxySelector();
109
110 List<Proxy> result = ps.select(TestUtil.HTTP_TEST_URI);
111 assertEquals(TestUtil.HTTP_TEST_PROXY, result.get(0));
112 }
113
114 /*************************************************************************
115 * Test method
116 *
117 * @throws ProxyException
118 * on proxy detection error.
119 * @throws URISyntaxException
120 * on invalid URL syntax.
121 ************************************************************************/
122 @Test
123 public void testWhiteList() throws ProxyException, URISyntaxException {
124 TestUtil.setTestDataFolder("gnome_white_list");
125
126 ProxySelector ps = new GnomeProxySearchStrategy().getProxySelector();
127
128 List<Proxy> result = ps.select(TestUtil.NO_PROXY_TEST_URI);
129 assertEquals(Proxy.NO_PROXY, result.get(0));
130 }
131
132 }