Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 150456 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/mylar/trac/tests/TracXmlRpcClientTest.java (-7 / +7 lines)
Lines 32-38 Link Here
32
	}
32
	}
33
33
34
	public void testValidateFailNoAuth() throws Exception {
34
	public void testValidateFailNoAuth() throws Exception {
35
		connect(Constants.TEST_REPOSITORY1_URL, "", "");
35
		connect(Constants.TEST_TRAC_010_URL, "", "");
36
		try {
36
		try {
37
			repository.validate();
37
			repository.validate();
38
			fail("Expected TracLoginException");
38
			fail("Expected TracLoginException");
Lines 60-71 Link Here
60
				return o1.getName().compareTo(o2.getName());
60
				return o1.getName().compareTo(o2.getName());
61
			}
61
			}
62
		});
62
		});
63
		assertEquals("v1", versions[0].getName());
63
		assertEquals("1.0", versions[0].getName());
64
		assertEquals("description1", versions[0].getDescription());
64
		assertEquals("", versions[0].getDescription());
65
		assertEquals(new Date(86400 * 1000), versions[0].getTime());
65
		assertEquals(new Date(0), versions[0].getTime());
66
		assertEquals("v2", versions[1].getName());
66
		assertEquals("2.0", versions[1].getName());
67
		assertEquals("description2", versions[1].getDescription());
67
		assertEquals("", versions[1].getDescription());
68
		assertEquals(new Date(86400 * 2 * 1000), versions[1].getTime());
68
		assertEquals(new Date(0), versions[1].getTime());
69
	}
69
	}
70
70
71
}
71
}
(-)src/org/eclipse/mylar/trac/tests/AbstractTracClientRepositoryTest.java (-13 / +15 lines)
Lines 11-16 Link Here
11
11
12
package org.eclipse.mylar.trac.tests;
12
package org.eclipse.mylar.trac.tests;
13
13
14
import org.eclipse.mylar.core.core.tests.support.MylarTestUtils;
15
import org.eclipse.mylar.core.core.tests.support.MylarTestUtils.Credentials;
16
import org.eclipse.mylar.core.core.tests.support.MylarTestUtils.PrivilegeLevel;
14
import org.eclipse.mylar.internal.trac.core.TracException;
17
import org.eclipse.mylar.internal.trac.core.TracException;
15
import org.eclipse.mylar.internal.trac.core.TracLoginException;
18
import org.eclipse.mylar.internal.trac.core.TracLoginException;
16
import org.eclipse.mylar.internal.trac.core.ITracClient.Version;
19
import org.eclipse.mylar.internal.trac.core.ITracClient.Version;
Lines 27-65 Link Here
27
	}
30
	}
28
31
29
	public void testValidate010() throws Exception {
32
	public void testValidate010() throws Exception {
30
		connect010();
33
		validate(Constants.TEST_TRAC_010_URL);
31
		validate();
32
	}	
34
	}	
33
35
34
	public void testValidate010DigestAuth() throws Exception {
36
	public void testValidate010DigestAuth() throws Exception {
35
		connect010DigestAuth();
37
		validate(Constants.TEST_TRAC_010_DIGEST_AUTH_URL);
36
		validate();
37
	}	
38
	}	
38
39
39
	protected void validate() throws TracException {
40
	protected void validate(String url) throws Exception {
41
		Credentials credentials = MylarTestUtils.readCredentials(PrivilegeLevel.USER);
42
		
43
		// standard connect
44
		connect(url);
40
		repository.validate();
45
		repository.validate();
41
	}
42
46
43
	public void testValidateFailWrongUrl() throws Exception {
47
		// invalid url
44
		connect("http://non.existant/repository");
48
		connect("http://non.existant/repository");
45
		try {
49
		try {
46
			repository.validate();
50
			repository.validate();
47
			fail("Expected TracException");
51
			fail("Expected TracException");
48
		} catch (TracException e) {
52
		} catch (TracException e) {
49
		}
53
		}
50
	}
51
54
52
	public void testValidateFailAuthWrongPassword() throws Exception {
55
		// invalid password
53
		connect(Constants.TEST_REPOSITORY1_URL, Constants.TEST_REPOSITORY1_ADMIN_USERNAME, "wrongpassword");
56
		connect(url, credentials.username, "wrongpassword");
54
		try {
57
		try {
55
			repository.validate();
58
			repository.validate();
56
			fail("Expected TracLoginException");
59
			fail("Expected TracLoginException");
57
		} catch (TracLoginException e) {
60
		} catch (TracLoginException e) {
58
		}
61
		}
59
	}
60
62
61
	public void testValidateFailAuthWrongUsername() throws Exception {
63
		// invalid username
62
		connect(Constants.TEST_REPOSITORY1_URL, "wrongusername", Constants.TEST_REPOSITORY1_ADMIN_PASSWORD);
64
		connect(url, "wrongusername", credentials.password);
63
		try {
65
		try {
64
			repository.validate();
66
			repository.validate();
65
			fail("Expected TracLoginException");
67
			fail("Expected TracLoginException");
(-)src/org/eclipse/mylar/trac/tests/Trac09ClientTest.java (-5 / +7 lines)
Lines 28-39 Link Here
28
	}
28
	}
29
29
30
	public void testValidate096() throws Exception {
30
	public void testValidate096() throws Exception {
31
		connect096();
31
		validate(Constants.TEST_TRAC_096_URL);
32
		validate();
33
	}
32
	}
34
33
35
	public void testValidateAnonymousLogin() throws Exception {
34
	public void testValidateAnonymousLogin() throws Exception {
36
		connect(Constants.TEST_REPOSITORY1_URL, "", "");
35
		connect(Constants.TEST_TRAC_010_URL, "", "");
36
		repository.validate();
37
		
38
		connect(Constants.TEST_TRAC_096_URL, "", "");
37
		repository.validate();
39
		repository.validate();
38
	}
40
	}
39
41
Lines 48-55 Link Here
48
				return o1.getName().compareTo(o2.getName());
50
				return o1.getName().compareTo(o2.getName());
49
			}
51
			}
50
		});
52
		});
51
		assertEquals("v1", versions[0].getName());
53
		assertEquals("1.0", versions[0].getName());
52
		assertEquals("v2", versions[1].getName());
54
		assertEquals("2.0", versions[1].getName());
53
	}
55
	}
54
56
55
}
57
}
(-)src/org/eclipse/mylar/trac/tests/Constants.java (-12 / +3 lines)
Lines 16-37 Link Here
16
 */
16
 */
17
public class Constants {
17
public class Constants {
18
18
19
	public static final String TEST_REPOSITORY1_URL = "http://trac.steffenpingel.de/mylar-test";
20
21
	public static final String TEST_REPOSITORY1_SSL_URL = "https://trac.steffenpingel.de/mylar-test";
22
23
	public static final String TEST_REPOSITORY1_ADMIN_USERNAME = "trac-ticket-admin";
24
25
	public static final String TEST_REPOSITORY1_ADMIN_PASSWORD = "trac-ticket-admin";
26
27
	public static final String TEST_REPOSITORY1_USERNAME = "trac-test";
28
29
	public static final String TEST_REPOSITORY1_PASSWORD = "trac-test";
30
31
	public static final String TEST_TRAC_096_URL = "http://mylar.eclipse.org/trac096";
19
	public static final String TEST_TRAC_096_URL = "http://mylar.eclipse.org/trac096";
32
20
33
	public static final String TEST_TRAC_010_URL = "http://mylar.eclipse.org/trac010";
21
	public static final String TEST_TRAC_010_URL = "http://mylar.eclipse.org/trac010";
34
22
23
	public static final String TEST_TRAC_010_SSL_URL = "https://mylar.eclipse.org/trac010";
24
35
	public static final String TEST_TRAC_010_DIGEST_AUTH_URL = "http://mylar.eclipse.org/trac010digest";
25
	public static final String TEST_TRAC_010_DIGEST_AUTH_URL = "http://mylar.eclipse.org/trac010digest";
26
	
36
27
37
}
28
}
(-)src/org/eclipse/mylar/trac/tests/AbstractTracClientTest.java (-21 / +6 lines)
Lines 11-24 Link Here
11
11
12
package org.eclipse.mylar.trac.tests;
12
package org.eclipse.mylar.trac.tests;
13
13
14
import java.io.File;
15
import java.io.FileInputStream;
16
import java.net.URL;
17
import java.util.Properties;
18
19
import junit.framework.TestCase;
14
import junit.framework.TestCase;
20
15
21
import org.eclipse.core.runtime.FileLocator;
16
import org.eclipse.mylar.core.core.tests.support.MylarTestUtils;
17
import org.eclipse.mylar.core.core.tests.support.MylarTestUtils.Credentials;
18
import org.eclipse.mylar.core.core.tests.support.MylarTestUtils.PrivilegeLevel;
22
import org.eclipse.mylar.internal.trac.core.ITracClient;
19
import org.eclipse.mylar.internal.trac.core.ITracClient;
23
import org.eclipse.mylar.internal.trac.core.TracClientFactory;
20
import org.eclipse.mylar.internal.trac.core.TracClientFactory;
24
import org.eclipse.mylar.internal.trac.core.ITracClient.Version;
21
import org.eclipse.mylar.internal.trac.core.ITracClient.Version;
Lines 49-56 Link Here
49
	}
46
	}
50
47
51
	public ITracClient connect010() throws Exception {
48
	public ITracClient connect010() throws Exception {
52
		return connect(Constants.TEST_REPOSITORY1_URL, Constants.TEST_REPOSITORY1_ADMIN_USERNAME,
49
		return connect(Constants.TEST_TRAC_010_URL);
53
				Constants.TEST_REPOSITORY1_ADMIN_PASSWORD);
54
	}
50
	}
