IndexerTest.java revision 861
352N/A/*
352N/A * CDDL HEADER START
352N/A *
352N/A * The contents of this file are subject to the terms of the
352N/A * Common Development and Distribution License (the "License").
352N/A * You may not use this file except in compliance with the License.
352N/A *
352N/A * See LICENSE.txt included in this distribution for the specific
352N/A * language governing permissions and limitations under the License.
352N/A *
352N/A * When distributing Covered Code, include this CDDL HEADER in each
352N/A * file and include the License file at LICENSE.txt.
352N/A * If applicable, add the following below this CDDL HEADER, with the
352N/A * fields enclosed by brackets "[]" replaced with your own identifying
352N/A * information: Portions Copyright [yyyy] [name of copyright owner]
352N/A *
352N/A * CDDL HEADER END
352N/A */
352N/A
352N/A/*
352N/A * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
352N/A * Use is subject to license terms.
352N/A */
352N/Apackage org.opensolaris.opengrok.index;
352N/A
560N/Aimport java.io.File;
560N/Aimport java.io.FileInputStream;
352N/Aimport java.io.IOException;
560N/Aimport java.io.InputStream;
560N/Aimport java.io.StringWriter;
480N/Aimport java.util.ArrayList;
480N/Aimport java.util.List;
352N/Aimport org.junit.After;
352N/Aimport org.junit.AfterClass;
352N/Aimport org.junit.Before;
352N/Aimport org.junit.BeforeClass;
352N/Aimport org.junit.Test;
560N/Aimport org.opensolaris.opengrok.analysis.AnalyzerGuru;
560N/Aimport org.opensolaris.opengrok.analysis.FileAnalyzerFactory;
480N/Aimport org.opensolaris.opengrok.configuration.Project;
352N/Aimport org.opensolaris.opengrok.configuration.RuntimeEnvironment;
480N/Aimport org.opensolaris.opengrok.history.HistoryGuru;
592N/Aimport org.opensolaris.opengrok.history.Repository;
665N/Aimport org.opensolaris.opengrok.history.RepositoryFactory;
665N/Aimport org.opensolaris.opengrok.history.RepositoryInfo;
560N/Aimport org.opensolaris.opengrok.util.FileUtilities;
377N/Aimport org.opensolaris.opengrok.util.TestRepository;
480N/Aimport static org.junit.Assert.*;
352N/A
352N/A/**
352N/A *
352N/A * @author Trond Norbye
352N/A */
352N/Apublic class IndexerTest {
377N/A TestRepository repository;
352N/A
352N/A public IndexerTest() {
352N/A }
352N/A
352N/A @BeforeClass
352N/A public static void setUpClass() throws Exception {
861N/A assertTrue("No point in running indexer tests without valid ctags",
861N/A RuntimeEnvironment.getInstance().validateExuberantCtags());
352N/A }
352N/A
352N/A @AfterClass
352N/A public static void tearDownClass() throws Exception {
352N/A }
352N/A
352N/A @Before
367N/A public void setUp() throws IOException {
377N/A repository = new TestRepository();
377N/A repository.create(IndexerTest.class.getResourceAsStream("source.zip"));
352N/A }
352N/A
352N/A @After
352N/A public void tearDown() {
377N/A repository.destroy();
352N/A }
352N/A
352N/A /**
352N/A * Test of doIndexerExecution method, of class Indexer.
352N/A */
352N/A @Test
352N/A public void testIndexGeneration() throws Exception {
365N/A System.out.println("Generating index by using the class methods");
352N/A RuntimeEnvironment env = RuntimeEnvironment.getInstance();
352N/A env.setCtags(System.getProperty("org.opensolaris.opengrok.configuration.ctags", "ctags"));
352N/A if (env.validateExuberantCtags()) {
489N/A env.setSourceRoot(repository.getSourceRoot());
377N/A env.setDataRoot(repository.getDataRoot());
352N/A env.setVerbose(true);
352N/A Indexer.getInstance().prepareIndexer(env, true, true, "/c", null, false, false, false, null, null);
352N/A Indexer.getInstance().doIndexerExecution(true, 1, null, null);
352N/A } else {
352N/A System.out.println("Skipping test. Could not find a ctags I could use in path.");
352N/A }
352N/A }
352N/A
365N/A /**
365N/A * Test of doIndexerExecution method, of class Indexer.
365N/A */
365N/A @Test
365N/A public void testMain() throws IOException {
365N/A System.out.println("Generate index by using command line options");
365N/A RuntimeEnvironment env = RuntimeEnvironment.getInstance();
365N/A env.setCtags(System.getProperty("org.opensolaris.opengrok.configuration.ctags", "ctags"));
365N/A if (env.validateExuberantCtags()) {
489N/A String[] argv = { "-S", "-P", "-p", "/c", "-H", "-Q", "off", "-s", repository.getSourceRoot(), "-d", repository.getDataRoot(), "-v"};
365N/A Indexer.main(argv);
365N/A } else {
365N/A System.out.println("Skipping test. Could not find a ctags I could use in path.");
365N/A }
365N/A }
480N/A
480N/A private class MyIndexChangeListener implements org.opensolaris.opengrok.index.IndexChangedListener {
480N/A List<String> files = new ArrayList<String>();
480N/A
480N/A public void fileAdded(String path, String analyzer) {
480N/A files.add(path);
480N/A }
480N/A
480N/A public void fileRemoved(String path) {
480N/A files.add(path);
480N/A }
480N/A }
480N/A
480N/A @Test
678N/A public void testRFE2575() throws Exception {
480N/A RuntimeEnvironment env = RuntimeEnvironment.getInstance();
480N/A env.setCtags(System.getProperty("org.opensolaris.opengrok.configuration.ctags", "ctags"));
489N/A env.setSourceRoot(repository.getSourceRoot());
480N/A env.setDataRoot(repository.getDataRoot());
489N/A HistoryGuru.getInstance().addRepositories(repository.getSourceRoot());
480N/A
665N/A List<RepositoryInfo> repos = env.getRepositories();
665N/A Repository r = null;
665N/A for (RepositoryInfo ri : repos) {
807N/A if (ri.getDirectoryName().equals(repository.getSourceRoot()+"/rfe2575")) {
665N/A r = RepositoryFactory.getRepository(ri);
665N/A break;
665N/A }
665N/A }
592N/A
592N/A if (r != null && r.isWorking() && env.validateExuberantCtags()) {
480N/A Project project = new Project();
480N/A project.setPath("/rfe2575");
480N/A IndexDatabase idb = new IndexDatabase(project);
480N/A assertNotNull(idb);
480N/A MyIndexChangeListener listener = new MyIndexChangeListener();
480N/A idb.addIndexChangedListener(listener);
480N/A idb.update();
480N/A assertEquals(2, listener.files.size());
480N/A repository.purgeData();
480N/A RuntimeEnvironment.getInstance().setIndexVersionedFilesOnly(true);
480N/A idb = new IndexDatabase(project);
480N/A listener = new MyIndexChangeListener();
480N/A idb.addIndexChangedListener(listener);
480N/A idb.update();
480N/A assertEquals(1, listener.files.size());
807N/A RuntimeEnvironment.getInstance().setIndexVersionedFilesOnly(false);
480N/A } else {
807N/A System.out.println("Skipping test. Repository for rfe2575 not found or could not find a ctags or an sccs I could use in path.");
480N/A }
480N/A }
560N/A
560N/A @Test
560N/A public void testXref() throws IOException {
560N/A List<File> files = new ArrayList<File>();
560N/A FileUtilities.getAllFiles(new File(repository.getSourceRoot()), files, false);
560N/A for (File f : files) {
560N/A FileAnalyzerFactory factory = AnalyzerGuru.find(f.getAbsolutePath());
560N/A if (factory == null) {
560N/A continue;
560N/A }
560N/A InputStream in = new FileInputStream(f);
560N/A StringWriter out = new StringWriter();
560N/A try {
560N/A AnalyzerGuru.writeXref(factory, in, out, null, null);
560N/A } catch (UnsupportedOperationException exp) {
560N/A // ignore
560N/A }
560N/A in.close();
560N/A out.close();
560N/A }
560N/A }
593N/A @Test
678N/A public void testBug3430() throws Exception {
593N/A RuntimeEnvironment env = RuntimeEnvironment.getInstance();
593N/A env.setCtags(System.getProperty("org.opensolaris.opengrok.configuration.ctags", "ctags"));
593N/A env.setSourceRoot(repository.getSourceRoot());
593N/A env.setDataRoot(repository.getDataRoot());
593N/A
593N/A if (env.validateExuberantCtags()) {
593N/A Project project = new Project();
593N/A project.setPath("/bug3430");
593N/A IndexDatabase idb = new IndexDatabase(project);
593N/A assertNotNull(idb);
593N/A MyIndexChangeListener listener = new MyIndexChangeListener();
593N/A idb.addIndexChangedListener(listener);
593N/A idb.update();
593N/A assertEquals(1, listener.files.size());
593N/A } else {
593N/A System.out.println("Skipping test. Could not find a ctags I could use in path.");
593N/A }
593N/A }
593N/A}