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, 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 org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.mylyn.internal.bugzilla.core.BugzillaClient;
import org.eclipse.mylyn.internal.bugzilla.core.BugzillaReportElement;
import org.eclipse.mylyn.internal.bugzilla.core.BugzillaTask;
import org.eclipse.mylyn.tasks.core.RepositoryTaskData;
import org.eclipse.mylyn.tasks.ui.TasksUiPlugin;
/**
* @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 CoreException {
init222();
repository.setCharacterEncoding("UTF-8");
BugzillaTask task = (BugzillaTask) connector.createTaskFromExistingId(repository, "57",
new NullProgressMonitor());
assertNotNull(task);
//TasksUiPlugin.getSynchronizationManager().synchronize(connector, task, true, null);
assertTrue(task.getSummary().equals("\u00E6"));//"\u05D0"));
taskList.deleteTask(task);
connector.getClientManager().repositoryRemoved(repository);
repository.setCharacterEncoding("ISO-8859-1");
task = (BugzillaTask) connector.createTaskFromExistingId(repository, "57", new NullProgressMonitor());
assertNotNull(task);
//TasksUiPlugin.getSynchronizationManager().synchronize(connector, task, true, null);
// iso-8859-1 'incorrect' interpretation
assertFalse(task.getSummary().equals("\u00E6"));//"\u05D0"));
}
public void testProperEncodingUponPost() throws CoreException {
init222();
repository.setCharacterEncoding("UTF-8");
BugzillaTask task = (BugzillaTask) connector.createTaskFromExistingId(repository, "57",
new NullProgressMonitor());
RepositoryTaskData taskData = TasksUiPlugin.getTaskDataManager().getNewTaskData(task.getRepositoryUrl(),
task.getTaskId());
assertNotNull(task);
assertTrue(task.getSummary().equals("\u00E6"));//"\u05D0"));
String priority = null;
if (task.getPriority().equals("P1")) {
priority = "P2";
taskData.setAttributeValue(BugzillaReportElement.PRIORITY.getKeyString(), priority);
} else {
priority = "P1";
taskData.setAttributeValue(BugzillaReportElement.PRIORITY.getKeyString(), priority);
}
submit(task, taskData);
taskList.deleteTask(task);
task = (BugzillaTask) connector.createTaskFromExistingId(repository, "57", new NullProgressMonitor());
assertNotNull(task);
assertTrue(task.getSummary().equals("\u00E6"));//"\u05D0"));
}
}
|