Debian Codegraph @

src/test/java/com/github/markusbernhardt/proxy/search/browser/FirefoxTest.java

raw symbols SCIP
1 package com.github.markusbernhardt.proxy.search.browser;
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.BeforeClass;
11 import org.junit.Test;
12
13 import com.github.markusbernhardt.proxy.TestUtil;
14 import com.github.markusbernhardt.proxy.search.browser.firefox.FirefoxProxySearchStrategy;
15 import com.github.markusbernhardt.proxy.util.ProxyException;
16
17 /*****************************************************************************
18 * Unit tests for the firefox search.
19 *
20 * @author Markus Bernhardt, Copyright 2016
21 * @author Bernd Rosstauscher, Copyright 2009
22 ****************************************************************************/
23
24 public class FirefoxTest {
25
26 /*************************************************************************
27 * Setup environment for tests.
28 ************************************************************************/
29 @BeforeClass
30 public static void setup() {
31 // Fake the OS for this tests.
32 System.setProperty("os.name", "Linux");
33 }
34
35 /*************************************************************************
36 * Test method.
37 *
38 * @throws ProxyException
39 * on error.
40 ************************************************************************/
41 @Test
42 public void testNone() throws ProxyException {
43 TestUtil.setTestDataFolder("ff3_none");
44
45 FirefoxProxySearchStrategy ff = new FirefoxProxySearchStrategy();
46 ProxySelector ps = ff.getProxySelector();
47
48 List<Proxy> result = ps.select(TestUtil.HTTPS_TEST_URI);
49 assertEquals(Proxy.NO_PROXY, result.get(0));
50
51 }
52
53 /*************************************************************************
54 * Test method
55 *
56 * @throws ProxyException
57 * on proxy detection error.
58 * @throws URISyntaxException
59 * on invalid URL syntax.
60 ************************************************************************/
61 @Test
62 public void testManualHttp() throws ProxyException, URISyntaxException {
63 TestUtil.setTestDataFolder("ff3_manual");
64
65 ProxySelector ps = new FirefoxProxySearchStrategy().getProxySelector();
66
67 List<Proxy> result = ps.select(TestUtil.HTTP_TEST_URI);
68 assertEquals(TestUtil.HTTP_TEST_PROXY, result.get(0));
69 }
70
71 /*************************************************************************
72 * Test method
73 *
74 * @throws ProxyException
75 * on proxy detection error.
76 * @throws URISyntaxException
77 * on invalid URL syntax.
78 ************************************************************************/
79 @Test
80 public void testManualHttps() throws ProxyException, URISyntaxException {
81 TestUtil.setTestDataFolder("ff3_manual");
82
83 ProxySelector ps = new FirefoxProxySearchStrategy().getProxySelector();
84
85 List<Proxy> result = ps.select(TestUtil.HTTPS_TEST_URI);
86 assertEquals(TestUtil.HTTPS_TEST_PROXY, result.get(0));
87 }
88
89 /*************************************************************************
90 * Test method
91 *
92 * @throws ProxyException
93 * on proxy detection error.
94 * @throws URISyntaxException
95 * on invalid URL syntax.
96 ************************************************************************/
97 @Test
98 public void testManualFtp() throws ProxyException, URISyntaxException {
99 TestUtil.setTestDataFolder("ff3_manual");
100
101 ProxySelector ps = new FirefoxProxySearchStrategy().getProxySelector();
102
103 List<Proxy> result = ps.select(TestUtil.FTP_TEST_URI);
104 assertEquals(TestUtil.FTP_TEST_PROXY, result.get(0));
105 }
106
107 /*************************************************************************
108 * Test method
109 *
110 * @throws ProxyException
111 * on proxy detection error.
112 * @throws URISyntaxException
113 * on invalid URL syntax.
114 ************************************************************************/
115 @Test
116 public void testManualSocks() throws ProxyException, URISyntaxException {
117 TestUtil.setTestDataFolder("ff3_manual");
118
119 ProxySelector ps = new FirefoxProxySearchStrategy().getProxySelector();
120
121 List<Proxy> result = ps.select(TestUtil.SOCKS_TEST_URI);
122 assertEquals(TestUtil.SOCKS_TEST_PROXY, result.get(0));
123 }
124
125 /*************************************************************************
126 * Test method
127 *
128 * @throws ProxyException
129 * on proxy detection error.
130 * @throws URISyntaxException
131 * on invalid URL syntax.
132 ************************************************************************/
133 @Test
134 public void testPac() throws ProxyException, URISyntaxException {
135 TestUtil.setTestDataFolder("ff3_pac_script");
136
137 ProxySelector ps = new FirefoxProxySearchStrategy().getProxySelector();
138
139 List<Proxy> result = ps.select(TestUtil.HTTP_TEST_URI);
140 assertEquals(TestUtil.HTTP_TEST_PROXY, result.get(0));
141 }
142
143 /*************************************************************************
144 * Test method
145 *
146 * @throws ProxyException
147 * on proxy detection error.
148 * @throws URISyntaxException
149 * on invalid URL syntax.
150 ************************************************************************/
151 @Test
152 public void testWhiteList() throws ProxyException, URISyntaxException {
153 TestUtil.setTestDataFolder("ff3_white_list");
154
155 ProxySelector ps = new FirefoxProxySearchStrategy().getProxySelector();
156
157 List<Proxy> result = ps.select(TestUtil.NO_PROXY_TEST_URI);
158 assertEquals(Proxy.NO_PROXY, result.get(0));
159 }
160
161 }