use of org.opengrok.indexer.util.TestRepository in project OpenGrok by OpenGrok.
the class IndexerTest method testRemoveFileOnFileChange.
/**
* Test that reindex after changing a file does not wipe out history index
* for this file. This is important for the incremental history indexing.
*/
@Test
@EnabledForRepository(MERCURIAL)
void testRemoveFileOnFileChange() throws Exception {
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
String path = "/mercurial/bar.txt";
TestRepository testrepo = new TestRepository();
testrepo.create(HistoryGuru.class.getResource("/repositories"));
env.setSourceRoot(testrepo.getSourceRoot());
env.setDataRoot(testrepo.getDataRoot());
env.setRepositories(testrepo.getSourceRoot());
// Create history cache.
Indexer.getInstance().prepareIndexer(env, true, true, false, null, List.of("mercurial"));
File historyFile = new File(env.getDataRootPath(), TandemPath.join("historycache" + path, ".gz"));
assertTrue(historyFile.exists(), String.format("history cache for %s has to exist", path));
// create index
Project project = new Project("mercurial", "/mercurial");
IndexDatabase idb = new IndexDatabase(project);
assertNotNull(idb);
RemoveIndexChangeListener listener = new RemoveIndexChangeListener(path);
idb.addIndexChangedListener(listener);
idb.update();
assertEquals(5, listener.filesToAdd.size());
listener.reset();
// Change a file so that it gets picked up by the indexer.
File bar = new File(testrepo.getSourceRoot() + File.separator + "mercurial", "bar.txt");
assertTrue(bar.exists());
try (BufferedWriter bw = new BufferedWriter(new FileWriter(bar, true))) {
bw.write("foo\n");
}
// reindex
idb.update();
// Make sure that the file was actually processed.
assertEquals(1, listener.removedFiles.size());
assertEquals(1, listener.filesToAdd.size());
assertEquals("/mercurial/bar.txt", listener.removedFiles.peek());
testrepo.destroy();
}
use of org.opengrok.indexer.util.TestRepository in project OpenGrok by OpenGrok.
the class IndexerTest method testSetRepositories.
@Test
@EnabledForRepository(MERCURIAL)
void testSetRepositories() throws Exception {
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
TestRepository testrepo = new TestRepository();
testrepo.create(HistoryGuru.class.getResource("/repositories"));
env.setSourceRoot(testrepo.getSourceRoot());
env.setRepositories(testrepo.getSourceRoot());
assertEquals(7, env.getRepositories().size());
String[] repoNames = { "mercurial", "git" };
env.setRepositories(Arrays.stream(repoNames).map(t -> Paths.get(env.getSourceRootPath(), t).toString()).distinct().toArray(String[]::new));
assertEquals(2, env.getRepositories().size());
}
use of org.opengrok.indexer.util.TestRepository in project OpenGrok by OpenGrok.
the class MercurialRepositoryTest method setUpTestRepository.
/**
* Set up a test repository. Should be called by the tests that need it. The
* test repository will be destroyed automatically when the test finishes.
*/
private void setUpTestRepository() throws IOException, URISyntaxException {
repository = new TestRepository();
repository.create(getClass().getResource("/repositories"));
}
use of org.opengrok.indexer.util.TestRepository in project OpenGrok by OpenGrok.
the class RepositoryFactoryTest method testNotWorkingRepository.
/*
* There is no conditional run based on whether given repository is installed because
* this test is not supposed to have working Mercurial anyway.
*/
static void testNotWorkingRepository(TestRepository repository, String repoPath, String propName) throws InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, IOException, ForbiddenSymlinkException {
String origPropValue = System.setProperty(propName, "/foo/bar/nonexistent");
try {
File root = new File(repository.getSourceRoot(), repoPath);
RuntimeEnvironment.getInstance().setSourceRoot(repository.getSourceRoot());
Repository repo = RepositoryFactory.getRepository(root);
assertNotNull(repo, "should have defined repo");
assertFalse(repo.isWorking(), "repo should not be working");
} finally {
if (origPropValue != null) {
System.setProperty(propName, origPropValue);
} else {
System.clearProperty(propName);
}
}
}
use of org.opengrok.indexer.util.TestRepository in project OpenGrok by OpenGrok.
the class RepositoryWithPerPartesHistoryTest method setUp.
@BeforeEach
public void setUp() throws Exception {
repositories = new TestRepository();
repositories.create(getClass().getResource("/repositories"));
File reposRoot = new File(repositories.getSourceRoot(), "git");
Repository repo = RepositoryFactory.getRepository(reposRoot);
assertNotNull(repo);
assertTrue(repo instanceof RepositoryWithPerPartesHistory);
gitRepository = (GitRepository) repo;
}
Aggregations