Skip to main content
summaryrefslogtreecommitdiffstats
blob: 575706444b9a013f309a4d9672e4f4b1dd9bf372 (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
/*******************************************************************************
 * 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.util.ArrayList;
import java.util.List;
import java.util.Map;

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.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.XmlRpcServer.TestData;
import org.eclipse.mylyn.trac.tests.support.XmlRpcServer.Ticket;

/**
 * Test cases that validate search results for classes that implement {@link ITracClient}.
 * 
 * @author Steffen Pingel
 */
public abstract class AbstractTracClientSearchTest extends AbstractTracClientTest {

	protected List<Ticket> tickets;

	private TestData data;

	public AbstractTracClientSearchTest(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();
	}

	protected void assertTicketEquals(Ticket ticket, TracTicket tracTicket) throws Exception {
		assertTrue(tracTicket.isValid());

		Map<?, ?> expectedValues = ticket.getValues();
		Map<String, String> values = tracTicket.getValues();
		for (String key : values.keySet()) {
			assertEquals("Values for key '" + key + "' did not match", expectedValues.get(key), values.get(key));
		}
	}

	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 = repository.getTicket(tickets.get(0).getId(), null);
		assertTicketEquals(tickets.get(0), ticket);

		ticket = repository.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 {
			repository.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 = repository.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>();
		repository.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>();
		repository.search(search, result, null);
		assertEquals(0, result.size());
	}

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

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

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

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

	public void testSearchMilestone2011() 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>();
		repository.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>();
		repository.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 = repository.getTicket(data.offlineHandlerTicketId, null);
		assertEquals("closed", ticket.getValue(Key.STATUS));
		assertEquals("fixed", ticket.getValue(Key.RESOLUTION));
	}

}

Back to the top