55
51
56
	public ITracClient connect010DigestAuth() throws Exception {
52
	public ITracClient connect010DigestAuth() throws Exception {
Lines 58-73 Link Here
58
	}
54
	}
59
55
60
	public ITracClient connect(String url) throws Exception {
56
	public ITracClient connect(String url) throws Exception {
61
		try {
57
		Credentials credentials = MylarTestUtils.readCredentials(PrivilegeLevel.USER);
62
			Properties properties = new Properties();
58
		return connect(url, credentials.username, credentials.password);
63
			URL localURL = FileLocator.toFileURL(TracTestPlugin.getDefault().getBundle().getEntry(
64
					"credentials.properties"));
65
			properties.load(new FileInputStream(new File(localURL.getFile())));
66
			return connect(url, properties.getProperty("username"), properties.getProperty("password"));
67
		} catch (Throwable t) {
68
			fail("must define credentials in <plug-in dir>/credentials.properties");
69
		}
70
		return null; // never reached
71
	}
59
	}
72
60
73
	public ITracClient connect(String url, String username, String password) throws Exception {
61
	public ITracClient connect(String url, String username, String password) throws Exception {
Lines 76-84 Link Here
76
		this.password = password;
64
		this.password = password;
77
		this.repository = TracClientFactory.createClient(url, version, username, password);
65
		this.repository = TracClientFactory.createClient(url, version, username, password);
78
66
79
		// make sure no dialog pops up to prompt for a password
80
		// Authenticator.setDefault(null);
81
82
		return this.repository;
67
		return this.repository;
83
	}
68
	}
84
69
(-)src/org/eclipse/mylar/trac/tests/TracXmlRpcClientSearchTest.java (-2 / +2 lines)
Lines 37-44 Link Here
37
		assertTicketEquals(tickets.get(0), result.get(0));
37
		assertTicketEquals(tickets.get(0), result.get(0));
38
		assertEquals("component1", result.get(0).getValue(Key.COMPONENT));
38
		assertEquals("component1", result.get(0).getValue(Key.COMPONENT));
39
		assertEquals("description1", result.get(0).getValue(Key.DESCRIPTION));
39
		assertEquals("description1", result.get(0).getValue(Key.DESCRIPTION));
40
		assertEquals("m1", result.get(0).getValue(Key.MILESTONE));
40
		assertEquals("milestone1", result.get(0).getValue(Key.MILESTONE));
41
		assertEquals(username, result.get(0).getValue(Key.REPORTER));
41
		assertEquals("anonymous", result.get(0).getValue(Key.REPORTER));
42
		assertEquals("summary1", result.get(0).getValue(Key.SUMMARY));
42
		assertEquals("summary1", result.get(0).getValue(Key.SUMMARY));
43
		// assertEquals("", result.get(0).getValue(Key.VERSION));
43
		// assertEquals("", result.get(0).getValue(Key.VERSION));
44
	}
44
	}
(-)src/org/eclipse/mylar/trac/tests/TracXmlRpcTest.java (-78 / +75 lines)
Lines 25-38 Link Here
25
import org.apache.xmlrpc.XmlRpcException;
25
import org.apache.xmlrpc.XmlRpcException;
26
import org.apache.xmlrpc.client.XmlRpcClient;
26
import org.apache.xmlrpc.client.XmlRpcClient;
27
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
27
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
28
import org.eclipse.mylar.core.core.tests.support.MylarTestUtils;
29
import org.eclipse.mylar.core.core.tests.support.MylarTestUtils.Credentials;
30
import org.eclipse.mylar.core.core.tests.support.MylarTestUtils.PrivilegeLevel;
28
import org.eclipse.mylar.internal.trac.core.TracHttpClientTransportFactory;
31
import org.eclipse.mylar.internal.trac.core.TracHttpClientTransportFactory;
29
32
30
/**
33
/**
31
 * Test cases for <a href="http://trac-hacks.org/wiki/XmlRpcPlugin">Trac XML-RPC
34
 * Test cases for <a href="http://trac-hacks.org/wiki/XmlRpcPlugin">Trac XML-RPC
32
 * Plugin</a> API. Revision 848 or higher is required.
35
 * Plugin</a> API. Revision 1070 or higher is required.
33
 * 
36
 * 
34
 * <p>
37
 * <p>
35
 * This class does not depend on any of the Mylar connector classes.
38
 * This class does not depend on any Mylar (connector) classes except for
39
 * TracHttpClientTransportFactory which is needed for initialization of
40
 * HttpClient.
36
 * 
41
 * 
37
 * @author Steffen Pingel
42
 * @author Steffen Pingel
38
 */
43
 */
Lines 48-60 Link Here
48
53
49
	private Random random;
54
	private Random random;
50
55
56
	private ArrayList<Integer> tickets;
57
58
	@Override
51
	protected void setUp() throws Exception {
59
	protected void setUp() throws Exception {
52
		super.setUp();
60
		super.setUp();
53
61
54
		random = new Random();
62
		random = new Random();
55
63
56
		createConnection(new URL(Constants.TEST_REPOSITORY1_URL + XMLRPC_URL),
64
		Credentials credentials = MylarTestUtils.readCredentials(PrivilegeLevel.ADMIN);
57
				Constants.TEST_REPOSITORY1_ADMIN_USERNAME, Constants.TEST_REPOSITORY1_ADMIN_PASSWORD);
65
		createConnection(new URL(Constants.TEST_TRAC_010_URL + XMLRPC_URL), credentials.username, credentials.password);
66
67
		tickets = new ArrayList<Integer>();
68
	}
69
70
	@Override
71
	protected void tearDown() throws Exception {
72
		super.tearDown();
73
74
		for (int id : tickets) {
75
			call("ticket.delete", id);
76
		}
58
	}
77
	}
59
78
60
	private void createConnection(URL url, String username, String password) throws Exception {
79
	private void createConnection(URL url, String username, String password) throws Exception {
Lines 63-72 Link Here
63
		config.setBasicUserName(username);
82
		config.setBasicUserName(username);
64
		config.setBasicPassword(password);
83
		config.setBasicPassword(password);
65
		config.setServerURL(url);
84
		config.setServerURL(url);
66
		
85
67
		xmlrpc = new XmlRpcClient();
86
		xmlrpc = new XmlRpcClient();
68
		xmlrpc.setConfig(config);
87
		xmlrpc.setConfig(config);
69
		
88
70
		TracHttpClientTransportFactory factory = new TracHttpClientTransportFactory(xmlrpc);
89
		TracHttpClientTransportFactory factory = new TracHttpClientTransportFactory(xmlrpc);
71
		xmlrpc.setTransportFactory(factory);
90
		xmlrpc.setTransportFactory(factory);
72
91
Lines 74-81 Link Here
74
		// this.password = password;
93
		// this.password = password;
75
	}
94
	}
76
95
77
	protected void tearDown() throws Exception {
96
	private int createTicket(String summary, String description, Map attributes) throws XmlRpcException, IOException {
78
		super.tearDown();
97
		int id = (Integer) call("ticket.create", summary, description, attributes);
98
		tickets.add(id);
99
		return id;
79
	}
100
	}
80
101
81
	private Object call(String method, Object... parameters) throws XmlRpcException, IOException {
102
	private Object call(String method, Object... parameters) throws XmlRpcException, IOException {
Lines 101-114 Link Here
101
		}
122
		}
102
123
103
		call(module + ".create", "foo", "bar");
124
		call(module + ".create", "foo", "bar");
125
		try {
126
			assertHasValue((Object[]) call(module + ".getAll"), "foo");
127
			assertEquals("bar", (String) (call(module + ".get", "foo")));
104
128
105
		assertHasValue((Object[]) call(module + ".getAll"), "foo");
129
			call(module + ".update", "foo", "baz");
106
		assertEquals("bar", (String) (call(module + ".get", "foo")));
130
			assertEquals("baz", (String) (call(module + ".get", "foo")));
107
131
		} finally {
108
		call(module + ".update", "foo", "baz");
132
			call(module + ".delete", "foo");
109
		assertEquals("baz", (String) (call(module + ".get", "foo")));
133
		}
110
111
		call(module + ".delete", "foo");
112
	}
134
	}
113
135
114
	private Object createValue(Object fieldName, Object clazz) {
136
	private Object createValue(Object fieldName, Object clazz) {
Lines 140-162 Link Here
140
162
141
		call(module + ".create", "foo", attributes);
163
		call(module + ".create", "foo", attributes);
142
164
143
		assertHasValue((Object[]) call(module + ".getAll"), "foo");
165
		try {
144
		Map values = (Map) call(module + ".get", "foo");
166
			assertHasValue((Object[]) call(module + ".getAll"), "foo");
145
		for (String attribute : attributes.keySet()) {
167
			Map values = (Map) call(module + ".get", "foo");
146
			assertEquals(attributes.get(attribute), values.get(attribute));
168
			for (String attribute : attributes.keySet()) {
147
		}
169
				assertEquals(attributes.get(attribute), values.get(attribute));
170
			}
148
171
149
		for (int i = 0; i < fields.length; i += 2) {
172
			for (int i = 0; i < fields.length; i += 2) {
150
			attributes.put((String) fields[i], createValue(fields[i], fields[i + 1]));
173
				attributes.put((String) fields[i], createValue(fields[i], fields[i + 1]));
151
		}
174
			}
152
175
153
		call(module + ".update", "foo", attributes);
176
			call(module + ".update", "foo", attributes);
154
		values = (Map) call(module + ".get", "foo");
177
			values = (Map) call(module + ".get", "foo");
155
		for (String attribute : attributes.keySet()) {
178
			for (String attribute : attributes.keySet()) {
156
			assertEquals(attributes.get(attribute), values.get(attribute));
179
				assertEquals(attributes.get(attribute), values.get(attribute));
180
			}
181
		} finally {
182
			call(module + ".delete", "foo");
157
		}
183
		}
158
159
		call(module + ".delete", "foo");
160
	}
184
	}
