Search in sources :

Example 6 with IndexService

use of com.searchcode.app.service.index.IndexService in project searchcode-server by boyter.

the class ApiRouteServiceTest method testRepositoryReindexApiAuthEnabledValidSig.

public void testRepositoryReindexApiAuthEnabledValidSig() {
    JobService mockJobService = mock(JobService.class);
    ApiService mockApiService = mock(ApiService.class);
    IndexService mockIndexService = mock(IndexService.class);
    Request mockRequest = mock(Request.class);
    when(mockRequest.queryParams("pub")).thenReturn("test");
    when(mockRequest.queryParams("sig")).thenReturn("test");
    when(mockApiService.validateRequest("test", "test", "pub=test", ApiService.HmacType.SHA1)).thenReturn(true);
    ApiRouteService apiRouteService = new ApiRouteService(mockApiService, mockJobService, null, null, null, mockIndexService, new Helpers(), new LoggerWrapper());
    apiRouteService.apiEnabled = true;
    apiRouteService.apiAuth = true;
    ApiResponse apiResponse = apiRouteService.repositoryReindex(mockRequest, null);
    assertThat(apiResponse.getMessage()).isEqualTo("reindex forced");
    assertThat(apiResponse.isSucessful()).isEqualTo(true);
}
Also used : ApiRouteService(com.searchcode.app.service.route.ApiRouteService) IndexService(com.searchcode.app.service.index.IndexService) Helpers(com.searchcode.app.util.Helpers) LoggerWrapper(com.searchcode.app.util.LoggerWrapper) Request(spark.Request) ApiResponse(com.searchcode.app.dto.api.ApiResponse) RepoResultApiResponse(com.searchcode.app.dto.api.RepoResultApiResponse)

Example 7 with IndexService

use of com.searchcode.app.service.index.IndexService in project searchcode-server by boyter.

the class AdminRouteServiceTest method testGetStatValuesExpectValue.

public void testGetStatValuesExpectValue() {
    SQLiteRepo SQLiteRepoMock = mock(SQLiteRepo.class);
    StatsService statsServiceMock = mock(StatsService.class);
    IndexService indexServiceMock = mock(IndexService.class);
    when(statsServiceMock.getMemoryUsage(any())).thenReturn("Yep");
    when(statsServiceMock.getLoadAverage()).thenReturn("Yep");
    when(statsServiceMock.getUpTime()).thenReturn("Yep");
    when(SQLiteRepoMock.getRepoCount()).thenReturn(1);
    when(indexServiceMock.getIndexedDocumentCount()).thenReturn(100);
    when(indexServiceMock.shouldPause(IIndexService.JobType.REPO_PARSER)).thenReturn(false);
    AdminRouteService adminRouteService = new AdminRouteService(SQLiteRepoMock, null, null, null, indexServiceMock, statsServiceMock, null, null, Singleton.getLogger());
    List<String> statValue = Arrays.asList("memoryusage", "loadaverage", "uptime", "searchcount", "spellingcount", "repocount", "numdocs", "servertime", "deletionqueue");
    for (String stat : statValue) {
        Request mockRequest = Mockito.mock(Request.class);
        Set<String> returnSet = new HashSet<>();
        returnSet.add("statname");
        when(mockRequest.queryParams()).thenReturn(returnSet);
        when(mockRequest.queryParams("statname")).thenReturn(stat);
        String result = adminRouteService.getStat(mockRequest, null);
        assertThat(result).as("For value %s", stat).isNotEmpty();
    }
}
Also used : IndexService(com.searchcode.app.service.index.IndexService) IIndexService(com.searchcode.app.service.index.IIndexService) SQLiteRepo(com.searchcode.app.dao.SQLiteRepo) AdminRouteService(com.searchcode.app.service.route.AdminRouteService) Request(spark.Request)

Example 8 with IndexService

use of com.searchcode.app.service.index.IndexService in project searchcode-server by boyter.

the class EndToEndITCase method testEndToEndGitPath.

