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
|
/*******************************************************************************
* Copyright (c) 2009 IBM Corporation 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:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.ua.tests.help.remote;
import java.util.ArrayList;
import java.util.List;
import junit.framework.TestCase;
import org.eclipse.help.IIndex;
import org.eclipse.help.IIndexEntry;
import org.eclipse.help.internal.HelpPlugin;
import org.eclipse.help.internal.base.BaseHelpSystem;
public class LoadIndexUsingRemoteHelp extends TestCase {
private int mode;
protected void setUp() throws Exception {
RemotePreferenceStore.savePreferences();
mode = BaseHelpSystem.getMode();
BaseHelpSystem.setMode(BaseHelpSystem.MODE_INFOCENTER);
}
protected void tearDown() throws Exception {
RemotePreferenceStore.restorePreferences();
BaseHelpSystem.setMode(mode);
}
public void testIndexContribution() throws Exception {
String locale = "en";
HelpPlugin.getIndexManager().clearCache();
IIndex index = HelpPlugin.getIndexManager().getIndex(locale);
assertEquals(0, matchingEntries(index, "entry1_" + locale).length);
assertEquals(0, matchingEntries(index, "entry2_" + locale).length);
RemotePreferenceStore.setMockRemoteServer();
HelpPlugin.getIndexManager().clearCache();
index = HelpPlugin.getIndexManager().getIndex(locale);
assertEquals(1, matchingEntries(index, "entry1_" + locale).length);
assertEquals(1, matchingEntries(index, "entry2_" + locale).length);
}
public void testIndexWithTwoRemoteServers() throws Exception {
String locale = "en";
HelpPlugin.getIndexManager().clearCache();
IIndex index = HelpPlugin.getIndexManager().getIndex(locale);
IIndexEntry[] entry1 = matchingEntries(index, "entry1_" + locale);
assertEquals(0, entry1.length);
IIndexEntry[] entry2 = matchingEntries(index, "entry2_" + locale);
assertEquals(0, entry2.length);
RemotePreferenceStore.setTwoMockRemoteServers();
HelpPlugin.getIndexManager().clearCache();
index = HelpPlugin.getIndexManager().getIndex(locale);
// Entry 1 has the same child on each remote server, Entry 2 has different children
entry1 = matchingEntries(index, "entry1_" + locale);
entry2 = matchingEntries(index, "entry2_" + locale);
assertEquals(1, entry1.length);
assertEquals(1, entry1[0].getTopics().length);
assertEquals(1, entry2.length);
assertEquals(2, entry2[0].getTopics().length);
}
private IIndexEntry[] matchingEntries(IIndex index, String keyword) {
List matches = new ArrayList();
IIndexEntry[] entries = index.getEntries();
for (int i = 0; i < entries.length; i++) {
if (keyword.equals(entries[i].getKeyword())) {
matches.add(entries[i]);
}
}
return (IIndexEntry[]) matches.toArray(new IIndexEntry[matches.size()]);
}
}
|