Skip to main content
summaryrefslogtreecommitdiffstats
blob: 8dcdbaa19c0549558732b52d50fb0ec2bb9d877a (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
/*******************************************************************************
 * 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 org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.mylyn.bugzilla.tests.support.BugzillaFixture;
import org.eclipse.mylyn.commons.net.AuthenticationType;
import org.eclipse.mylyn.commons.net.WebLocation;
import org.eclipse.mylyn.commons.repositories.core.auth.UserCredentials;
import org.eclipse.mylyn.commons.sdk.util.CommonTestUtil;
import org.eclipse.mylyn.commons.sdk.util.CommonTestUtil.PrivilegeLevel;
import org.eclipse.mylyn.internal.bugzilla.core.BugzillaAttribute;
import org.eclipse.mylyn.internal.bugzilla.core.BugzillaClient;
import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal;
import org.eclipse.mylyn.tasks.core.ITask;
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
import org.eclipse.mylyn.tasks.core.data.TaskData;
import org.eclipse.mylyn.tasks.core.data.TaskDataModel;
import org.eclipse.mylyn.tasks.ui.TasksUi;

/**
 * @author Mik Kersten
 */
public class EncodingTest extends AbstractBugzillaTest {

	public void testEncodingSetting() {

		String charset = BugzillaClient.getCharsetFromString("text/html; charset=UTF-8");
		assertEquals("UTF-8", charset);

		charset = BugzillaClient.getCharsetFromString("text/html");
		assertEquals(null, charset);

		charset = BugzillaClient.getCharsetFromString("<<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-2\">>");
		assertEquals("iso-8859-2", charset);

		charset = BugzillaClient.getCharsetFromString("<<meta http-equiv=\"Content-Type\" content=\"text/html\">>");
		assertEquals(null, charset);
	}

	/**
	 * This test just shows that when the encoding is changed on the repository, synchronization does in fact return in
	 * a different encoding (though it may not be legible)
	 */
	public void testDifferentReportEncoding() throws Exception {
		TaskData data = BugzillaFixture.current().createTask(PrivilegeLevel.USER, "\u00E6", null);
		assertNotNull(data);
		assertTrue(data.getRoot().getMappedAttribute(TaskAttribute.SUMMARY).getValue().equals("\u00E6"));//"\u05D0"));

		WebLocation location = new WebLocation(repository.getRepositoryUrl());
		UserCredentials credentials = CommonTestUtil.getCredentials(PrivilegeLevel.USER);
		location.setCredentials(AuthenticationType.REPOSITORY, credentials.getUserName(), credentials.getPassword());
		BugzillaClient client2 = BugzillaFixture.current().client(location, "ISO-8859-1");
		data = BugzillaFixture.current().getTask(data.getTaskId(), client2);
		assertNotNull(data);
		// iso-8859-1 'incorrect' interpretation
		assertFalse(data.getRoot().getMappedAttribute(TaskAttribute.SUMMARY).getValue().equals("\u00E6"));//"\u05D0"));
	}

	public void testProperEncodingUponPost() throws Exception {
		TaskData data = BugzillaFixture.current().createTask(PrivilegeLevel.USER, "\u00E6", null);
		assertNotNull(data);
		ITask task = TasksUi.getRepositoryModel().createTask(repository, data.getTaskId());
		TasksUiPlugin.getTaskList().addTask(task);
		Set<ITask> tasks = new HashSet<ITask>();
		tasks.add(task);
		TasksUiInternal.synchronizeTasks(connector, tasks, true, null);
		String priority = null;
		TaskDataModel model = createModel(task);
		if (task.getPriority().equals("P1")) {
			priority = "P2";
			TaskAttribute attrPriority = model.getTaskData()
					.getRoot()
					.getAttribute(BugzillaAttribute.PRIORITY.getKey());
			if (attrPriority != null) {
				attrPriority.setValue(priority);
				model.attributeChanged(attrPriority);
			} else {
				fail();
			}
		} else {
			priority = "P1";
			TaskAttribute attrPriority = model.getTaskData()
					.getRoot()
					.getAttribute(BugzillaAttribute.PRIORITY.getKey());
			if (attrPriority != null) {
				attrPriority.setValue(priority);
				model.attributeChanged(attrPriority);
			} else {
				fail();
			}
		}
		model.save(new NullProgressMonitor());

		submit(model);
		data = BugzillaFixture.current().getTask(data.getTaskId(), client);
		assertNotNull(data);
		assertTrue(data.getRoot().getMappedAttribute(TaskAttribute.SUMMARY).getValue().equals("\u00E6"));//"\u05D0"));
	}
}

Back to the top