Search in sources :

Example 11 with IndexGitRepoJob

use of com.searchcode.app.jobs.repository.IndexGitRepoJob in project searchcode-server by boyter.

the class IndexBaseRepoJobTest method testGetMinified.

public void testGetMinified() {
    IndexGitRepoJob indexGitRepoJob = new IndexGitRepoJob();
    indexGitRepoJob.LOGINDEXED = true;
    List<String[]> reportList = new ArrayList<>();
    IndexBaseRepoJob.IsMinifiedReturn isMinified = indexGitRepoJob.getIsMinified(new ArrayList<>(), "", reportList);
    assertThat(isMinified.isMinified()).isFalse();
    assertThat(isMinified.getReportList().isEmpty()).isTrue();
}
Also used : IndexBaseRepoJob(com.searchcode.app.jobs.repository.IndexBaseRepoJob) ArrayList(java.util.ArrayList) IndexGitRepoJob(com.searchcode.app.jobs.repository.IndexGitRepoJob)

Example 12 with IndexGitRepoJob

use of com.searchcode.app.jobs.repository.IndexGitRepoJob in project searchcode-server by boyter.

the class IndexBaseAndGitRepoJobTest method testShouldJobTerminate.

public void testShouldJobTerminate() {
    IndexGitRepoJob gitRepoJob = new IndexGitRepoJob();
    StatsService statsServiceMock = Mockito.mock(StatsService.class);
    when(statsServiceMock.getLoadAverage()).thenReturn("0.0");
    Singleton.setStatsService(statsServiceMock);
    assertThat(gitRepoJob.shouldJobPauseOrTerminate()).isFalse();
    Singleton.getSharedService().setBackgroundJobsEnabled(false);
    assertThat(gitRepoJob.shouldJobPauseOrTerminate()).isTrue();
    Singleton.getSharedService().setBackgroundJobsEnabled(true);
    assertThat(gitRepoJob.shouldJobPauseOrTerminate()).isFalse();
    Singleton.getSharedService().setPauseBackgroundJobs(true);
    Singleton.getSharedService().setBackgroundJobsEnabled(false);
    assertThat(gitRepoJob.shouldJobPauseOrTerminate()).isTrue();
}
Also used : StatsService(com.searchcode.app.service.StatsService) IndexGitRepoJob(com.searchcode.app.jobs.repository.IndexGitRepoJob)

Example 13 with IndexGitRepoJob

use of com.searchcode.app.jobs.repository.IndexGitRepoJob in project searchcode-server by boyter.

the class IndexBaseAndGitRepoJobTest method testCheckCloneSuccessEmptyReturnsTrue.

public void testCheckCloneSuccessEmptyReturnsTrue() throws IOException {
    File location = TestHelpers.clearAndCreateTempPath("testCheckCloneSuccessEmptyReturnsTrue");
    File projectLocation = TestHelpers.createDirectory(location, "myawesomeproject");
    TestHelpers.createFile(projectLocation, "myfile.java", "some file content");
    IndexGitRepoJob indexGitRepoJob = new IndexGitRepoJob();
    boolean actual = indexGitRepoJob.checkCloneSuccess("myawesomeproject", location.getAbsolutePath());
    assertThat(actual).isTrue();
    File toCheck = new File(projectLocation.getAbsolutePath());
    assertThat(toCheck.exists()).isFalse();
}
Also used : File(java.io.File) IndexGitRepoJob(com.searchcode.app.jobs.repository.IndexGitRepoJob)

Example 14 with IndexGitRepoJob

use of com.searchcode.app.jobs.repository.IndexGitRepoJob in project searchcode-server by boyter.

the class IndexBaseAndGitRepoJobTest method testGetFileLocationFilename.

public void testGetFileLocationFilename() {
    IndexGitRepoJob gitRepoJob = new IndexGitRepoJob();
    String fileLocationFilename = gitRepoJob.getFileLocationFilename(".git/filename", "./repo/");
    assertThat(fileLocationFilename).isEqualTo(".git/filename");
    fileLocationFilename = gitRepoJob.getFileLocationFilename("./repo/.git/filename", "./repo/");
    assertThat(fileLocationFilename).isEqualTo(".git/filename");
}
Also used : IndexGitRepoJob(com.searchcode.app.jobs.repository.IndexGitRepoJob)

Example 15 with IndexGitRepoJob

use of com.searchcode.app.jobs.repository.IndexGitRepoJob in project searchcode-server by boyter.

the class EndToEndITCase method testEndToEndGitDelta.

