diff options
author | Chris Goldthorpe | 2009-11-30 21:24:30 +0000 |
---|---|---|
committer | Chris Goldthorpe | 2009-11-30 21:24:30 +0000 |
commit | 4e84d864163b6e36de5bcaa5708ea42669bf1849 (patch) | |
tree | 8123c7b1db55936abea6c758c11d1d3adf93d06b /org.eclipse.ua.tests | |
parent | c39c32c8fe53ee81f0571c212ecb4882d6fb7e27 (diff) | |
download | eclipse.platform.ua-4e84d864163b6e36de5bcaa5708ea42669bf1849.tar.gz eclipse.platform.ua-4e84d864163b6e36de5bcaa5708ea42669bf1849.tar.xz eclipse.platform.ua-4e84d864163b6e36de5bcaa5708ea42669bf1849.zip |
Diffstat (limited to 'org.eclipse.ua.tests')
7 files changed, 216 insertions, 15 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 f78b669ba..1a56646d7 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 @@ -40,5 +40,6 @@ public class AllRemoteTests extends TestSuite { addTestSuite(LoadIndexUsingRemoteHelp.class); addTestSuite(GetContentUsingRemoteHelp.class); addTestSuite(GetContextUsingRemoteHelp.class); + addTestSuite(TocManagerTest.class); } } 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 index d70c5e9f8..6f940ff8a 100644 --- 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 @@ -50,30 +50,97 @@ public class GetContentUsingRemoteHelp extends TestCase { 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"); + int port = TestServerManager.getPort(0); + String expectedContent = RemoteTestUtils.createMockContent("mock.toc", path, "en", port); 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"); + int port = TestServerManager.getPort(0); + String expectedContent = RemoteTestUtils.createMockContent("mock.toc", path, "de", port); 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 helpContent = getHelpContent(plugin, path, "en"); String localContent = RemoteTestUtils.getLocalContent(plugin, path); - assertEquals(localContent, remoteContent); + assertEquals(localContent, helpContent); + } + + public void testRemoteHelpPreferredPreference() throws Exception { + RemotePreferenceStore.setMockRemotePriority(); + HelpPlugin.getTocManager().clearCache(); + HelpPlugin.getTocManager().getTocs("en"); + final String path = "/doc/help_home.html"; + String plugin = "org.eclipse.help.base"; + String helpContent = getHelpContent(plugin, path, "en"); + + int port = TestServerManager.getPort(0); + String remoteContent = RemoteTestUtils.createMockContent(plugin, path, "en", port); + assertEquals(remoteContent, helpContent); + } + + public void testRemoteOrdering() throws Exception { + RemotePreferenceStore.setTwoMockRemoteServers(); + RemotePreferenceStore.setMockRemotePriority(); + HelpPlugin.getTocManager().clearCache(); + HelpPlugin.getTocManager().getTocs("en"); + //Verify help coming from first one + final String path = "/doc/help_home.html"; + String plugin = "org.eclipse.help.base"; + String helpContent = GetContentUsingRemoteHelp.getHelpContent(plugin, path, "en"); + + //Get remote content from first one in prefs + + int port0 = TestServerManager.getPort(0); + String remoteContent0 = RemoteTestUtils.createMockContent(plugin, path, "en", port0); + + int port1 = TestServerManager.getPort(1); + String remoteContent1 = RemoteTestUtils.createMockContent(plugin, path, "en", port1); + + assertEquals(remoteContent0, helpContent); + assertFalse(remoteContent1.equals(helpContent)); + } + + public void testRemoteOrderingReversed() throws Exception { + RemotePreferenceStore.setTwoMockRemoteServersReversePriority(); + RemotePreferenceStore.setMockRemotePriority(); + HelpPlugin.getTocManager().clearCache(); + HelpPlugin.getTocManager().getTocs("en"); + //Verify help coming from first one + final String path = "/doc/help_home.html"; + String plugin = "org.eclipse.help.base"; + String helpContent = GetContentUsingRemoteHelp.getHelpContent(plugin, path, "en"); + + //Get remote content from second in prefs + + int port0 = TestServerManager.getPort(0); + String remoteContent0 = RemoteTestUtils.createMockContent(plugin, path, "en", port0); + + int port1 = TestServerManager.getPort(1); + String remoteContent1 = RemoteTestUtils.createMockContent(plugin, path, "en", port1); + + + assertEquals(remoteContent1, helpContent); + assertFalse(remoteContent0.equals(helpContent)); + } + + public void testRemoteUsedIfLocalUnavaliable() throws Exception { - final String path = "/data/help/nonlocal.html"; + RemotePreferenceStore.setMockRemoteServer(); + HelpPlugin.getTocManager().clearCache(); + HelpPlugin.getTocManager().getTocs("en"); + 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"); + String remoteContent = getHelpContent(plugin, path, "en"); + int port = TestServerManager.getPort(0); + String expectedContent = RemoteTestUtils.createMockContent(plugin, path, "en", port); assertEquals(expectedContent, remoteContent); } diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/LoadTocUsingRemoteHelp.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/LoadTocUsingRemoteHelp.java index 11a5353e1..764102076 100644 --- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/LoadTocUsingRemoteHelp.java +++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/LoadTocUsingRemoteHelp.java @@ -63,8 +63,6 @@ public class LoadTocUsingRemoteHelp extends TestCase { RemotePreferenceStore.disableRemoteHelp(); } - /* - * Fails, see Bug 292176 public void testTocContributionFromTwoServers() throws Exception { BaseHelpSystem.setMode(BaseHelpSystem.MODE_INFOCENTER); RemotePreferenceStore.setTwoMockRemoteServers(); @@ -76,7 +74,6 @@ public class LoadTocUsingRemoteHelp extends TestCase { assertEquals(0, deTocs); RemotePreferenceStore.disableRemoteHelp(); } - */ /* * Return the number of tocs with this label 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 index e1546aa23..63d2d47de 100644 --- 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 @@ -40,7 +40,8 @@ public class MockContentServlet extends HttpServlet { if (file.startsWith("/invalid")) { resp.setStatus(HttpServletResponse.SC_NOT_FOUND); } else { - String response = RemoteTestUtils.createMockContent(plugin, file, locale); + int port = req.getLocalPort(); + String response = RemoteTestUtils.createMockContent(plugin, file, locale, port); resp.getWriter().write(response); } } 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 3c8f859a8..1ec508428 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 remoteHelpPreferred; private static String pageNotFound; public static void savePreferences() throws Exception { @@ -50,6 +51,9 @@ public class RemotePreferenceStore { helpOn = Platform.getPreferencesService().getString (HelpBasePlugin.PLUGIN_ID, IHelpBaseConstants.P_KEY_REMOTE_HELP_ON, "", null); + remoteHelpPreferred = Platform.getPreferencesService().getString + (HelpBasePlugin.PLUGIN_ID, IHelpBaseConstants.P_KEY_REMOTE_HELP_PREFERRED, + "", null); pageNotFound = Platform.getPreferencesService().getString (HelpBasePlugin.PLUGIN_ID, IHelpBaseConstants.P_PAGE_NOT_FOUND, "", null); @@ -65,6 +69,7 @@ public class RemotePreferenceStore { 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_PREFERRED, remoteHelpPreferred); prefs.put(IHelpBaseConstants.P_PAGE_NOT_FOUND, pageNotFound); } @@ -79,7 +84,7 @@ public class RemotePreferenceStore { RemotePreferenceTest.setPreference("remoteHelpICEnabled", "true"); RemotePreferenceTest.setPreference("remoteHelpICContributed", "false"); } - + public static void setTwoMockRemoteServers() throws Exception { TestServerManager.start("ua.test", 0); TestServerManager.start("ua.test2", 1); @@ -93,6 +98,19 @@ public class RemotePreferenceStore { RemotePreferenceTest.setPreference("remoteHelpICEnabled", "true,true"); RemotePreferenceTest.setPreference("remoteHelpICContributed", "false,false"); } + public static void setTwoMockRemoteServersReversePriority() throws Exception { + TestServerManager.start("ua.test", 0); + TestServerManager.start("ua.test2", 1); + RemotePreferenceTest.setPreference("remoteHelpOn", "true"); + RemotePreferenceTest.setPreference("remoteHelpHost", "localhost,localhost"); + RemotePreferenceTest.setPreference("remoteHelpPath", "/help,/help"); + RemotePreferenceTest.setPreference("remoteHelpUseDefaultPort", "true,true"); + RemotePreferenceTest.setPreference("remoteHelpPort", "" + + TestServerManager.getPort(1) + ',' + TestServerManager.getPort(0)); + RemotePreferenceTest.setPreference("remoteHelpName", "uatest,uatest2"); + RemotePreferenceTest.setPreference("remoteHelpICEnabled", "true,true"); + RemotePreferenceTest.setPreference("remoteHelpICContributed", "false,false"); + } public static void disableRemoteHelp() throws Exception { RemotePreferenceTest.setPreference("remoteHelpOn", "false"); @@ -102,4 +120,13 @@ public class RemotePreferenceStore { RemotePreferenceTest.setPreference(IHelpBaseConstants.P_PAGE_NOT_FOUND, ""); } + public static void setMockLocalPriority() throws Exception { + RemotePreferenceTest.setPreference("remoteHelpOn", "true"); + RemotePreferenceTest.setPreference("remoteHelpPreferred", "false"); + } + + public static void setMockRemotePriority() throws Exception { + RemotePreferenceTest.setPreference("remoteHelpOn", "true"); + RemotePreferenceTest.setPreference("remoteHelpPreferred", "true"); + } } 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 index d83e78487..30ac88c73 100644 --- 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 @@ -25,11 +25,11 @@ import org.osgi.framework.Bundle; public class RemoteTestUtils { public static String createMockContent(String plugin, String path, - String locale) { + String locale, int port) { 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>"; + + "<BODY><P>Path is: " + path + ",Port is: "+port+"</P></BODY></HTML>"; return result; } diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/TocManagerTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/TocManagerTest.java new file mode 100644 index 000000000..3e028c003 --- /dev/null +++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/TocManagerTest.java @@ -0,0 +1,108 @@ +/******************************************************************************* + * 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.HashSet; +import junit.framework.TestCase; + +import org.eclipse.help.AbstractTocProvider; +import org.eclipse.help.internal.HelpPlugin; +import org.eclipse.help.internal.base.BaseHelpSystem; +import org.eclipse.help.internal.base.remote.RemoteTocProvider; +import org.eclipse.help.internal.toc.TocContribution; +import org.eclipse.help.internal.toc.TocFileProvider; + +public class TocManagerTest extends TestCase { + + private int mode; + + protected void setUp() throws Exception { + BaseHelpSystem.ensureWebappRunning(); + mode = BaseHelpSystem.getMode(); + RemotePreferenceStore.savePreferences(); + BaseHelpSystem.setMode(BaseHelpSystem.MODE_INFOCENTER); + } + + protected void tearDown() throws Exception { + BaseHelpSystem.setMode(mode); + RemotePreferenceStore.restorePreferences(); + } + + public void testDuplicatesOneRemote() throws Exception { + + RemotePreferenceStore.setMockRemoteServer(); + HelpPlugin.getTocManager().clearCache(); + boolean hasDuplicates=hasDuplicateContributions(HelpPlugin.getTocManager().getTocContributions("en")); + assertFalse(hasDuplicates); + } + + public void testDuplicatesTwoRemote() throws Exception { + + RemotePreferenceStore.setTwoMockRemoteServers(); + HelpPlugin.getTocManager().clearCache(); + boolean hasDuplicates=hasDuplicateContributions(HelpPlugin.getTocManager().getTocContributions("en")); + assertFalse(hasDuplicates); + } + + public void testLocalProviderPriority() throws Exception { + + int localPriority=0,remotePriority=0; + RemotePreferenceStore.setMockRemoteServer(); + RemotePreferenceStore.setMockLocalPriority(); + HelpPlugin.getTocManager().clearCache(); + AbstractTocProvider [] tocProviders = HelpPlugin.getTocManager().getTocProviders(); + for(int i=0;i<tocProviders.length;i++) + { + if(tocProviders[i] instanceof TocFileProvider) + localPriority = tocProviders[i].getPriority(); + + if(tocProviders[i] instanceof RemoteTocProvider) + remotePriority = tocProviders[i].getPriority(); + } + + assertTrue(localPriority<remotePriority); + } + + public void testRemoteProviderPriority() throws Exception { + + RemotePreferenceStore.setMockRemoteServer(); + RemotePreferenceStore.setMockRemotePriority(); + HelpPlugin.getTocManager().clearCache(); + int localPriority=0,remotePriority=0; + + AbstractTocProvider [] tocProviders = HelpPlugin.getTocManager().getTocProviders(); + for(int i=0;i<tocProviders.length;i++) + { + if(tocProviders[i] instanceof TocFileProvider) + localPriority = tocProviders[i].getPriority(); + + if(tocProviders[i] instanceof RemoteTocProvider) + remotePriority = tocProviders[i].getPriority(); + } + + assertTrue(remotePriority<localPriority); + } + + public static boolean hasDuplicateContributions(TocContribution[] tocContributions) + { + HashSet contributionsFound = new HashSet(); + + for(int i=0;i<tocContributions.length;i++) + { + if(contributionsFound.contains(tocContributions[i].getId())) + return true; + else + contributionsFound.add(tocContributions[i].getId()); + } + + return false; + } +} |