Search in sources :

Example 1 with IndexGitRepoJob

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

the class IndexBaseRepoJobTest method testExecuteHasMethodInQueueNewRepository.

public void testExecuteHasMethodInQueueNewRepository() throws JobExecutionException {
    SharedService sharedServiceMock = mock(SharedService.class);
    when(sharedServiceMock.getPauseBackgroundJobs()).thenReturn(false);
    when(sharedServiceMock.getBackgroundJobsEnabled()).thenReturn(true);
    IndexGitRepoJob indexGitRepoJob = new IndexGitRepoJob(sharedServiceMock);
    IndexGitRepoJob spy = spy(indexGitRepoJob);
    spy.haveRepoResult = false;
    UniqueRepoQueue uniqueRepoQueue = new UniqueRepoQueue();
    uniqueRepoQueue.add(new RepoResult(1, "name", "scm", "url", "username", "password", "source", "branch", "{}"));
    when(spy.getNextQueuedRepo()).thenReturn(uniqueRepoQueue);
    when(spy.isEnabled()).thenReturn(true);
    when(spy.getNewRepository(anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyBoolean())).thenReturn(new RepositoryChanged(false, null, null));
    when(mockCodeIndexer.shouldPauseAdding()).thenReturn(false);
    spy.codeIndexer = mockCodeIndexer;
    spy.execute(this.mockContext);
    assertThat(spy.haveRepoResult).isTrue();
    assertThat(spy.LOWMEMORY).isTrue();
    verify(spy).getNextQueuedRepo();
    verify(spy, times(2)).getNewRepository(anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyBoolean());
}
Also used : RepositoryChanged(com.searchcode.app.dto.RepositoryChanged) SharedService(com.searchcode.app.service.SharedService) IndexGitRepoJob(com.searchcode.app.jobs.repository.IndexGitRepoJob) UniqueRepoQueue(com.searchcode.app.util.UniqueRepoQueue) RepoResult(com.searchcode.app.model.RepoResult)

Example 2 with IndexGitRepoJob

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

the class IndexBaseRepoJobTest method testGetCodeLinesLogNotIndexedInvalid.

public void testGetCodeLinesLogNotIndexedInvalid() {
    IndexGitRepoJob indexGitRepoJob = new IndexGitRepoJob();
    indexGitRepoJob.LOGINDEXED = false;
    List<String[]> reportList = new ArrayList<>();
    IndexBaseRepoJob.CodeLinesReturn codeLines = indexGitRepoJob.getCodeLines("", reportList);
    assertThat(codeLines.isError()).isTrue();
    assertThat(codeLines.getReportList().isEmpty()).isTrue();
}
Also used : IndexBaseRepoJob(com.searchcode.app.jobs.repository.IndexBaseRepoJob) ArrayList(java.util.ArrayList) IndexGitRepoJob(com.searchcode.app.jobs.repository.IndexGitRepoJob)

Example 3 with IndexGitRepoJob

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

the class IndexBaseAndGitRepoJobTest method testGetBlameFilePath.

public void testGetBlameFilePath() {
    IndexGitRepoJob gitRepoJob = new IndexGitRepoJob();
    String actual = gitRepoJob.getBlameFilePath("./repo/something/test");
    assertEquals("repo/something/test", actual);
}
Also used : IndexGitRepoJob(com.searchcode.app.jobs.repository.IndexGitRepoJob)

Example 4 with IndexGitRepoJob

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

the class IndexBaseAndGitRepoJobTest method testMissingPathFilesShouldPage.

public void testMissingPathFilesShouldPage() {
    IndexGitRepoJob gitRepoJob = new IndexGitRepoJob();
    CodeSearcher codeSearcherMock = Mockito.mock(CodeSearcher.class);
    List<String> repoReturn = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        repoReturn.add("string" + i);
    }
    when(codeSearcherMock.getRepoDocuments("testRepoName", 0)).thenReturn(repoReturn);
    when(codeSearcherMock.getRepoDocuments("testRepoName", 1)).thenReturn(repoReturn);
    when(codeSearcherMock.getRepoDocuments("testRepoName", 2)).thenReturn(new ArrayList<>());
    gitRepoJob.cleanMissingPathFiles(codeSearcherMock, "testRepoName", new HashMap<String, String>());
    verify(codeSearcherMock, times(1)).getRepoDocuments("testRepoName", 0);
    verify(codeSearcherMock, times(1)).getRepoDocuments("testRepoName", 1);
    verify(codeSearcherMock, times(1)).getRepoDocuments("testRepoName", 2);
}
Also used : ArrayList(java.util.ArrayList) CodeSearcher(com.searchcode.app.service.CodeSearcher) IndexGitRepoJob(com.searchcode.app.jobs.repository.IndexGitRepoJob)

Example 5 with IndexGitRepoJob

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

the class IndexBaseAndGitRepoJobTest method testIndexSucess.

public void testIndexSucess() throws IOException {
    IndexGitRepoJob gitRepoJob = new IndexGitRepoJob();
    File baseDir = new File(System.getProperty("java.io.tmpdir"));
    File tempDir = new File(baseDir, "testIndexSucess");
    if (tempDir.exists()) {
        FileUtils.deleteDirectory(tempDir);
    }
    tempDir.mkdir();
    String tempDirString = tempDir.toString();
    assertFalse(gitRepoJob.checkIndexSucess(tempDirString));
    gitRepoJob.createIndexSuccess(tempDirString);
    assertTrue(gitRepoJob.checkIndexSucess(tempDirString));
    gitRepoJob.deleteIndexSuccess(tempDirString);
    assertFalse(gitRepoJob.checkIndexSucess(tempDirString));
}
Also used : File(java.io.File) 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