Search in sources :

Example 11 with EnabledForRepository

use of org.opengrok.indexer.condition.EnabledForRepository in project OpenGrok by OpenGrok.

the class PerforceRepositoryTest method testHistoryAndAnnotations.

/**
 * Following are steps to set up for testing:
 * <p><ul>
 * <li>Install a Perforce server instance. I elected to install the
 * helix-p4d package on Ubuntu by following the instructions at
 * <a href="https://www.perforce.com/manuals/p4sag/Content/P4SAG/install.linux.packages.install.html">
 * Helix Core Server Administrator Guide &gt; Installing the server &gt; Linux
 * package-based installation &gt; Installation</a>.
 * <li>Configure the Perforce server. Follow the instructions at
 * <a href="https://www.perforce.com/manuals/p4sag/Content/P4SAG/install.linux.packages.configure.html">
 * Helix Core Server Administrator Guide &gt; Installing the server &gt; Linux
 * package-based installation &gt; Post-installation configuration</a>.
 * <li>Secure the Perforce server transport layer. I deployed a private key
 * and certificate following the instructions at
 * <a href="https://www.perforce.com/manuals/p4sag/Content/P4SAG/DB5-16618.html">
 * Helix Core Server Administrator Guide &gt; Securing the server &gt; Using SSL
 * to encrypt connections to a Helix server &gt; Key and certificate
 * management</a>.
 * <li>Define an authentication method for the Perforce server. I elected to
 * authenticate against my home Active Directory following the instructions
 * at <a href="https://www.perforce.com/manuals/p4sag/Content/P4SAG/security.ldap.auth.html">
 * Helix Core Server Administrator Guide &gt; Securing the server &gt; LDAP
 * authentication &gt; Authenticating against Active Directory and LDAP
 * servers</a> and then testing the LDAP configuration per
 * <a href="https://www.perforce.com/manuals/p4sag/Content/P4SAG/security.ldap.testing.html">
 * Helix Core Server Administrator Guide &gt; Securing the server &gt; LDAP
 * authentication &gt; Testing and enabling LDAP configurations</a>.
 * <li>Install Perforce on the development workstation. I used Homebrew to
 * install: {@code admin$ brew cask install perforce}
 * <li>Set environment to connect to the Perforce server. My server is named
 * p4: {@code export P4PORT=ssl:p4.localdomain:1666}
 * <li>Define a Perforce client view on the workstation. For a workstation
 * named workstation1: {@code cd /var/opengrok/src && p4 client workstation1}
 * <li>Add sample code and submit: {@code p4 add *.h && p4 submit}
 * <li>Add more sample code and submit: {@code p4 add *.c && p4 submit}
 * <li>Add more sample code and submit: {@code p4 add *.txt && p4 submit}
 * <li>Code, Index, Test, and Debug.
 * </ul><p>
 */
@Test
@EnabledForRepository(PERFORCE)
public void testHistoryAndAnnotations() throws Exception {
    if (skip) {
        return;
    }
    PerforceRepository instance = new PerforceRepository();
    instance.setDirectoryName(new File(root.getAbsolutePath()));
    for (File f : files) {
        if (instance.fileHasHistory(f)) {
            History history = instance.getHistory(f);
            assertNotNull(history, "Failed to get history for: " + f.getAbsolutePath());
            for (HistoryEntry entry : history.getHistoryEntries()) {
                String revision = entry.getRevision();
                InputStream in = instance.getHistoryGet(f.getParent(), f.getName(), revision);
                assertNotNull(in, "Failed to get revision " + revision + " of " + f.getAbsolutePath());
                if (instance.fileHasAnnotation(f)) {
                    assertNotNull(instance.annotate(f, revision), "Failed to annotate: " + f.getAbsolutePath());
                }
            }
        }
    }
}
Also used : InputStream(java.io.InputStream) File(java.io.File) Test(org.junit.jupiter.api.Test) EnabledForRepository(org.opengrok.indexer.condition.EnabledForRepository)

Example 12 with EnabledForRepository

