Skip to main content
summaryrefslogtreecommitdiffstats
blob: 3b957e105a5860b7a3ca509cc8041154d7a20927 (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
/*******************************************************************************
 * Copyright (c) 2004 - 2006 University Of British Columbia 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:
 *     University Of British Columbia - initial API and implementation
 *******************************************************************************/

package org.eclipse.mylar.bugzilla.tests.headless;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.security.GeneralSecurityException;
import java.security.KeyManagementException;
import java.util.List;

import junit.framework.TestCase;

import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.mylar.context.tests.support.MylarTestUtils;
import org.eclipse.mylar.context.tests.support.MylarTestUtils.Credentials;
import org.eclipse.mylar.internal.bugzilla.core.BugzillaCorePlugin;
import org.eclipse.mylar.internal.bugzilla.core.BugzillaException;
import org.eclipse.mylar.internal.bugzilla.core.BugzillaReportElement;
import org.eclipse.mylar.internal.bugzilla.core.BugzillaRepositoryConnector;
import org.eclipse.mylar.internal.bugzilla.core.BugzillaRepositoryQuery;
import org.eclipse.mylar.internal.bugzilla.core.BugzillaServerFacade;
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants;
import org.eclipse.mylar.tasks.core.AbstractQueryHit;
import org.eclipse.mylar.tasks.core.QueryHitCollector;
import org.eclipse.mylar.tasks.core.RepositoryTaskData;
import org.eclipse.mylar.tasks.core.TaskList;
import org.eclipse.mylar.tasks.core.TaskRepository;

/**
 * 
 * Runs headless (can be run as regular junit test without platform plugin
 * support).
 * 
 * @author Rob Elves
 * @author Nathan Hapke
 */
public class BugzillaQueryTest extends TestCase {

	private TaskRepository repository;

	@Override
	protected void setUp() throws Exception {
		super.setUp();
		repository = new TaskRepository(BugzillaCorePlugin.REPOSITORY_KIND, IBugzillaConstants.TEST_BUGZILLA_222_URL);
	}

	/**
	 * This is the first test so that the repository credentials are correctly
	 * set for the other tests
	 */
	public void testAddCredentials() {
		if (!repository.hasCredentials()) {
			Credentials credentials = MylarTestUtils.readCredentials();
			repository.setAuthenticationCredentials(credentials.username, credentials.password);

			assertTrue(repository.hasCredentials());
		}
	}

	public void testValidateCredentials() throws IOException, BugzillaException, KeyManagementException,
			GeneralSecurityException {
		BugzillaServerFacade.validateCredentials(null, repository.getUrl(), repository.getCharacterEncoding(),
				repository.getUserName(), repository.getPassword());
	}

	public void testValidateCredentialsInvalidProxy() throws IOException, BugzillaException, KeyManagementException,
			GeneralSecurityException {
		BugzillaServerFacade.validateCredentials(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("localhost", 12356)),
				repository.getUrl(), repository.getCharacterEncoding(), repository.getUserName(), repository
						.getPassword());
	}

	public void testCredentialsEncoding() throws IOException, BugzillaException, KeyManagementException,
			GeneralSecurityException {
		String poundSignUTF8 = BugzillaServerFacade.addCredentials(IBugzillaConstants.TEST_BUGZILLA_222_URL, "UTF-8",
				"testUser", "£");
		assertTrue(poundSignUTF8.endsWith("password=%C2%A3"));
		String poundSignISO = BugzillaServerFacade.addCredentials(IBugzillaConstants.TEST_BUGZILLA_222_URL,
				"ISO-8859-1", "testUser", "£");
		assertFalse(poundSignISO.contains("%C2%A3"));
		assertTrue(poundSignISO.endsWith("password=%A3"));
	}

	public void testGetBug() throws Exception {
		RepositoryTaskData taskData = BugzillaServerFacade.getBug(repository.getUrl(), repository.getUserName(),
				repository.getPassword(), null, repository.getCharacterEncoding(), 1);
		assertNotNull(taskData);
		assertEquals("user@mylar.eclipse.org", taskData.getAssignedTo());

		// Notice that comment 0 is the Bug Description
		assertEquals("foo", taskData.getComments().get(0).getText());
		assertEquals("nhapke@cs.ubc.ca", taskData.getComments().get(0).getAuthor());

		// You can use the getAttributeValue to pull up the information on any
		// part of the bug
		assertEquals("P1", taskData.getAttributeValue(BugzillaReportElement.PRIORITY.getKeyString()));
	}

	public void testGetProductList() throws Exception {
		List<String> products = BugzillaServerFacade.getProductList(repository.getUrl(), null,
				repository.getUserName(), repository.getPassword(), repository.getCharacterEncoding());

		assertEquals(3, products.size());
		assertTrue(products.contains("Read Only Test Cases"));
		assertTrue(products.contains("Read Write Test Cases"));
		assertTrue(products.contains("TestProduct"));
	}

	public void testQueryViaConnector() throws Exception {
		String queryUrlString = repository.getUrl()
				+ "/buglist.cgi?ctype=rdf&query_format=advanced&short_desc_type=allwordssubstr&short_desc=search-match-test&product=TestProduct&long_desc_type=substring&long_desc=&bug_file_loc_type=allwordssubstr&bug_file_loc=&deadlinefrom=&deadlineto=&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&emailassigned_to1=1&emailtype1=substring&email1=&emailassigned_to2=1&emailreporter2=1&emailcc2=1&emailtype2=substring&email2=&bugidtype=include&bug_id=&votes=&chfieldfrom=&chfieldto=Now&chfieldvalue=&cmdtype=doit&order=Reuse+same+sort+as+last+time&field0-0-0=noop&type0-0-0=noop&value0-0-0=";

		// holds onto actual hit objects
		TaskList taskList = new TaskList();
		QueryHitCollector collector = new QueryHitCollector(new TaskList());
		BugzillaRepositoryConnector connector = new BugzillaRepositoryConnector();
		connector.init(taskList);
		BugzillaRepositoryQuery query = new BugzillaRepositoryQuery(repository.getUrl(), queryUrlString, "description",
				"-1", taskList);
		connector.performQuery(query, repository, null, new NullProgressMonitor(), collector);
		assertEquals(2, collector.getHits().size());
		for (AbstractQueryHit hit : collector.getHits()) {
			assertTrue(hit.getDescription().contains("search-match-test"));
		}
	}
}

