Skip to main content
summaryrefslogtreecommitdiffstats
blob: d4135bfa00d0b29e02f7e13bdd433dd2feb11dd0 (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*******************************************************************************
* Copyright (c) 2006, 2008 Steffen Pingel and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Tasktop Technologies - initial API and implementation
 *******************************************************************************/

package org.eclipse.mylyn.trac.tests.client;

import java.net.Proxy;

import junit.framework.TestCase;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.mylyn.commons.net.IProxyProvider;
import org.eclipse.mylyn.commons.net.WebLocation;
import org.eclipse.mylyn.context.tests.support.TestUtil;
import org.eclipse.mylyn.context.tests.support.TestUtil.Credentials;
import org.eclipse.mylyn.context.tests.support.TestUtil.PrivilegeLevel;
import org.eclipse.mylyn.internal.trac.core.TracClientFactory;
import org.eclipse.mylyn.internal.trac.core.client.ITracClient;
import org.eclipse.mylyn.internal.trac.core.client.ITracClient.Version;
import org.eclipse.mylyn.trac.tests.support.TracTestConstants;

/**
 * Provides a base implementation for test cases that access trac repositories.
 * 
 * @author Steffen Pingel
 */
public abstract class AbstractTracClientTest extends TestCase {

	public String repositoryUrl;

	public ITracClient repository;

	public String username;

	public String password;

	public Version version;

	private final PrivilegeLevel level;

	final IProgressMonitor callback = new NullProgressMonitor();

	public AbstractTracClientTest(Version version, PrivilegeLevel level) {
		this.version = version;
		this.level = level;
	}

	public AbstractTracClientTest(Version version) {
		this(version, PrivilegeLevel.USER);
	}

	public AbstractTracClientTest() {
		this(null, PrivilegeLevel.USER);
	}

	public ITracClient connect096() throws Exception {
		return connect(TracTestConstants.TEST_TRAC_096_URL);
	}

	public ITracClient connect010() throws Exception {
		return connect(TracTestConstants.TEST_TRAC_010_URL);
	}

	public ITracClient connect010DigestAuth() throws Exception {
		return connect(TracTestConstants.TEST_TRAC_010_DIGEST_AUTH_URL);
	}

	public ITracClient connect011() throws Exception {
		return connect(TracTestConstants.TEST_TRAC_011_URL);
	}

	public ITracClient connect(String url) throws Exception {
		return connect(url, Proxy.NO_PROXY);
	}

	public ITracClient connect(String url, Proxy proxy) throws Exception {
		Credentials credentials = TestUtil.readCredentials(level);
		return connect(url, credentials.username, credentials.password, proxy);
	}

	public ITracClient connect(String url, String username, String password) throws Exception {
		return connect(url, username, password, Proxy.NO_PROXY);
	}

	public ITracClient connect(String url, String username, String password, Proxy proxy) throws Exception {
		return connect(url, username, password, proxy, version);
	}

	public ITracClient connect(String url, String username, String password, final Proxy proxy, Version version)
			throws Exception {
		this.repositoryUrl = url;
		this.username = username;
		this.password = password;

		WebLocation location = new WebLocation(url, username, password, new IProxyProvider() {
			public Proxy getProxyForHost(String host, String proxyType) {
				return proxy;
			}
		});
		this.repository = TracClientFactory.createClient(location, version);

		return this.repository;
	}

}

Back to the top