Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Goldthorpe2010-02-09 23:21:56 +0000
committerChris Goldthorpe2010-02-09 23:21:56 +0000
commit3a67bf3253ba63a2946c4508e0918c4c5971f4cb (patch)
tree45b6433320d50abddab384657a21d444307f342e /org.eclipse.ua.tests
parent76bec69c81b997a3ab4ac2b6738e9426a62405da (diff)
downloadeclipse.platform.ua-3a67bf3253ba63a2946c4508e0918c4c5971f4cb.tar.gz
eclipse.platform.ua-3a67bf3253ba63a2946c4508e0918c4c5971f4cb.tar.xz
eclipse.platform.ua-3a67bf3253ba63a2946c4508e0918c4c5971f4cb.zip
Added tests for WorkingSetManager
Diffstat (limited to 'org.eclipse.ua.tests')
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/AllSearchTests.java1
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/WorkingSetManagerTest.java181
2 files changed, 182 insertions, 0 deletions
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/AllSearchTests.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/AllSearchTests.java
index 18c06fa12..a85f9f00b 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/AllSearchTests.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/AllSearchTests.java
@@ -42,5 +42,6 @@ public class AllSearchTests extends TestSuite {
addTest(SearchParticipantXMLTest.suite());
addTest(LuceneParticipantTest.suite());
addTest(LuceneXMLParticipantTest.suite());
+ addTestSuite(WorkingSetManagerTest.class);
}
}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/WorkingSetManagerTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/WorkingSetManagerTest.java
new file mode 100644
index 000000000..1346ad777
--- /dev/null
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/WorkingSetManagerTest.java
@@ -0,0 +1,181 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.search;
+
+import org.eclipse.help.internal.workingset.AdaptableHelpResource;
+import org.eclipse.help.internal.workingset.AdaptableToc;
+import org.eclipse.help.internal.workingset.AdaptableTopic;
+import org.eclipse.help.internal.workingset.WorkingSet;
+import org.eclipse.help.internal.workingset.WorkingSetManager;
+
+import junit.framework.TestCase;
+
+public class WorkingSetManagerTest extends TestCase {
+
+ private WorkingSet[] workingSets;
+
+ protected void setUp() throws Exception {
+ WorkingSetManager manager = new WorkingSetManager();
+ manager.restoreState();
+ workingSets = manager.getWorkingSets();
+ for (int i = 0; i < workingSets.length; i++) {
+ manager.removeWorkingSet(workingSets[i]);
+ }
+ manager.saveState();
+ }
+
+ protected void tearDown() throws Exception {
+ WorkingSetManager manager = new WorkingSetManager();
+ WorkingSet[] wsetsToRemove = manager.getWorkingSets();
+ for (int i = 0; i < wsetsToRemove.length; i++) {
+ manager.removeWorkingSet(wsetsToRemove[i]);
+ }
+ for (int i = 0; i < workingSets.length; i++) {
+ manager.addWorkingSet(workingSets[i]);
+ }
+ manager.saveState();
+ }
+
+ public void testNewWSM() {
+ WorkingSetManager mgr = new WorkingSetManager();
+ assertEquals(0, mgr.getWorkingSets().length);
+ WorkingSetManager mgr2 = new WorkingSetManager();
+ assertEquals(mgr, mgr2);
+ assertEquals(mgr.hashCode(), mgr2.hashCode());
+ }
+
+ public void testWSMWithToc() {
+ WorkingSetManager mgr = new WorkingSetManager();
+ WorkingSet wset = new WorkingSet("test");
+ AdaptableToc toc = mgr.getAdaptableToc("/org.eclipse.ua.tests/data/help/toc/root.xml");
+ assertNotNull(toc);
+ wset.setElements(new AdaptableHelpResource[] { toc });
+ mgr.addWorkingSet(wset);
+ WorkingSet[] readWsets = mgr.getWorkingSets();
+ assertEquals(1, readWsets.length);
+ AdaptableHelpResource[] resources = readWsets[0].getElements();
+ assertEquals(1, resources.length);
+ assertTrue(resources[0].equals(toc));
+ };
+
+ public void testSaveRestoreWSMWithToc() {
+ WorkingSetManager mgr = new WorkingSetManager();
+ WorkingSet wset = new WorkingSet("test");
+ AdaptableToc toc = mgr.getAdaptableToc("/org.eclipse.ua.tests/data/help/toc/root.xml");
+ wset.setElements(new AdaptableHelpResource[] { toc });
+ mgr.addWorkingSet(wset);
+ mgr.saveState();
+ WorkingSetManager mgr2 = new WorkingSetManager();
+ mgr2.restoreState();
+ WorkingSet[] readWsets = mgr2.getWorkingSets();
+ assertEquals(1, readWsets.length);
+ AdaptableHelpResource[] resources = readWsets[0].getElements();
+ assertEquals(1, resources.length);
+ assertTrue(resources[0].equals(toc));
+ };
+
+ public void testWSMWithTopics() {
+ WorkingSetManager mgr = new WorkingSetManager();
+ WorkingSet wset = new WorkingSet("test2");
+ AdaptableTopic topic1 = mgr.getAdaptableTopic("/org.eclipse.ua.tests/data/help/toc/root.xml_1_");
+ AdaptableTopic topic3 = mgr.getAdaptableTopic("/org.eclipse.ua.tests/data/help/toc/root.xml_3_");
+ assertNotNull(topic1);
+ assertNotNull(topic3);
+ wset.setElements(new AdaptableHelpResource[] { topic1, topic3 });
+ mgr.addWorkingSet(wset);
+ WorkingSet[] readWsets = mgr.getWorkingSets();
+ assertEquals(1, readWsets.length);
+ AdaptableHelpResource[] resources = readWsets[0].getElements();
+ assertEquals(2, resources.length);
+ if (resources[0].equals(topic1)) {
+ assertEquals(topic3, resources[1]);
+ assertNotSame(topic3, resources[0]);
+ } else {
+ assertEquals(topic3, resources[0]);
+ assertEquals(topic1, resources[1]);
+ assertNotSame(topic3, resources[1]);
+ }
+ };
+
+ public void testSaveRestoreWSMWithTopics() {
+ WorkingSetManager mgr = new WorkingSetManager();
+ WorkingSet wset = new WorkingSet("test2");
+ AdaptableTopic topic1 = mgr.getAdaptableTopic("/org.eclipse.ua.tests/data/help/toc/root.xml_1_");
+ AdaptableTopic topic3 = mgr.getAdaptableTopic("/org.eclipse.ua.tests/data/help/toc/root.xml_3_");
+ assertNotNull(topic1);
+ assertNotNull(topic3);
+ wset.setElements(new AdaptableHelpResource[] { topic1, topic3 });
+ mgr.addWorkingSet(wset);
+ mgr.saveState();
+ WorkingSetManager mgr2 = new WorkingSetManager();
+ WorkingSet[] readWsets = mgr2.getWorkingSets();
+ assertEquals(1, readWsets.length);
+ AdaptableHelpResource[] resources = readWsets[0].getElements();
+ assertEquals(2, resources.length);
+ if (resources[0].equals(topic1)) {
+ assertEquals(topic3, resources[1]);
+ assertNotSame(topic3, resources[0]);
+ } else {
+ assertEquals(topic3, resources[0]);
+ assertEquals(topic1, resources[1]);
+ assertNotSame(topic3, resources[1]);
+ }
+ };
+
+ public void testWSMWithMultipleWsets() {
+ WorkingSetManager mgr = new WorkingSetManager();
+ WorkingSet wset1 = new WorkingSet("test3");
+ WorkingSet wset2 = new WorkingSet("test4");
+ AdaptableTopic topic1 = mgr.getAdaptableTopic("/org.eclipse.ua.tests/data/help/toc/root.xml_1_");
+ AdaptableTopic topic3 = mgr.getAdaptableTopic("/org.eclipse.ua.tests/data/help/toc/root.xml_3_");
+ assertNotNull(topic1);
+ assertNotNull(topic3);
+ wset1.setElements(new AdaptableHelpResource[] { topic1 });
+ wset2.setElements(new AdaptableHelpResource[] { topic3 });
+ mgr.addWorkingSet(wset1);
+ mgr.addWorkingSet(wset2);
+ WorkingSet[] readWsets = mgr.getWorkingSets();
+ assertEquals(2, readWsets.length);
+ AdaptableHelpResource[] resourcesT3 = mgr.getWorkingSet("test3").getElements();
+ assertEquals(1, resourcesT3.length);
+ assertEquals(topic1, resourcesT3[0]);
+ AdaptableHelpResource[] resourcesT4 = mgr.getWorkingSet("test4").getElements();
+ assertEquals(1, resourcesT4.length);
+ assertEquals(topic3, resourcesT4[0]);
+ };
+
+ public void testSaveRestoreWSMWithMultipleWsets() {
+ WorkingSetManager mgr = new WorkingSetManager();
+ WorkingSet wset1 = new WorkingSet("test3");
+ WorkingSet wset2 = new WorkingSet("test4");
+ AdaptableTopic topic1 = mgr.getAdaptableTopic("/org.eclipse.ua.tests/data/help/toc/root.xml_1_");
+ AdaptableTopic topic3 = mgr.getAdaptableTopic("/org.eclipse.ua.tests/data/help/toc/root.xml_3_");
+ assertNotNull(topic1);
+ assertNotNull(topic3);
+ wset1.setElements(new AdaptableHelpResource[] { topic1 });
+ wset2.setElements(new AdaptableHelpResource[] { topic3 });
+ mgr.addWorkingSet(wset1);
+ mgr.addWorkingSet(wset2);
+
+ WorkingSetManager mgr2 = new WorkingSetManager();
+ WorkingSet[] readWsets = mgr2.getWorkingSets();
+
+ assertEquals(2, readWsets.length);
+ AdaptableHelpResource[] resourcesT3 = mgr2.getWorkingSet("test3").getElements();
+ assertEquals(1, resourcesT3.length);
+ assertEquals(topic1, resourcesT3[0]);
+ AdaptableHelpResource[] resourcesT4 = mgr2.getWorkingSet("test4").getElements();
+ assertEquals(1, resourcesT4.length);
+ assertEquals(topic3, resourcesT4[0]);
+ };
+
+}

Back to the top