public void testEndToEndGitDelta() throws IOException {
    CodeSearcher cs = new CodeSearcher();
    IndexGitRepoJob indexGitRepoJob = new IndexGitRepoJob();
    File directoryWithFiles = TestHelpers.createDirectoryWithFiles("EndToEndGitTest");
    this.runCommand(directoryWithFiles.toString(), this.GITPATH, "init", ".");
    this.runCommand(directoryWithFiles.toString(), this.GITPATH, "add", ".");
    this.runCommand(directoryWithFiles.toString(), this.GITPATH, "commit", "-m", "\"First commit\"");
    // Clone from the above into a new directory
    File tempPath = TestHelpers.clearAndCreateTempPath("EndToEndGitCloneTest");
    this.runCommand(tempPath.toString(), this.GITPATH, "clone", directoryWithFiles.toString(), "EndToEndGitTest");
    // Index
    indexGitRepoJob.indexDocsByPath(Paths.get(tempPath.toString()), "EndToEndGitTest", "", tempPath.toString(), false);
    SearchResult searchResult = cs.search("endtoendtestfile", 0);
    assertThat(searchResult.getCodeResultList().size()).isEqualTo(3);
    // Update the source
    TestHelpers.createFile(directoryWithFiles, "EndToEndTestFile4.cpp", "EndToEndTestFile EndToEndTestFile4");
    this.runCommand(directoryWithFiles.toString(), this.GITPATH, "add", ".");
    this.runCommand(directoryWithFiles.toString(), this.GITPATH, "commit", "-m", "\"Add new\"");
    // Index and lets dance
    RepositoryChanged repositoryChanged = indexGitRepoJob.updateExistingRepository("EndToEndGitTest", "repoRemoteLocation", "", "", tempPath.toString(), "", false);
    String repoGitLocation = tempPath.toString() + "/" + "EndToEndGitTest";
    Path docDir = Paths.get(repoGitLocation);
    indexGitRepoJob.indexDocsByDelta(docDir, "EndToEndGitTest", tempPath.toString(), "", repositoryChanged);
    searchResult = cs.search("endtoendtestfile", 0);
    assertThat(searchResult.getCodeResultList().size()).isEqualTo(4);
    // Update the source
    this.runCommand(directoryWithFiles.toString(), this.GITPATH, "rm", "EndToEndTestFile4.cpp");
    this.runCommand(directoryWithFiles.toString(), this.GITPATH, "commit", "-m", "\"Baleted\"");
    // Index and lets dance
    repositoryChanged = indexGitRepoJob.updateExistingRepository("EndToEndGitTest", "repoRemoteLocation", "", "", tempPath.toString(), "", false);
    repoGitLocation = tempPath.toString() + "/" + "EndToEndGitTest";
    docDir = Paths.get(repoGitLocation);
    indexGitRepoJob.indexDocsByDelta(docDir, "EndToEndGitTest", tempPath.toString(), "", repositoryChanged);
    searchResult = cs.search("endtoendtestfile", 0);
    assertThat(searchResult.getCodeResultList().size()).isEqualTo(3);
    Singleton.getCodeIndexer().deleteByReponame("EndToEndGitTest");
    searchResult = cs.search("endtoendtestfile".toLowerCase(), 0);
    assertThat(searchResult.getCodeResultList().size()).isEqualTo(0);
}
Also used : Path(java.nio.file.Path) RepositoryChanged(com.searchcode.app.dto.RepositoryChanged) SearchResult(com.searchcode.app.dto.SearchResult) CodeSearcher(com.searchcode.app.service.CodeSearcher) IndexGitRepoJob(com.searchcode.app.jobs.repository.IndexGitRepoJob)

Aggregations

IndexGitRepoJob (com.searchcode.app.jobs.repository.IndexGitRepoJob)21 ArrayList (java.util.ArrayList)5 CodeSearcher (com.searchcode.app.service.CodeSearcher)4 File (java.io.File)4 RepositoryChanged (com.searchcode.app.dto.RepositoryChanged)3 IndexBaseRepoJob (com.searchcode.app.jobs.repository.IndexBaseRepoJob)3 SearchResult (com.searchcode.app.dto.SearchResult)2 UniqueRepoQueue (com.searchcode.app.util.UniqueRepoQueue)2 Path (java.nio.file.Path)2 TestHelpers (com.searchcode.app.TestHelpers)1 Values (com.searchcode.app.config.Values)1 CodeResult (com.searchcode.app.dto.CodeResult)1 IndexFileRepoJob (com.searchcode.app.jobs.repository.IndexFileRepoJob)1 IndexSvnRepoJob (com.searchcode.app.jobs.repository.IndexSvnRepoJob)1 RepoResult (com.searchcode.app.model.RepoResult)1 CodeIndexer (com.searchcode.app.service.CodeIndexer)1 SharedService (com.searchcode.app.service.SharedService)1 Singleton (com.searchcode.app.service.Singleton)1 StatsService (com.searchcode.app.service.StatsService)1 Properties (com.searchcode.app.util.Properties)1