// public void testQueryBugs() throws Exception {
//
// QueryHitCollector collector = new QueryHitCollector(new TaskList());
//
// // Note need for ctype=rdf in query url
// String urlString =
// "http://mylar.eclipse.org/bugs222/buglist.cgi?ctype=rdf&query_format=advanced&short_desc_type=allwordssubstr&short_desc=search-match-test&product=TestProduct&long_desc_type=substring&long_desc=&bug_file_loc_type=allwordssubstr&bug_file_loc=&deadlinefrom=&deadlineto=&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&emailassigned_to1=1&emailtype1=substring&email1=&emailassigned_to2=1&emailreporter2=1&emailcc2=1&emailtype2=substring&email2=&bugidtype=include&bug_id=&votes=&chfieldfrom=&chfieldto=Now&chfieldvalue=&cmdtype=doit&order=Reuse+same+sort+as+last+time&field0-0-0=noop&type0-0-0=noop&value0-0-0=";
// RepositoryQueryResultsFactory queryFactory = new
// RepositoryQueryResultsFactory();
//		
// // Tasklist can be null but calls to hit.getOrCreateCorrespondingTask() will
// return null.
// queryFactory.performQuery(null, repository.getUrl(), collector, urlString,
// null, -1, repository
// .getCharacterEncoding());
//
// assertEquals(2, collector.getHits().size());
// for (AbstractQueryHit hit : collector.getHits()) {
// assertTrue(hit.getDescription().contains("search-match-test"));
// }
// }

Back to the top