IndexerTest.java revision 489
222N/A/*
98N/A * CDDL HEADER START
306N/A *
98N/A * The contents of this file are subject to the terms of the
98N/A * Common Development and Distribution License (the "License").
98N/A * You may not use this file except in compliance with the License.
98N/A *
98N/A * See LICENSE.txt included in this distribution for the specific
98N/A * language governing permissions and limitations under the License.
98N/A *
98N/A * When distributing Covered Code, include this CDDL HEADER in each
98N/A * file and include the License file at LICENSE.txt.
98N/A * If applicable, add the following below this CDDL HEADER, with the
98N/A * fields enclosed by brackets "[]" replaced with your own identifying
98N/A * information: Portions Copyright [yyyy] [name of copyright owner]
98N/A *
98N/A * CDDL HEADER END
98N/A */
98N/A
98N/A/*
98N/A * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
98N/A * Use is subject to license terms.
98N/A */
98N/Apackage org.opensolaris.opengrok.index;
98N/A
98N/Aimport java.io.IOException;
98N/Aimport java.util.ArrayList;
98N/Aimport java.util.List;
98N/Aimport org.junit.After;
98N/Aimport org.junit.AfterClass;
653N/Aimport org.junit.Before;
98N/Aimport org.junit.BeforeClass;
98N/Aimport org.junit.Test;
98N/Aimport org.opensolaris.opengrok.configuration.Project;
561N/Aimport org.opensolaris.opengrok.configuration.RuntimeEnvironment;
561N/Aimport org.opensolaris.opengrok.history.HistoryGuru;
561N/Aimport org.opensolaris.opengrok.util.TestRepository;
493N/Aimport static org.junit.Assert.*;
222N/A
306N/A/**
222N/A *
306N/A * @author Trond Norbye
653N/A */
372N/Apublic class IndexerTest {
561N/A TestRepository repository;
561N/A
561N/A public IndexerTest() {
561N/A }
561N/A
306N/A @BeforeClass
561N/A public static void setUpClass() throws Exception {
561N/A }
561N/A
561N/A @AfterClass
561N/A public static void tearDownClass() throws Exception {
561N/A }
561N/A
306N/A @Before
561N/A public void setUp() throws IOException {
561N/A repository = new TestRepository();
306N/A repository.create(IndexerTest.class.getResourceAsStream("source.zip"));
561N/A }
561N/A
561N/A @After
561N/A public void tearDown() {
306N/A repository.destroy();
561N/A }
561N/A
561N/A /**
561N/A * Test of doIndexerExecution method, of class Indexer.
561N/A */
561N/A @Test
561N/A public void testIndexGeneration() throws Exception {
561N/A System.out.println("Generating index by using the class methods");
561N/A RuntimeEnvironment env = RuntimeEnvironment.getInstance();
561N/A env.setCtags(System.getProperty("org.opensolaris.opengrok.configuration.ctags", "ctags"));
561N/A if (env.validateExuberantCtags()) {
561N/A env.setSourceRoot(repository.getSourceRoot());
561N/A env.setDataRoot(repository.getDataRoot());
561N/A env.setVerbose(true);
561N/A Indexer.getInstance().prepareIndexer(env, true, true, "/c", null, false, false, false, null, null);
98N/A Indexer.getInstance().doIndexerExecution(true, 1, null, null);
493N/A } else {
493N/A System.out.println("Skipping test. Could not find a ctags I could use in path.");
98N/A }
493N/A }
493N/A
380N/A /**
493N/A * Test of doIndexerExecution method, of class Indexer.
493N/A */
493N/A @Test
493N/A public void testMain() throws IOException {
System.out.println("Generate index by using command line options");
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
env.setCtags(System.getProperty("org.opensolaris.opengrok.configuration.ctags", "ctags"));
if (env.validateExuberantCtags()) {
String[] argv = { "-S", "-P", "-p", "/c", "-H", "-Q", "off", "-s", repository.getSourceRoot(), "-d", repository.getDataRoot(), "-v"};
Indexer.main(argv);
} else {
System.out.println("Skipping test. Could not find a ctags I could use in path.");
}
}
private class MyIndexChangeListener implements org.opensolaris.opengrok.index.IndexChangedListener {
List<String> files = new ArrayList<String>();
public void fileAdded(String path, String analyzer) {
files.add(path);
}
public void fileRemoved(String path) {
files.add(path);
}
}
@Test
public void testRFE2575() throws IOException {
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
env.setCtags(System.getProperty("org.opensolaris.opengrok.configuration.ctags", "ctags"));
env.setSourceRoot(repository.getSourceRoot());
env.setDataRoot(repository.getDataRoot());
HistoryGuru.getInstance().addRepositories(repository.getSourceRoot());
if (env.validateExuberantCtags()) {
Project project = new Project();
project.setPath("/rfe2575");
IndexDatabase idb = new IndexDatabase(project);
assertNotNull(idb);
MyIndexChangeListener listener = new MyIndexChangeListener();
idb.addIndexChangedListener(listener);
idb.update();
assertEquals(2, listener.files.size());
repository.purgeData();
RuntimeEnvironment.getInstance().setIndexVersionedFilesOnly(true);
idb = new IndexDatabase(project);
listener = new MyIndexChangeListener();
idb.addIndexChangedListener(listener);
idb.update();
assertEquals(1, listener.files.size());
} else {
System.out.println("Skipping test. Could not find a ctags I could use in path.");
}
}
}