1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
/*******************************************************************************
* Copyright (c) 2004, 2007 Mylyn project committers 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
*******************************************************************************/
package org.eclipse.mylyn.bugzilla.tests;
import java.util.HashSet;
import java.util.Set;
import junit.framework.TestCase;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.mylyn.bugzilla.deprecated.BugzillaRepositoryQuery;
import org.eclipse.mylyn.internal.bugzilla.core.BugzillaCorePlugin;
import org.eclipse.mylyn.internal.bugzilla.core.IBugzillaConstants;
import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector;
import org.eclipse.mylyn.tasks.core.TaskRepository;
import org.eclipse.mylyn.tasks.core.data.TaskData;
import org.eclipse.mylyn.tasks.core.data.TaskDataCollector;
/**
* @author Rob Elves
*/
public class BugzillaSearchEngineTest extends TestCase {
private static final String QUERY_NAME = "Query Page Name";
private static final String BUG_DESC_SUBSTRING_SEARCH = "/buglist.cgi?short_desc_type=allwordssubstr&short_desc=";// search-match-test&";
private static final String SEARCH_DESCRIPTION = "search-match-test";
private static final int NUM_EXPECTED_HITS = 2;
private static final int NUM_REPOSITORIES = 0;
@Override
protected void setUp() throws Exception {
super.setUp();
TasksUiPlugin.getRepositoryManager().clearRepositories(TasksUiPlugin.getDefault().getRepositoriesFilePath());
assertEquals(NUM_REPOSITORIES, TasksUiPlugin.getRepositoryManager().getRepositories(
BugzillaCorePlugin.CONNECTOR_KIND).size());
}
@Override
protected void tearDown() throws Exception {
TasksUiPlugin.getRepositoryManager().clearRepositories(TasksUiPlugin.getDefault().getRepositoriesFilePath());
super.tearDown();
}
public void testSearching218() throws Exception {
TaskRepository repository = new TaskRepository(BugzillaCorePlugin.CONNECTOR_KIND,
IBugzillaConstants.TEST_BUGZILLA_218_URL);
repository.setVersion(IBugzillaConstants.BugzillaServerVersion.SERVER_218.toString());
TasksUiPlugin.getRepositoryManager().addRepository(repository);
assertEquals(NUM_EXPECTED_HITS, runQuery(IBugzillaConstants.TEST_BUGZILLA_218_URL, SEARCH_DESCRIPTION).size());
}
public void testSearching220() throws Exception {
TaskRepository repository = new TaskRepository(BugzillaCorePlugin.CONNECTOR_KIND,
IBugzillaConstants.TEST_BUGZILLA_220_URL);
repository.setVersion(IBugzillaConstants.BugzillaServerVersion.SERVER_220.toString());
TasksUiPlugin.getRepositoryManager().addRepository(repository);
assertEquals(NUM_EXPECTED_HITS, runQuery(IBugzillaConstants.TEST_BUGZILLA_220_URL, SEARCH_DESCRIPTION).size());
}
public void testSearching2201() throws Exception {
TaskRepository repository = new TaskRepository(BugzillaCorePlugin.CONNECTOR_KIND,
IBugzillaConstants.TEST_BUGZILLA_2201_URL);
repository.setVersion(IBugzillaConstants.BugzillaServerVersion.SERVER_220.toString());
TasksUiPlugin.getRepositoryManager().addRepository(repository);
assertEquals(NUM_EXPECTED_HITS, runQuery(IBugzillaConstants.TEST_BUGZILLA_2201_URL, SEARCH_DESCRIPTION).size());
}
public void testSearching222() throws Exception {
TaskRepository repository = new TaskRepository(BugzillaCorePlugin.CONNECTOR_KIND,
IBugzillaConstants.TEST_BUGZILLA_222_URL);
repository.setVersion(IBugzillaConstants.BugzillaServerVersion.SERVER_222.toString());
TasksUiPlugin.getRepositoryManager().addRepository(repository);
Set<TaskData> hits = runQuery(IBugzillaConstants.TEST_BUGZILLA_222_URL, SEARCH_DESCRIPTION);
assertEquals(NUM_EXPECTED_HITS, hits.size());
}
@SuppressWarnings("deprecation")
private Set<TaskData> runQuery(String repositoryURL, String SearchString) throws Exception {
TaskRepository repository = TasksUiPlugin.getRepositoryManager().getRepository(
BugzillaCorePlugin.CONNECTOR_KIND, repositoryURL);
assertNotNull(repository);
final BugzillaRepositoryQuery repositoryQuery = new BugzillaRepositoryQuery(repository.getRepositoryUrl(),
repository.getRepositoryUrl() + BUG_DESC_SUBSTRING_SEARCH + SearchString, QUERY_NAME);
AbstractRepositoryConnector connector = TasksUiPlugin.getRepositoryManager().getRepositoryConnector(
BugzillaCorePlugin.CONNECTOR_KIND);
final Set<TaskData> changedTaskData = new HashSet<TaskData>();
TaskDataCollector collector = new TaskDataCollector() {
@Override
public void accept(TaskData taskData) {
changedTaskData.add(taskData);
}
};
connector.performQuery(repository, repositoryQuery, collector, null, new NullProgressMonitor());
return changedTaskData;
}
}
|