summaryrefslogtreecommitdiffstats
path: root/src/test/java/com/btr/proxy/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/com/btr/proxy/util')
-rw-r--r--src/test/java/com/btr/proxy/util/PListParserTest.java101
-rw-r--r--src/test/java/com/btr/proxy/util/ProxyUtilTest.java78
-rw-r--r--src/test/java/com/btr/proxy/util/UriFilterTest.java122
3 files changed, 301 insertions, 0 deletions
diff --git a/src/test/java/com/btr/proxy/util/PListParserTest.java b/src/test/java/com/btr/proxy/util/PListParserTest.java
new file mode 100644
index 0000000..98ea57b
--- /dev/null
+++ b/src/test/java/com/btr/proxy/util/PListParserTest.java
@@ -0,0 +1,101 @@
+package com.btr.proxy.util;
+
+import static org.junit.Assert.*;
+
+import java.io.File;
+import java.io.IOException;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.btr.proxy.TestUtil;
+import com.btr.proxy.util.PListParser.Dict;
+import com.btr.proxy.util.PListParser.XmlParseException;
+
+/*****************************************************************************
+ *
+ * @author Bernd Rosstauscher (proxyvole@rosstauscher.de) Copyright 2009
+ ****************************************************************************/
+
+public class PListParserTest {
+
+ private static final String TEST_SETTINGS = TestUtil.class.getResource("/").getFile() + "data"+File.separator+"osx"+File.separator+"osx_all.plist";
+
+ private static Dict pList;
+
+ /*************************************************************************
+ * Setup the dictionary from the test data file.
+ ************************************************************************/
+ @BeforeClass
+ public static void setupClass() throws XmlParseException,
+ IOException {
+ pList = PListParser.load(new File(TEST_SETTINGS));
+ }
+
+ /**
+ * Test method for {@link com.btr.proxy.util.PListParser#load(java.io.File)}.
+ */
+ @Test
+ public void testLoadFile() {
+ pList.dump();
+ assertTrue(pList.size() > 0);
+ }
+
+ /*************************************************************************
+ * Test method
+ ************************************************************************/
+
+ @Test
+ public void testStructure() {
+ String currentSet = (String) pList.get("CurrentSet");
+ assertNotNull(currentSet);
+ Object networkServices = pList.get("NetworkServices");
+ assertTrue(networkServices instanceof Dict);
+ }
+
+ /*************************************************************************
+ * Test method
+ ************************************************************************/
+
+ @Test
+ public void testNavigate() {
+ Object result = pList.getAtPath("NetworkServices/299B07C0-D0E0-4840-8486-9E77B9ED84DB/AppleTalk");
+ assertNotNull(result);
+ assertTrue(result instanceof Dict);
+ }
+
+ /*************************************************************************
+ * Test method
+ ************************************************************************/
+
+ @Test
+ public void testNavigate2() {
+ Object result = pList.getAtPath("/NetworkServices/299B07C0-D0E0-4840-8486-9E77B9ED84DB/AppleTalk");
+ assertNotNull(result);
+ assertTrue(result instanceof Dict);
+ }
+
+ /*************************************************************************
+ * Test method
+ ************************************************************************/
+
+ @Test
+ public void testNavigate3() {
+ Object result = pList.getAtPath("/NetworkServices/299B07C0-D0E0-4840-8486-9E77B9ED84DB/AppleTalk/");
+ assertNotNull(result);
+ assertTrue(result instanceof Dict);
+ }
+
+ /*************************************************************************
+ * Test method
+ ************************************************************************/
+
+ @Test
+ public void testNavigate4() {
+ Object result = pList.getAtPath("/NetworkServices/299B07C0-D0E0-4840-8486-9E77B9ED84DB/AppleTalkXXX/");
+ assertNull(result);
+ }
+
+
+
+}
+
diff --git a/src/test/java/com/btr/proxy/util/ProxyUtilTest.java b/src/test/java/com/btr/proxy/util/ProxyUtilTest.java
new file mode 100644
index 0000000..d8e10c5
--- /dev/null
+++ b/src/test/java/com/btr/proxy/util/ProxyUtilTest.java
@@ -0,0 +1,78 @@
+package com.btr.proxy.util;
+
+import static junit.framework.Assert.*;
+
+import java.net.Proxy;
+import java.util.List;
+
+import org.junit.Test;
+
+import com.btr.proxy.TestUtil;
+import com.btr.proxy.selector.fixed.FixedProxySelector;
+
+
+/*****************************************************************************
+ * Unit tests for proxy util methods
+ * @author Bernd Rosstauscher (proxyvole@rosstauscher.de) Copyright 2009
+ ****************************************************************************/
+
+public class ProxyUtilTest {
+
+ /*************************************************************************
+ * Test parsing method.
+ ************************************************************************/
+
+ @Test
+ public void testParseProxySettings() {
+ FixedProxySelector rs = ProxyUtil.parseProxySettings("http://http_proxy.unit-test.invalid/");
+ List<Proxy> psList = rs.select(TestUtil.HTTP_TEST_URI);
+ assertEquals("HTTP @ http_proxy.unit-test.invalid:80", psList.get(0).toString());
+ }
+
+ /*************************************************************************
+ * Test parsing method.
+ ************************************************************************/
+
+ @Test
+ public void testParseProxySettings2() {
+ FixedProxySelector rs = ProxyUtil.parseProxySettings("http://http_proxy.unit-test.invalid:8080/");
+ List<Proxy> psList = rs.select(TestUtil.HTTP_TEST_URI);
+ assertEquals("HTTP @ http_proxy.unit-test.invalid:8080", psList.get(0).toString());
+ }
+
+ /*************************************************************************
+ * Test parsing method.
+ ************************************************************************/
+
+ @Test
+ public void testParseProxySettings3() {
+ FixedProxySelector rs = ProxyUtil.parseProxySettings("http_proxy.unit-test.invalid");
+ List<Proxy> psList = rs.select(TestUtil.HTTP_TEST_URI);
+ assertEquals("HTTP @ http_proxy.unit-test.invalid:80", psList.get(0).toString());
+ }
+
+ /*************************************************************************
+ * Test parsing method.
+ ************************************************************************/
+
+ @Test
+ public void testParseProxySettings4() {
+ FixedProxySelector rs = ProxyUtil.parseProxySettings("http_proxy.unit-test.invalid:8080");
+ List<Proxy> psList = rs.select(TestUtil.HTTP_TEST_URI);
+ assertEquals("HTTP @ http_proxy.unit-test.invalid:8080", psList.get(0).toString());
+ }
+
+ /*************************************************************************
+ * Test parsing method.
+ ************************************************************************/
+
+ @Test
+ public void testParseProxySettings5() {
+ FixedProxySelector rs = ProxyUtil.parseProxySettings("192.123.123.1:8080");
+ List<Proxy> psList = rs.select(TestUtil.HTTP_TEST_URI);
+ assertEquals("HTTP @ 192.123.123.1:8080", psList.get(0).toString());
+ }
+
+
+}
+
diff --git a/src/test/java/com/btr/proxy/util/UriFilterTest.java b/src/test/java/com/btr/proxy/util/UriFilterTest.java
new file mode 100644
index 0000000..f1750ad
--- /dev/null
+++ b/src/test/java/com/btr/proxy/util/UriFilterTest.java
@@ -0,0 +1,122 @@
+package com.btr.proxy.util;
+
+import static org.junit.Assert.*;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.junit.Test;
+
+import com.btr.proxy.TestUtil;
+import com.btr.proxy.selector.whitelist.HostnameFilter;
+import com.btr.proxy.selector.whitelist.IpRangeFilter;
+import com.btr.proxy.selector.whitelist.HostnameFilter.Mode;
+
+
+/*****************************************************************************
+ * Some unit tests for the UriFilter class.
+ * @author Bernd Rosstauscher (proxyvole@rosstauscher.de) Copyright 2009
+ ****************************************************************************/
+
+public class UriFilterTest {
+
+ /*************************************************************************
+ * Test method
+ ************************************************************************/
+ @Test
+ public void testBeginsWithFilter1() {
+ UriFilter filter = new HostnameFilter(Mode.BEGINS_WITH, "no_proxy");
+
+ assertTrue(filter.accept(TestUtil.NO_PROXY_TEST_URI));
+ }
+
+ /*************************************************************************
+ * Test method
+ ************************************************************************/
+ @Test
+ public void testBeginsWithFilter2() {
+ UriFilter filter = new HostnameFilter(Mode.BEGINS_WITH, "no_proxy");
+
+ assertFalse(filter.accept(TestUtil.HTTP_TEST_URI));
+ }
+
+ /*************************************************************************
+ * Test method
+ * @throws URISyntaxException on invalid URL syntax.
+ ************************************************************************/
+ @Test
+ public void testBeginsWithFilter3() throws URISyntaxException {
+ UriFilter filter = new HostnameFilter(Mode.BEGINS_WITH, "192.168.0");
+
+ assertTrue(filter.accept(new URI("http://192.168.0.100:81/test.data")));
+ }
+
+ /*************************************************************************
+ * Test method
+ * @throws URISyntaxException on invalid URL syntax.
+ ************************************************************************/
+ @Test
+ public void testBeginsWithFilter4() throws URISyntaxException {
+ UriFilter filter = new HostnameFilter(Mode.BEGINS_WITH, "192.168.0");
+
+ assertFalse(filter.accept(new URI("http://192.168.1.100:81/test.data")));
+ }
+
+ /*************************************************************************
+ * Test method
+ ************************************************************************/
+ @Test
+ public void testBeginsWithFilter() {
+ UriFilter filter = new HostnameFilter(Mode.BEGINS_WITH, "no_proxy");
+
+ assertTrue(filter.accept(TestUtil.NO_PROXY_TEST_URI));
+ assertFalse(filter.accept(TestUtil.HTTP_TEST_URI));
+ }
+
+ /*************************************************************************
+ * Test method
+ * @throws URISyntaxException on invalid URL syntax.
+ ************************************************************************/
+ @Test
+ public void testEndsWithFilter() throws URISyntaxException {
+ UriFilter filter = new HostnameFilter(Mode.ENDS_WITH, ".unit-test.invalid");
+
+ assertTrue(filter.accept(TestUtil.NO_PROXY_TEST_URI));
+ }
+
+ /*************************************************************************
+ * Test method
+ * @throws URISyntaxException on invalid URL syntax.
+ ************************************************************************/
+ @Test
+ public void testEndsWithFilter2() throws URISyntaxException {
+ UriFilter filter = new HostnameFilter(Mode.ENDS_WITH, ".unit-test.invalid");
+
+ assertFalse(filter.accept(new URI("http://test.no-host.invalid:81/test.data")));
+ }
+
+ /*************************************************************************
+ * Test method
+ * @throws URISyntaxException on invalid URL syntax.
+ ************************************************************************/
+ @Test
+ public void testEndsWithFilter3() throws URISyntaxException {
+ UriFilter filter = new HostnameFilter(Mode.ENDS_WITH, ".100");
+
+ assertTrue(filter.accept(new URI("http://192.168.1.100:81/test.data")));
+ }
+
+ /*************************************************************************
+ * Test method
+ * @throws URISyntaxException on invalid URL syntax.
+ ************************************************************************/
+ @Test
+ public void testIpRangeFilter() throws URISyntaxException {
+ UriFilter filter = new IpRangeFilter("192.168.0.0/24");
+
+ assertTrue(filter.accept(new URI("http://192.168.0.100:81/test.data")));
+ assertFalse(filter.accept(new URI("http://192.168.1.100:81/test.data")));
+ }
+
+}
+