| 1 |
package com.github.markusbernhardt.proxy.selector.misc; |
| 2 |
|
| 3 |
import static org.junit.Assert.assertEquals; |
| 4 |
import static org.junit.Assert.assertNull; |
| 5 |
|
| 6 |
import java.net.Proxy; |
| 7 |
import java.util.List; |
| 8 |
|
| 9 |
import org.junit.BeforeClass; |
| 10 |
import org.junit.Test; |
| 11 |
|
| 12 |
import com.github.markusbernhardt.proxy.TestUtil; |
| 13 |
import com.github.markusbernhardt.proxy.selector.fixed.FixedProxySelector; |
| 14 |
import com.github.markusbernhardt.proxy.selector.misc.ProtocolDispatchSelector; |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
public class ProtocolDispatchTest { |
| 24 |
|
| 25 |
private static ProtocolDispatchSelector ps; |
| 26 |
|
| 27 |
@BeforeClass |
| 28 |
public static void setup() { |
| 29 |
ps = new ProtocolDispatchSelector(); |
| 30 |
ps.setSelector("http", new FixedProxySelector(TestUtil.HTTP_TEST_PROXY)); |
| 31 |
ps.setSelector("https", new FixedProxySelector(TestUtil.HTTPS_TEST_PROXY)); |
| 32 |
ps.setSelector("ftp", new FixedProxySelector(TestUtil.FTP_TEST_PROXY)); |
| 33 |
} |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
@Test |
| 39 |
public void testDispatchHttp() { |
| 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 |
@Test |
| 48 |
public void testDispatchHttps() { |
| 49 |
List<Proxy> result = ps.select(TestUtil.HTTPS_TEST_URI); |
| 50 |
assertEquals(TestUtil.HTTPS_TEST_PROXY, result.get(0)); |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
@Test |
| 57 |
public void testDispatchFtp() { |
| 58 |
List<Proxy> result = ps.select(TestUtil.FTP_TEST_URI); |
| 59 |
assertEquals(TestUtil.FTP_TEST_PROXY, result.get(0)); |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
@Test |
| 66 |
public void testRemove() { |
| 67 |
ProtocolDispatchSelector px = new ProtocolDispatchSelector(); |
| 68 |
FixedProxySelector selector = new FixedProxySelector(TestUtil.HTTP_TEST_PROXY); |
| 69 |
px.setSelector("http", selector); |
| 70 |
assertEquals(selector, px.getSelector("http")); |
| 71 |
px.removeSelector("http"); |
| 72 |
assertNull(px.getSelector("http")); |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
@Test |
| 79 |
public void testFallback() { |
| 80 |
ProtocolDispatchSelector px = new ProtocolDispatchSelector(); |
| 81 |
FixedProxySelector selector = new FixedProxySelector(TestUtil.HTTP_TEST_PROXY); |
| 82 |
px.setFallbackSelector(selector); |
| 83 |
|
| 84 |
List<Proxy> proxies = px.select(TestUtil.HTTP_TEST_URI); |
| 85 |
|
| 86 |
assertEquals(TestUtil.HTTP_TEST_PROXY, proxies.get(0)); |
| 87 |
} |
| 88 |
|
| 89 |
} |