Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Goldthorpe2010-01-07 18:23:07 +0000
committerChris Goldthorpe2010-01-07 18:23:07 +0000
commit63b7537ecfefa9018a5971141eca7b23fdb529ab (patch)
tree9bb2712ca9f9babd58c22c9a0f905a0e3b732bb9 /org.eclipse.ua.tests
parentadb0f3b0c56dd793b932c18cf3480b5c6f46893c (diff)
downloadeclipse.platform.ua-63b7537ecfefa9018a5971141eca7b23fdb529ab.tar.gz
eclipse.platform.ua-63b7537ecfefa9018a5971141eca7b23fdb529ab.tar.xz
eclipse.platform.ua-63b7537ecfefa9018a5971141eca7b23fdb529ab.zip
Add tests for Lucene based XMLSearchParticipant
Diffstat (limited to 'org.eclipse.ua.tests')
-rw-r--r--org.eclipse.ua.tests/data/help/search/lucene_xml_1.xml23
-rw-r--r--org.eclipse.ua.tests/data/help/search/lucene_xml_2.xml23
-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/LuceneXMLParticipantTest.java70
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/MockLuceneParticipant.java4
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/MockLuceneXMLParticipant.java64
-rw-r--r--org.eclipse.ua.tests/plugin.xml7
7 files changed, 192 insertions, 0 deletions
diff --git a/org.eclipse.ua.tests/data/help/search/lucene_xml_1.xml b/org.eclipse.ua.tests/data/help/search/lucene_xml_1.xml
new file mode 100644
index 000000000..5d96806ae
--- /dev/null
+++ b/org.eclipse.ua.tests/data/help/search/lucene_xml_1.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ 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
+ -->
+
+<contentExtension>
+ <searchable title = "Lucene XML 1">
+ <text title="ignored title" summary = "Summary for">
+ search word hujnjujnh
+ </text>
+ <text summary = "file Lucene XML1">
+ search word dusudusud
+ </text>
+ </searchable>
+</contentExtension>
diff --git a/org.eclipse.ua.tests/data/help/search/lucene_xml_2.xml b/org.eclipse.ua.tests/data/help/search/lucene_xml_2.xml
new file mode 100644
index 000000000..f933ba581
--- /dev/null
+++ b/org.eclipse.ua.tests/data/help/search/lucene_xml_2.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ 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
+ -->
+
+<outer>
+<searchable title = "Lucene XML 2 - tests nesting">
+ <text title="ignored title" summary = "Summary for">
+ search word kfkkfjeeej
+ <text summary = "file Lucene XML2">
+ search word syueuduehj
+ </text>
+ </text>
+</searchable>
+</outer>
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 5c07135c7..67be066b8 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
@@ -38,5 +38,6 @@ public class AllSearchTests extends TestSuite {
addTest(EncodedCharacterSearch.suite());
addTest(MetaKeywords.suite());
addTest(LuceneParticipantTest.suite());
+ addTest(LuceneXMLParticipantTest.suite());
}
}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/LuceneXMLParticipantTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/LuceneXMLParticipantTest.java
new file mode 100644
index 000000000..794b10b92
--- /dev/null
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/LuceneXMLParticipantTest.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 LuceneXMLParticipantTest extends TestCase {
+
+ /*
+ * Returns an instance of this Test.
+ */
+ public static Test suite() {
+ return new TestSuite(LuceneXMLParticipantTest.class);
+ }
+
+ public void testSearchFirstWordInFirstDoc() {
+ SearchTestUtils.searchAllLocales("hujnjujnh", new String[] { MockLuceneXMLParticipant.DOC_1 });
+ }
+
+ public void testSearchLastWordInFirstDoc() {
+ SearchTestUtils.searchAllLocales("dusudusud", new String[] { MockLuceneXMLParticipant.DOC_1 });
+ }
+
+ public void testSearchWordFromOuterElement() {
+ SearchTestUtils.searchAllLocales("kfkkfjeeej", new String[] { MockLuceneXMLParticipant.DOC_2 });
+ }
+
+ public void testSearchWordFromNestedElement() {
+ SearchTestUtils.searchAllLocales("syueuduehj", new String[] { MockLuceneXMLParticipant.DOC_2 });
+ }
+
+ public void testReturnedTitle() {
+ SearchHit[] hits = SearchTestUtils.getSearchHits("hujnjujnh", "en");
+ assertEquals(hits.length,1);
+ assertEquals("Lucene XML 1", hits[0].getLabel());
+ }
+
+ public void testReturnedSummary() {
+ SearchHit[] hits = SearchTestUtils.getSearchHits("hujnjujnh", "en");
+ assertEquals(hits.length,1);
+ assertEquals("Summary for file Lucene XML1", hits[0].getSummary());
+ }
+
+ public void testReturnedTitleNestedCase() {
+ SearchHit[] hits = SearchTestUtils.getSearchHits("kfkkfjeeej", "en");
+ assertEquals(hits.length,1);
+ assertEquals("Lucene XML 2 - tests nesting", hits[0].getLabel());
+ }
+
+ public void testReturnedSummaryNestedCase() {
+ SearchHit[] hits = SearchTestUtils.getSearchHits("kfkkfjeeej", "en");
+ assertEquals(hits.length,1);
+ assertEquals("Summary for file Lucene XML2", hits[0].getSummary());
+ }
+
+}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/MockLuceneParticipant.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/MockLuceneParticipant.java
index ff11a1810..d91a39ac6 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/MockLuceneParticipant.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/MockLuceneParticipant.java
@@ -47,5 +47,9 @@ public class MockLuceneParticipant extends LuceneSearchParticipant {
set.add(DOC_2);
return set;
}
+
+ public String getId() {
+ return super.getId();
+ }
}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/MockLuceneXMLParticipant.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/MockLuceneXMLParticipant.java
new file mode 100644
index 000000000..b45a969dc
--- /dev/null
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/MockLuceneXMLParticipant.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.XMLSearchParticipant;
+import org.xml.sax.Attributes;
+
+public class MockLuceneXMLParticipant extends XMLSearchParticipant {
+
+ public static final String DOC_1 = "/org.eclipse.ua.tests/data/help/search/lucene_xml_1.xml";
+ public static final String DOC_2 = "/org.eclipse.ua.tests/data/help/search/lucene_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 ("searchable".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/plugin.xml b/org.eclipse.ua.tests/plugin.xml
index a817ff874..830069de2 100644
--- a/org.eclipse.ua.tests/plugin.xml
+++ b/org.eclipse.ua.tests/plugin.xml
@@ -610,6 +610,13 @@
name="Lucene Search Participant Test"
participant="org.eclipse.ua.tests.help.search.MockLuceneParticipant">
</searchParticipant>
+ <searchParticipant
+ headless="false"
+ icon="icons/sample4.gif"
+ id="org.eclipse.ua.tests.xmlLuceneParticipant"
+ name="XML Lucene Participant"
+ participant="org.eclipse.ua.tests.help.search.MockLuceneXMLParticipant">
+ </searchParticipant>
</extension>
</plugin>

Back to the top