Skip to main content
summaryrefslogtreecommitdiffstats
blob: 2ae6b2bc69cab41c9de9a46d36eae941439d318f (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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
/*******************************************************************************
 * 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.InetSocketAddress;
import java.net.Proxy;
import java.net.Proxy.Type;
import java.util.ArrayList;
import java.util.List;

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.client.ITracClient;
import org.eclipse.mylyn.internal.trac.core.client.TracException;
import org.eclipse.mylyn.internal.trac.core.client.TracLoginException;
import org.eclipse.mylyn.internal.trac.core.client.ITracClient.Version;
import org.eclipse.mylyn.internal.trac.core.model.TracSearch;
import org.eclipse.mylyn.internal.trac.core.model.TracTicket;
import org.eclipse.mylyn.internal.trac.core.model.TracTicket.Key;
import org.eclipse.mylyn.trac.tests.support.TestFixture;
import org.eclipse.mylyn.trac.tests.support.TracTestConstants;
import org.eclipse.mylyn.trac.tests.support.XmlRpcServer.TestData;
import org.eclipse.mylyn.trac.tests.support.XmlRpcServer.Ticket;

/**
 * Test cases for classes that implement {@link ITracClient}.
 * 
 * @author Steffen Pingel
 */
public class AbstractTracClientRepositoryTest extends AbstractTracClientTest {

	protected List<Ticket> tickets;

	private TestData data;

	public AbstractTracClientRepositoryTest(Version version) {
		super(version);
	}

	@Override
	protected void setUp() throws Exception {
		super.setUp();

		data = TestFixture.init010();
		tickets = data.tickets;
	}

	@Override
	protected void tearDown() throws Exception {
		super.tearDown();

		// TestFixture.cleanupRepository1();
	}

	public void testValidate010() throws Exception {
		validate(TracTestConstants.TEST_TRAC_010_URL);
	}

	public void testValidate010DigestAuth() throws Exception {
		validate(TracTestConstants.TEST_TRAC_010_DIGEST_AUTH_URL);
	}

	public void testValidate011() throws Exception {
		validate(TracTestConstants.TEST_TRAC_011_URL);
	}

	public void testValidate010FormAuth() throws Exception {
		validate(TracTestConstants.TEST_TRAC_010_FORM_AUTH_URL);
	}

	protected void validate(String url) throws Exception {
		Credentials credentials = TestUtil.readCredentials(PrivilegeLevel.USER);

		// standard connect
		connect(url);
		client.validate(callback);

		// invalid url
		connect("http://non.existant/repository");
		try {
			client.validate(callback);
			fail("Expected TracException");
		} catch (TracException e) {
		}

		// invalid password
		connect(url, credentials.username, "wrongpassword");
		try {
			client.validate(callback);
			fail("Expected TracLoginException");
		} catch (TracLoginException e) {
		}

		// invalid username
		connect(url, "wrongusername", credentials.password);
		try {
			client.validate(callback);
			fail("Expected TracLoginException");
		} catch (TracLoginException e) {
		}
	}

	public void testProxy() throws Exception {
		connect(TracTestConstants.TEST_TRAC_010_URL, "", "", new Proxy(Type.HTTP, new InetSocketAddress(
				"invalidhostname", 8080)));
		try {
			client.validate(callback);
			fail("Expected IOException");
		} catch (TracException e) {
		}
	}

	public void testGetTicket096() throws Exception {
		if (version == Version.XML_RPC) {
			return;
		}

		connect096();
		getTicket();
	}

	public void testGetTicket010() throws Exception {
		connect010();
		getTicket();
	}

	public void testGetTicket011() throws Exception {
		if (version == Version.TRAC_0_9) {
			// XXX web mode is broken for Trac 0.11: need to fix bug 175211
			return;
		}

		connect011();
		getTicket();
	}

	private void getTicket() throws Exception {
		TracTicket ticket = client.getTicket(tickets.get(0).getId(), null);
		assertTicketEquals(tickets.get(0), ticket);

		ticket = client.getTicket(tickets.get(1).getId(), null);
		assertTicketEquals(tickets.get(1), ticket);
	}

	public void testGetTicketInvalidId096() throws Exception {
		if (version == Version.XML_RPC) {
			return;
		}

		connect096();
		getTicketInvalidId();
	}

	public void testGetTicketInvalidId010() throws Exception {
		connect010();
		getTicketInvalidId();
	}

	public void testGetTicketInvalidId011() throws Exception {
		connect011();
		getTicketInvalidId();
	}

	private void getTicketInvalidId() throws Exception {
		try {
			client.getTicket(Integer.MAX_VALUE, null);
			fail("Expected TracException");
		} catch (TracException e) {
		}
	}

	public void testGetTicketUmlaute010() throws Exception {
		connect010();
		getTicketUmlaute();
	}

	public void testGetTicketUmlaute011() throws Exception {
		if (version == Version.TRAC_0_9) {
			// XXX need to fix bug 175211
			return;
		}

		connect011();
		getTicketUmlaute();
	}

	private void getTicketUmlaute() throws Exception {
		TracTicket ticket = client.getTicket(data.htmlEntitiesTicketId, null);
		assertEquals("test html entities: \u00E4\u00F6\u00FC", ticket.getValue(Key.SUMMARY));
		if (version == Version.XML_RPC) {
			assertEquals("\u00C4\u00D6\u00DC\n\nmulti\nline\n\n'''bold'''\n", ticket.getValue(Key.DESCRIPTION));
		} else {
			assertEquals(null, ticket.getValue(Key.DESCRIPTION));
		}
	}

	public void testSearchAll010() throws Exception {
		connect010();
		searchAll();
	}

	public void testSearchAll011() throws Exception {
		connect011();
		searchAll();
	}

	private void searchAll() throws Exception {
		TracSearch search = new TracSearch();
		List<TracTicket> result = new ArrayList<TracTicket>();
		client.search(search, result, null);
		//assertEquals(tickets.size(), result.size());
		assertTrue(result.size() >= tickets.size());
	}

	public void testSearchEmpty010() throws Exception {
		connect010();
		searchEmpty();
	}

	public void testSearchEmpty011() throws Exception {
		connect011();
		searchEmpty();
	}

	private void searchEmpty() throws Exception {
		TracSearch search = new TracSearch();
		search.addFilter("milestone", "does not exist");
		List<TracTicket> result = new ArrayList<TracTicket>();
		client.search(search, result, null);
		assertEquals(0, result.size());
	}

	public void testSearchMilestone1_010() throws Exception {
		connect010();
		searchMilestone1();
	}

	public void testSearchMilestone1_011() throws Exception {
		connect011();
		searchMilestone1();
	}

	private void searchMilestone1() throws Exception {
		TracSearch search = new TracSearch();
		search.addFilter("milestone", "milestone1");
		List<TracTicket> result = new ArrayList<TracTicket>();
		client.search(search, result, null);
		assertEquals(1, result.size());
		assertTicketEquals(tickets.get(0), result.get(0));
	}

	public void testSearchMilestone2_0_10() throws Exception {
		connect010();
		searchMilestone2();
	}

	public void testSearchMilestone2_0_11() throws Exception {
		connect011();
		searchMilestone2();
	}

	private void searchMilestone2() throws Exception {
		TracSearch search = new TracSearch();
		search.addFilter("milestone", "milestone1");
		search.addFilter("milestone", "milestone2");
		search.setOrderBy("id");
		List<TracTicket> result = new ArrayList<TracTicket>();
		client.search(search, result, null);
		assertEquals(3, result.size());
		assertTicketEquals(tickets.get(0), result.get(0));
		assertTicketEquals(tickets.get(1), result.get(1));
		assertTicketEquals(tickets.get(2), result.get(2));
	}

	public void testSearchExactMatch010() throws Exception {
		connect010();
		searchExactMatch();
	}

	public void testSearchExactMatch011() throws Exception {
		connect011();
		searchExactMatch();
	}

	private void searchExactMatch() throws Exception {
		TracSearch search = new TracSearch();
		search.addFilter("milestone", "milestone1");
		search.addFilter("summary", "summary1");
		List<TracTicket> result = new ArrayList<TracTicket>();
		client.search(search, result, null);
		assertEquals(1, result.size());
		assertTicketEquals(tickets.get(0), result.get(0));
		assertEquals("milestone1", result.get(0).getValue(Key.MILESTONE));
		assertEquals("summary1", result.get(0).getValue(Key.SUMMARY));
	}

	public void testStatusClosed010() throws Exception {
		connect010();
		statusClosed();
	}

	public void testStatusClosed011() throws Exception {
		connect011();
		statusClosed();
	}

	protected void statusClosed() throws Exception {
		TracTicket ticket = client.getTicket(data.offlineHandlerTicketId, null);
		assertEquals("closed", ticket.getValue(Key.STATUS));
		assertEquals("fixed", ticket.getValue(Key.RESOLUTION));
	}

}

Back to the top