diff options
author | Chris Goldthorpe | 2010-02-01 23:40:28 +0000 |
---|---|---|
committer | Chris Goldthorpe | 2010-02-01 23:40:28 +0000 |
commit | 8838c5ba73765dfddc973430d48f93e43bdc7b7d (patch) | |
tree | cb3a1f4b17cd4c0c5c40a64f877b63a89de723d5 /org.eclipse.ua.tests | |
parent | 96abc27993e15a9f3b10af0385bca2866fb0eb75 (diff) | |
download | eclipse.platform.ua-8838c5ba73765dfddc973430d48f93e43bdc7b7d.tar.gz eclipse.platform.ua-8838c5ba73765dfddc973430d48f93e43bdc7b7d.tar.xz eclipse.platform.ua-8838c5ba73765dfddc973430d48f93e43bdc7b7d.zip |
Bug 76005 [Help] Ability for users to filter what they see in the help system navigation acc to some criteria (all help modes)
Diffstat (limited to 'org.eclipse.ua.tests')
7 files changed, 459 insertions, 0 deletions
diff --git a/org.eclipse.ua.tests/data/help/criteria/c1.xml b/org.eclipse.ua.tests/data/help/criteria/c1.xml new file mode 100644 index 000000000..dc2526907 --- /dev/null +++ b/org.eclipse.ua.tests/data/help/criteria/c1.xml @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?NLS TYPE="org.eclipse.help.toc"?> + +<!-- + 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 + --> + +<toc label="Criteria"> + <criteria name= "version" value="1.0" /> + <criteria name= "version" value="2.0" /> + <criteria name= "platform" value="win32" /> + <criteria name= "platform" value="linux" /> + <topic label="Topic 1.0" href="A_topic.html"> + <criteria name= "version" value="1.0" /> + <criteria name= "platform" value="win32" /> + <criteria name= "platform" value="linux" /> + </topic> + <topic label="Topic 2.0" href="A_topic.html"> + <criteria name= "version" value="2.0" /> + </topic> +</toc> diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/AllHelpTests.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/AllHelpTests.java index 916d15769..78996dbd1 100644 --- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/AllHelpTests.java +++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/AllHelpTests.java @@ -13,6 +13,7 @@ package org.eclipse.ua.tests.help; import junit.framework.Test; import junit.framework.TestSuite; +import org.eclipse.ua.tests.help.criteria.AllCriteriaTests; import org.eclipse.ua.tests.help.dynamic.AllDynamicTests; import org.eclipse.ua.tests.help.index.AllIndexTests; import org.eclipse.ua.tests.help.other.AllOtherHelpTests; @@ -40,6 +41,7 @@ public class AllHelpTests extends TestSuite { */ public AllHelpTests() { addTest(AllPreferencesTests.suite()); + addTest(AllCriteriaTests.suite()); addTest(AllDynamicTests.suite()); addTest(AllSearchTests.suite()); addTest(AllTocTests.suite()); diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/criteria/AllCriteriaTests.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/criteria/AllCriteriaTests.java new file mode 100644 index 000000000..56acccdc5 --- /dev/null +++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/criteria/AllCriteriaTests.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * 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.criteria; + +import junit.framework.Test; +import junit.framework.TestSuite; + +/* + * Tests help keyword index functionality. + */ +public class AllCriteriaTests extends TestSuite { + + /* + * Returns the entire test suite. + */ + public static Test suite() { + return new AllCriteriaTests(); + } + + /* + * Constructs a new test suite. + */ + public AllCriteriaTests() { + addTestSuite(ParseTocWithCriteria.class); + } +} diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/criteria/ParseTocWithCriteria.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/criteria/ParseTocWithCriteria.java new file mode 100644 index 000000000..70c201d78 --- /dev/null +++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/criteria/ParseTocWithCriteria.java @@ -0,0 +1,252 @@ +/******************************************************************************* + * 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.criteria; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +import javax.xml.parsers.ParserConfigurationException; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.eclipse.help.ICriteria; +import org.eclipse.help.IToc; +import org.eclipse.help.IToc2; +import org.eclipse.help.ITopic; +import org.eclipse.help.ITopic2; +import org.eclipse.help.internal.Topic; +import org.eclipse.help.internal.base.util.CriteriaUtilities; +import org.eclipse.help.internal.criteria.CriterionResource; +import org.eclipse.help.internal.toc.Toc; +import org.eclipse.help.internal.toc.TocContribution; +import org.eclipse.help.internal.toc.TocFile; +import org.eclipse.help.internal.toc.TocFileParser; +import org.eclipse.help.internal.workingset.CriteriaHelpScope; +import org.eclipse.ua.tests.help.other.UserCriteria; +import org.eclipse.ua.tests.help.other.UserToc2; +import org.eclipse.ua.tests.help.other.UserTopic2; +import org.eclipse.ua.tests.plugin.UserAssistanceTestPlugin; +import org.xml.sax.SAXException; + +public class ParseTocWithCriteria extends TestCase { + + /* + * Returns an instance of this Test. + */ + public static Test suite() { + return new TestSuite(ParseTocWithCriteria.class); + } + + private IToc2 parseToc(String filename) throws IOException, SAXException, + ParserConfigurationException { + IToc toc; + TocFileParser parser = new TocFileParser(); + TocContribution cToc = parser.parse(new TocFile( + UserAssistanceTestPlugin.getPluginId(), filename, true, "en", + null, null)); + toc = cToc.getToc(); + return (IToc2) toc; + } + + public void testTocWithCriteria() throws Exception { + IToc2 toc = parseToc("data/help/criteria/c1.xml"); + Map criteria = new HashMap(); + CriteriaUtilities.addCriteriaToMap(criteria, toc.getCriteria()); + assertEquals(2, criteria.size()); + Object versions = criteria.get("version"); + assertNotNull(versions); + Set versionSet = (Set)versions; + assertEquals(2, versionSet.size()); + assertTrue(versionSet.contains("1.0")); + assertTrue(versionSet.contains("2.0")); + + Object platforms = criteria.get("platform"); + assertNotNull(platforms); + Set platformSet = (Set)platforms; + assertEquals(2, platformSet.size()); + assertTrue(platformSet.contains("linux")); + assertTrue(platformSet.contains("win32")); + } + + public void testCopyTocWithCriteria() throws Exception { + IToc toc0 = parseToc("data/help/criteria/c1.xml"); + Toc toc = new Toc(toc0); + Map criteria = new HashMap(); + CriteriaUtilities.addCriteriaToMap(criteria, toc.getCriteria()); + assertEquals(2, criteria.size()); + Object versions = criteria.get("version"); + assertNotNull(versions); + Set versionSet = (Set)versions; + assertEquals(2, versionSet.size()); + assertTrue(versionSet.contains("1.0")); + assertTrue(versionSet.contains("2.0")); + + Object platforms = criteria.get("platform"); + assertNotNull(platforms); + Set platformSet = (Set)platforms; + assertEquals(2, platformSet.size()); + assertTrue(platformSet.contains("linux")); + assertTrue(platformSet.contains("win32")); + } + + public void testTopicWithCriteria() throws Exception { + IToc toc = parseToc("data/help/criteria/c1.xml"); + ITopic[] topics = (ITopic[]) toc.getTopics(); + assertEquals(topics.length, 2); + // First topic + Map criteria = new HashMap(); + assertTrue(topics[0] instanceof ITopic2); + CriteriaUtilities.addCriteriaToMap(criteria, ((ITopic2)topics[0]).getCriteria()); + assertEquals(2, criteria.size()); + Object versions = criteria.get("version"); + assertNotNull(versions); + Set versionSet = (Set)versions; + assertEquals(1, versionSet.size()); + assertTrue(versionSet.contains("1.0")); + assertFalse(versionSet.contains("2.0")); + + // Second topic + + criteria = new HashMap(); + assertTrue(topics[1] instanceof ITopic2); + CriteriaUtilities.addCriteriaToMap(criteria, ((ITopic2)topics[1]).getCriteria()); + versions = criteria.get("version"); + assertNotNull(versions); + versionSet = (Set)versions; + assertEquals(1, versionSet.size()); + assertTrue(versionSet.contains("2.0")); + assertFalse(versionSet.contains("1.0")); + } + + public void testCriteriaScoping1() throws Exception { + IToc toc = parseToc("data/help/criteria/c1.xml"); + ITopic[] topics = toc.getTopics(); + assertEquals(topics.length, 2); + CriterionResource[] resource = new CriterionResource[1]; + resource[0] = new CriterionResource("version"); + resource[0].addCriterionValue("1.0"); + CriteriaHelpScope scope = new CriteriaHelpScope(resource); + assertTrue(scope.inScope(toc)); + assertTrue(scope.inScope(topics[0])); + assertFalse(scope.inScope(topics[1])); + } + + public void testCriteriaScoping2() throws Exception { + IToc toc = parseToc("data/help/criteria/c1.xml"); + ITopic[] topics = toc.getTopics(); + assertEquals(topics.length, 2); + CriterionResource[] resource = new CriterionResource[1]; + resource[0] = new CriterionResource("platform"); + resource[0].addCriterionValue("linux"); + CriteriaHelpScope scope = new CriteriaHelpScope(resource); + assertTrue(scope.inScope(toc)); + assertTrue(scope.inScope(topics[0])); + assertFalse(scope.inScope(topics[1])); + } + + public void testMultipleCriteriaScoping() throws Exception { + IToc toc = parseToc("data/help/criteria/c1.xml"); + ITopic[] topics = toc.getTopics(); + assertEquals(topics.length, 2); + CriterionResource[] resource = new CriterionResource[2]; + resource[0] = new CriterionResource("platform"); + resource[0].addCriterionValue("linux"); + resource[1] = new CriterionResource("version"); + resource[1].addCriterionValue("1.0"); + CriteriaHelpScope scope = new CriteriaHelpScope(resource); + assertTrue(scope.inScope(toc)); + assertTrue(scope.inScope(topics[0])); + assertFalse(scope.inScope(topics[1])); + } + + public void testMultipleCriteriaOnlyOneSatisfied() throws Exception { + IToc toc = parseToc("data/help/criteria/c1.xml"); + ITopic[] topics = toc.getTopics(); + CriterionResource[] resource = new CriterionResource[2]; + resource[0] = new CriterionResource("platform"); + resource[0].addCriterionValue("linux"); + resource[1] = new CriterionResource("version"); + resource[1].addCriterionValue("2.0"); + assertEquals(topics.length, 2); + CriteriaHelpScope scope = new CriteriaHelpScope(resource); + assertTrue(scope.inScope(toc)); + assertFalse(scope.inScope(topics[0])); + assertFalse(scope.inScope(topics[1])); + } + + public void testUserTocWithCriteria() throws Exception { + UserToc2 toc = new UserToc2("myToc", null, true); + UserCriteria criterion1 = new UserCriteria("version", "1.0", true); + UserCriteria criterion2 = new UserCriteria("version", "2.0", true); + toc.addCriterion(criterion1); + toc.addCriterion(criterion2); + + ICriteria[] criteria = toc.getCriteria(); + assertEquals(2, criteria.length); + assertEquals("version", criteria[0].getName()); + assertEquals("1.0", criteria[0].getValue()); + assertEquals("version", criteria[1].getName()); + assertEquals("2.0", criteria[1].getValue()); + } + + public void testCopyUserTocWithCriteria() throws Exception { + UserToc2 toc = new UserToc2("myToc", null, true); + UserCriteria criterion1 = new UserCriteria("version", "1.0", true); + UserCriteria criterion2 = new UserCriteria("version", "2.0", true); + toc.addCriterion(criterion1); + toc.addCriterion(criterion2); + + Toc copy = new Toc(toc); + + ICriteria[] criteria = copy.getCriteria(); + assertEquals(2, criteria.length); + assertEquals("version", criteria[0].getName()); + assertEquals("1.0", criteria[0].getValue()); + assertEquals("version", criteria[1].getName()); + assertEquals("2.0", criteria[1].getValue()); + } + + public void testUserTopicWithCriteria() throws Exception { + UserTopic2 topic = new UserTopic2("myToc", null, true); + UserCriteria criterion1 = new UserCriteria("version", "1.0", true); + UserCriteria criterion2 = new UserCriteria("version", "2.0", true); + topic.addCriterion(criterion1); + topic.addCriterion(criterion2); + + Topic copy = new Topic(topic); + + ICriteria[] criteria = copy.getCriteria(); + assertEquals(2, criteria.length); + assertEquals("version", criteria[0].getName()); + assertEquals("1.0", criteria[0].getValue()); + assertEquals("version", criteria[1].getName()); + assertEquals("2.0", criteria[1].getValue()); + } + + public void testCopyUserTopicWithCriteria() throws Exception { + UserTopic2 topic = new UserTopic2("myToc", null, true); + UserCriteria criterion1 = new UserCriteria("version", "1.0", true); + UserCriteria criterion2 = new UserCriteria("version", "2.0", true); + topic.addCriterion(criterion1); + topic.addCriterion(criterion2); + ICriteria[] criteria = topic.getCriteria(); + assertEquals(2, criteria.length); + assertEquals("version", criteria[0].getName()); + assertEquals("1.0", criteria[0].getValue()); + assertEquals("version", criteria[1].getName()); + assertEquals("2.0", criteria[1].getValue()); + } + +} diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/UserCriteria.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/UserCriteria.java new file mode 100644 index 000000000..77e52713b --- /dev/null +++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/UserCriteria.java @@ -0,0 +1,35 @@ +package org.eclipse.ua.tests.help.other; + +import org.eclipse.core.expressions.IEvaluationContext; +import org.eclipse.help.ICriteria; +import org.eclipse.help.IUAElement; + +public class UserCriteria implements ICriteria { + + private String name; + private String value; + private boolean enabled; + + public UserCriteria(String name, String value, boolean enabled) { + this.name = name; + this.value = value; + this.enabled = enabled; + } + + public boolean isEnabled(IEvaluationContext context) { + return enabled; + } + + public IUAElement[] getChildren() { + return null; + } + + public String getName() { + return name; + } + + public String getValue() { + return value; + } + +} diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/UserToc2.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/UserToc2.java new file mode 100644 index 000000000..c352d7ffc --- /dev/null +++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/UserToc2.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * 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.other; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.help.ICriteria; +import org.eclipse.help.IToc2; +import org.eclipse.help.IUAElement; + +public class UserToc2 extends UserToc implements IToc2 { + + public UserToc2(String label, String href, boolean isEnabled) { + super(label, href, isEnabled); + } + + private List criteria = new ArrayList(); + + public IUAElement[] getChildren() { + IUAElement[] criteriaElements = getCriteria(); + IUAElement[] topics = getTopics(); + IUAElement[] result = new IUAElement[criteriaElements.length + topics.length]; + System.arraycopy(topics, 0, result, 0, topics.length); + System.arraycopy(criteriaElements, 0, result, topics.length, criteriaElements.length); + return result; + } + + public void addCriterion(ICriteria child) { + criteria.add(child); + } + + public ICriteria[] getCriteria() { + return (ICriteria[])criteria.toArray(new ICriteria[0]); + } + + public String getIcon() { + return null; + } + + public boolean isSorted() { + return false; + } + +} diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/UserTopic2.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/UserTopic2.java new file mode 100644 index 000000000..d7488ef8a --- /dev/null +++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/other/UserTopic2.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * 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.other; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.help.ICriteria; +import org.eclipse.help.ITopic2; +import org.eclipse.help.IUAElement; + +public class UserTopic2 extends UserTopic implements ITopic2 { + + private List criteria = new ArrayList(); + + public IUAElement[] getChildren() { + IUAElement[] criteriaElements = getCriteria(); + IUAElement[] topics = getSubtopics(); + IUAElement[] result = new IUAElement[criteriaElements.length + topics.length]; + System.arraycopy(topics, 0, result, 0, topics.length); + System.arraycopy(criteriaElements, 0, result, topics.length, criteriaElements.length); + return result; + } + + public UserTopic2(String label, String href, boolean isEnabled) { + super(label, href, isEnabled); + } + + public void addCriterion(ICriteria child) { + criteria.add(child); + } + + public ICriteria[] getCriteria() { + return (ICriteria[])criteria.toArray(new ICriteria[0]); + } + + public String getIcon() { + return null; + } + + public boolean isSorted() { + return false; + } + +} |