diff options
Diffstat (limited to 'src/test/java/com/btr/proxy/search/browser')
-rw-r--r-- | src/test/java/com/btr/proxy/search/browser/FirefoxTest.java | 144 | ||||
-rw-r--r-- | src/test/java/com/btr/proxy/search/browser/IeTest.java | 59 |
2 files changed, 203 insertions, 0 deletions
diff --git a/src/test/java/com/btr/proxy/search/browser/FirefoxTest.java b/src/test/java/com/btr/proxy/search/browser/FirefoxTest.java new file mode 100644 index 0000000..2a45140 --- /dev/null +++ b/src/test/java/com/btr/proxy/search/browser/FirefoxTest.java @@ -0,0 +1,144 @@ +package com.btr.proxy.search.browser; + +import static org.junit.Assert.*; + +import java.net.Proxy; +import java.net.ProxySelector; +import java.net.URISyntaxException; +import java.util.List; + +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; + +import com.btr.proxy.TestUtil; +import com.btr.proxy.search.browser.firefox.FirefoxProxySearchStrategy; +import com.btr.proxy.util.ProxyException; + +/***************************************************************************** + * Unit tests for the firefox search. + * + * @author Bernd Rosstauscher (proxyvole@rosstauscher.de) Copyright 2009 + ****************************************************************************/ + +@Ignore +public class FirefoxTest { + + /************************************************************************* + * Setup environment for tests. + ************************************************************************/ + @BeforeClass + public static void setup() { + // Fake the OS for this tests. + System.setProperty("os.name", "Linux"); + } + + /************************************************************************* + * Test method. + * @throws ProxyException on error. + ************************************************************************/ + @Test + public void testNone() throws ProxyException { + TestUtil.setTestDataFolder("ff3_none"); + + FirefoxProxySearchStrategy ff = new FirefoxProxySearchStrategy(); + ProxySelector ps = ff.getProxySelector(); + + List<Proxy> result = ps.select(TestUtil.HTTPS_TEST_URI); + assertEquals(Proxy.NO_PROXY , result.get(0)); + + } + + /************************************************************************* + * Test method + * @throws ProxyException on proxy detection error. + * @throws URISyntaxException on invalid URL syntax. + ************************************************************************/ + @Test + public void testManualHttp() throws ProxyException, URISyntaxException { + TestUtil.setTestDataFolder("ff3_manual"); + + ProxySelector ps = new FirefoxProxySearchStrategy().getProxySelector(); + + List<Proxy> result = ps.select(TestUtil.HTTP_TEST_URI); + assertEquals(TestUtil.HTTP_TEST_PROXY, result.get(0)); + } + + /************************************************************************* + * Test method + * @throws ProxyException on proxy detection error. + * @throws URISyntaxException on invalid URL syntax. + ************************************************************************/ + @Test + public void testManualHttps() throws ProxyException, URISyntaxException { + TestUtil.setTestDataFolder("ff3_manual"); + + ProxySelector ps = new FirefoxProxySearchStrategy().getProxySelector(); + + List<Proxy> result = ps.select(TestUtil.HTTPS_TEST_URI); + assertEquals(TestUtil.HTTPS_TEST_PROXY, result.get(0)); + } + + /************************************************************************* + * Test method + * @throws ProxyException on proxy detection error. + * @throws URISyntaxException on invalid URL syntax. + ************************************************************************/ + @Test + public void testManualFtp() throws ProxyException, URISyntaxException { + TestUtil.setTestDataFolder("ff3_manual"); + + ProxySelector ps = new FirefoxProxySearchStrategy().getProxySelector(); + + List<Proxy> result = ps.select(TestUtil.FTP_TEST_URI); + assertEquals(TestUtil.FTP_TEST_PROXY, result.get(0)); + } + + /************************************************************************* + * Test method + * @throws ProxyException on proxy detection error. + * @throws URISyntaxException on invalid URL syntax. + ************************************************************************/ + @Test + public void testManualSocks() throws ProxyException, URISyntaxException { + TestUtil.setTestDataFolder("ff3_manual"); + + ProxySelector ps = new FirefoxProxySearchStrategy().getProxySelector(); + + List<Proxy> result = ps.select(TestUtil.SOCKS_TEST_URI); + assertEquals(TestUtil.SOCKS_TEST_PROXY, result.get(0)); + } + + + /************************************************************************* + * Test method + * @throws ProxyException on proxy detection error. + * @throws URISyntaxException on invalid URL syntax. + ************************************************************************/ + @Test + public void testPac() throws ProxyException, URISyntaxException { + TestUtil.setTestDataFolder("ff3_pac_script"); + + ProxySelector ps = new FirefoxProxySearchStrategy().getProxySelector(); + + List<Proxy> result = ps.select(TestUtil.HTTP_TEST_URI); + assertEquals(TestUtil.HTTP_TEST_PROXY, result.get(0)); + } + + /************************************************************************* + * Test method + * @throws ProxyException on proxy detection error. + * @throws URISyntaxException on invalid URL syntax. + ************************************************************************/ + @Test + public void testWhiteList() throws ProxyException, URISyntaxException { + TestUtil.setTestDataFolder("ff3_white_list"); + + ProxySelector ps = new FirefoxProxySearchStrategy().getProxySelector(); + + List<Proxy> result = ps.select(TestUtil.NO_PROXY_TEST_URI); + assertEquals(Proxy.NO_PROXY, result.get(0)); + } + +} + diff --git a/src/test/java/com/btr/proxy/search/browser/IeTest.java b/src/test/java/com/btr/proxy/search/browser/IeTest.java new file mode 100644 index 0000000..3c7e72c --- /dev/null +++ b/src/test/java/com/btr/proxy/search/browser/IeTest.java @@ -0,0 +1,59 @@ +package com.btr.proxy.search.browser; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertFalse; + +import java.net.MalformedURLException; +import java.net.URISyntaxException; +import java.net.URL; + +import org.junit.Test; + +import com.btr.proxy.TestUtil; +import com.btr.proxy.search.browser.ie.IELocalByPassFilter; +import com.btr.proxy.search.browser.ie.IEProxySearchStrategy; +import com.btr.proxy.util.PlatformUtil; +import com.btr.proxy.util.ProxyException; +import com.btr.proxy.util.PlatformUtil.Platform; +import com.btr.proxy.util.UriFilter; + +/***************************************************************************** + * Unit tests for the InternetExplorer search. + * Only limited testing as this only runs on windwos and needs a + * installed IE and IE proxy settings written to the registry. + * + * @author Bernd Rosstauscher (proxyvole@rosstauscher.de) Copyright 2009 + ****************************************************************************/ + +public class IeTest { + + /************************************************************************* + * Test method. + * @throws ProxyException on proxy detection error. + ************************************************************************/ + @Test + public void testInvoke() throws ProxyException { + if (Platform.WIN.equals(PlatformUtil.getCurrentPlattform())) { + IEProxySearchStrategy st = new IEProxySearchStrategy(); + + // Try at least to invoke it and test if the dll does not crash + st.getProxySelector(); + } + } + + /************************************************************************* + * Test method. + * @throws ProxyException on proxy detection error. + * @throws URISyntaxException if url syntax is wrong. + * @throws MalformedURLException on wrong url format. + ************************************************************************/ + @Test + public void testLocalByPassFilter() throws ProxyException, MalformedURLException, URISyntaxException { + UriFilter filter = new IELocalByPassFilter(); + assertTrue(filter.accept(TestUtil.LOCAL_TEST_URI)); + assertFalse(filter.accept(TestUtil.HTTP_TEST_URI)); + assertFalse(filter.accept(new URL("http://123.45.55.6").toURI())); + } + +} + |