use of org.opengrok.indexer.condition.EnabledForRepository in project OpenGrok by OpenGrok.

the class RepositoryFactoryTest method testNormallyEnabledMercurialRepository.

@EnabledForRepository(RepositoryInstalled.Type.MERCURIAL)
@Test
public void testNormallyEnabledMercurialRepository() throws IllegalAccessException, InvocationTargetException, ForbiddenSymlinkException, InstantiationException, NoSuchMethodException, IOException {
    File root = new File(repository.getSourceRoot(), "mercurial");
    env.setSourceRoot(root.getAbsolutePath());
    assertNotNull(RepositoryFactory.getRepository(root), "should get repository for mercurial/");
    List<Class<? extends Repository>> clazzes = RepositoryFactory.getRepositoryClasses();
    assertTrue(clazzes.contains(MercurialRepository.class), "should contain MercurialRepository");
}
Also used : EnabledForRepository(org.opengrok.indexer.condition.EnabledForRepository) TestRepository(org.opengrok.indexer.util.TestRepository) File(java.io.File) Test(org.junit.jupiter.api.Test) EnabledForRepository(org.opengrok.indexer.condition.EnabledForRepository)

Example 13 with EnabledForRepository

use of org.opengrok.indexer.condition.EnabledForRepository in project OpenGrok by OpenGrok.

the class RepositoryFactoryTest method testRepositoryMatchingSourceRoot.

@EnabledForRepository(RepositoryInstalled.Type.MERCURIAL)
@Test
public void testRepositoryMatchingSourceRoot() throws IllegalAccessException, InvocationTargetException, ForbiddenSymlinkException, InstantiationException, NoSuchMethodException, IOException {
    File root = new File(repository.getSourceRoot(), "mercurial");
    env.setSourceRoot(root.getAbsolutePath());
    env.setProjectsEnabled(true);
    Repository repo = RepositoryFactory.getRepository(root);
    assertNull(repo, "should not get repo for root if projects enabled");
}
Also used : EnabledForRepository(org.opengrok.indexer.condition.EnabledForRepository) TestRepository(org.opengrok.indexer.util.TestRepository) File(java.io.File) Test(org.junit.jupiter.api.Test) EnabledForRepository(org.opengrok.indexer.condition.EnabledForRepository)

Example 14 with EnabledForRepository

use of org.opengrok.indexer.condition.EnabledForRepository in project OpenGrok by OpenGrok.

the class HistoryContextTest method testGetContext3Args.

@Test
@EnabledForRepository(MERCURIAL)
public void testGetContext3Args() throws Exception {
    String path = "/mercurial/Makefile";
    String filename = Paths.get(repositories.getSourceRoot(), "mercurial", "Makefile").toString();
    // Construct a query equivalent to hist:dummy
    TermQuery q1 = new TermQuery(new Term("hist", "dummy"));
    ArrayList<Hit> hits = new ArrayList<>();
    boolean gotCtx = new HistoryContext(q1).getContext(filename, path, hits);
    assertTrue(gotCtx, filename + " has context");
    assertEquals(1, hits.size());
    assertTrue(hits.get(0).getLine().contains("Created a small <b>dummy</b> program"));
    // Construct a query equivalent to hist:"dummy program"
    PhraseQuery.Builder q2 = new PhraseQuery.Builder();
    q2.add(new Term("hist", "dummy"));
    q2.add(new Term("hist", "program"));
    hits.clear();
    gotCtx = new HistoryContext(q2.build()).getContext(filename, path, hits);
    assertTrue(gotCtx, filename + " has context");
    assertEquals(1, hits.size());
    assertTrue(hits.get(0).getLine().contains("Created a small <b>dummy program</b>"));
    // Search for a term that doesn't exist
    TermQuery q3 = new TermQuery(new Term("hist", "term_does_not_exist"));
    hits.clear();
    gotCtx = new HistoryContext(q3).getContext(filename, path, hits);
    assertFalse(gotCtx, filename + " has no context");
    assertEquals(0, hits.size());
    // Search for term with multiple hits - hist:small OR hist:target
    BooleanQuery.Builder q4 = new BooleanQuery.Builder();
    q4.add(new TermQuery(new Term("hist", "small")), Occur.SHOULD);
    q4.add(new TermQuery(new Term("hist", "target")), Occur.SHOULD);
    hits.clear();
    gotCtx = new HistoryContext(q4.build()).getContext(filename, path, hits);
    assertTrue(gotCtx, filename + " has context");
    assertEquals(2, hits.size());
    assertTrue(hits.get(0).getLine().contains("Add lint make <b>target</b> and fix lint warnings"));
    assertTrue(hits.get(1).getLine().contains("Created a <b>small</b> dummy program"));
}
Also used : TermQuery(org.apache.lucene.search.TermQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) PhraseQuery(org.apache.lucene.search.PhraseQuery) ArrayList(java.util.ArrayList) Term(org.apache.lucene.index.Term) Hit(org.opengrok.indexer.search.Hit) Test(org.junit.jupiter.api.Test) EnabledForRepository(org.opengrok.indexer.condition.EnabledForRepository)

