summaryrefslogtreecommitdiffstats
path: root/src/test/java/com/btr/proxy/selector/misc/ProtocolDispatchTest.java
blob: da27327d1a0c50ebcfe89c02bedd1ef97d2f8e56 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package com.btr.proxy.selector.misc;

import static org.junit.Assert.*;

import java.net.Proxy;
import java.util.List;

import org.junit.BeforeClass;
import org.junit.Test;

import com.btr.proxy.TestUtil;
import com.btr.proxy.selector.fixed.FixedProxySelector;

/*****************************************************************************
 *  Unit Tests for the ProtocolDispatchSelector
 *  
 * @author Bernd Rosstauscher (proxyvole@rosstauscher.de) Copyright 2009
 ****************************************************************************/

public class ProtocolDispatchTest {

	private static ProtocolDispatchSelector ps;

	@BeforeClass
	public static void setup() {
		ps = new ProtocolDispatchSelector();
		ps.setSelector("http", new FixedProxySelector(TestUtil.HTTP_TEST_PROXY));
		ps.setSelector("https", new FixedProxySelector(TestUtil.HTTPS_TEST_PROXY));
		ps.setSelector("ftp", new FixedProxySelector(TestUtil.FTP_TEST_PROXY));
	}
	
	/*************************************************************************
	 * Test method
	 ************************************************************************/
	@Test
	public void testDispatchHttp() {
		List<Proxy> result = ps.select(TestUtil.HTTP_TEST_URI);
		assertEquals(TestUtil.HTTP_TEST_PROXY, result.get(0));
	}

	/*************************************************************************
	 * Test method
	 ************************************************************************/
	@Test
	public void testDispatchHttps() {
		List<Proxy> result = ps.select(TestUtil.HTTPS_TEST_URI);
		assertEquals(TestUtil.HTTPS_TEST_PROXY, result.get(0));
	}

	/*************************************************************************
	 * Test method
	 ************************************************************************/
	@Test
	public void testDispatchFtp() {
		List<Proxy> result = ps.select(TestUtil.FTP_TEST_URI);
		assertEquals(TestUtil.FTP_TEST_PROXY, result.get(0));
	}
	
	/*************************************************************************
	 * Test method
	 ************************************************************************/
	@Test
	public void testRemove() {
		ProtocolDispatchSelector px = new ProtocolDispatchSelector();
		FixedProxySelector selector = new FixedProxySelector(TestUtil.HTTP_TEST_PROXY);
		px.setSelector("http", selector);
		assertEquals(selector, px.getSelector("http"));
		px.removeSelector("http");
		assertNull(px.getSelector("http"));
	}
	
	/*************************************************************************
	 * Test method
	 ************************************************************************/
	@Test
	public void testFallback() {
		ProtocolDispatchSelector px = new ProtocolDispatchSelector();
		FixedProxySelector selector = new FixedProxySelector(TestUtil.HTTP_TEST_PROXY);
		px.setFallbackSelector(selector);
		
		List<Proxy> proxies = px.select(TestUtil.HTTP_TEST_URI);
		
		assertEquals(TestUtil.HTTP_TEST_PROXY, proxies.get(0));
	}

}