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