Debian Codegraph @

src/test/java/com/github/markusbernhardt/proxy/util/ProxyUtilTest.java

raw symbols SCIP
1 package com.github.markusbernhardt.proxy.util;
2
3 import static org.junit.Assert.assertEquals;
4
5 import java.net.Proxy;
6 import java.util.List;
7
8 import org.junit.Test;
9
10 import com.github.markusbernhardt.proxy.TestUtil;
11 import com.github.markusbernhardt.proxy.selector.fixed.FixedProxySelector;
12 import com.github.markusbernhardt.proxy.util.ProxyUtil;
13
14 /*****************************************************************************
15 * Unit tests for proxy util methods
16 *
17 * @author Markus Bernhardt, Copyright 2016
18 * @author Bernd Rosstauscher, Copyright 2009
19 ****************************************************************************/
20
21 public class ProxyUtilTest {
22
23 /*************************************************************************
24 * Test parsing method.
25 ************************************************************************/
26
27 @Test
28 public void testParseProxySettings() {
29 FixedProxySelector rs = ProxyUtil.parseProxySettings("http://http_proxy.unit-test.invalid/");
30 List<Proxy> psList = rs.select(TestUtil.HTTP_TEST_URI);
31 assertEquals("HTTP @ http_proxy.unit-test.invalid:80", psList.get(0).toString());
32 }
33
34 /*************************************************************************
35 * Test parsing method.
36 ************************************************************************/
37
38 @Test
39 public void testParseProxySettings2() {
40 FixedProxySelector rs = ProxyUtil.parseProxySettings("http://http_proxy.unit-test.invalid:8080/");
41 List<Proxy> psList = rs.select(TestUtil.HTTP_TEST_URI);
42 assertEquals("HTTP @ http_proxy.unit-test.invalid:8080", psList.get(0).toString());
43 }
44
45 /*************************************************************************
46 * Test parsing method.
47 ************************************************************************/
48
49 @Test
50 public void testParseProxySettings3() {
51 FixedProxySelector rs = ProxyUtil.parseProxySettings("http_proxy.unit-test.invalid");
52 List<Proxy> psList = rs.select(TestUtil.HTTP_TEST_URI);
53 assertEquals("HTTP @ http_proxy.unit-test.invalid:80", psList.get(0).toString());
54 }
55
56 /*************************************************************************
57 * Test parsing method.
58 ************************************************************************/
59
60 @Test
61 public void testParseProxySettings4() {
62 FixedProxySelector rs = ProxyUtil.parseProxySettings("http_proxy.unit-test.invalid:8080");
63 List<Proxy> psList = rs.select(TestUtil.HTTP_TEST_URI);
64 assertEquals("HTTP @ http_proxy.unit-test.invalid:8080", psList.get(0).toString());
65 }
66
67 /*************************************************************************
68 * Test parsing method.
69 ************************************************************************/
70
71 @Test
72 public void testParseProxySettings5() {
73 FixedProxySelector rs = ProxyUtil.parseProxySettings("192.123.123.1:8080");
74 List<Proxy> psList = rs.select(TestUtil.HTTP_TEST_URI);
75 assertEquals("HTTP @ 192.123.123.1:8080", psList.get(0).toString());
76 }
77
78 /*************************************************************************
79 * Test parsing method.
80 ************************************************************************/
81
82 @Test
83 public void testParseIPv6WithoutProtocol() {
84 FixedProxySelector rs = ProxyUtil.parseProxySettings("[2001:4860:0:2001::68]:8080");
85 List<Proxy> psList = rs.select(TestUtil.HTTP_TEST_URI);
86 assertEquals("HTTP @ 2001:4860:0:2001::68:8080", psList.get(0).toString());
87 }
88
89 /*************************************************************************
90 * Test parsing method.
91 ************************************************************************/
92
93 @Test
94 public void testParseIPv6WithProtocol() {
95 FixedProxySelector rs = ProxyUtil.parseProxySettings("http://[2001:4860:0:2001::68]:8080/");
96 List<Proxy> psList = rs.select(TestUtil.HTTP_TEST_URI);
97 assertEquals("HTTP @ 2001:4860:0:2001::68:8080", psList.get(0).toString());
98 }
99
100 }