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();
}
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);
}
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);
}
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);
}
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();
}
Aggregations