diff options
Diffstat (limited to 'src/test/java/com/btr/proxy/search/desktop')
-rw-r--r-- | src/test/java/com/btr/proxy/search/desktop/DesktopProxySearchTest.java | 45 | ||||
-rw-r--r-- | src/test/java/com/btr/proxy/search/desktop/win/DLLManagerTest.java | 78 |
2 files changed, 123 insertions, 0 deletions
diff --git a/src/test/java/com/btr/proxy/search/desktop/DesktopProxySearchTest.java b/src/test/java/com/btr/proxy/search/desktop/DesktopProxySearchTest.java new file mode 100644 index 0000000..0f8e6be --- /dev/null +++ b/src/test/java/com/btr/proxy/search/desktop/DesktopProxySearchTest.java @@ -0,0 +1,45 @@ +package com.btr.proxy.search.desktop; + +import java.net.ProxySelector; +import java.net.URI; +import java.net.URISyntaxException; + +import org.junit.Test; + +import com.btr.proxy.search.ProxySearch; +import com.btr.proxy.util.ProxyException; + +/***************************************************************************** + * Unit tests for the desktop facade search strategy. + * + * @author Bernd Rosstauscher (proxyvole@rosstauscher.de) Copyright 2009 + ****************************************************************************/ + +public class DesktopProxySearchTest { + + /************************************************************************* + * Test method. + * @throws ProxyException on error. + ************************************************************************/ + @Test + public void testDesktopStrategsIsWorking() throws ProxyException { + new DesktopProxySearchStrategy().getProxySelector(); + } + + /************************************************************************* + * Test method. + * @throws URISyntaxException on error parsing the URI. + * @throws ProxyException on selector error. + ************************************************************************/ + @Test + public void emptyURIShouldNotRaiseNPE() throws URISyntaxException, ProxyException { + ProxySearch proxySearch = ProxySearch.getDefaultProxySearch(); + ProxySelector myProxySelector = proxySearch.getProxySelector(); + if (myProxySelector != null) { + myProxySelector.select(new URI("")); + } + } + + +} + diff --git a/src/test/java/com/btr/proxy/search/desktop/win/DLLManagerTest.java b/src/test/java/com/btr/proxy/search/desktop/win/DLLManagerTest.java new file mode 100644 index 0000000..0711a8c --- /dev/null +++ b/src/test/java/com/btr/proxy/search/desktop/win/DLLManagerTest.java @@ -0,0 +1,78 @@ +package com.btr.proxy.search.desktop.win; + +import static org.junit.Assert.*; + +import java.io.File; +import java.io.IOException; +import org.junit.AfterClass; +import org.junit.Ignore; +import org.junit.Test; + +import com.btr.proxy.TestUtil; + +/***************************************************************************** + * Unit tests for DLL loading code. + * @author Bernd Rosstauscher (proxyvole@rosstauscher.de) Copyright 2009 + ****************************************************************************/ + +@Ignore +public class DLLManagerTest { + + /************************************************************************* + * Reset system property at the end. + ************************************************************************/ + @AfterClass + public static void teardown() { + System.setProperty(DLLManager.LIB_DIR_OVERRIDE, ""); + } + + /************************************************************************* + * Test method + * @throws IOException on error + ************************************************************************/ + @Test + public void testFindLibFileOverride() throws IOException { + String path = TestUtil.class.getResource("/").getFile() + File.separator+"data"+File.separator+"win"; + System.setProperty(DLLManager.LIB_DIR_OVERRIDE, path); + File actual = DLLManager.findLibFile(); + assertTrue(actual.getAbsolutePath().contains(path)); + } + + /************************************************************************* + * Test method + * @throws IOException on error + ************************************************************************/ + @Test + public void testFindLibFileDefault() throws IOException { + System.setProperty(DLLManager.LIB_DIR_OVERRIDE, ""); + File actual = DLLManager.findLibFile(); + assertTrue(actual.getAbsolutePath().contains("lib"+File.separator)); + } + + /************************************************************************* + * Test method + * @throws IOException on error + ************************************************************************/ + @Test + public void testCleanupTempFiles() throws IOException { + File f1 = File.createTempFile(DLLManager.TEMP_FILE_PREFIX+"_ABC", DLLManager.DLL_EXTENSION); + assertTrue(f1.exists()); + DLLManager.cleanupTempFiles(); + assertFalse(f1.exists()); + } + + /************************************************************************* + * Test method + * @throws IOException on error + ************************************************************************/ +// @Test +// public void testFileCopy() throws IOException { +// URL originalFile = DLLManagerTest.class.getResource("/lib/proxy_util_w32.dll"); +// File tempFile = File.createTempFile(DLLManager.TEMP_FILE_PREFIX, DLLManager.TEMP_FILE_PREFIX); +// DLLManager.copy(originalFile.openStream(), new FileOutputStream(tempFile)); +// assertTrue(tempFile.exists() && tempFile.length() == originalFile.length()); +// tempFile.delete(); +// } + +} + |