public void testEndToEndGitPath() throws IOException {
    IndexService indexService = new IndexService();
    File directoryWithFiles = TestHelpers.createDirectoryWithFiles("EndToEndGitTest");
    String result = this.runCommand(directoryWithFiles.toString(), this.GITPATH, "init", ".");
    result = this.runCommand(directoryWithFiles.toString(), this.GITPATH, "add", ".");
    result = this.runCommand(directoryWithFiles.toString(), this.GITPATH, "commit", "-m", "\"First commit\"");
    IndexGitRepoJob indexGitRepoJob = new IndexGitRepoJob();
    indexGitRepoJob.indexDocsByPath(Paths.get(directoryWithFiles.toString()), new RepoResult().setRowId(0).setName("ENDTOENDTEST").setScm("scm").setUrl("url").setUsername("username").setPassword("password").setSource("source").setBranch("branch").setData("{}"), "", directoryWithFiles.toString(), false);
    SearchResult searchResult = indexService.search("endtoendtestfile", null, 0, false);
    assertThat(searchResult.getCodeResultList().size()).isEqualTo(3);
    CodeResult codeResult1 = searchResult.getCodeResultList().stream().filter(x -> x.getFileName().equals("EndToEndTestFile1.php")).findFirst().get();
    CodeResult codeResult2 = searchResult.getCodeResultList().stream().filter(x -> x.getFileName().equals("EndToEndTestFile2.py")).findFirst().get();
    CodeResult codeResult3 = searchResult.getCodeResultList().stream().filter(x -> x.getFileName().equals("EndToEndTestFile3.java")).findFirst().get();
    assertThat(codeResult1.getCode().get(0)).isEqualTo("EndToEndTestFile EndToEndTestFile1");
    assertThat(codeResult2.getCode().get(0)).isEqualTo("EndToEndTestFile EndToEndTestFile2");
    assertThat(codeResult3.getCode().get(0)).isEqualTo("EndToEndTestFile EndToEndTestFile3");
    // Delete a single file
    String codeId = searchResult.getCodeResultList().get(0).getCodeId();
    indexService.deleteByCodeId(codeId);
    searchResult = indexService.search("endtoendtestfile".toLowerCase(), null, 0, false);
    assertThat(searchResult.getCodeResultList().size()).isEqualTo(2);
    // Delete file from disk then index to ensure it is removed from the index
    File toDelete = new File(directoryWithFiles.toString() + "/EndToEndTestFile2.py");
    toDelete.delete();
    indexGitRepoJob.indexDocsByPath(Paths.get(directoryWithFiles.toString()), new RepoResult().setRowId(0).setName("ENDTOENDTEST").setScm("scm").setUrl("url").setUsername("username").setPassword("password").setSource("source").setBranch("branch").setData("{}"), "", directoryWithFiles.toString(), true);
    searchResult = indexService.search("endtoendtestfile", null, 0, false);
    assertThat(searchResult.getCodeResultList().size()).isEqualTo(2);
    codeResult1 = searchResult.getCodeResultList().stream().filter(x -> x.getFileName().equals("EndToEndTestFile1.php")).findFirst().get();
    codeResult2 = searchResult.getCodeResultList().stream().filter(x -> x.getFileName().equals("EndToEndTestFile3.java")).findFirst().get();
    assertThat(codeResult1.getCode().get(0)).isEqualTo("EndToEndTestFile EndToEndTestFile1");
    assertThat(codeResult2.getCode().get(0)).isEqualTo("EndToEndTestFile EndToEndTestFile3");
    indexService.deleteByRepo(new RepoResult().setRowId(0).setName("ENDTOENDTEST").setScm("scm").setUrl("url").setUsername("username").setPassword("password").setSource("source").setBranch("branch").setData("{}"));
    searchResult = indexService.search("endtoendtestfile".toLowerCase(), null, 0, false);
    assertThat(searchResult.getCodeResultList().size()).isEqualTo(0);
}
Also used : IndexSvnRepoJob(com.searchcode.app.jobs.repository.IndexSvnRepoJob) SearchResult(com.searchcode.app.dto.SearchResult) IndexService(com.searchcode.app.service.index.IndexService) RepoResult(com.searchcode.app.model.RepoResult) IndexGitRepoJob(com.searchcode.app.jobs.repository.IndexGitRepoJob) TestHelpers(com.searchcode.app.TestHelpers) Values(com.searchcode.app.config.Values) CodeResult(com.searchcode.app.dto.CodeResult) java.io(java.io) Paths(java.nio.file.Paths) AssertionsForInterfaceTypes.assertThat(org.assertj.core.api.AssertionsForInterfaceTypes.assertThat) Properties(com.searchcode.app.util.Properties) TestCase(junit.framework.TestCase) IndexFileRepoJob(com.searchcode.app.jobs.repository.IndexFileRepoJob) IndexService(com.searchcode.app.service.index.IndexService) CodeResult(com.searchcode.app.dto.CodeResult) SearchResult(com.searchcode.app.dto.SearchResult) IndexGitRepoJob(com.searchcode.app.jobs.repository.IndexGitRepoJob) RepoResult(com.searchcode.app.model.RepoResult)

