| 1 |
package com.github.markusbernhardt.proxy.search.osx; |
| 2 |
|
| 3 |
import static org.junit.Assert.assertEquals; |
| 4 |
|
| 5 |
import java.io.File; |
| 6 |
import java.net.Proxy; |
| 7 |
import java.net.ProxySelector; |
| 8 |
import java.net.URISyntaxException; |
| 9 |
import java.util.List; |
| 10 |
|
| 11 |
import org.junit.Test; |
| 12 |
|
| 13 |
import com.github.markusbernhardt.proxy.TestUtil; |
| 14 |
import com.github.markusbernhardt.proxy.search.desktop.osx.OsxProxySearchStrategy; |
| 15 |
import com.github.markusbernhardt.proxy.util.ProxyException; |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
public class OsxProxySearchTest { |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
@Test |
| 35 |
public void testManualHttp() throws ProxyException, URISyntaxException { |
| 36 |
System.setProperty(OsxProxySearchStrategy.OVERRIDE_SETTINGS_FILE, |
| 37 |
TestUtil.TEST_DATA_FOLDER + File.separator + "osx" + File.separator + "osx_manual.plist"); |
| 38 |
System.setProperty(OsxProxySearchStrategy.OVERRIDE_ACCEPTED_DEVICES, "en0"); |
| 39 |
ProxySelector ps = new OsxProxySearchStrategy().getProxySelector(); |
| 40 |
List<Proxy> result = ps.select(TestUtil.HTTP_TEST_URI); |
| 41 |
assertEquals(TestUtil.HTTP_TEST_PROXY, result.get(0)); |
| 42 |
} |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
@Test |
| 53 |
public void wrongIntfaceShouldBeSkipped() throws ProxyException, URISyntaxException { |
| 54 |
System.setProperty(OsxProxySearchStrategy.OVERRIDE_SETTINGS_FILE, |
| 55 |
TestUtil.TEST_DATA_FOLDER + File.separator + "osx" + File.separator + "osx_manual.plist"); |
| 56 |
System.setProperty(OsxProxySearchStrategy.OVERRIDE_ACCEPTED_DEVICES, "junit"); |
| 57 |
ProxySelector ps = new OsxProxySearchStrategy().getProxySelector(); |
| 58 |
List<Proxy> result = ps.select(TestUtil.HTTP_TEST_URI); |
| 59 |
assertEquals(Proxy.NO_PROXY, result.get(0)); |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
@Test |
| 71 |
public void testManualHttps() throws ProxyException, URISyntaxException { |
| 72 |
System.setProperty(OsxProxySearchStrategy.OVERRIDE_SETTINGS_FILE, |
| 73 |
TestUtil.TEST_DATA_FOLDER + "osx" + File.separator + "osx_manual.plist"); |
| 74 |
ProxySelector ps = new OsxProxySearchStrategy().getProxySelector(); |
| 75 |
List<Proxy> result = ps.select(TestUtil.HTTPS_TEST_URI); |
| 76 |
assertEquals(TestUtil.HTTPS_TEST_PROXY, result.get(0)); |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
@Test |
| 88 |
public void testManualFtp() throws ProxyException, URISyntaxException { |
| 89 |
System.setProperty(OsxProxySearchStrategy.OVERRIDE_SETTINGS_FILE, |
| 90 |
TestUtil.TEST_DATA_FOLDER + "osx" + File.separator + "osx_manual.plist"); |
| 91 |
ProxySelector ps = new OsxProxySearchStrategy().getProxySelector(); |
| 92 |
List<Proxy> result = ps.select(TestUtil.FTP_TEST_URI); |
| 93 |
assertEquals(TestUtil.FTP_TEST_PROXY, result.get(0)); |
| 94 |
} |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
@Test |
| 105 |
public void testManualSocks() throws ProxyException, URISyntaxException { |
| 106 |
System.setProperty(OsxProxySearchStrategy.OVERRIDE_SETTINGS_FILE, |
| 107 |
TestUtil.TEST_DATA_FOLDER + "osx" + File.separator + "osx_manual.plist"); |
| 108 |
ProxySelector ps = new OsxProxySearchStrategy().getProxySelector(); |
| 109 |
List<Proxy> result = ps.select(TestUtil.SOCKS_TEST_URI); |
| 110 |
assertEquals(TestUtil.SOCKS_TEST_PROXY, result.get(0)); |
| 111 |
} |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
@Test |
| 122 |
public void testNoProxyList() throws ProxyException, URISyntaxException { |
| 123 |
System.setProperty(OsxProxySearchStrategy.OVERRIDE_SETTINGS_FILE, |
| 124 |
TestUtil.TEST_DATA_FOLDER + "osx" + File.separator + "osx_manual.plist"); |
| 125 |
ProxySelector ps = new OsxProxySearchStrategy().getProxySelector(); |
| 126 |
List<Proxy> result = ps.select(TestUtil.NO_PROXY_TEST_URI); |
| 127 |
assertEquals(Proxy.NO_PROXY, result.get(0)); |
| 128 |
} |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
@Test |
| 139 |
public void testSimpleHostTest() throws ProxyException, URISyntaxException { |
| 140 |
System.setProperty(OsxProxySearchStrategy.OVERRIDE_SETTINGS_FILE, |
| 141 |
TestUtil.TEST_DATA_FOLDER + "osx" + File.separator + "osx_manual.plist"); |
| 142 |
ProxySelector ps = new OsxProxySearchStrategy().getProxySelector(); |
| 143 |
List<Proxy> result = ps.select(TestUtil.LOCAL_TEST_URI); |
| 144 |
assertEquals(Proxy.NO_PROXY, result.get(0)); |
| 145 |
} |
| 146 |
|
| 147 |
} |