summaryrefslogtreecommitdiffstats
path: root/src/test/java/com/btr/proxy/TestUtil.java
blob: 24fe8e9b7e81d86065f94e46ef87cc1787e6c672 (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
package com.btr.proxy;

import java.io.File;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.Proxy.Type;

/*****************************************************************************
 * This class defines some constants and helper methods for the unit tests.
 * 
 * @author Bernd Rosstauscher (proxyvole@rosstauscher.de) Copyright 2009
 ****************************************************************************/

public class TestUtil {
	
	public static final String TEST_DATA_FOLDER = "data";
	
	public static final Proxy HTTP_TEST_PROXY 	= new Proxy(Type.HTTP, InetSocketAddress.createUnresolved("http_proxy.unit-test.invalid", 8090));
	public static final Proxy HTTPS_TEST_PROXY 	= new Proxy(Type.HTTP, InetSocketAddress.createUnresolved("https_proxy.unit-test.invalid", 8091));
	public static final Proxy FTP_TEST_PROXY 	= new Proxy(Type.HTTP, InetSocketAddress.createUnresolved("ftp_proxy.unit-test.invalid", 8092));
	public static final Proxy SOCKS_TEST_PROXY 	= new Proxy(Type.SOCKS, InetSocketAddress.createUnresolved("socks_proxy.unit-test.invalid", 8095));
	
	public static final URI NO_PROXY_TEST_URI;
	public static final URI HTTP_TEST_URI;
	public static final URI HTTPS_TEST_URI;
	public static final URI FTP_TEST_URI;
	public static final URI SOCKS_TEST_URI;
	public static final URI LOCAL_TEST_URI;
	public static final URI SOCKET_TEST_URI;
	
	// Setup some testing constants.
	static {
		try {
			NO_PROXY_TEST_URI 	= new URI("http://no_proxy.unit-test.invalid/");
			HTTP_TEST_URI 	= new URI("http://host1.unit-test.invalid/");
			HTTPS_TEST_URI 	= new URI("https://host1.unit-test.invalid/");
			FTP_TEST_URI 	= new URI("ftp://host1.unit-test.invalid/");
			SOCKS_TEST_URI 	= new URI("socks://host1.unit-test.invalid/");
			LOCAL_TEST_URI 	= new URI("http://myhost");
			SOCKET_TEST_URI	= new URI("socket://host1.unit-test.invalid/");
		} catch (URISyntaxException e) {
			throw new RuntimeException("URI error"+e.getMessage());
		}
	}
	
	/*************************************************************************
	 * Switch the current user home directory to the to the given test folder.
	 * @param folder the name of the test folder.
	 ************************************************************************/
	
	public static final void setTestDataFolder(String folder)  {
	    File testTargetDir = new File(TestUtil.class.getResource("/").getFile());
		System.setProperty("user.home", 
		        testTargetDir+
				File.separator+TestUtil.TEST_DATA_FOLDER+File.separator+folder);
	}
	
}