Example 9 with IndexService

use of com.searchcode.app.service.index.IndexService in project searchcode-server by boyter.

the class IndexBaseAndGitRepoJobTest method testMissingPathFilesNoLocations.

public void testMissingPathFilesNoLocations() {
    IndexService indexServiceMock = mock(IndexService.class);
    IndexGitRepoJob gitRepoJob = new IndexGitRepoJob(indexServiceMock);
    when(indexServiceMock.getRepoDocuments("testRepoName", 0)).thenReturn(new ArrayList<>());
    gitRepoJob.cleanMissingPathFiles("testRepoName", new HashMap<>());
    verify(indexServiceMock, times(1)).getRepoDocuments("testRepoName", 0);
}
Also used : IndexService(com.searchcode.app.service.index.IndexService) IndexGitRepoJob(com.searchcode.app.jobs.repository.IndexGitRepoJob)

Example 10 with IndexService

use of com.searchcode.app.service.index.IndexService in project searchcode-server by boyter.

the class IndexDocumentsJobTest method testExecute.

public void testExecute() throws JobExecutionException {
    JobExecutionContext jobExecutionContext = mock(JobExecutionContext.class);
    IndexService indexService = mock(IndexService.class);
    StatsService statsService = mock(StatsService.class);
    LoggerWrapper loggerWrapper = mock(LoggerWrapper.class);
// IndexDocumentsJob indexDocumentsJob = new IndexDocumentsJob(indexService, statsService, loggerWrapper);
// 
// indexDocumentsJob.execute(jobExecutionContext);
}
Also used : IndexService(com.searchcode.app.service.index.IndexService) StatsService(com.searchcode.app.service.StatsService) LoggerWrapper(com.searchcode.app.util.LoggerWrapper) JobExecutionContext(org.quartz.JobExecutionContext)

Aggregations

IndexService (com.searchcode.app.service.index.IndexService)10 IndexGitRepoJob (com.searchcode.app.jobs.repository.IndexGitRepoJob)5 LoggerWrapper (com.searchcode.app.util.LoggerWrapper)4 Request (spark.Request)4 TestHelpers (com.searchcode.app.TestHelpers)3 Values (com.searchcode.app.config.Values)3 CodeResult (com.searchcode.app.dto.CodeResult)3 SearchResult (com.searchcode.app.dto.SearchResult)3 ApiResponse (com.searchcode.app.dto.api.ApiResponse)3 RepoResultApiResponse (com.searchcode.app.dto.api.RepoResultApiResponse)3 IndexFileRepoJob (com.searchcode.app.jobs.repository.IndexFileRepoJob)3 IndexSvnRepoJob (com.searchcode.app.jobs.repository.IndexSvnRepoJob)3 RepoResult (com.searchcode.app.model.RepoResult)3 ApiRouteService (com.searchcode.app.service.route.ApiRouteService)3 Helpers (com.searchcode.app.util.Helpers)3 Properties (com.searchcode.app.util.Properties)3 java.io (java.io)3 Paths (java.nio.file.Paths)3 TestCase (junit.framework.TestCase)3 AssertionsForInterfaceTypes.assertThat (org.assertj.core.api.AssertionsForInterfaceTypes.assertThat)3