Skip to main content
summaryrefslogtreecommitdiffstats
blob: 78183a377859a94f255e21a12b0df082a08eb78e (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
/*******************************************************************************
 * Copyright (c) 2004, 2010 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.List;

import junit.framework.TestCase;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.mylyn.bugzilla.tests.support.BugzillaFixture;
import org.eclipse.mylyn.commons.net.AuthenticationCredentials;
import org.eclipse.mylyn.commons.net.AuthenticationType;
import org.eclipse.mylyn.internal.bugzilla.core.BugzillaAttribute;
import org.eclipse.mylyn.internal.bugzilla.core.BugzillaClient;
import org.eclipse.mylyn.internal.bugzilla.core.BugzillaRepositoryConnector;
import org.eclipse.mylyn.internal.bugzilla.core.RepositoryConfiguration;
import org.eclipse.mylyn.tasks.core.TaskRepository;
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
import org.eclipse.mylyn.tasks.core.data.TaskData;
import org.eclipse.mylyn.tasks.core.data.TaskMapper;
import org.eclipse.mylyn.commons.sdk.util.CommonTestUtil.PrivilegeLevel;

/**
 * @author Rob Elves
 * @author Mik Kersten
 */
public class RepositoryReportFactoryTest extends TestCase {

	TaskRepository repository;

	BugzillaClient client;

	BugzillaRepositoryConnector connector;

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

	public void testInvalidCredentials() throws Exception {
		try {
			client.logout(new NullProgressMonitor());
			repository.setCredentials(AuthenticationType.REPOSITORY,
					new AuthenticationCredentials("invalid", "invalid"), false);
			connector.getTaskData(repository, "1", new NullProgressMonitor());
			fail("CoreException expected but not found");
		} catch (CoreException e) {
			if (!e.getStatus().getMessage().startsWith("Unable to login")) {
				throw e;
			}
		}
		repository.flushAuthenticationCredentials();
	}

	public void testBugNotFound() throws Exception {
		try {
			connector.getClientManager().repositoryAdded(repository);
			connector.getTaskData(repository, "-1", new NullProgressMonitor());
			fail("Expected CoreException");
		} catch (CoreException e) {
			if (!e.getStatus().getMessage().startsWith("Repository error from")) {
				throw e;
			}
		}
	}

	public void testPostingAndReadingAttributes() throws Exception {
		RepositoryConfiguration repositoryConfiguration = connector.getRepositoryConfiguration(repository.getRepositoryUrl());
		List<String> priorities = repositoryConfiguration.getPriorities();
		String priority = priorities.get(priorities.size() > 0 ? priorities.size() - 1 : 0);
		TaskData data = BugzillaFixture.current().createTask(PrivilegeLevel.USER, "testPostingAndReading() summary",
				"testPostingAndReading() description");
		data.getRoot().getMappedAttribute(TaskAttribute.COMPONENT).setValue("ManualC2");
		data.getRoot().getMappedAttribute(TaskAttribute.PRIORITY).setValue(priority);
		data.getRoot().getMappedAttribute(TaskAttribute.SEVERITY).setValue("enhancement");
		data.getRoot().getMappedAttribute(BugzillaAttribute.REP_PLATFORM.getKey()).setValue("PC");
		data.getRoot().getMappedAttribute(BugzillaAttribute.OP_SYS.getKey()).setValue("Linux");
		data.getRoot().getMappedAttribute(BugzillaAttribute.VERSION.getKey()).setValue("R2.0");
//		data.getRoot().getMappedAttribute(BugzillaAttribute.DEPENDSON.getKey()).setValue("6, 7");
//		data.getRoot().getMappedAttribute(BugzillaAttribute.BLOCKED.getKey()).setValue("13, 14");

		BugzillaFixture.current().submitTask(data, client);
		data = BugzillaFixture.current().getTask(data.getTaskId(), client);
		assertNotNull(data);
		assertEquals("ManualC2", data.getRoot().getMappedAttribute(TaskAttribute.COMPONENT).getValue());
		assertEquals(priority, data.getRoot().getMappedAttribute(TaskAttribute.PRIORITY).getValue());
		assertEquals("enhancement", data.getRoot().getMappedAttribute(TaskAttribute.SEVERITY).getValue());
		assertEquals("PC", data.getRoot().getMappedAttribute(BugzillaAttribute.REP_PLATFORM.getKey()).getValue());
		assertEquals("Linux", data.getRoot().getMappedAttribute(BugzillaAttribute.OP_SYS.getKey()).getValue());
		assertEquals("R2.0", data.getRoot().getMappedAttribute(BugzillaAttribute.VERSION.getKey()).getValue());
		assertEquals("R2.0", data.getRoot().getMappedAttribute(BugzillaAttribute.VERSION.getKey()).getValue());
//		assertEquals("6, 7", root.getAttribute(BugzillaAttribute.BLOCKED.getKey()).getValue());
//		assertEquals("13, 14", root.getAttribute(BugzillaAttribute.BLOCKED.getKey()).getValue());

		TaskMapper mapper = new TaskMapper(data);
		assertEquals("testPostingAndReading() summary", mapper.getSummary());
		assertEquals("testPostingAndReading() description", mapper.getDescription());
		assertEquals("ManualTest", mapper.getProduct());
	}

	// FIXME: Test posting and retrieval of time values
//	public void testTimeTracking222() throws Exception {
//		assertEquals("7.50", report.getRoot().getAttribute(BugzillaAttribute.ESTIMATED_TIME.getKey()).getValue());
//		assertEquals("4.00", report.getRoot().getAttribute(BugzillaAttribute.ACTUAL_TIME.getKey()).getValue());
//		assertEquals("3.00", report.getRoot().getAttribute(BugzillaAttribute.REMAINING_TIME.getKey()).getValue());
//		assertEquals("2005-03-04", report.getRoot().getAttribute(BugzillaAttribute.DEADLINE.getKey()).getValue());
//	}

	public void testDeltaTsTruncation() {
		String ts1 = "2006-07-06 03:22:08 0900";
		String ts1_truncated = "2006-07-06 03:22:08";
		assertEquals(ts1_truncated, BugzillaClient.stripTimeZone(ts1));

		String ts2 = "2006-07-06 03:22:08";
		String ts2_truncated = "2006-07-06 03:22:08";
		assertEquals(ts2_truncated, BugzillaClient.stripTimeZone(ts2));

		String ts3 = "2006-07-06 03:22:08 PST";
		String ts3_truncated = "2006-07-06 03:22:08";
		assertEquals(ts3_truncated, BugzillaClient.stripTimeZone(ts3));
	}

}

Back to the top