Skip to main content
summaryrefslogtreecommitdiffstats
blob: 9c87e72e6b8ed918e05bdf4013ea94539e3fa400 (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
/*******************************************************************************
 * Copyright (c) 2004, 2009 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.bugzilla.tests;

import java.util.HashSet;
import java.util.Set;

import junit.framework.TestCase;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.mylyn.bugzilla.tests.support.BugzillaFixture;
import org.eclipse.mylyn.internal.bugzilla.core.BugzillaRepositoryConnector;
import org.eclipse.mylyn.tasks.core.IRepositoryQuery;
import org.eclipse.mylyn.tasks.core.TaskRepository;
import org.eclipse.mylyn.tasks.core.data.TaskData;
import org.eclipse.mylyn.tasks.core.data.TaskDataCollector;
import org.eclipse.mylyn.tasks.ui.TasksUi;
import org.eclipse.mylyn.commons.sdk.util.CommonTestUtil.PrivilegeLevel;

/**
 * @author Rob Elves
 */
public class BugzillaSearchTest extends TestCase {

	private static final String QUERY_NAME = "Query Page Name";

	private static final String BUG_SUMMARY_SUBSTRING_SEARCH = "/buglist.cgi?short_desc_type=allwordssubstr&short_desc=";

	private static final String BUG_COMMENT_SUBSTRING_SEARCH = "/buglist.cgi?long_desc_type=allwordssubstr&long_desc=";

	private TaskRepository repository;

	private BugzillaRepositoryConnector connector;

	@Override
	protected void setUp() throws Exception {
		super.setUp();
		BugzillaFixture.current().client();
		this.connector = BugzillaFixture.current().connector();
		this.repository = BugzillaFixture.current().repository();
	}

	public void testSummarySearching() throws Exception {
		long now = System.currentTimeMillis();
		TaskData newTaskData = BugzillaFixture.current().createTask(PrivilegeLevel.USER, now + "", null);
		assertNotNull(newTaskData);
		assertEquals(1, runQuery(BUG_SUMMARY_SUBSTRING_SEARCH, now + "").size());
	}

	public void testCommentSearching() throws Exception {
		long now = System.currentTimeMillis();
		TaskData newTaskData = BugzillaFixture.current().createTask(PrivilegeLevel.USER, null, now + "");
		assertNotNull(newTaskData);
		assertEquals(1, runQuery(BUG_COMMENT_SUBSTRING_SEARCH, now + "").size());
	}

	private Set<TaskData> runQuery(String requestUrl, String queryString) throws Exception {
		IRepositoryQuery repositoryQuery = TasksUi.getRepositoryModel().createRepositoryQuery(repository);
		repositoryQuery.setUrl(repository.getRepositoryUrl() + requestUrl + queryString);
		repositoryQuery.setSummary(QUERY_NAME);

		final Set<TaskData> changedTaskData = new HashSet<TaskData>();
		TaskDataCollector collector = new TaskDataCollector() {

			@Override
			public void accept(TaskData taskData) {
				changedTaskData.add(taskData);
			}
		};

		IStatus status = connector.performQuery(repository, repositoryQuery, collector, null, new NullProgressMonitor());
		assertEquals(IStatus.OK, status.getCode());
		return changedTaskData;
	}

}

Back to the top