diff options
author | Chris Goldthorpe | 2011-02-01 18:36:07 +0000 |
---|---|---|
committer | Chris Goldthorpe | 2011-02-01 18:36:07 +0000 |
commit | f29338d7538c4bc6614987fd901a875462ecadba (patch) | |
tree | 5c2387628abd2e60672094e1c652d35e69a21e8a /org.eclipse.ua.tests/help/org | |
parent | ea112677edd551000c08279ea773e38af29c08e4 (diff) | |
download | eclipse.platform.ua-f29338d7538c4bc6614987fd901a875462ecadba.tar.gz eclipse.platform.ua-f29338d7538c4bc6614987fd901a875462ecadba.tar.xz eclipse.platform.ua-f29338d7538c4bc6614987fd901a875462ecadba.zip |
Bug 335997 - [Help] Allow indexes created with Lucene 1.9.1 to be read
Diffstat (limited to 'org.eclipse.ua.tests/help/org')
-rw-r--r-- | org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/AllSearchTests.java | 3 | ||||
-rw-r--r-- | org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/PrebuiltIndexCompatibility.java | 151 |
2 files changed, 153 insertions, 1 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 f8cf33196..7e0fd10aa 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2010 IBM Corporation and others. + * Copyright (c) 2006, 2011 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 @@ -45,5 +45,6 @@ public class AllSearchTests extends TestSuite { addTest(LuceneXMLParticipantTest.suite()); addTestSuite(WorkingSetManagerTest.class); addTestSuite(InfocenterWorkingSetManagerTest.class); + addTestSuite(PrebuiltIndexCompatibility.class); } } diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/PrebuiltIndexCompatibility.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/PrebuiltIndexCompatibility.java new file mode 100644 index 000000000..8206ef994 --- /dev/null +++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/PrebuiltIndexCompatibility.java @@ -0,0 +1,151 @@ +/******************************************************************************* + * Copyright (c) 2011 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.io.File; +import java.io.IOException; +import java.net.URL; +import java.util.ArrayList; +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.apache.lucene.index.CorruptIndexException; +import org.apache.lucene.search.IndexSearcher; +import org.apache.lucene.search.Query; +import org.apache.lucene.search.TopDocs; +import org.apache.lucene.store.Directory; +import org.apache.lucene.store.NIOFSDirectory; +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Path; +import org.eclipse.help.internal.base.BaseHelpSystem; +import org.eclipse.help.internal.search.AnalyzerDescriptor; +import org.eclipse.help.internal.search.PluginIndex; +import org.eclipse.help.internal.search.QueryBuilder; +import org.eclipse.help.internal.search.SearchIndexWithIndexingProgress; +import org.eclipse.ua.tests.plugin.UserAssistanceTestPlugin; +import org.osgi.framework.Bundle; + +/** + * Verify that older versions of the index can be read by this + * version of Eclipse. + * + * How to maintain this test - if when upgrading to a new version + * of Lucene one of the IndexReadable tests fails you need to + * make the following changes: + * 1. Change the corresponding Compatible() test to expect a result of false + * 2. Comment out the failing test + * 3. Change the help system to recognize that version of Lucene as being incompatible + */ + +public class PrebuiltIndexCompatibility extends TestCase { + + /* + * Returns an instance of this Test. + */ + public static Test suite() { + return new TestSuite(PrebuiltIndexCompatibility.class); + } + + /** + * Test index built with Lucene 1.9.1 + */ + public void test1_9_1_IndexReadable() throws Exception { + checkReadable("data/help/searchindex/index191"); + } + + /** + * Test index built with Lucene 2.9.1 + */ + public void test2_9_1_IndexReadable() throws Exception { + checkReadable("data/help/searchindex/index291"); + } + + /** + ** Test compatibility of Lucene 1.9.1 index with current Lucene + */ + public void test1_9_1Compatible() + { + checkCompatible("data/help/searchindex/index191", true); + } + + /** + ** Test compatibility of Lucene 2.9.1 index with current Lucene + */ + public void test2_9_1Compatible() + { + checkCompatible("data/help/searchindex/index291", true); + } + + public void test1_9_1LuceneCompatible() + { + checkLuceneCompatible("1.9.1", true); + } + + public void test1_4_103NotLuceneCompatible() + { + checkLuceneCompatible("1.4.103", false); + } + + public void test2_9_1LuceneCompatible() + { + checkLuceneCompatible("2.9.1", true); + } + + /* + * Verifies that a prebuilt index can be searched + */ + private void checkReadable(String indexPath) throws IOException, + CorruptIndexException { + Path path = new Path(indexPath); + Bundle bundle = UserAssistanceTestPlugin.getDefault().getBundle(); + URL url = FileLocator.find(bundle, path, null); + URL resolved = FileLocator.resolve(url); + if ("file".equals(resolved.getProtocol())) { //$NON-NLS-1$ + String filePath = resolved.getFile(); + Directory luceneDirectory = new NIOFSDirectory(new File(filePath)); + IndexSearcher searcher = new IndexSearcher(luceneDirectory, true); + QueryBuilder queryBuilder = new QueryBuilder("eclipse", new AnalyzerDescriptor("en-us")); + Query luceneQuery = queryBuilder.getLuceneQuery(new ArrayList() , false); + TopDocs hits = searcher.search(luceneQuery, 500); + assertEquals(hits.totalHits, 1); + } else { + fail("Cannot resolve to file protocol"); + } + } + + /* + * Tests the isCompatible method in PluginIndex + */ + private void checkCompatible(String versionDirectory, boolean expected) { + SearchIndexWithIndexingProgress index = BaseHelpSystem.getLocalSearchManager().getIndex("en_us".toString()); + BaseHelpSystem.getLocalSearchManager().ensureIndexUpdated( + new NullProgressMonitor(), + index); + Path path = new Path(versionDirectory); + PluginIndex pluginIndex = new PluginIndex("org.eclipse.ua.tests", "data/help/searchindex/" + versionDirectory, index); + assertEquals(expected, pluginIndex.isCompatible(UserAssistanceTestPlugin.getDefault().getBundle(), path)); + } + + /* + * Tests the isLuceneCompatible method in SearchIndex + */ + private void checkLuceneCompatible(String version, boolean expected) { + SearchIndexWithIndexingProgress index = BaseHelpSystem.getLocalSearchManager().getIndex("en_us".toString()); + BaseHelpSystem.getLocalSearchManager().ensureIndexUpdated( + new NullProgressMonitor(), + index); + assertEquals(expected, index.isLuceneCompatible(version)); + } + +} |