use of com.searchcode.app.model.RepoResult in project searchcode-server by boyter.
the class JobServiceTest method testEnqueueByReporesultBackgroundDisabledReturnsFalse.
public void testEnqueueByReporesultBackgroundDisabledReturnsFalse() {
UniqueRepoQueue repoGitQueue = Singleton.getUniqueGitRepoQueue();
UniqueRepoQueue repoSvnQueue = Singleton.getUniqueSvnRepoQueue();
UniqueRepoQueue repoFileQueue = Singleton.getUniqueFileRepoQueue();
repoGitQueue.clear();
repoSvnQueue.clear();
repoFileQueue.clear();
JobService jobService = new JobService();
Singleton.getSharedService().setBackgroundJobsEnabled(true);
assertThat(jobService.forceEnqueue(new RepoResult(0, "name", "git", "url", "username", "password", "source", "branch", ""))).isTrue();
assertThat(jobService.forceEnqueue(new RepoResult(1, "name", "svn", "url", "username", "password", "source", "branch", ""))).isTrue();
assertThat(jobService.forceEnqueue(new RepoResult(2, "name", "file", "url", "username", "password", "source", "branch", ""))).isTrue();
assertThat(repoGitQueue.size()).isEqualTo(1);
assertThat(repoSvnQueue.size()).isEqualTo(1);
assertThat(repoFileQueue.size()).isEqualTo(1);
assertThat(repoGitQueue.poll().getRowId()).isEqualTo(0);
assertThat(repoSvnQueue.poll().getRowId()).isEqualTo(1);
assertThat(repoFileQueue.poll().getRowId()).isEqualTo(2);
}
use of com.searchcode.app.model.RepoResult in project searchcode-server by boyter.
the class ApiRouteServiceTest method testRepoDeleteAuthReponameNoSig.
public void testRepoDeleteAuthReponameNoSig() {
Request mockRequest = Mockito.mock(Request.class);
Repo mockRepo = Mockito.mock(Repo.class);
UniqueRepoQueue uniqueRepoQueue = new UniqueRepoQueue(new ConcurrentLinkedQueue<>());
when(mockRepo.getRepoByName("unit-test")).thenReturn(new RepoResult());
ApiRouteService apiRouteService = new ApiRouteService(null, null, mockRepo, null, null);
apiRouteService.apiEnabled = true;
apiRouteService.apiAuth = true;
when(mockRequest.queryParams("pub")).thenReturn("test");
when(mockRequest.queryParams("reponame")).thenReturn("unit-test");
ApiResponse apiResponse = apiRouteService.repoDelete(mockRequest, null);
assertThat(apiResponse.getMessage()).isEqualTo("sig is a required parameter");
assertThat(apiResponse.isSucessful()).isFalse();
assertThat(uniqueRepoQueue.size()).isEqualTo(0);
}
use of com.searchcode.app.model.RepoResult in project searchcode-server by boyter.
the class ApiRouteServiceTest method testGetAverageIndexTimeSeconds.
public void testGetAverageIndexTimeSeconds() {
Request mockRequest = mock(Request.class);
Repo repoMock = mock(Repo.class);
when(mockRequest.queryParams("reponame")).thenReturn("somename");
when(mockRequest.queryParams()).thenReturn((new HashMap<String, String>() {
{
put("reponame", "reponame");
}
}).keySet());
when(repoMock.getRepoByName("somename")).thenReturn(new RepoResult(0, "name", "scm", "url", "username", "password", "source", "branch", "{\"averageIndexTimeSeconds\":1}"));
ApiRouteService apiRouteService = new ApiRouteService(null, null, repoMock, null, null);
String averageIndexTimeSeconds = apiRouteService.getAverageIndexTimeSeconds(mockRequest, null);
assertThat(averageIndexTimeSeconds).isEqualTo("1");
}
use of com.searchcode.app.model.RepoResult in project searchcode-server by boyter.
the class ApiRouteServiceTest method testRepositoryIndexMatchingRepo.
public void testRepositoryIndexMatchingRepo() {
JobService mockJobService = Mockito.mock(JobService.class);
Request mockRequest = Mockito.mock(Request.class);
Repo mockRepo = Mockito.mock(Repo.class);
when(mockJobService.forceEnqueue(Matchers.<RepoResult>anyObject())).thenReturn(true);
when(mockRequest.queryParams("repoUrl")).thenReturn("http://test/");
when(mockRepo.getRepoByUrl("http://test/")).thenReturn(new RepoResult());
ApiRouteService apiRouteService = new ApiRouteService(null, mockJobService, mockRepo, null, null);
apiRouteService.apiEnabled = true;
ApiResponse apiResponse = apiRouteService.repositoryIndex(mockRequest, null);
assertThat(apiResponse.getMessage()).isEqualTo("Enqueued repository http://test/");
assertThat(apiResponse.isSucessful()).isEqualTo(true);
}
use of com.searchcode.app.model.RepoResult in project searchcode-server by boyter.
the class ValidatorServiceTest method testRepoResultValidReponame.
public void testRepoResultValidReponame() {
ValidatorService validatorService = new ValidatorService();
ValidatorResult validate = validatorService.validate(new RepoResult(0, "some_thing", "something", "url", "", "", "source", "branch", "{}"));
assertThat(validate.isValid).isTrue();
}
Aggregations