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
|
/*******************************************************************************
* Copyright (c) 2009, 2016 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.ua.tests.help.remote;
import static org.junit.Assert.assertEquals;
import org.eclipse.help.internal.HelpPlugin;
import org.eclipse.help.internal.base.BaseHelpSystem;
import org.eclipse.help.internal.toc.Toc;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class LoadTocUsingRemoteHelp {
private int mode;
@Before
public void setUp() throws Exception {
RemotePreferenceStore.savePreferences();
mode = BaseHelpSystem.getMode();
}
@After
public void tearDown() throws Exception {
RemotePreferenceStore.restorePreferences();
BaseHelpSystem.setMode(mode);
}
@Test
public void testTocContribution() throws Exception {
BaseHelpSystem.setMode(BaseHelpSystem.MODE_INFOCENTER);
RemotePreferenceStore.setMockRemoteServer();
HelpPlugin.getTocManager().clearCache();
Toc[] tocs = HelpPlugin.getTocManager().getTocs("en");
int enTocs = matchingTocs(tocs, "Mock Toc en");
assertEquals(1, enTocs);
enTocs = matchingTocs(tocs, "Mock Toc 2 en");
assertEquals(1, enTocs);
int deTocs = matchingTocs(tocs, "Mock Toc de");
assertEquals(0, deTocs);
deTocs = matchingTocs(tocs, "Mock Toc 2 de");
assertEquals(0, deTocs);
RemotePreferenceStore.disableRemoteHelp();
}
@Test
public void testTocContributionDe() throws Exception {
BaseHelpSystem.setMode(BaseHelpSystem.MODE_INFOCENTER);
RemotePreferenceStore.setMockRemoteServer();
HelpPlugin.getTocManager().clearCache();
Toc[] tocs = HelpPlugin.getTocManager().getTocs("de");
int enTocs = matchingTocs(tocs, "Mock Toc en");
assertEquals(0, enTocs);
enTocs = matchingTocs(tocs, "Mock Toc 2 en");
assertEquals(0, enTocs);
int deTocs = matchingTocs(tocs, "Mock Toc de");
assertEquals(1, deTocs);
deTocs = matchingTocs(tocs, "Mock Toc 2 de");
assertEquals(1, deTocs);
RemotePreferenceStore.disableRemoteHelp();
}
@Test
public void testTocContributionFromTwoServers() throws Exception {
BaseHelpSystem.setMode(BaseHelpSystem.MODE_INFOCENTER);
RemotePreferenceStore.setTwoMockRemoteServers();
HelpPlugin.getTocManager().clearCache();
Toc[] tocs = HelpPlugin.getTocManager().getTocs("en");
int enTocs = matchingTocs(tocs, "Mock Toc en");
assertEquals(1, enTocs);
int deTocs = matchingTocs(tocs, "Mock Toc de");
assertEquals(0, deTocs);
RemotePreferenceStore.disableRemoteHelp();
}
/*
* Return the number of tocs with this label
*/
private int matchingTocs(Toc[] tocs, String label) {
int result = 0;
for (Toc toc : tocs) {
if (label.equals(toc.getLabel())) {
result += 1;
}
}
return result;
}
}
|