Search in sources :

Example 1 with IndexService

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

the class ApiRouteServiceTest method testRepositoryReindexApiAuthNotEnabledRebuildAllFails.

public void testRepositoryReindexApiAuthNotEnabledRebuildAllFails() {
    Request mockRequest = mock(Request.class);
    IndexService mockIndexService = mock(IndexService.class);
    ApiRouteService apiRouteService = new ApiRouteService(null, null, null, null, null, mockIndexService, new Helpers(), new LoggerWrapper());
    apiRouteService.apiEnabled = true;
    apiRouteService.apiAuth = false;
    ApiResponse apiResponse = apiRouteService.repositoryReindex(mockRequest, null);
    assertThat(apiResponse.getMessage()).isEqualTo("reindex forced");
    assertThat(apiResponse.isSucessful()).isEqualTo(true);
    verify(mockIndexService, times(1)).reindexAll();
}
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 2 with IndexService

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

the class IndexBaseAndGitRepoJobTest method testMissingPathFilesShouldPage.

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

Example 3 with IndexService

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

the class EndToEndITCase method testEndToEndFilePath.

public void testEndToEndFilePath() throws IOException {
    IndexService indexService = new IndexService();
    File directoryWithFiles = TestHelpers.createDirectoryWithFiles("EndToEndFileTest");
    IndexFileRepoJob indexFileRepoJob = new IndexFileRepoJob();
    // Index created files
    indexFileRepoJob.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);
    codeResult1 = searchResult.getCodeResultList().stream().filter(x -> x.getFileName().equals("EndToEndTestFile2.py")).findFirst().get();
    codeResult2 = searchResult.getCodeResultList().stream().filter(x -> x.getFileName().equals("EndToEndTestFile3.java")).findFirst().get();
    assertThat(codeResult1.getCode().get(0)).isEqualTo("EndToEndTestFile EndToEndTestFile2");
    assertThat(codeResult2.getCode().get(0)).isEqualTo("EndToEndTestFile EndToEndTestFile3");
    // Delete file from disk then index to ensure it is removed from the index
    File toDelete = new File(directoryWithFiles.toString() + "/EndToEndTestFile2.py");
    toDelete.delete();
    indexFileRepoJob.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");
    // Delete everything
    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 : IndexFileRepoJob(com.searchcode.app.jobs.repository.IndexFileRepoJob) 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) RepoResult(com.searchcode.app.model.RepoResult)

Example 4 with IndexService

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

the class EndToEndITCase method testEndToEndSvnPath.

public void testEndToEndSvnPath() throws IOException {
    IndexService indexService = new IndexService();
    File directoryWithFiles = TestHelpers.createDirectoryWithFiles("EndToEndSvnTest");
    IndexSvnRepoJob indexSvnRepoJob = new IndexSvnRepoJob();
    indexSvnRepoJob.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();
    indexSvnRepoJob.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) IndexSvnRepoJob(com.searchcode.app.jobs.repository.IndexSvnRepoJob) SearchResult(com.searchcode.app.dto.SearchResult) RepoResult(com.searchcode.app.model.RepoResult)

Example 5 with IndexService

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

the class ApiRouteServiceTest method testRepositoryReindexApiAuthNotEnabledRebuildAllWorks.

public void testRepositoryReindexApiAuthNotEnabledRebuildAllWorks() {
    Request mockRequest = mock(Request.class);
    IndexService mockIndexService = mock(IndexService.class);
    ApiRouteService apiRouteService = new ApiRouteService(null, null, null, null, null, mockIndexService, new Helpers(), new LoggerWrapper());
    apiRouteService.apiEnabled = true;
    apiRouteService.apiAuth = false;
    ApiResponse apiResponse = apiRouteService.repositoryReindex(mockRequest, null);
    assertThat(apiResponse.getMessage()).isEqualTo("reindex forced");
    assertThat(apiResponse.isSucessful()).isEqualTo(true);
    verify(mockIndexService, times(1)).reindexAll();
}
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)

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