161
185
162
	public void testMilestoneDate() throws XmlRpcException, IOException {
186
	public void testMilestoneDate() throws XmlRpcException, IOException {
Lines 195-202 Link Here
195
		assertTicketHasAttributes(attributes, id, ticket, true);
219
		assertTicketHasAttributes(attributes, id, ticket, true);
196
	}
220
	}
197
221
198
	private void assertTicketHasAttributes(Map<String, Object> attributes, int id, Object[] ticket,
222
	private void assertTicketHasAttributes(Map<String, Object> attributes, int id, Object[] ticket, boolean newTicket) {
199
			boolean newTicket) {
200
		assertEquals(id, ticket[0]);
223
		assertEquals(id, ticket[0]);
201
		assertTrue(ticket[1] instanceof Integer); // time created
224
		assertTrue(ticket[1] instanceof Integer); // time created
202
		// time changed
225
		// time changed
Lines 215-229 Link Here
215
		Map<String, Object> attributes = new Hashtable<String, Object>();
238
		Map<String, Object> attributes = new Hashtable<String, Object>();
216
		attributes.put("type", "task");
239
		attributes.put("type", "task");
217
		attributes.put("status", "closed");
240
		attributes.put("status", "closed");
218
		int id = (Integer) call("ticket.create", "summary", "description", attributes);
241
		int id = createTicket("summary", "description", attributes);
219
242
220
		attributes.put("summary", "summary");
243
		attributes.put("summary", "summary");
221
		attributes.put("description", "description");
244
		attributes.put("description", "description");
222
245
223
		Object[] ticket = (Object[]) call("ticket.get", id);
246
		Object[] ticket = (Object[]) call("ticket.get", id);
224
		assertTicketHasAttributes(attributes, id, ticket);
247
		assertTicketHasAttributes(attributes, id, ticket);
225
226
		call("ticket.delete", id);
227
	}
248
	}
