Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Goldthorpe2009-10-16 18:35:18 +0000
committerChris Goldthorpe2009-10-16 18:35:18 +0000
commit3779a2ef497f7fe3858fe7673bdc94c5f356cbb4 (patch)
tree00a3577d25741b6f6d520fdc3f50f27eb67fdf80
parentad0c322b86679a8acfab77a9ec01313f4ff0bcb3 (diff)
downloadeclipse.platform.ua-3779a2ef497f7fe3858fe7673bdc94c5f356cbb4.tar.gz
eclipse.platform.ua-3779a2ef497f7fe3858fe7673bdc94c5f356cbb4.tar.xz
eclipse.platform.ua-3779a2ef497f7fe3858fe7673bdc94c5f356cbb4.zip
Add test to read remote content
-rwxr-xr-xorg.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/AllRemoteTests.java1
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/ContentServletTest.java60
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/GetContentUsingRemoteHelp.java89
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/MockContentServlet.java48
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/MockIndexSevlet.java22
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/MockTocServlet.java6
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/RemotePreferenceStore.java11
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/RemoteTestUtils.java72
-rw-r--r--org.eclipse.ua.tests/plugin.xml8
9 files changed, 263 insertions, 54 deletions
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/AllRemoteTests.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/AllRemoteTests.java
index b300c4058..786f35cc6 100755
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/AllRemoteTests.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/AllRemoteTests.java
@@ -38,5 +38,6 @@ public class AllRemoteTests extends TestSuite {
addTestSuite(SearchUsingRemoteHelp.class);
addTestSuite(LoadTocUsingRemoteHelp.class);
addTestSuite(GetContextUsingRemoteHelp.class);
+ addTestSuite(GetContentUsingRemoteHelp.class);
}
}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/ContentServletTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/ContentServletTest.java
index fcef5e472..1ad0dd1be 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/ContentServletTest.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/ContentServletTest.java
@@ -11,18 +11,10 @@
package org.eclipse.ua.tests.help.remote;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.UnsupportedEncodingException;
-import java.net.URL;
import junit.framework.TestCase;
-import org.eclipse.core.runtime.FileLocator;
-import org.eclipse.core.runtime.Platform;
import org.eclipse.help.internal.base.BaseHelpSystem;
-import org.eclipse.help.internal.server.WebappManager;
-import org.osgi.framework.Bundle;
public class ContentServletTest extends TestCase {
@@ -41,75 +33,43 @@ public class ContentServletTest extends TestCase {
public void testSimpleContent() throws Exception {
final String path = "/data/help/index/topic1.html";
- String remoteContent = getRemoteContent(UA_TESTS, path, "en");
- String localContent = getLocalContent(UA_TESTS, path);
+ String remoteContent = RemoteTestUtils.getRemoteContent(UA_TESTS, path, "en");
+ String localContent = RemoteTestUtils.getLocalContent(UA_TESTS, path);
assertEquals(remoteContent, localContent);
}
public void testFilteredContent() throws Exception {
final String path = "/data/help/manual/filter.xhtml";
- String remoteContent = getRemoteContent(UA_TESTS, path, "en");
- String localContent = getLocalContent(UA_TESTS, path);
+ String remoteContent = RemoteTestUtils.getRemoteContent(UA_TESTS, path, "en");
+ String localContent = RemoteTestUtils.getLocalContent(UA_TESTS, path);
assertEquals(remoteContent, localContent);
}
public void testContentInEnLocale() throws Exception {
final String path = "/data/help/search/testnl1.xhtml";
- String remoteContent = getRemoteContent(UA_TESTS, path, "en");
- String localContent = getLocalContent(UA_TESTS, path);
+ String remoteContent = RemoteTestUtils.getRemoteContent(UA_TESTS, path, "en");
+ String localContent = RemoteTestUtils.getLocalContent(UA_TESTS, path);
assertEquals(remoteContent, localContent);
}
public void testContentInDeLocale() throws Exception {
final String path = "/data/help/search/testnl1.xhtml";
- String remoteContent = getRemoteContent(UA_TESTS, path, "de");
- String enLocalContent = getLocalContent(UA_TESTS, path);
- String deLocalContent = getLocalContent(UA_TESTS, "/nl/de" + path);
+ String remoteContent = RemoteTestUtils.getRemoteContent(UA_TESTS, path, "de");
+ String enLocalContent = RemoteTestUtils.getLocalContent(UA_TESTS, path);
+ String deLocalContent = RemoteTestUtils.getLocalContent(UA_TESTS, "/nl/de" + path);
assertEquals(remoteContent, deLocalContent);
assertFalse(remoteContent.equals(enLocalContent));
}
public void testRemoteContentNotFound() throws Exception {
try {
- getRemoteContent(UA_TESTS, "/no/such/path.html", "en");
+ RemoteTestUtils.getRemoteContent(UA_TESTS, "/no/such/path.html", "en");
fail("No exception thrown");
} catch (IOException e) {
// Exception caught as expected
}
}
- private String getRemoteContent(String plugin, String path, String locale)
- throws Exception {
- int port = WebappManager.getPort();
- URL url = new URL("http", "localhost", port, "/help/rtopic/" + plugin + path + "?lang=" + locale);
- return readFromURL(url);
- }
- private String getLocalContent(String plugin, String path) throws Exception {
- Bundle bundle = Platform.getBundle(plugin);
- URL url;
- if (bundle != null) {
- url=FileLocator.toFileURL(new URL(bundle.getEntry("/"), path)); //$NON-NLS-1$
- } else {
- return null;
- }
- return readFromURL(url);
- }
-
- protected String readFromURL(URL url) throws IOException,
- UnsupportedEncodingException {
- InputStream is = url.openStream();
- InputStreamReader inputStreamReader = new InputStreamReader(is, "UTF-8");
- StringBuffer buffer = new StringBuffer();
- char[] cbuf = new char[256];
- int len;
- do {
- len = inputStreamReader.read(cbuf);
- if (len > 0) {
- buffer.append(cbuf, 0, len);
- }
- } while (len >= 0);
- return buffer.toString();
- }
}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/GetContentUsingRemoteHelp.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/GetContentUsingRemoteHelp.java
new file mode 100644
index 000000000..863559b0d
--- /dev/null
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/GetContentUsingRemoteHelp.java
@@ -0,0 +1,89 @@
+/*******************************************************************************
+ * 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.net.URL;
+
+import junit.framework.TestCase;
+
+import org.eclipse.help.internal.HelpPlugin;
+import org.eclipse.help.internal.base.BaseHelpSystem;
+import org.eclipse.help.internal.server.WebappManager;
+
+public class GetContentUsingRemoteHelp extends TestCase {
+
+ private int mode;
+
+ protected void setUp() throws Exception {
+ BaseHelpSystem.ensureWebappRunning();
+ mode = BaseHelpSystem.getMode();
+ RemotePreferenceStore.savePreferences();
+ RemotePreferenceStore.setMockRemoteServer();
+ RemotePreferenceStore.disableErrorPage();
+ BaseHelpSystem.setMode(BaseHelpSystem.MODE_INFOCENTER);
+ HelpPlugin.getTocManager().getTocs("en");
+ }
+
+ protected void tearDown() throws Exception {
+ RemotePreferenceStore.restorePreferences();
+ BaseHelpSystem.setMode(mode);
+ }
+
+ public void testContentNotFound() {
+ try {
+ getHelpContent("mock.toc", "/invalid/nosuchfile.html", "en");
+ fail("No exception thrown");
+ } catch (Exception e) {
+ // Exception thrown as expected
+ }
+ }
+
+ public void testContentFound() throws Exception {
+ final String path = "/data/help/index/topic1.html";
+ String remoteContent = getHelpContent("mock.toc", path, "en");
+ String expectedContent = RemoteTestUtils.createMockContent("mock.toc", path, "en");
+ assertEquals(expectedContent, remoteContent);
+ }
+
+ public void testContentFoundDe() throws Exception {
+ final String path = "/data/help/index/topic2.html";
+ String remoteContent = getHelpContent("mock.toc", path, "de");
+ String expectedContent = RemoteTestUtils.createMockContent("mock.toc", path, "de");
+ assertEquals(expectedContent, remoteContent);
+ }
+
+ public void testLocalBeatsRemote() throws Exception {
+ final String path = "/doc/help_home.html";
+ String plugin = "org.eclipse.help.base";
+ String remoteContent = getHelpContent(plugin, path, "en");
+ String localContent = RemoteTestUtils.getLocalContent(plugin, path);
+ assertEquals(localContent, remoteContent);
+ }
+
+ /*
+ public void testRemoteUsedIfLocalUnavaliable() throws Exception {
+ final String path = "/data/help/nonlocal.html";
+ String plugin = "org.eclipse.help.base";
+ String remoteContent = getHelpContent(plugin, path, "en");
+ String expectedContent = RemoteTestUtils.createMockContent(plugin, path, "en");
+ assertEquals(expectedContent, remoteContent);
+ }
+ */
+
+ public 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);
+ }
+
+}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/MockContentServlet.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/MockContentServlet.java
new file mode 100644
index 000000000..e1546aa23
--- /dev/null
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/MockContentServlet.java
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * 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.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.eclipse.help.internal.webapp.data.UrlUtil;
+
+public class MockContentServlet extends HttpServlet {
+
+ private static final long serialVersionUID = 2360013070409217702L;
+
+ /**
+ * Return a create page based on the path and locale unless the path
+ * starts with "/invalid" in which case return an I/O error
+ */
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+ throws ServletException, IOException {
+ String locale = UrlUtil.getLocale(req, resp);
+ req.setCharacterEncoding("UTF-8"); //$NON-NLS-1$
+ resp.setContentType("application/xml; charset=UTF-8"); //$NON-NLS-1$
+ String path = req.getPathInfo();
+ int slash = path.indexOf('/', 1);
+ String plugin = path.substring(1, slash);
+ String file = path.substring(slash);
+ if (file.startsWith("/invalid")) {
+ resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
+ } else {
+ String response = RemoteTestUtils.createMockContent(plugin, file, locale);
+ resp.getWriter().write(response);
+ }
+ }
+
+}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/MockIndexSevlet.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/MockIndexSevlet.java
new file mode 100644
index 000000000..ae1e3a5df
--- /dev/null
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/MockIndexSevlet.java
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * 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 org.eclipse.help.internal.webapp.servlet.IndexServlet;
+
+public class MockIndexSevlet extends IndexServlet {
+
+ private static final long serialVersionUID = -930969620357059313L;
+
+ // TODO implement servlet
+
+}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/MockTocServlet.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/MockTocServlet.java
index b32439eb9..d9f1b211d 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/MockTocServlet.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/MockTocServlet.java
@@ -37,11 +37,11 @@ public class MockTocServlet extends TocServlet {
UserToc toc1 = new UserToc("Mock Toc " + locale, null, true);
UserTopic topic1 = new UserTopic("Topic_" + locale, "http://www.eclipse.org", true);
toc1.addTopic(topic1);
- TocContribution contribution1 = createToc(toc1, "mockToc", locale);
+ TocContribution contribution1 = createToc(toc1, "org.eclipse.help.base", locale);
UserToc toc2 = new UserToc("Mock Toc 2 " + locale, null, true);
UserTopic topic2 = new UserTopic("Topic_" + locale, "http://www.eclipse.org", true);
toc2.addTopic(topic2);
- TocContribution contribution2 = createToc(toc2, "mockToc2", locale);
+ TocContribution contribution2 = createToc(toc2, "mock.toc", locale);
String response;
try {
response = serialize(new TocContribution[] { contribution1, contribution2 }, locale);
@@ -55,7 +55,7 @@ public class MockTocServlet extends TocServlet {
TocContribution contribution;
contribution = new TocContribution();
contribution.setCategoryId(null);
- contribution.setContributorId("org.eclipse.ua.tests");
+ contribution.setContributorId(id);
contribution.setExtraDocuments(new String[0]);
contribution.setLocale(locale);
contribution.setPrimary(true);
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/RemotePreferenceStore.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/RemotePreferenceStore.java
index d98529c93..3c8f859a8 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/RemotePreferenceStore.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/RemotePreferenceStore.java
@@ -26,6 +26,7 @@ public class RemotePreferenceStore {
private static String icEnabledPreference;
private static String helpOn;
private static String defaultPort;
+ private static String pageNotFound;
public static void savePreferences() throws Exception {
namePreference = Platform.getPreferencesService().getString
@@ -49,6 +50,9 @@ public class RemotePreferenceStore {
helpOn = Platform.getPreferencesService().getString
(HelpBasePlugin.PLUGIN_ID, IHelpBaseConstants.P_KEY_REMOTE_HELP_ON,
"", null);
+ pageNotFound = Platform.getPreferencesService().getString
+ (HelpBasePlugin.PLUGIN_ID, IHelpBaseConstants.P_PAGE_NOT_FOUND,
+ "", null);
}
public static void restorePreferences() throws Exception {
@@ -60,7 +64,8 @@ public class RemotePreferenceStore {
prefs.put(IHelpBaseConstants.P_KEY_REMOTE_HELP_PORT, portPreference);
prefs.put(IHelpBaseConstants.P_KEY_REMOTE_HELP_DEFAULT_PORT, defaultPort);
prefs.put(IHelpBaseConstants.P_KEY_REMOTE_HELP_ON, helpOn);
- prefs.put(IHelpBaseConstants.P_KEY_REMOTE_HELP_ICEnabled, icEnabledPreference);
+ prefs.put(IHelpBaseConstants.P_KEY_REMOTE_HELP_ICEnabled, icEnabledPreference);
+ prefs.put(IHelpBaseConstants.P_PAGE_NOT_FOUND, pageNotFound);
}
public static void setMockRemoteServer() throws Exception {
@@ -92,5 +97,9 @@ public class RemotePreferenceStore {
public static void disableRemoteHelp() throws Exception {
RemotePreferenceTest.setPreference("remoteHelpOn", "false");
}
+
+ public static void disableErrorPage() throws Exception {
+ RemotePreferenceTest.setPreference(IHelpBaseConstants.P_PAGE_NOT_FOUND, "");
+ }
}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/RemoteTestUtils.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/RemoteTestUtils.java
new file mode 100644
index 000000000..d83e78487
--- /dev/null
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/RemoteTestUtils.java
@@ -0,0 +1,72 @@
+/*******************************************************************************
+ * 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.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.UnsupportedEncodingException;
+import java.net.URL;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.help.internal.server.WebappManager;
+import org.osgi.framework.Bundle;
+
+public class RemoteTestUtils {
+
+ public static String createMockContent(String plugin, String path,
+ String locale) {
+ String result = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\">"
+ + "<HTML lang =\"" + locale + "\"><HEAD>"
+ + "<TITLE> Content from: " + plugin + "</TITLE></HEAD>"
+ + "<BODY><P>Path is: " + path + "</P></BODY></HTML>";
+ return result;
+ }
+
+ public static String getRemoteContent(String plugin, String path,
+ String locale) throws Exception {
+ int port = WebappManager.getPort();
+ URL url = new URL("http", "localhost", port, "/help/rtopic/" + plugin
+ + path + "?lang=" + locale);
+ return readFromURL(url);
+ }
+
+ public static String getLocalContent(String plugin, String path)
+ throws IOException {
+ Bundle bundle = Platform.getBundle(plugin);
+ URL url;
+ if (bundle != null) {
+ url = FileLocator.toFileURL(new URL(bundle.getEntry("/"), path)); //$NON-NLS-1$
+ } else {
+ throw new IOException("Invalid bundle " + plugin);
+ }
+ return readFromURL(url);
+ }
+
+ public static String readFromURL(URL url) throws IOException,
+ UnsupportedEncodingException {
+ InputStream is = url.openStream();
+ InputStreamReader inputStreamReader = new InputStreamReader(is, "UTF-8");
+ StringBuffer buffer = new StringBuffer();
+ char[] cbuf = new char[256];
+ int len;
+ do {
+ len = inputStreamReader.read(cbuf);
+ if (len > 0) {
+ buffer.append(cbuf, 0, len);
+ }
+ } while (len >= 0);
+ return buffer.toString();
+ }
+
+}
diff --git a/org.eclipse.ua.tests/plugin.xml b/org.eclipse.ua.tests/plugin.xml
index fc791f15b..d1d49fced 100644
--- a/org.eclipse.ua.tests/plugin.xml
+++ b/org.eclipse.ua.tests/plugin.xml
@@ -585,6 +585,14 @@
alias="/context"
class="org.eclipse.ua.tests.help.remote.MockContextServlet">
</servlet>
+ <servlet
+ alias="/rtopic"
+ class="org.eclipse.ua.tests.help.remote.MockContentServlet">
+ </servlet>
+ <servlet
+ alias="/index"
+ class="org.eclipse.ua.tests.help.remote.MockIndexServlet">
+ </servlet>
<serviceSelector
filter="(other.info=org.eclipse.ua.tests)">

Back to the top