Skip to main content
summaryrefslogtreecommitdiffstats
blob: 33fd05b4c5bf6321700a8d2d902ecd8808e9b0fe (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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
/*******************************************************************************
 * Copyright (c) 2004, 2008 Tasktop Technologies 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.sandbox.tests;

import java.util.ArrayList;
import java.util.List;

import junit.framework.TestCase;

import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IType;
import org.eclipse.mylyn.internal.bugzilla.core.BugzillaCorePlugin;
import org.eclipse.mylyn.internal.bugzilla.core.IBugzillaConstants;
import org.eclipse.mylyn.internal.context.core.IActiveSearchListener;
import org.eclipse.mylyn.internal.sandbox.bridge.bugs.BugzillaMylynSearch;
import org.eclipse.mylyn.internal.sandbox.bridge.bugs.BugzillaReportInfo;
import org.eclipse.mylyn.internal.sandbox.bridge.bugs.MylynBugsManager;
import org.eclipse.mylyn.internal.tasks.core.AbstractTask;
import org.eclipse.mylyn.internal.tasks.core.TaskCategory;
import org.eclipse.mylyn.internal.tasks.core.TaskTask;
import org.eclipse.mylyn.internal.tasks.ui.TaskListManager;
import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
import org.eclipse.mylyn.java.tests.search.SearchPluginTestHelper;
import org.eclipse.mylyn.java.tests.search.WorkspaceSetupHelper;
import org.eclipse.mylyn.tasks.core.TaskRepository;

/*
 * TEST CASES TO HANDLE 1. what is here 2. different scopes ( local and remote )
 * 3. no bugs 4. offline bugs
 * 
 * DEGREE OF SEPARATIONS 1 Local bug, qualified reference 2 local bug,
 * unqualified reference 3 remote bug, qualified reference 4 remote bug,
 * unqualified reference 5 NONE
 */

/**
 * Test the bugzilla search functionality of the bridge
 * 
 * @author Shawn Minto
 */
public class BugzillaActiveSearchTest extends TestCase {

	private TaskRepository repository;

	// SHAWNTODO Add tests for the different types of searches (local qual,
	// local unqual, fully qual, unqual) and mock up a bugs db for testing

	/** The expected number of results when searching for astNode */
	// SHAWNTODO add back in when we have a test server mocked up
	// private static final int NUM_AST_RESULTS = 302;
	//	
	// private static final int NUM_AST_SETSOURCERANGE_RESULTS = 15;
	/** list to add collectors to when notified */
	private final List<List<?>> lists = new ArrayList<List<?>>();

	private IType astNodeType;

	@Override
	protected void setUp() throws Exception {
		WorkspaceSetupHelper.setupWorkspace();
		repository = new TaskRepository(BugzillaCorePlugin.CONNECTOR_KIND, IBugzillaConstants.ECLIPSE_BUGZILLA_URL);
		TasksUiPlugin.getRepositoryManager().addRepository(repository);

		IJavaProject jp = WorkspaceSetupHelper.getJdtCoreDomProject();
		astNodeType = WorkspaceSetupHelper.getType(jp, "org.eclipse.jdt.core.dom.ASTNode");
	}

	@Override
	protected void tearDown() throws Exception {
		WorkspaceSetupHelper.clearDoiModel();
		TasksUiPlugin.getRepositoryManager().removeRepository(repository,
				TasksUiPlugin.getDefault().getRepositoriesFilePath());
	}

	/**
	 * Test adding and removing ISearchCompletedListeners
	 */
	public void testSearchCompletedListenerAddAndRemove() {
		lists.clear();

		// create 2 listeners
		IActiveSearchListener l1 = new IActiveSearchListener() {
			private boolean gathered = false;

			public void searchCompleted(List<?> l) {
				lists.add(l);
				gathered = true;
			}

			public boolean resultsGathered() {
				return gathered;
			}
		};
		IActiveSearchListener l2 = new IActiveSearchListener() {
			private boolean gathered = false;

			public void searchCompleted(List<?> l) {
				lists.add(l);
				gathered = true;
			}

			public boolean resultsGathered() {
				return gathered;
			}
		};

		BugzillaMylynSearch s = new BugzillaMylynSearch(BugzillaMylynSearch.UNQUAL, astNodeType,
				IBugzillaConstants.ECLIPSE_BUGZILLA_URL);

		// add the first listener
		s.addListener(l1);
		// remove the first listener
		s.removeListener(l1);

		// perform the search
		SearchPluginTestHelper.search(s, l2);

		// make sure that only the second listener added has any results left
		assertTrue("listener was not removed", lists.size() >= 1 && !l1.resultsGathered());
		assertTrue("listener was not added", lists.size() == 1);

		// display the time it took for the search
		MylynBugsManager.getBridge().removeFromLandmarksHash(astNodeType);
	}

	/**
	 * Tests that the bridge gets the right data for us This test is wierd because it waits on results.
	 */
	public void testBridge() {
		lists.clear();
		BugzillaMylynSearch s = new BugzillaMylynSearch(BugzillaMylynSearch.UNQUAL, astNodeType,
				IBugzillaConstants.ECLIPSE_BUGZILLA_URL);

		IActiveSearchListener l = new IActiveSearchListener() {
			private boolean gathered = false;

			public void searchCompleted(List<?> results) {
				lists.add(results);
				gathered = true;
			}

			public boolean resultsGathered() {
				return gathered;
			}
		};

		// perform the search
		SearchPluginTestHelper.search(s, l);

		// make sure we got the right number of bugs back
		assertTrue("No collector returned", lists.size() != 0);
		List<?> c = lists.get(0);
		assertTrue("Results not the right size", c.size() > 0); // TODO should
		// be
		// assertEquals
		// on expected
		// size

		// display the time it took for the search and the results returned
		MylynBugsManager.getBridge().removeFromLandmarksHash(astNodeType);

	}

	/**
	 * Tests that the bridge saves the results of a search so that it can be used later
	 */
	public void testSaveResults() {
		lists.clear();
		BugzillaMylynSearch s = new BugzillaMylynSearch(BugzillaMylynSearch.UNQUAL, astNodeType,
				IBugzillaConstants.ECLIPSE_BUGZILLA_URL);

		IActiveSearchListener l = new IActiveSearchListener() {
			private boolean gathered = false;

			public void searchCompleted(List<?> results) {
				lists.add(results);
				gathered = true;
			}

			public boolean resultsGathered() {
				return gathered;
			}
		};

		// perform the search
		SearchPluginTestHelper.search(s, l);

		// do an inital search
		assertTrue("No collectors returned", lists.size() != 0);
		List<?> c = lists.get(0);
		assertTrue("Results not the right size", c.size() > 0);
		// TODO should be assertEquals on expected size

		// check that the search has been saved
		List<BugzillaReportInfo> saved = MylynBugsManager.getBridge().getFromLandmarksHash(astNodeType,
				BugzillaMylynSearch.UNQUAL);
		assertTrue("Results not cached", saved != null);
		if (saved == null) {
			fail();
		} else {
			assertTrue("Results not the right size", saved.size() > 0);
			// TODO should be assertEquals on expected size

			assertTrue(c.containsAll(saved) && saved.containsAll(c));
			MylynBugsManager.getBridge().removeFromLandmarksHash(astNodeType);
		}
	}

	public void testLocalBugUnqual() throws InterruptedException {
		lists.clear();

		String bugPrefix = "<server>-";

		TaskListManager manager = TasksUiPlugin.getTaskListManager();
		TaskCategory cat = new TaskCategory("Testing Category");
		manager.getTaskList().addCategory(cat);
		AbstractTask bugTask1 = new TaskTask(bugPrefix, "" + 94185, "<bugzilla info>");

		manager.getTaskList().addTask(bugTask1, cat);
		// cat.addTask(bugTask1);
		while (bugTask1.isSynchronizing()) {
			Thread.sleep(500);
		}
		AbstractTask bugTask2 = new TaskTask(bugPrefix, "" + 3692, "<bugzilla info>");
		manager.getTaskList().addTask(bugTask2, cat);
		// cat.addTask(bugTask2);
		while (bugTask2.isSynchronizing()) {
			Thread.sleep(500);
		}
		AbstractTask bugTask3 = new TaskTask(bugPrefix, "" + 3693, "<bugzilla info>");
		manager.getTaskList().addTask(bugTask3, cat);
		// cat.addTask(bugTask3);
		while (bugTask3.isSynchronizing()) {
			Thread.sleep(500);
		}

		AbstractTask bugTask4 = new TaskTask(bugPrefix, "" + 9583, "<bugzilla info>");
		manager.getTaskList().addTask(bugTask4, cat);
		// cat.addTask(bugTask4);
		while (bugTask4.isSynchronizing()) {
			Thread.sleep(500);
		}

		BugzillaMylynSearch s = new BugzillaMylynSearch(BugzillaMylynSearch.LOCAL_UNQUAL, astNodeType,
				IBugzillaConstants.ECLIPSE_BUGZILLA_URL);

		IActiveSearchListener l = new IActiveSearchListener() {
			private boolean gathered = false;

			public void searchCompleted(List<?> results) {
				lists.add(results);
				gathered = true;
			}

			public boolean resultsGathered() {
				return gathered;
			}
		};

		// perform the search
		SearchPluginTestHelper.search(s, l);

		// do an inital search
		assertTrue("No collectors returned", lists.size() != 0);
		List<?> c = lists.get(0);
		assertEquals("Results not the right size", 3, c.size());

		MylynBugsManager.getBridge().removeFromLandmarksHash(astNodeType);
		TasksUiPlugin.getTaskList().deleteCategory(cat);
	}

	// TODO need to test a bug that wraps...should fail since we can only search
	// on a single line
	public void testLocalBugFullyQual() throws InterruptedException {
		lists.clear();

		String bugPrefix = "Bugzilla-";

		TaskListManager manager = TasksUiPlugin.getTaskListManager();
		TaskCategory cat = new TaskCategory("Testing Category");
		manager.getTaskList().addCategory(cat);
		AbstractTask bugTask1 = new TaskTask(bugPrefix, "" + 94185, "<bugzilla info>");
		manager.getTaskList().addTask(bugTask1, cat);
		// cat.addTask(bugTask1);
		while (bugTask1.isSynchronizing()) {
			Thread.sleep(500);
		}

		AbstractTask bugTask2 = new TaskTask(bugPrefix, "" + 9583, "<bugzilla info>");
		manager.getTaskList().addTask(bugTask2, cat);
		// cat.addTask(bugTask2);
		while (bugTask2.isSynchronizing()) {
			Thread.sleep(500);
		}
		AbstractTask bugTask3 = new TaskTask(bugPrefix, "" + 3693, "<bugzilla info>");
		manager.getTaskList().addTask(bugTask3, cat);
		// cat.addTask(bugTask3);
		while (bugTask3.isSynchronizing()) {
			Thread.sleep(500);
		}

		BugzillaMylynSearch s = new BugzillaMylynSearch(BugzillaMylynSearch.LOCAL_QUAL, astNodeType,
				IBugzillaConstants.ECLIPSE_BUGZILLA_URL);

		IActiveSearchListener l = new IActiveSearchListener() {
			private boolean gathered = false;

			public void searchCompleted(List<?> results) {
				lists.add(results);
				gathered = true;
			}

			public boolean resultsGathered() {
				return gathered;
			}
		};

		// perform the search
		SearchPluginTestHelper.search(s, l);

		// do an inital search
		assertTrue("No collectors returned", lists.size() != 0);
		List<?> c = lists.get(0);
		assertEquals("Results not the right size", 1, c.size());

		MylynBugsManager.getBridge().removeFromLandmarksHash(astNodeType);
		TasksUiPlugin.getTaskList().deleteCategory(cat);
	}

}

Back to the top