228
249
229
	public void testGetTicketNonExistant() throws XmlRpcException, IOException {
250
	public void testGetTicketNonExistant() throws XmlRpcException, IOException {
Lines 243-261 Link Here
243
264
244
	public void testGetTicketUmlaute() throws XmlRpcException, IOException {
265
	public void testGetTicketUmlaute() throws XmlRpcException, IOException {
245
		Map<String, Object> attributes = new Hashtable<String, Object>();
266
		Map<String, Object> attributes = new Hashtable<String, Object>();
246
		int id = (Integer) call("ticket.create", "summaryäÖÜ", "ßßß", attributes);
267
		int id = createTicket("summaryäÖÜ", "ßßß", attributes);
247
268
248
		attributes.put("summary", "summaryäÖÜ");
269
		attributes.put("summary", "summaryäÖÜ");
249
		attributes.put("description", "ßßß");
270
		attributes.put("description", "ßßß");
250
271
251
		Object[] ticket = (Object[]) call("ticket.get", id);
272
		Object[] ticket = (Object[]) call("ticket.get", id);
252
		assertTicketHasAttributes(attributes, id, ticket);
273
		assertTicketHasAttributes(attributes, id, ticket);
253
254
		call("ticket.delete", id);
255
	}
274
	}
256
275
257
	public void testUpdateTicket() throws XmlRpcException, IOException {
276
	public void testUpdateTicket() throws XmlRpcException, IOException {
258
		int id = (Integer) call("ticket.create", "summary", "description", new Hashtable());
277
		int id = createTicket("summary", "description", new Hashtable());
259
278
260
		Map<String, Object> attributes = new Hashtable<String, Object>();
279
		Map<String, Object> attributes = new Hashtable<String, Object>();
261
		attributes.put("summary", "changed");
280
		attributes.put("summary", "changed");
Lines 268-281 Link Here
268
		for (String attribute : attributes.keySet()) {
287
		for (String attribute : attributes.keySet()) {
269
			assertEquals(attributes.get(attribute), values.get(attribute));
288
			assertEquals(attributes.get(attribute), values.get(attribute));
270
		}
289
		}
271
272
		call("ticket.delete", id);
273
	}
290
	}
274
291
275
	public void testTicketCustomFields() throws XmlRpcException, IOException {
292
	public void testTicketCustomFields() throws XmlRpcException, IOException {
276
		Map<String, Object> attributes = new Hashtable<String, Object>();
293
		Map<String, Object> attributes = new Hashtable<String, Object>();
277
		attributes.put("custom_text_field", "myvalue");
294
		attributes.put("custom_text_field", "myvalue");
278
		int id = (Integer) call("ticket.create", "summary", "description", attributes);
295
		int id = createTicket("summary", "description", attributes);
279
296
280
		// check for default values
297
		// check for default values
281
		attributes.put("custom_checkbox_field", "1");
298
		attributes.put("custom_checkbox_field", "1");
Lines 296-307 Link Here
296
313
297
		ticket = (Object[]) call("ticket.get", id);
314
		ticket = (Object[]) call("ticket.get", id);
298
		assertTicketHasAttributes(attributes, id, ticket, false);
315
		assertTicketHasAttributes(attributes, id, ticket, false);
299
300
		call("ticket.delete", id);
301
	}
316
	}
302
317
303
	public void testGetChangeLog() throws XmlRpcException, IOException {
318
	public void testGetChangeLog() throws XmlRpcException, IOException {
304
		int id = (Integer) call("ticket.create", "summary", "description", new Hashtable());
319
		int id = createTicket("summary", "description", new Hashtable());
305
320
306
		Map<String, Object> attributes = new Hashtable<String, Object>();
321
		Map<String, Object> attributes = new Hashtable<String, Object>();
307
		attributes.put("summary", "changed");
322
		attributes.put("summary", "changed");
Lines 314-326 Link Here
314
		assertEquals("summary", entry[2]); // field
329
		assertEquals("summary", entry[2]); // field
315
		assertEquals("summary", entry[3]); // old value
330
		assertEquals("summary", entry[3]); // old value
316
		assertEquals("changed", entry[4]); // new value
331
		assertEquals("changed", entry[4]); // new value
317
318
		call("ticket.delete", id);
319
	}
332
	}
320
333
321
	public void testMultiGetTicket() throws XmlRpcException, IOException {
334
	public void testMultiGetTicket() throws XmlRpcException, IOException {
322
		int id1 = (Integer) call("ticket.create", "summary1", "description1", new Hashtable());
335
		int id1 = createTicket("summary1", "description1", new Hashtable());
323
		int id2 = (Integer) call("ticket.create", "summary2", "description2", new Hashtable());
336
		int id2 = createTicket("summary2", "description2", new Hashtable());
324
337
325
		List<Map> calls = new ArrayList<Map>();
338
		List<Map> calls = new ArrayList<Map>();
326
		calls.add(createMultiCall("ticket.get", id1));
339
		calls.add(createMultiCall("ticket.get", id1));
Lines 338-350 Link Here
338
		attributes.put("summary", "summary2");
351
		attributes.put("summary", "summary2");
339
		attributes.put("description", "description2");
352
		attributes.put("description", "description2");
340
		assertTicketHasAttributes(attributes, id2, ticket);
353
		assertTicketHasAttributes(attributes, id2, ticket);
341
342
		call("ticket.delete", id1);
343
		call("ticket.delete", id2);
344
	}
354
	}
345
355
346
	public void testAttachment() throws XmlRpcException, IOException {
356
	public void testAttachment() throws XmlRpcException, IOException {
347
		int id = (Integer) call("ticket.create", "summary", "description", new Hashtable());
357
		int id = createTicket("summary", "description", new Hashtable());
348
358
349
		String filename = (String) call("ticket.putAttachment", id, "attach.txt", "data".getBytes(), true);
359
		String filename = (String) call("ticket.putAttachment", id, "attach.txt", "data".getBytes(), true);
350
		// the returned filename may differ, since another ticket may have an
360
		// the returned filename may differ, since another ticket may have an
Lines 371-382 Link Here
371
		assertEquals(2, ret.length);
381
		assertEquals(2, ret.length);
372
		assertHasValue(ret, filename);
382
		assertHasValue(ret, filename);
373
		assertHasValue(ret, filename3);
383
		assertHasValue(ret, filename3);
374
375
		call("ticket.delete", id);
376
	}
384
	}
377
385
378
	public void testDeleteAttachment() throws XmlRpcException, IOException {
386
	public void testDeleteAttachment() throws XmlRpcException, IOException {
379
		int id = (Integer) call("ticket.create", "summary", "description", new Hashtable());
387
		int id = createTicket("summary", "description", new Hashtable());
380
388
381
		String filename = (String) call("ticket.putAttachment", id, "attach.txt", "data".getBytes(), true);
389
		String filename = (String) call("ticket.putAttachment", id, "attach.txt", "data".getBytes(), true);
382
390
Lines 388-440 Link Here
388
396
389
		ret = (Object[]) call("ticket.listAttachments", id);
397
		ret = (Object[]) call("ticket.listAttachments", id);
390
		assertEquals(0, ret.length);
398
		assertEquals(0, ret.length);
391
392
		call("ticket.delete", id);
393
	}
399
	}
394
400
395
	public void testQuery() throws XmlRpcException, IOException {
401
	public void testQuery() throws XmlRpcException, IOException {
396
		Object[] ret = (Object[]) call("ticket.query", "summary~=foo|bar|baz|summary|ticket");
402
		Object[] ret = (Object[]) call("ticket.query", "summary~=foo|bar|baz");
397
		for (Object id : ret) {
403
		for (Object id : ret) {
398
			call("ticket.delete", (Integer) id);
404
			call("ticket.delete", (Integer) id);
399
		}
405
		}
400
406
401
		int id1 = (Integer) call("ticket.create", "foobarsummary1", "description", new Hashtable());
407
		int id1 = createTicket("foobarsum1", "description", new Hashtable());
402
		int id2 = (Integer) call("ticket.create", "foobaz summary2", "description", new Hashtable());
408
		int id2 = createTicket("foobaz sum2", "description", new Hashtable());
403
		int id3 = (Integer) call("ticket.create", "ticket3", "description3", new Hashtable());
409
		int id3 = createTicket("foobarbaz3", "foobarbaz description3", new Hashtable());
404
410
405
		ret = (Object[]) call("ticket.query", "summary=foobarsummary1|foobaz summary2");
411
		ret = (Object[]) call("ticket.query", "summary=foobarsum1|foobaz sum2");
406
		assertEquals(2, ret.length);
412
		assertEquals(2, ret.length);
407
		assertEquals(id1, ret[0]);
413
		assertEquals(id1, ret[0]);
408
		assertEquals(id2, ret[1]);
414
		assertEquals(id2, ret[1]);
409
415
410
		ret = (Object[]) call("ticket.query", "summary~=fooba&summary~=summary");
416
		// the first criterium is ignored
411
		assertEquals(2, ret.length);
417
		ret = (Object[]) call("ticket.query", "summary~=foobarsum1&summary~=foobaz sum2");
412
		assertEquals(id1, ret[0]);
418
		assertEquals(1, ret.length);
413
		assertEquals(id2, ret[1]);
419
		assertEquals(id2, ret[0]);
414
415
		// ret = (Vector) call("ticket.query", "summary~=bar&summary~=baz");
416
		// assertEquals(0, ret.size());
417
420
418
		ret = (Object[]) call("ticket.query", "summary~=bar|baz");
421
		ret = (Object[]) call("ticket.query", "summary~=bar|baz");
419
		assertEquals(2, ret.length);
422
		assertEquals(3, ret.length);
420
423
421
		ret = (Object[]) call("ticket.query", "description~=description3");
424
		ret = (Object[]) call("ticket.query", "description~=foobarbaz description3");
422
		assertEquals(1, ret.length);
425
		assertEquals(1, ret.length);
423
		assertEquals(id3, ret[0]);
426
		assertEquals(id3, ret[0]);
424
425
		call("ticket.delete", id1);
426
		call("ticket.delete", id2);
427
		call("ticket.delete", id3);
428
	}
427
	}
429
428
430
	public void testQueryAll() throws XmlRpcException, IOException {
429
	public void testQueryAll() throws XmlRpcException, IOException {
431
		int id = (Integer) call("ticket.create", "foo", "description", new Hashtable());
430
		int id = createTicket("foo", "description", new Hashtable());
432
431
433
		Object[] ret = (Object[]) call("ticket.query", "order=id");
432
		Object[] ret = (Object[]) call("ticket.query", "order=id");
434
		assertTrue(ret.length > 0);
433
		assertTrue(ret.length > 0);
435
		assertHasValue(ret, id);
434
		assertHasValue(ret, id);
436
437
		call("ticket.delete", id);
438
	}
435
	}
439
436
440
	public void testPriorities() throws XmlRpcException, IOException {
437
	public void testPriorities() throws XmlRpcException, IOException {
(-)src/org/eclipse/mylar/trac/tests/AbstractTracClientSearchTest.java (-5 / +5 lines)
Lines 100-106 Link Here
100
100
101
	public void testSearchMilestone1() throws Exception {
101
	public void testSearchMilestone1() throws Exception {
102
		TracSearch search = new TracSearch();
102
		TracSearch search = new TracSearch();
103
		search.addFilter("milestone", "m1");
103
		search.addFilter("milestone", "milestone1");
104
		List<TracTicket> result = new ArrayList<TracTicket>();
104
		List<TracTicket> result = new ArrayList<TracTicket>();
105
		repository.search(search, result);
105
		repository.search(search, result);
106
		assertEquals(1, result.size());
106
		assertEquals(1, result.size());
Lines 109-116 Link Here
109
109
110
	public void testSearchMilestone2() throws Exception {
110
	public void testSearchMilestone2() throws Exception {
111
		TracSearch search = new TracSearch();
111
		TracSearch search = new TracSearch();
112
		search.addFilter("milestone", "m1");
112
		search.addFilter("milestone", "milestone1");
113
		search.addFilter("milestone", "m2");
113
		search.addFilter("milestone", "milestone2");
114
		search.setOrderBy("id");
114
		search.setOrderBy("id");
115
		List<TracTicket> result = new ArrayList<TracTicket>();
115
		List<TracTicket> result = new ArrayList<TracTicket>();
116
		repository.search(search, result);
116
		repository.search(search, result);
Lines 122-134 Link Here
122
122
123
	public void testSearchExactMatch() throws Exception {
123
	public void testSearchExactMatch() throws Exception {
124
		TracSearch search = new TracSearch();
124
		TracSearch search = new TracSearch();
125
		search.addFilter("milestone", "m1");
125
		search.addFilter("milestone", "milestone1");
126
		search.addFilter("summary", "summary1");
126
		search.addFilter("summary", "summary1");
127
		List<TracTicket> result = new ArrayList<TracTicket>();
127
		List<TracTicket> result = new ArrayList<TracTicket>();
128
		repository.search(search, result);
128
		repository.search(search, result);
129
		assertEquals(1, result.size());
129
		assertEquals(1, result.size());
130
		assertTicketEquals(tickets.get(0), result.get(0));
130
		assertTicketEquals(tickets.get(0), result.get(0));
131
		assertEquals("m1", result.get(0).getValue(Key.MILESTONE));
131
		assertEquals("milestone1", result.get(0).getValue(Key.MILESTONE));
132
		assertEquals("summary1", result.get(0).getValue(Key.SUMMARY));
132
		assertEquals("summary1", result.get(0).getValue(Key.SUMMARY));
133
	}
133
	}
134
134
(-)src/org/eclipse/mylar/trac/tests/TracRepositoryConnectorTest.java (-26 / +37 lines)
Lines 20-30 Link Here
20
import org.eclipse.core.runtime.MultiStatus;
20
import org.eclipse.core.runtime.MultiStatus;
21
import org.eclipse.core.runtime.NullProgressMonitor;
21
import org.eclipse.core.runtime.NullProgressMonitor;
22
import org.eclipse.jface.wizard.WizardDialog;
22
import org.eclipse.jface.wizard.WizardDialog;
23
import org.eclipse.mylar.core.core.tests.support.MylarTestUtils;
24
import org.eclipse.mylar.core.core.tests.support.MylarTestUtils.Credentials;
25
import org.eclipse.mylar.core.core.tests.support.MylarTestUtils.PrivilegeLevel;
23
import org.eclipse.mylar.internal.tasks.ui.wizards.EditRepositoryWizard;
26
import org.eclipse.mylar.internal.tasks.ui.wizards.EditRepositoryWizard;
24
import org.eclipse.mylar.internal.trac.TracUiPlugin;
25
import org.eclipse.mylar.internal.trac.TracRepositoryConnector;
27
import org.eclipse.mylar.internal.trac.TracRepositoryConnector;
26
import org.eclipse.mylar.internal.trac.TracRepositoryQuery;
28
import org.eclipse.mylar.internal.trac.TracRepositoryQuery;
27
import org.eclipse.mylar.internal.trac.TracTask;
29
import org.eclipse.mylar.internal.trac.TracTask;
30
import org.eclipse.mylar.internal.trac.TracUiPlugin;
28
import org.eclipse.mylar.internal.trac.core.ITracClient;
31
import org.eclipse.mylar.internal.trac.core.ITracClient;
29
import org.eclipse.mylar.internal.trac.core.InvalidTicketException;
32
import org.eclipse.mylar.internal.trac.core.InvalidTicketException;
30
import org.eclipse.mylar.internal.trac.core.ITracClient.Version;
33
import org.eclipse.mylar.internal.trac.core.ITracClient.Version;
Lines 76-87 Link Here
76
		// TestFixture.cleanupRepository1();
79
		// TestFixture.cleanupRepository1();
77
	}
80
	}
78
81
79
	protected void init(Version version) {
82
	protected void init(String url, Version version) {
80
		String kind = TracUiPlugin.REPOSITORY_KIND;
83
		String kind = TracUiPlugin.REPOSITORY_KIND;
84
		Credentials credentials = MylarTestUtils.readCredentials(PrivilegeLevel.USER);
81
85
82
		repository = new TaskRepository(kind, Constants.TEST_REPOSITORY1_URL);
86
		repository = new TaskRepository(kind, url);
83
		repository.setAuthenticationCredentials(Constants.TEST_REPOSITORY1_USERNAME,
87
		repository.setAuthenticationCredentials(credentials.username, credentials.password);
84
				Constants.TEST_REPOSITORY1_USERNAME);
85
		repository.setTimeZoneId(ITracClient.TIME_ZONE);
88
		repository.setTimeZoneId(ITracClient.TIME_ZONE);
86
		repository.setCharacterEncoding(ITracClient.CHARSET);
89
		repository.setCharacterEncoding(ITracClient.CHARSET);
87
		repository.setVersion(version.name());
90
		repository.setVersion(version.name());
Lines 103-115 Link Here
103
		assertEquals(null, connector.getRepositoryUrlFromTaskUrl("http://host/repo/ticket-2342"));
106
		assertEquals(null, connector.getRepositoryUrlFromTaskUrl("http://host/repo/ticket-2342"));
104
	}
107
	}
105
108
106
	public void testCreateTaskFromExistingKeyXmlRpc() {
109
	public void testCreateTaskFromExistingKeyXmlRpc_010() {
107
		init(Version.XML_RPC);
110
		init(Constants.TEST_TRAC_010_URL, Version.XML_RPC);
111
		createTaskFromExistingKey();
112
	}
113
114
	public void testCreateTaskFromExistingKeyTrac09_010() {
115
		init(Constants.TEST_TRAC_010_URL, Version.TRAC_0_9);
108
		createTaskFromExistingKey();
116
		createTaskFromExistingKey();
109
	}
117
	}
110
118
111
	public void testCreateTaskFromExistingKeyTrac09() {
119
	public void testCreateTaskFromExistingKeyTrac09_096() {
112
		init(Version.TRAC_0_9);
120
		init(Constants.TEST_TRAC_096_URL, Version.TRAC_0_9);
113
		createTaskFromExistingKey();
121
		createTaskFromExistingKey();
114
	}
122
	}
115
123
Lines 129-135 Link Here
129
	}
137
	}
130
138
131
	public void testClientManagerChangeTaskRepositorySettings() throws MalformedURLException {
139
	public void testClientManagerChangeTaskRepositorySettings() throws MalformedURLException {
132
		init(Version.TRAC_0_9);
140
		init(Constants.TEST_TRAC_010_URL, Version.TRAC_0_9);
133
		ITracClient client = connector.getClientManager().getRepository(repository);
141
		ITracClient client = connector.getClientManager().getRepository(repository);
134
		assertEquals(Version.TRAC_0_9, client.getVersion());
142
		assertEquals(Version.TRAC_0_9, client.getVersion());
135
143
Lines 145-169 Link Here
145
		assertEquals(Version.XML_RPC, client.getVersion());
153
		assertEquals(Version.XML_RPC, client.getVersion());
146
	}
154
	}
147
155
148
	public void testPerformQueryXmlRpc() {
156
	public void testPerformQueryXmlRpc_010() {
149
		init(Version.XML_RPC);
157
		performQuery(Constants.TEST_TRAC_010_URL, Version.XML_RPC);
150
		performQuery();
158
	}
159
160
	public void testPerformQueryTrac09_010() {
161
		performQuery(Constants.TEST_TRAC_010_URL, Version.TRAC_0_9);
151
	}
162
	}
152
163
153
	public void testPerformQueryTrac09() {
164
	public void testPerformQueryTrac09_096() {
154
		init(Version.TRAC_0_9);
165
		performQuery(Constants.TEST_TRAC_096_URL, Version.TRAC_0_9);
155
		performQuery();
156
	}
166
	}
157
167
158
	protected void performQuery() {
168
	protected void performQuery(String url, Version version) {
169
		init(url, version);
170
159
		TracSearch search = new TracSearch();
171
		TracSearch search = new TracSearch();
160
		search.addFilter("milestone", "m1");
172
		search.addFilter("milestone", "milestone1");
161
		search.addFilter("milestone", "m2");
173
		search.addFilter("milestone", "milestone2");
162
		search.setOrderBy("id");
174
		search.setOrderBy("id");
163
175
164
		String queryUrl = Constants.TEST_REPOSITORY1_URL + ITracClient.QUERY_URL + search.toUrl();
176
		String queryUrl = url + ITracClient.QUERY_URL + search.toUrl();
165
		TracRepositoryQuery query = new TracRepositoryQuery(Constants.TEST_REPOSITORY1_URL, queryUrl, "description",
177
		TracRepositoryQuery query = new TracRepositoryQuery(url, queryUrl, "description", tasklist);
166
				tasklist);
167
178
168
		MultiStatus queryStatus = new MultiStatus(TracUiPlugin.PLUGIN_ID, IStatus.OK, "Query result", null);
179
		MultiStatus queryStatus = new MultiStatus(TracUiPlugin.PLUGIN_ID, IStatus.OK, "Query result", null);
169
		List<AbstractQueryHit> result = connector.performQuery(query, new NullProgressMonitor(), queryStatus);
180
		List<AbstractQueryHit> result = connector.performQuery(query, new NullProgressMonitor(), queryStatus);
Lines 183-191 Link Here
183
		ticket.putBuiltinValue(Key.TYPE, "mytype");
194
		ticket.putBuiltinValue(Key.TYPE, "mytype");
184
195
185
		TracTask task = new TracTask("", "", true);
196
		TracTask task = new TracTask("", "", true);
186
		TracRepositoryConnector.updateTaskDetails(Constants.TEST_REPOSITORY1_URL, task, ticket, false);
197
		TracRepositoryConnector.updateTaskDetails(Constants.TEST_TRAC_010_URL, task, ticket, false);
187
198
188
		assertEquals(Constants.TEST_REPOSITORY1_URL + ITracClient.TICKET_URL + "123", task.getUrl());
199
		assertEquals(Constants.TEST_TRAC_010_URL + ITracClient.TICKET_URL + "123", task.getUrl());
189
		assertEquals("123: mysummary", task.getDescription());
200
		assertEquals("123: mysummary", task.getDescription());
190
		assertEquals("P3", task.getPriority());
201
		assertEquals("P3", task.getPriority());
191
		assertEquals("mytype", task.getTaskType());
202
		assertEquals("mytype", task.getTaskType());
Lines 196-204 Link Here
196
		ticket.putBuiltinValue(Key.SUMMARY, "mysummary");
207
		ticket.putBuiltinValue(Key.SUMMARY, "mysummary");
197
208
198
		TracTask task = new TracTask("", "", true);
209
		TracTask task = new TracTask("", "", true);
199
		TracRepositoryConnector.updateTaskDetails(Constants.TEST_REPOSITORY1_URL, task, ticket, false);
210
		TracRepositoryConnector.updateTaskDetails(Constants.TEST_TRAC_010_URL, task, ticket, false);
200
211
201
		assertEquals(Constants.TEST_REPOSITORY1_URL + ITracClient.TICKET_URL + "456", task.getUrl());
212
		assertEquals(Constants.TEST_TRAC_010_URL + ITracClient.TICKET_URL + "456", task.getUrl());
202
		assertEquals("456: mysummary", task.getDescription());
213
		assertEquals("456: mysummary", task.getDescription());
203
		assertEquals("P3", task.getPriority());
214
		assertEquals("P3", task.getPriority());
204
		assertEquals(null, task.getTaskType());
215
		assertEquals(null, task.getTaskType());
(-)src/org/eclipse/mylar/trac/tests/TracClientFactoryTest.java (-24 / +31 lines)
Lines 11-20 Link Here
11
11
12
package org.eclipse.mylar.trac.tests;
12
package org.eclipse.mylar.trac.tests;
13
13
14
import java.net.Authenticator;
15
16
import junit.framework.TestCase;
14
import junit.framework.TestCase;
17
15
16
import org.eclipse.mylar.core.core.tests.support.MylarTestUtils;
17
import org.eclipse.mylar.core.core.tests.support.MylarTestUtils.Credentials;
18
import org.eclipse.mylar.core.core.tests.support.MylarTestUtils.PrivilegeLevel;
18
import org.eclipse.mylar.internal.trac.core.ITracClient;
19
import org.eclipse.mylar.internal.trac.core.ITracClient;
19
import org.eclipse.mylar.internal.trac.core.Trac09Client;
20
import org.eclipse.mylar.internal.trac.core.Trac09Client;
20
import org.eclipse.mylar.internal.trac.core.TracClientFactory;
21
import org.eclipse.mylar.internal.trac.core.TracClientFactory;
Lines 28-80 Link Here
28
 */
29
 */
29
public class TracClientFactoryTest extends TestCase {
30
public class TracClientFactoryTest extends TestCase {
30
31
31
	@Override
32
	protected void setUp() throws Exception {
33
		super.setUp();
34
		
35
		// make sure no dialog pops up to prompt for a password
36
		Authenticator.setDefault(null);
37
	}
38
	
39
	public void testCreateClient() throws Exception {
32
	public void testCreateClient() throws Exception {
40
		ITracClient client = TracClientFactory.createClient(Constants.TEST_REPOSITORY1_URL, Version.TRAC_0_9, "user",
33
		ITracClient client = TracClientFactory.createClient(Constants.TEST_TRAC_010_URL, Version.TRAC_0_9, "user",
41
				"password");
34
				"password");
42
		assertTrue(client instanceof Trac09Client);
35
		assertTrue(client instanceof Trac09Client);
43
		client = TracClientFactory.createClient(Constants.TEST_REPOSITORY1_SSL_URL, Version.TRAC_0_9, "user",
36
		client = TracClientFactory.createClient(Constants.TEST_TRAC_010_SSL_URL, Version.TRAC_0_9, "user", "password");
44
				"password");
45
		assertTrue(client instanceof Trac09Client);
37
		assertTrue(client instanceof Trac09Client);
46
38
47
		client = TracClientFactory.createClient(Constants.TEST_REPOSITORY1_URL, Version.XML_RPC, "user", "password");
39
		client = TracClientFactory.createClient(Constants.TEST_TRAC_010_URL, Version.XML_RPC, "user", "password");
48
		assertTrue(client instanceof TracXmlRpcClient);
40
		assertTrue(client instanceof TracXmlRpcClient);
49
		client = TracClientFactory
41
		client = TracClientFactory.createClient(Constants.TEST_TRAC_010_SSL_URL, Version.XML_RPC, "user", "password");
50
				.createClient(Constants.TEST_REPOSITORY1_SSL_URL, Version.XML_RPC, "user", "password");
51
		assertTrue(client instanceof TracXmlRpcClient);
42
		assertTrue(client instanceof TracXmlRpcClient);
52
	}
43
	}
53
44
54
	public void testCreateClientNull() throws Exception {
45
	public void testCreateClientNull() throws Exception {
55
		try {
46
		try {
56
			TracClientFactory.createClient(Constants.TEST_REPOSITORY1_SSL_URL, null, "user", "password");
47
			TracClientFactory.createClient(Constants.TEST_TRAC_010_URL, null, "user", "password");
57
			fail("Expected Exception");
48
			fail("Expected Exception");
58
		} catch (Exception e) {
49
		} catch (Exception e) {
59
		}
50
		}
60
	}
51
	}
61
52
62
	public void testProbeClient() throws Exception {
53
	public void testProbeClient096() throws Exception {
63
		Version version = TracClientFactory.probeClient(Constants.TEST_REPOSITORY1_URL,
54
		probeClient(Constants.TEST_TRAC_096_URL, false);
64
				Constants.TEST_REPOSITORY1_USERNAME, Constants.TEST_REPOSITORY1_PASSWORD);
55
	}
65
		assertEquals(Version.XML_RPC, version);
56
57
	public void testProbeClient010() throws Exception {
58
		probeClient(Constants.TEST_TRAC_010_URL, true);
59
	}
60
61
	public void testProbeClient010DigestAuth() throws Exception {
62
		probeClient(Constants.TEST_TRAC_010_DIGEST_AUTH_URL, true);
63
	}
64
65
	protected void probeClient(String url, boolean xmlrpcInstalled) throws Exception {
66
		Credentials credentials = MylarTestUtils.readCredentials(PrivilegeLevel.USER);
67
		Version version = TracClientFactory.probeClient(url, credentials.username, credentials.password);
68
		if (xmlrpcInstalled) {
69
			assertEquals(Version.XML_RPC, version);
70
		} else {
71
			assertEquals(Version.TRAC_0_9, version);
72
		}
66
73
67
		version = TracClientFactory.probeClient(Constants.TEST_REPOSITORY1_URL, "", "");
74
		version = TracClientFactory.probeClient(url, "", "");
68
		assertEquals(Version.TRAC_0_9, version);
75
		assertEquals(Version.TRAC_0_9, version);
69
76
70
		try {
77
		try {
71
			version = TracClientFactory.probeClient(Constants.TEST_REPOSITORY1_URL, "invaliduser", "password");
78
			version = TracClientFactory.probeClient(url, "invaliduser", "password");
72
			fail("Expected TracLoginException, got " + version);
79
			fail("Expected TracLoginException, got " + version);
73
		} catch (TracLoginException e) {
80
		} catch (TracLoginException e) {
74
		}
81
		}
75
82
76
		try {
83
		try {
77
			version = TracClientFactory.probeClient(Constants.TEST_REPOSITORY1_URL + "/nonexistant", "", "");
84
			version = TracClientFactory.probeClient(url + "/nonexistant", "", "");
78
			fail("Expected TracException, got " + version);
85
			fail("Expected TracException, got " + version);
79
		} catch (TracException e) {
86
		} catch (TracException e) {
80
		}
87
		}
(-).refactorings/2006/7/30/refactorings.history (+2 lines)
Lines 3-6 Link Here
3
<refactoring comment="Rename method 'org.eclipse.mylar.trac.tests.support.TracTestRepositoryFactory.connectRepository1()' to 'connect010'&#10;- Original element: 'org.eclipse.mylar.trac.tests.support.TracTestRepositoryFactory.connectRepository1()'&#10;- Renamed element: 'org.eclipse.mylar.trac.tests.support.TracTestRepositoryFactory.connect010()'&#10;- Update references to refactored element" delegate="false" deprecate="true" description="Rename method 'connectRepository1'" flags="589830" id="org.eclipse.jdt.ui.rename.method" input="/src&lt;org.eclipse.mylar.trac.tests.support{TracTestRepositoryFactory.java[TracTestRepositoryFactory~connectRepository1" name="connect010" references="true" stamp="1154029296744" version="1.0"/>
3
<refactoring comment="Rename method 'org.eclipse.mylar.trac.tests.support.TracTestRepositoryFactory.connectRepository1()' to 'connect010'&#10;- Original element: 'org.eclipse.mylar.trac.tests.support.TracTestRepositoryFactory.connectRepository1()'&#10;- Renamed element: 'org.eclipse.mylar.trac.tests.support.TracTestRepositoryFactory.connect010()'&#10;- Update references to refactored element" delegate="false" deprecate="true" description="Rename method 'connectRepository1'" flags="589830" id="org.eclipse.jdt.ui.rename.method" input="/src&lt;org.eclipse.mylar.trac.tests.support{TracTestRepositoryFactory.java[TracTestRepositoryFactory~connectRepository1" name="connect010" references="true" stamp="1154029296744" version="1.0"/>
4
<refactoring comment="Rename method 'org.eclipse.mylar.trac.tests.support.TestFixture.initializeRepository1()' to 'init010'&#10;- Original element: 'org.eclipse.mylar.trac.tests.support.TestFixture.initializeRepository1()'&#10;- Renamed element: 'org.eclipse.mylar.trac.tests.support.TestFixture.init010()'&#10;- Update references to refactored element" delegate="false" deprecate="true" description="Rename method 'initializeRepository1'" flags="589830" id="org.eclipse.jdt.ui.rename.method" input="/src&lt;org.eclipse.mylar.trac.tests.support{TestFixture.java[TestFixture~initializeRepository1" name="init010" references="true" stamp="1154029842945" version="1.0"/>
4
<refactoring comment="Rename method 'org.eclipse.mylar.trac.tests.support.TestFixture.initializeRepository1()' to 'init010'&#10;- Original element: 'org.eclipse.mylar.trac.tests.support.TestFixture.initializeRepository1()'&#10;- Renamed element: 'org.eclipse.mylar.trac.tests.support.TestFixture.init010()'&#10;- Update references to refactored element" delegate="false" deprecate="true" description="Rename method 'initializeRepository1'" flags="589830" id="org.eclipse.jdt.ui.rename.method" input="/src&lt;org.eclipse.mylar.trac.tests.support{TestFixture.java[TestFixture~initializeRepository1" name="init010" references="true" stamp="1154029842945" version="1.0"/>
5
<refactoring comment="Rename method 'org.eclipse.mylar.trac.tests.support.TestFixture.cleanupRepository1()' to 'cleanup010'&#10;- Original element: 'org.eclipse.mylar.trac.tests.support.TestFixture.cleanupRepository1()'&#10;- Renamed element: 'org.eclipse.mylar.trac.tests.support.TestFixture.cleanup010()'&#10;- Update references to refactored element" delegate="false" deprecate="true" description="Rename method 'cleanupRepository1'" flags="589830" id="org.eclipse.jdt.ui.rename.method" input="/src&lt;org.eclipse.mylar.trac.tests.support{TestFixture.java[TestFixture~cleanupRepository1" name="cleanup010" references="true" stamp="1154029855355" version="1.0"/>
5
<refactoring comment="Rename method 'org.eclipse.mylar.trac.tests.support.TestFixture.cleanupRepository1()' to 'cleanup010'&#10;- Original element: 'org.eclipse.mylar.trac.tests.support.TestFixture.cleanupRepository1()'&#10;- Renamed element: 'org.eclipse.mylar.trac.tests.support.TestFixture.cleanup010()'&#10;- Update references to refactored element" delegate="false" deprecate="true" description="Rename method 'cleanupRepository1'" flags="589830" id="org.eclipse.jdt.ui.rename.method" input="/src&lt;org.eclipse.mylar.trac.tests.support{TestFixture.java[TestFixture~cleanupRepository1" name="cleanup010" references="true" stamp="1154029855355" version="1.0"/>
6
<refactoring comment="Rename field 'TEST_REPOSITORY1_URL' in 'org.eclipse.mylar.trac.tests.Constants' to 'TEST_TRAC_010_URL'&#10;- Original element: 'org.eclipse.mylar.trac.tests.Constants.TEST_REPOSITORY1_URL'&#10;- Renamed element: 'org.eclipse.mylar.trac.tests.Constants.TEST_TRAC_010_URL'&#10;- Update references to refactored element&#10;- Update textual occurrences in comments and strings" delegate="false" deprecate="true" description="Rename field 'TEST_REPOSITORY1_URL'" flags="589830" getter="false" id="org.eclipse.jdt.ui.rename.field" input="/src&lt;org.eclipse.mylar.trac.tests{Constants.java[Constants^TEST_REPOSITORY1_URL" name="TEST_TRAC_010_URL" references="true" setter="false" stamp="1154273808025" textual="false" version="1.0"/>
7
<refactoring comment="Rename type 'org.eclipse.mylar.trac.tests.support.TracTestUtils' to 'MylarTestUtils'&#10;- Original element: 'org.eclipse.mylar.trac.tests.support.TracTestUtils'&#10;- Renamed element: 'org.eclipse.mylar.trac.tests.support.MylarTestUtils'&#10;- Update references to refactored element&#10;- Update textual occurrences in comments and strings" description="Rename type 'TracTestUtils'" flags="589830" id="org.eclipse.jdt.ui.rename.type" input="/src&lt;org.eclipse.mylar.trac.tests.support{TracTestUtils.java[TracTestUtils" matchStrategy="1" name="MylarTestUtils" qualified="false" references="true" similarDeclarations="false" stamp="1154294077466" textual="false" version="1.0"/>
6
</session>
8
</session>
(-).refactorings/2006/7/30/refactorings.index (+2 lines)
Lines 1-3 Link Here
1
1154029296744	Rename method 'connectRepository1'
1
1154029296744	Rename method 'connectRepository1'
2
1154294077466	Rename type 'TracTestUtils'
3
1154273808025	Rename field 'TEST_REPOSITORY1_URL'
2
1154029855355	Rename method 'cleanupRepository1'
4
1154029855355	Rename method 'cleanupRepository1'
3
1154029842945	Rename method 'initializeRepository1'
5
1154029842945	Rename method 'initializeRepository1'
(-)src/org/eclipse/mylar/trac/tests/support/XmlRpcServer.java (-2 / +2 lines)
Lines 35-45 Link Here
35
35
36
		public abstract void delete() throws Exception;
36
		public abstract void delete() throws Exception;
37
37
38
		protected void itemCreated() {
38
		void itemCreated() {
39
			data.items.add(this);
39
			data.items.add(this);
40
		}
40
		}
41
41
42
		protected void itemDeleted() {
42
		void itemDeleted() {
43
			data.items.remove(this);
43
			data.items.remove(this);
44
		}
44
		}
45
45
(-)src/org/eclipse/mylar/trac/tests/support/TestFixture.java (-27 / +53 lines)
Lines 11-18 Link Here
11
11
12
package org.eclipse.mylar.trac.tests.support;
12
package org.eclipse.mylar.trac.tests.support;
13
13
14
import org.eclipse.mylar.core.core.tests.support.MylarTestUtils;
15
import org.eclipse.mylar.core.core.tests.support.MylarTestUtils.Credentials;
16
import org.eclipse.mylar.core.core.tests.support.MylarTestUtils.PrivilegeLevel;
14
import org.eclipse.mylar.trac.tests.Constants;
17
import org.eclipse.mylar.trac.tests.Constants;
15
import org.eclipse.mylar.trac.tests.support.XmlRpcServer.Ticket;
16
18
17
/**
19
/**
18
 * Initializes Trac repositories to a defined state. This is done once per test
20
 * Initializes Trac repositories to a defined state. This is done once per test
Lines 23-62 Link Here
23
 */
25
 */
24
public class TestFixture {
26
public class TestFixture {
25
27
26
	public static XmlRpcServer.TestData data1;
28
	public static XmlRpcServer.TestData data010;
27
29
28
	public static XmlRpcServer.TestData init010() throws Exception {
30
	/**
29
		if (data1 == null) {
31
	 * Adds the existing repository content to the test data of
30
			XmlRpcServer server = new XmlRpcServer(Constants.TEST_REPOSITORY1_URL,
32
	 * <code>server</code>.
31
					Constants.TEST_REPOSITORY1_ADMIN_USERNAME, Constants.TEST_REPOSITORY1_ADMIN_PASSWORD);
33
	 */
32
34
	private static void initializeTestData(XmlRpcServer server) throws Exception {
33
			server.ticketVersion(null).deleteAll();
35
		server.ticketMilestone("milestone1").itemCreated();
34
			server.ticketVersion("v1").create(86400, "description1");
36
		server.ticketMilestone("milestone2").itemCreated();
35
			server.ticketVersion("v2").create(86400 * 2, "description2");
37
		server.ticketMilestone("milestone3").itemCreated();
36
38
		server.ticketMilestone("milestone4").itemCreated();
37
			server.ticket().deleteAll();
39
38
40
		server.ticketVersion("1.0").itemCreated();
39
			server.ticketMilestone("m1").deleteAndCreate();
41
		server.ticketVersion("2.0").itemCreated();
40
			Ticket ticket = server.ticket().create("summary1", "description1");
42
41
			ticket.update("comment", "milestone", "m1");
43
		server.ticket(1).itemCreated();
44
		server.ticket(2).itemCreated();
45
		server.ticket(3).itemCreated();
46
		server.ticket(4).itemCreated();
47
	}
42
48
43
			server.ticketMilestone("m2").deleteAndCreate();
49
//	private static void initializeRepository(XmlRpcServer server) throws Exception {
44
			ticket = server.ticket().create("summary2", "description2");
50
//		server.ticketVersion(null).deleteAll();
45
			ticket.update("comment", "milestone", "m2");
51
//		server.ticketVersion("1.0").create(0, "");
46
			ticket = server.ticket().create("summary3", "description3");
52
//		server.ticketVersion("2.0").create(0, "");
47
			ticket.update("comment", "milestone", "m2");
53
//
54
//		server.ticketMilestone(null).deleteAll();
55
//		server.ticketMilestone("milestone1").create();
56
//		server.ticketMilestone("milestone2").create();
57
//		server.ticketMilestone("milestone3").create();
58
//		server.ticketMilestone("milestone4").create();
59
//
60
//		server.ticket().deleteAll();
61
//		Ticket ticket = server.ticket().create("summary1", "description1");
62
//		ticket.update("comment", "milestone", "milestone1");
63
//		ticket = server.ticket().create("summary2", "description2");
64
//		ticket.update("comment", "milestone", "milestone2");
65
//		ticket = server.ticket().create("summary3", "description3");
66
//		ticket.update("comment", "milestone", "milestone2");
67
//		ticket = server.ticket().create("summary4", "description4");
68
//	}
48
69
49
			ticket = server.ticket().create("summary4", "description4");
70
	public static XmlRpcServer.TestData init010() throws Exception {
71
		if (data010 == null) {
72
			Credentials credentials = MylarTestUtils.readCredentials(PrivilegeLevel.USER);
73
			XmlRpcServer server = new XmlRpcServer(Constants.TEST_TRAC_010_URL, credentials.username,
74
					credentials.password);
50
75
51
			data1 = server.getData();
76
			initializeTestData(server);
77
			data010 = server.getData();
52
		}
78
		}
53
		return data1;
79
		return data010;
54
	}
80
	}
55
81
56
	public static void cleanup010() throws Exception {
82
	public static void cleanup010() throws Exception {
57
		if (data1 != null) {
83
		if (data010 != null) {
58
			data1.cleanup();
84
			// data010.cleanup();
59
			data1 = null;
85
			data010 = null;
60
		}
86
		}
61
	}
87
	}
62
88
(-)META-INF/MANIFEST.MF (-1 / +2 lines)
Lines 10-16 Link Here
10
 org.eclipse.mylar.context.core,
10
 org.eclipse.mylar.context.core,
11
 org.eclipse.mylar.tasks.ui,
11
 org.eclipse.mylar.tasks.ui,
12
 org.eclipse.mylar.trac.ui,
12
 org.eclipse.mylar.trac.ui,
13
 org.eclipse.mylar.tasks.core
13
 org.eclipse.mylar.tasks.core,
14
 org.eclipse.mylar.core.tests
14
Export-Package: org.eclipse.mylar.trac.tests
15
Export-Package: org.eclipse.mylar.trac.tests
15
Bundle-Activator: org.eclipse.mylar.trac.tests.TracTestPlugin
16
Bundle-Activator: org.eclipse.mylar.trac.tests.TracTestPlugin
16
Eclipse-LazyStart: true
17
Eclipse-LazyStart: true
(-)src/org/eclipse/mylar/bugzilla/tests/RepositoryReportFactoryTest.java (-17 / +4 lines)
Lines 11-27 Link Here
11
11
12
package org.eclipse.mylar.bugzilla.tests;
12
package org.eclipse.mylar.bugzilla.tests;
13
13
14
import java.io.File;
15
import java.io.FileInputStream;
16
import java.io.IOException;
14
import java.io.IOException;
17
import java.net.URL;
18
import java.util.Properties;
19
15
20
import javax.security.auth.login.LoginException;
16
import javax.security.auth.login.LoginException;
21
17
22
import junit.framework.TestCase;
18
import junit.framework.TestCase;
23
19
24
import org.eclipse.core.runtime.FileLocator;
20
import org.eclipse.mylar.core.core.tests.support.MylarTestUtils;
21
import org.eclipse.mylar.core.core.tests.support.MylarTestUtils.Credentials;
25
import org.eclipse.mylar.internal.bugzilla.core.BugzillaAttributeFactory;
22
import org.eclipse.mylar.internal.bugzilla.core.BugzillaAttributeFactory;
26
import org.eclipse.mylar.internal.bugzilla.core.BugzillaPlugin;
23
import org.eclipse.mylar.internal.bugzilla.core.BugzillaPlugin;
27
import org.eclipse.mylar.internal.bugzilla.core.BugzillaReportElement;
24
import org.eclipse.mylar.internal.bugzilla.core.BugzillaReportElement;
Lines 57-74 Link Here
57
54
58
	private TaskRepository getRepository(String kind, String url) {
55
	private TaskRepository getRepository(String kind, String url) {
59
		TaskRepository repository = new TaskRepository(kind, url);
56
		TaskRepository repository = new TaskRepository(kind, url);
60
57
		Credentials credentials = MylarTestUtils.readCredentials();
61
		// Valid user name and password must be set for tests to pass
58
		repository.setAuthenticationCredentials(credentials.username, credentials.password);
62
		try {
63
			Properties properties = new Properties();
64
			URL localURL = FileLocator.toFileURL(BugzillaTestPlugin.getDefault().getBundle().getEntry(
65
					"credentials.properties"));
66
			properties.load(new FileInputStream(new File(localURL.getFile())));
67
			repository.setAuthenticationCredentials(properties.getProperty("username"), properties
68
					.getProperty("password"));
69
		} catch (Throwable t) {
70
			fail("must define credentials in <plug-in dir>/credentials.properties");
71
		}
72
		return repository;
59
		return repository;
73
	}
60
	}
74
61
(-)src/org/eclipse/mylar/bugzilla/tests/BugzillaRepositoryConnectorTest.java (-15 / +4 lines)
Lines 13-31 Link Here
13
13
14
import java.io.BufferedWriter;
14
import java.io.BufferedWriter;
15
import java.io.File;
15
import java.io.File;
16
import java.io.FileInputStream;
17
import java.io.FileWriter;
16
import java.io.FileWriter;
18
import java.io.UnsupportedEncodingException;
17
import java.io.UnsupportedEncodingException;
19
import java.net.InetAddress;
18
import java.net.InetAddress;
20
import java.net.MalformedURLException;
19
import java.net.MalformedURLException;
21
import java.net.Proxy;
20
import java.net.Proxy;
22
import java.net.Socket;
21
import java.net.Socket;
23
import java.net.URL;
24
import java.util.ArrayList;
22
import java.util.ArrayList;
25
import java.util.Date;
23
import java.util.Date;
26
import java.util.HashSet;
24
import java.util.HashSet;
27
import java.util.Iterator;
25
import java.util.Iterator;
28
import java.util.Properties;
29
import java.util.Set;
26
import java.util.Set;
30
27
31
import javax.security.auth.login.LoginException;
28
import javax.security.auth.login.LoginException;
Lines 33-39 Link Here
33
import junit.framework.TestCase;
30
import junit.framework.TestCase;
34
31
35
import org.apache.commons.httpclient.params.HttpConnectionParams;
32
import org.apache.commons.httpclient.params.HttpConnectionParams;
36
import org.eclipse.core.runtime.FileLocator;
33
import org.eclipse.mylar.core.core.tests.support.MylarTestUtils;
34
import org.eclipse.mylar.core.core.tests.support.MylarTestUtils.Credentials;
37
import org.eclipse.mylar.internal.bugzilla.core.BugzillaAttachmentHandler;
35
import org.eclipse.mylar.internal.bugzilla.core.BugzillaAttachmentHandler;
38
import org.eclipse.mylar.internal.bugzilla.core.BugzillaException;
36
import org.eclipse.mylar.internal.bugzilla.core.BugzillaException;
39
import org.eclipse.mylar.internal.bugzilla.core.BugzillaPlugin;
37
import org.eclipse.mylar.internal.bugzilla.core.BugzillaPlugin;
Lines 102-118 Link Here
102
100
103
	protected void init(String url) {
101
	protected void init(String url) {
104
		repository = new TaskRepository(DEFAULT_KIND, url);
102
		repository = new TaskRepository(DEFAULT_KIND, url);
105
		// Valid user name and password must be set for tests to pass
103
		Credentials credentials = MylarTestUtils.readCredentials();
106
		try {
104
		repository.setAuthenticationCredentials(credentials.username, credentials.password);
107
			Properties properties = new Properties();
108
			URL localURL = FileLocator.toFileURL(BugzillaTestPlugin.getDefault().getBundle().getEntry(
109
					"credentials.properties"));
110
			properties.load(new FileInputStream(new File(localURL.getFile())));
111
			repository.setAuthenticationCredentials(properties.getProperty("username"), properties
112
					.getProperty("password"));
113
		} catch (Throwable t) {
114
			fail("must define credentials in <plug-in dir>/credentials.properties");
115
		}
116
105
117
		repository.setTimeZoneId("Canada/Eastern");
106
		repository.setTimeZoneId("Canada/Eastern");
118
		manager.addRepository(repository);
107
		manager.addRepository(repository);
(-)src/org/eclipse/mylar/bugzilla/tests/RepositoryEditorWizardTest.java (-16 / +4 lines)
Lines 11-28 Link Here
11
11
12
package org.eclipse.mylar.bugzilla.tests;
12
package org.eclipse.mylar.bugzilla.tests;
13
13
14
import java.io.File;
15
import java.io.FileInputStream;
16
import java.net.URL;
17
import java.net.UnknownHostException;
14
import java.net.UnknownHostException;
18
import java.util.Properties;
19
15
20
import javax.security.auth.login.LoginException;
16
import javax.security.auth.login.LoginException;
21
17
22
import junit.framework.TestCase;
18
import junit.framework.TestCase;
23
19
24
import org.eclipse.core.runtime.FileLocator;
25
import org.eclipse.jface.wizard.WizardDialog;
20
import org.eclipse.jface.wizard.WizardDialog;
21
import org.eclipse.mylar.core.core.tests.support.MylarTestUtils;
22
import org.eclipse.mylar.core.core.tests.support.MylarTestUtils.Credentials;
26
import org.eclipse.mylar.internal.bugzilla.core.BugzillaPlugin;
23
import org.eclipse.mylar.internal.bugzilla.core.BugzillaPlugin;
27
import org.eclipse.mylar.internal.bugzilla.core.BugzillaServerFacade;
24
import org.eclipse.mylar.internal.bugzilla.core.BugzillaServerFacade;
28
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants;
25
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants;
Lines 48-64 Link Here
48
		manager = TasksUiPlugin.getRepositoryManager();
45
		manager = TasksUiPlugin.getRepositoryManager();
49
		manager.clearRepositories();
46
		manager.clearRepositories();
50
		repository = new TaskRepository(BugzillaPlugin.REPOSITORY_KIND, IBugzillaConstants.TEST_BUGZILLA_222_URL);
47
		repository = new TaskRepository(BugzillaPlugin.REPOSITORY_KIND, IBugzillaConstants.TEST_BUGZILLA_222_URL);
51
		// Valid user name and password must be set for tests to pass
48
		Credentials credentials = MylarTestUtils.readCredentials();
52
		try {
49
		repository.setAuthenticationCredentials(credentials.username, credentials.password);
53
			Properties properties = new Properties();
54
			URL localURL = FileLocator.toFileURL(BugzillaTestPlugin.getDefault().getBundle().getEntry(
55
					"credentials.properties"));
56
			properties.load(new FileInputStream(new File(localURL.getFile())));
57
			repository.setAuthenticationCredentials(properties.getProperty("username"), properties
58
					.getProperty("password"));
59
		} catch (Throwable t) {
60
			fail("Must define credentials in <plug-in dir>/credentials.properties");
61
		}
62
50
63
		TasksUiPlugin.getRepositoryManager().addRepository(repository);
51
		TasksUiPlugin.getRepositoryManager().addRepository(repository);
64
	}
52
	}
(-).cvsignore (+1 lines)
Line 1 Link Here
1
bin
1
bin
2
credentials.properties
(-)src/org/eclipse/mylar/core/core/tests/support/MylarTestUtils.java (+86 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 - 2006 Mylar eclipse.org project and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Mylar project committers - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylar.core.core.tests.support;
13
14
import java.io.File;
15
import java.io.FileInputStream;
16
import java.net.URL;
17
import java.util.Properties;
18
19
import junit.framework.AssertionFailedError;
20
21
import org.eclipse.core.runtime.FileLocator;
22
import org.eclipse.mylar.core.core.tests.MylarCoreTestsPlugin;
23
24
/**
25
 * @author Steffen Pingel
26
 */
27
public class MylarTestUtils {
28
29
	public enum PrivilegeLevel {
30
		ANONYMOUS, USER, ADMIN
31
	};
32
33
	public static class Credentials {
34
35
		public final String username;
36
37
		public final String password;
38
39
		public Credentials(String username, String password) {
40
			this.username = username;
41
			this.password = password;
42
		}
43
44
		public Credentials(Properties properties, String prefix) {
45
			this.username = properties.getProperty(prefix + "username");
46
			this.password = properties.getProperty(prefix + "password");
47
48
			if (username == null || password == null) {
49
				throw new AssertionFailedError(
50
						"username or password not found in <plug-in dir>/credentials.properties, make sure file is valid");
51
			}
52
		}
53
54
	}
55
56
	public static Credentials readCredentials() {
57
		return readCredentials(PrivilegeLevel.USER, null);
58
	}
59
60
	public static Credentials readCredentials(PrivilegeLevel level) {
61
		return readCredentials(level, null);
62
	}
63
64
	public static Credentials readCredentials(PrivilegeLevel level, String realm) {
65
		if (level == PrivilegeLevel.ANONYMOUS) {
66
			return new Credentials("", "");
67
		}
68
69
		Properties properties = new Properties();
70
		try {
71
			URL localURL = FileLocator.toFileURL(MylarCoreTestsPlugin.getDefault().getBundle().getEntry(
72
					"credentials.properties"));
73
			properties.load(new FileInputStream(new File(localURL.getFile())));
74
		} catch (Exception e) {
75
			throw new AssertionFailedError("must define credentials in <plug-in dir>/credentials.properties");
76
		}
77
78
		realm = (realm != null) ? realm + "." : "";
79
		if (level == PrivilegeLevel.ADMIN) {
80
			return new Credentials(properties, realm + "admin.");
81
		} else {
82
			return new Credentials(properties, "");
83
		}
84
	}
85
86
}

Return to bug 150456