Example 15 with EnabledForRepository

use of org.opengrok.indexer.condition.EnabledForRepository in project OpenGrok by OpenGrok.

the class FileHistoryCacheTest method testRenameFileThenDoIncrementalReindex.

/**
 * Check how incremental reindex behaves when indexing changesets that
 * rename+change file.
 *
 * The scenario goes as follows:
 * - create Mercurial repository
 * - perform full reindex
 * - add changesets which renamed and modify a file
 * - perform incremental reindex
 * - change+rename the file again
 * - incremental reindex
 */
@EnabledOnOs({ OS.LINUX, OS.MAC, OS.SOLARIS, OS.AIX, OS.OTHER })
@EnabledForRepository(MERCURIAL)
@Test
void testRenameFileThenDoIncrementalReindex() throws Exception {
    File reposRoot = new File(repositories.getSourceRoot(), "mercurial");
    History updatedHistory;
    // The test expects support for renamed files.
    env.setHandleHistoryOfRenamedFiles(true);
    // Use tags for better coverage.
    env.setTagsEnabled(true);
    // Generate history index.
    // It is necessary to call getRepository() only after tags were enabled
    // to produce list of tags.
    Repository repo = RepositoryFactory.getRepository(reposRoot);
    History historyToStore = repo.getHistory(reposRoot);
    cache.store(historyToStore, repo);
    // Import changesets which rename one of the files in the repository.
    MercurialRepositoryTest.runHgCommand(reposRoot, "import", Paths.get(getClass().getResource("/history/hg-export-renamed.txt").toURI()).toString());
    // Perform incremental reindex.
    repo.createCache(cache, cache.getLatestCachedRevision(repo));
    // Verify size of complete history for the directory.
    updatedHistory = cache.get(reposRoot, repo, true);
    assertEquals(14, updatedHistory.getHistoryEntries().size());
    // Check changesets for the renames and changes of single file.
    File main2File = new File(reposRoot.toString() + File.separatorChar + "main2.c");
    updatedHistory = cache.get(main2File, repo, false);
    // Changesets e0-e3 were brought in by the import done above.
    HistoryEntry e0 = new HistoryEntry("13:e55a793086da", // whole minutes only
    new Date(1245447973L / 60 * 60 * 1000), "xyz", "Do something else", true);
    HistoryEntry e1 = new HistoryEntry("12:97b5392fec0d", // whole minutes only
    new Date(1393515253L / 60 * 60 * 1000), "Vladimir Kotal <Vladimir.Kotal@oracle.com>", "rename2", true);
    HistoryEntry e2 = new HistoryEntry("11:5c203a0bc12b", // whole minutes only
    new Date(1393515291L / 60 * 60 * 1000), "Vladimir Kotal <Vladimir.Kotal@oracle.com>", "rename1", true);
    HistoryEntry e3 = new HistoryEntry("10:1e392ef0b0ed", // whole minutes only
    new Date(1245446973L / 60 * 60 * 1000), "xyz", "Return failure when executed with no arguments", true);
    HistoryEntry e4 = new HistoryEntry("2:585a1b3f2efb", // whole minutes only
    new Date(1218571989L / 60 * 60 * 1000), "Trond Norbye <trond.norbye@sun.com>", "Add lint make target and fix lint warnings", true);
    HistoryEntry e5 = new HistoryEntry("1:f24a5fd7a85d", // whole minutes only
    new Date(1218571413L / 60 * 60 * 1000), "Trond Norbye <trond.norbye@sun.com>", "Created a small dummy program", true);
    History histConstruct = new History();
    LinkedList<HistoryEntry> entriesConstruct = new LinkedList<>();
    entriesConstruct.add(e0);
    entriesConstruct.add(e1);
    entriesConstruct.add(e2);
    entriesConstruct.add(e3);
    entriesConstruct.add(e4);
    entriesConstruct.add(e5);
    histConstruct.setHistoryEntries(entriesConstruct);
    assertEquals(6, updatedHistory.getHistoryEntries().size());
    assertSameEntries(histConstruct.getHistoryEntries(), updatedHistory.getHistoryEntries(), false);
    // Add some changes and rename the file again.
    MercurialRepositoryTest.runHgCommand(reposRoot, "import", Paths.get(getClass().getResource("/history/hg-export-renamed-again.txt").toURI()).toString());
    // Perform incremental reindex.
    repo.createCache(cache, cache.getLatestCachedRevision(repo));
    HistoryEntry e6 = new HistoryEntry("14:55c41cd4b348", // whole minutes only
    new Date(1489505558L / 60 * 60 * 1000), "Vladimir Kotal <Vladimir.Kotal@oracle.com>", "rename + cstyle", true);
    entriesConstruct = new LinkedList<>();
    entriesConstruct.add(e6);
    entriesConstruct.add(e0);
    entriesConstruct.add(e1);
    entriesConstruct.add(e2);
    entriesConstruct.add(e3);
    entriesConstruct.add(e4);
    entriesConstruct.add(e5);
    histConstruct.setHistoryEntries(entriesConstruct);
    // Check changesets for the renames and changes of single file.
    File main3File = new File(reposRoot.toString() + File.separatorChar + "main3.c");
    updatedHistory = cache.get(main3File, repo, false);
    assertEquals(7, updatedHistory.getHistoryEntries().size());
    assertSameEntries(histConstruct.getHistoryEntries(), updatedHistory.getHistoryEntries(), false);
}
Also used : TestRepository(org.opengrok.indexer.util.TestRepository) EnabledForRepository(org.opengrok.indexer.condition.EnabledForRepository) File(java.io.File) Date(java.util.Date) LinkedList(java.util.LinkedList) EnabledOnOs(org.junit.jupiter.api.condition.EnabledOnOs) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) EnabledForRepository(org.opengrok.indexer.condition.EnabledForRepository)

Aggregations

Test (org.junit.jupiter.api.Test)21 EnabledForRepository (org.opengrok.indexer.condition.EnabledForRepository)21 File (java.io.File)19 TestRepository (org.opengrok.indexer.util.TestRepository)14 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)12 LinkedList (java.util.LinkedList)5 EnabledOnOs (org.junit.jupiter.api.condition.EnabledOnOs)5 Path (java.nio.file.Path)3 Date (java.util.Date)3 RuntimeEnvironment (org.opengrok.indexer.configuration.RuntimeEnvironment)3 BufferedWriter (java.io.BufferedWriter)2 FileWriter (java.io.FileWriter)2 StringWriter (java.io.StringWriter)2 ArrayList (java.util.ArrayList)2 Term (org.apache.lucene.index.Term)2 BooleanQuery (org.apache.lucene.search.BooleanQuery)2 PhraseQuery (org.apache.lucene.search.PhraseQuery)2 TermQuery (org.apache.lucene.search.TermQuery)2 Project (org.opengrok.indexer.configuration.Project)2 HistoryGuru (org.opengrok.indexer.history.HistoryGuru)2