diff options
Diffstat (limited to 'org.eclipse.ua.tests/help/org/eclipse/ua')
6 files changed, 318 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 67be066b8..fa661e6cc 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 @@ -37,6 +37,8 @@ public class AllSearchTests extends TestSuite { addTest(SearchCheatsheet.suite()); addTest(EncodedCharacterSearch.suite()); addTest(MetaKeywords.suite()); + addTest(SearchParticipantTest.suite()); + addTest(SearchParticipantXMLTest.suite()); addTest(LuceneParticipantTest.suite()); addTest(LuceneXMLParticipantTest.suite()); } diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/MockSearchParticipant.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/MockSearchParticipant.java new file mode 100644 index 000000000..bbd340ab3 --- /dev/null +++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/MockSearchParticipant.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * 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 java.net.URL; +import java.util.HashSet; +import java.util.Set; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.help.search.IHelpSearchIndex; +import org.eclipse.help.search.ISearchDocument; +import org.eclipse.help.search.SearchParticipant; + +public class MockSearchParticipant extends SearchParticipant { + + private static final String DOC_1 = "/org.eclipse.ua.tests/participant1.xml"; + private static final String DOC_2 = "/org.eclipse.ua.tests/participant2.xml"; + + public Set getAllDocuments(String locale) { + HashSet set = new HashSet(); + set.add(DOC_1); + set.add(DOC_2); + return set; + } + + public IStatus addDocument(IHelpSearchIndex index, String pluginId, + String name, URL url, String id, ISearchDocument doc) { + boolean isDoc1 = url.getPath().equals(DOC_1) ; + String title = isDoc1 ? "Title1" : "Title2"; + String summary = isDoc1? "Summary1" : "Summary2"; + String contents = isDoc1? "jkijkijkk frgeded" : "olhoykk lgktihku"; + doc.addTitle(title); + doc.addSummary(summary); + doc.addContents(contents); + return Status.OK_STATUS; + } + +} diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/MockSearchParticipantXML.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/MockSearchParticipantXML.java new file mode 100644 index 000000000..1f45b4797 --- /dev/null +++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/MockSearchParticipantXML.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * 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 java.util.HashSet; +import java.util.Set; + +import org.eclipse.help.search.SearchParticipantXML; +import org.xml.sax.Attributes; + +public class MockSearchParticipantXML extends SearchParticipantXML { + + public static final String DOC_1 = "/org.eclipse.ua.tests/data/help/search/participant_xml_1.xml"; + public static final String DOC_2 = "/org.eclipse.ua.tests/data/help/search/participant_xml_2.xml"; + + public Set getAllDocuments(String locale) { + HashSet set = new HashSet(); + set.add(DOC_1 + "?id=xml1" + "?id=xml2"); + set.add(DOC_2); + return set; + } + + public Set getContributingPlugins() { + Set result = new HashSet(); + result.add("org.eclipse.ua.tests"); + return result; + } + + protected void handleStartElement(String name, Attributes attributes, + IParsedXMLContent data) { + if ("participant".equalsIgnoreCase(name)) { + data.setTitle(attributes.getValue("title")); + } + String summary = attributes.getValue("summary"); + if (summary != null) { + data.addToSummary(summary); + } + } + + protected void handleEndElement(String name, IParsedXMLContent data) { + } + + protected void handleText(String text, IParsedXMLContent data) { + String top = getTopElement(); + if ("text".equalsIgnoreCase(top)) { + data.addText(text); + } + } + + public boolean open(String id) { + System.out.println("Open " + id); + return true; + } + +} diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/SearchIntro.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/SearchIntro.java new file mode 100644 index 000000000..c2b7f4ff4 --- /dev/null +++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/SearchIntro.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * 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 java.util.ArrayList; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Platform; +import org.eclipse.help.internal.base.BaseHelpSystem; +import org.eclipse.help.internal.search.ISearchQuery; +import org.eclipse.help.internal.search.SearchHit; +import org.eclipse.help.internal.search.SearchQuery; +import org.eclipse.help.internal.search.SearchResults; + +public class SearchIntro extends TestCase { + + /* + * Returns an instance of this Test. + */ + public static Test suite() { + return new TestSuite(SearchIntro.class); + } + + public SearchHit[] findHits(String searchWord) { + ISearchQuery query = new SearchQuery(searchWord, false, new ArrayList(), Platform.getNL()); + SearchResults collector = new SearchResults(null, 10, Platform.getNL()); + BaseHelpSystem.getSearchManager().search(query, collector, new NullProgressMonitor()); + return collector.getSearchHits(); + } + + public void testSearchIntroGroupLabel() { + SearchHit[] hits = SearchTestUtils.getSearchHits("ifirifjrnfj", "en"); + assertEquals(1, hits.length); + } + + public void testSearchIntroGroupText() { + SearchHit[] hits = SearchTestUtils.getSearchHits("nenfhhdhhed", "en"); + assertEquals(1, hits.length); + } + + public void testSearchIntroLinkLabel() { + SearchHit[] hits = SearchTestUtils.getSearchHits("hydefefed", "en"); + assertEquals(1, hits.length); + } + + public void testSearchIntroLinkText() { + SearchHit[] hits = SearchTestUtils.getSearchHits("hfuejfujduj", "en"); + assertEquals(1, hits.length); + } + +} diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/SearchParticipantTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/SearchParticipantTest.java new file mode 100644 index 000000000..223e42a99 --- /dev/null +++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/SearchParticipantTest.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * 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.search.SearchHit; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + + +public class SearchParticipantTest extends TestCase { + + /* + * Returns an instance of this Test. + */ + public static Test suite() { + return new TestSuite(SearchParticipantTest.class); + } + + public void testSearchFirstWordInFirstDoc() { + SearchTestUtils.searchAllLocales("jkijkijkk", new String[] { "/org.eclipse.ua.tests/participant1.xml" }); + } + + public void testSearchLastWordInFirstDoc() { + SearchTestUtils.searchAllLocales("frgeded", new String[] { "/org.eclipse.ua.tests/participant1.xml" }); + } + + public void testSearchUsingAndInFirstDoc() { + SearchTestUtils.searchAllLocales("jkijkijkk AND frgeded", new String[] { "/org.eclipse.ua.tests/participant1.xml" }); + } + + public void testSearchUsingAndInSeparateDocs() { + SearchTestUtils.searchAllLocales("jduehdye and olhoykk", new String[0]); + } + + public void testSearchExactMatch() { + SearchTestUtils.searchAllLocales("\"jkijkijkk frgeded\"", new String[] { "/org.eclipse.ua.tests/participant1.xml" }); + } + + public void testSearchExactMatchNotFound() { + SearchTestUtils.searchAllLocales("\"frgeded jkijkijkk\"", new String[0]); + } + + public void testSearchWordInSecondDoc() { + SearchTestUtils.searchAllLocales("olhoykk", new String[] { "/org.eclipse.ua.tests/participant2.xml" }); + } + + public void testReturnedTitle() { + SearchHit[] hits = SearchTestUtils.getSearchHits("jkijkijkk", "en"); + assertEquals(hits.length,1); + assertEquals("Title1", hits[0].getLabel()); + } + + public void testReturnedSummary() { + SearchHit[] hits = SearchTestUtils.getSearchHits("jkijkijkk", "en"); + assertEquals(hits.length,1); + assertEquals("Summary1", hits[0].getSummary()); + } + +} diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/SearchParticipantXMLTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/SearchParticipantXMLTest.java new file mode 100644 index 000000000..181c3644e --- /dev/null +++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/SearchParticipantXMLTest.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * 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.search.SearchHit; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + + +public class SearchParticipantXMLTest extends TestCase { + + /* + * Returns an instance of this Test. + */ + public static Test suite() { + return new TestSuite(SearchParticipantXMLTest.class); + } + + public void testSearchFirstWordInFirstDoc() { + SearchTestUtils.searchAllLocales("jfplepdl", new String[] { MockSearchParticipantXML.DOC_1 }); + } + + public void testSearchLastWordInFirstDoc() { + SearchTestUtils.searchAllLocales("memdjkemd", new String[] { MockSearchParticipantXML.DOC_1 }); + } + + public void testSearchWordFromOuterElement() { + SearchTestUtils.searchAllLocales("odoeofoedo", new String[] { MockSearchParticipantXML.DOC_2 }); + } + + public void testSearchWordFromNestedElement() { + SearchTestUtils.searchAllLocales("odkeofkeks", new String[] { MockSearchParticipantXML.DOC_2 }); + } + + public void testReturnedTitle() { + SearchHit[] hits = SearchTestUtils.getSearchHits("jfplepdl", "en"); + assertEquals(hits.length,1); + assertEquals("Participant XML 1", hits[0].getLabel()); + } + + public void testReturnedSummary() { + SearchHit[] hits = SearchTestUtils.getSearchHits("jfplepdl", "en"); + assertEquals(hits.length,1); + assertEquals("Summary for file Participant XML1", hits[0].getSummary()); + } + + public void testReturnedTitleNestedCase() { + SearchHit[] hits = SearchTestUtils.getSearchHits("odoeofoedo", "en"); + assertEquals(hits.length,1); + assertEquals("Participant XML 2 - tests nesting", hits[0].getLabel()); + } + + public void testReturnedSummaryNestedCase() { + SearchHit[] hits = SearchTestUtils.getSearchHits("odoeofoedo", "en"); + assertEquals(hits.length,1); + assertEquals("Summary for file Participant XML2", hits[0].getSummary()); + } + +} |