import java.util.Map;\r
\r
import org.eclipse.jgit.lib.Repository;\r
+import org.junit.After;\r
+import org.junit.Before;\r
import org.junit.Test;\r
\r
import com.gitblit.LuceneExecutor;\r
*/\r
public class LuceneExecutorTest {\r
\r
+ LuceneExecutor lucene;\r
+ \r
private LuceneExecutor newLuceneExecutor() {\r
Map<String, Object> map = new HashMap<String, Object>();\r
MemorySettings settings = new MemorySettings(map); \r
return model;\r
}\r
\r
+ @Before\r
+ public void setup() {\r
+ lucene = newLuceneExecutor();\r
+ }\r
+ \r
+ @After\r
+ public void tearDown() {\r
+ lucene.close();\r
+ }\r
+ \r
@Test\r
public void testIndex() throws Exception {\r
- LuceneExecutor lucene = newLuceneExecutor();\r
- \r
// reindex helloworld\r
Repository repository = GitBlitSuite.getHelloworldRepository();\r
RepositoryModel model = newRepositoryModel(repository);\r
result = lucene.search("type:blob AND path:clipper.prg", 1, 1, model.name).get(0); \r
assertEquals("tinogomes", result.author); \r
\r
- // reindex theoretical physics\r
- repository = GitBlitSuite.getTheoreticalPhysicsRepository();\r
- model = newRepositoryModel(repository);\r
- lucene.reindex(model, repository);\r
- repository.close();\r
- \r
// reindex JGit\r
repository = GitBlitSuite.getJGitRepository();\r
model = newRepositoryModel(repository);\r
lucene.reindex(model, repository);\r
repository.close();\r
- \r
- lucene.close();\r
}\r
\r
@Test\r
public void testQuery() throws Exception {\r
- LuceneExecutor lucene = new LuceneExecutor(null, GitBlitSuite.REPOSITORIES);\r
- \r
// 2 occurrences on the master branch\r
Repository repository = GitBlitSuite.getHelloworldRepository(); \r
RepositoryModel model = newRepositoryModel(repository);\r
assertEquals(1, results.size());\r
assertEquals("d.D", results.get(0).path);\r
\r
- // 1 occurrence on the gh-pages branch\r
- repository = GitBlitSuite.getTheoreticalPhysicsRepository();\r
+ // commit test\r
+ repository = GitBlitSuite.getJGitRepository();\r
model = newRepositoryModel(repository);\r
repository.close();\r
\r
- results = lucene.search("\"add the .nojekyll file\"", 1, 10, model.name);\r
+ results = lucene.search("\"initial jgit contribution to eclipse.org\"", 1, 10, model.name);\r
assertEquals(1, results.size());\r
- assertEquals("Ondrej Certik", results.get(0).author);\r
- assertEquals("2648c0c98f2101180715b4d432fc58d0e21a51d7", results.get(0).commitId);\r
- assertEquals("refs/heads/gh-pages", results.get(0).branch);\r
- \r
- results = lucene.search("type:blob AND \"src/intro.rst\"", 1, 10, model.name);\r
- assertEquals(4, results.size());\r
+ assertEquals("Git Development Community", results.get(0).author);\r
+ assertEquals("1a6964c8274c50f0253db75f010d78ef0e739343", results.get(0).commitId);\r
+ assertEquals("refs/heads/master", results.get(0).branch);\r
\r
// hash id tests\r
- results = lucene.search("commit:57c4f26f157ece24b02f4f10f5f68db1d2ce7ff5", 1, 10, model.name);\r
+ results = lucene.search("type:commit AND commit:1a6964c8274c50f0253db75f010d78ef0e739343", 1, 10, model.name);\r
assertEquals(1, results.size());\r
\r
- results = lucene.search("commit:57c4f26f157*", 1, 10, model.name);\r
+ results = lucene.search("type:commit AND commit:1a6964c8274*", 1, 10, model.name);\r
+ assertEquals("Shawn O. Pearce", results.get(0).committer);\r
assertEquals(1, results.size()); \r
\r
// annotated tag test\r
- repository = GitBlitSuite.getJGitRepository();\r
- model = newRepositoryModel(repository);\r
- repository.close();\r
- \r
results = lucene.search("I663208919f297836a9c16bf458e4a43ffaca4c12", 1, 10, model.name);\r
assertEquals(1, results.size());\r
assertEquals("[v1.3.0.201202151440-r]", results.get(0).tags.toString()); \r
- \r
- lucene.close();\r
}\r
\r
@Test\r
public void testMultiSearch() throws Exception {\r
- LuceneExecutor lucene = newLuceneExecutor();\r
List<String> list = new ArrayList<String>();\r
Repository repository = GitBlitSuite.getHelloworldRepository();\r
list.add(newRepositoryModel(repository).name);\r
repository.close();\r
\r
List<SearchResult> results = lucene.search("test", 1, 10, list);\r
- lucene.close();\r
assertEquals(10, results.size());\r
}\r
\r
@Test\r
public void testDeleteBlobFromIndex() throws Exception {\r
// start with a fresh reindex of entire repository\r
- LuceneExecutor lucene = newLuceneExecutor();\r
Repository repository = GitBlitSuite.getHelloworldRepository();\r
RepositoryModel model = newRepositoryModel(repository);\r
lucene.reindex(model, repository);\r