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) 2018 Red Hat Inc. 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:
* Lucas Bullen (Red Hat Inc.) - initial API and implementation
*******************************************************************************/
package org.eclipse.ua.tests.help.webapp;
import static org.junit.Assert.assertEquals;
import java.net.URL;
import org.eclipse.core.runtime.URIUtil;
import org.eclipse.help.internal.HelpPlugin;
import org.eclipse.help.internal.base.BaseHelpSystem;
import org.eclipse.help.internal.server.WebappManager;
import org.eclipse.ua.tests.help.remote.RemotePreferenceStore;
import org.eclipse.ua.tests.help.remote.RemoteTestUtils;
import org.eclipse.ua.tests.help.remote.TestServerManager;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class EclipseConnectorTests {
private int mode;
@Before
public void setUp() throws Exception {
BaseHelpSystem.ensureWebappRunning();
mode = BaseHelpSystem.getMode();
RemotePreferenceStore.savePreferences();
RemotePreferenceStore.setMockRemoteServer();
BaseHelpSystem.setMode(BaseHelpSystem.MODE_INFOCENTER);
HelpPlugin.getTocManager().getTocs("en");
}
@After
public void tearDown() throws Exception {
RemotePreferenceStore.restorePreferences();
BaseHelpSystem.setMode(mode);
}
@Test
public void testEncodedAmpersand() throws Exception {
final String path = "/data/help/index/" + URIUtil.fromString("topic&.html").toString();
String remoteContent = getHelpContent("mock.toc", path, "en");
int port = TestServerManager.getPort(0);
String expectedContent = RemoteTestUtils.createMockContent("mock.toc", path, "en", port);
assertEquals(expectedContent, remoteContent);
}
@Test
public void testEncodedSpace() throws Exception {
final String path = "/data/help/index/" + URIUtil.fromString("topic .html").toString();
String remoteContent = getHelpContent("mock.toc", path, "en");
int port = TestServerManager.getPort(0);
String expectedContent = RemoteTestUtils.createMockContent("mock.toc", path, "en", port);
assertEquals(expectedContent, remoteContent);
}
@Test
public void testEncodedPercentSign() throws Exception {
final String path = "/data/help/index/" + URIUtil.fromString("topic%.html").toString();
String remoteContent = getHelpContent("mock.toc", path, "en");
int port = TestServerManager.getPort(0);
String expectedContent = RemoteTestUtils.createMockContent("mock.toc", path, "en", port);
assertEquals(expectedContent, remoteContent);
}
private static String getHelpContent(String plugin, String path, String locale) throws Exception {
int port = WebappManager.getPort();
URL url = new URL("http", "localhost", port, "/help/nftopic/" + plugin + path + "?lang=" + locale);
return RemoteTestUtils.readFromURL(url);
}
}
|