use of spark.Request in project searchcode-server by boyter.
the class ApiRouteServiceTest method testRepoAddAuthSigMissing.
public void testRepoAddAuthSigMissing() {
Request mockRequest = Mockito.mock(Request.class);
Repo mockRepo = Mockito.mock(Repo.class);
ApiService mockApiService = Mockito.mock(ApiService.class);
when(mockApiService.validateRequest("test", "test", "pub=test", ApiService.HmacType.SHA1)).thenReturn(false);
ApiRouteService apiRouteService = new ApiRouteService(mockApiService, null, mockRepo, null, null);
apiRouteService.apiEnabled = true;
apiRouteService.apiAuth = true;
when(mockRequest.queryParams("reponame")).thenReturn("test");
when(mockRequest.queryParams("repourl")).thenReturn("test");
when(mockRequest.queryParams("repotype")).thenReturn("test");
when(mockRequest.queryParams("repousername")).thenReturn("test");
when(mockRequest.queryParams("repopassword")).thenReturn("test");
when(mockRequest.queryParams("reposource")).thenReturn("test");
when(mockRequest.queryParams("repobranch")).thenReturn("test");
when(mockRequest.queryParams("pub")).thenReturn("test");
ApiResponse apiResponse = apiRouteService.repoAdd(mockRequest, null);
assertThat(apiResponse.getMessage()).isEqualTo("sig is a required parameter");
assertThat(apiResponse.isSucessful()).isFalse();
}
use of spark.Request in project searchcode-server by boyter.
the class ApiRouteServiceTest method testRepositoryReindexApiAuthEnabledSigMissing.
public void testRepositoryReindexApiAuthEnabledSigMissing() {
JobService mockJobService = Mockito.mock(JobService.class);
Request mockRequest = Mockito.mock(Request.class);
when(mockRequest.queryParams("pub")).thenReturn("test");
when(mockJobService.rebuildAll()).thenReturn(true);
ApiRouteService apiRouteService = new ApiRouteService(null, mockJobService, null, null, null);
apiRouteService.apiEnabled = true;
apiRouteService.apiAuth = true;
ApiResponse apiResponse = apiRouteService.repositoryReindex(mockRequest, null);
assertThat(apiResponse.getMessage()).isEqualTo("sig is a required parameter");
assertThat(apiResponse.isSucessful()).isEqualTo(false);
}
use of spark.Request 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 spark.Request in project searchcode-server by boyter.
the class ApiRouteServiceTest method testRepositoryIndexApiNoMatchinRepo.
public void testRepositoryIndexApiNoMatchinRepo() {
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("test");
ApiRouteService apiRouteService = new ApiRouteService(null, mockJobService, mockRepo, null, null);
apiRouteService.apiEnabled = true;
ApiResponse apiResponse = apiRouteService.repositoryIndex(mockRequest, null);
assertThat(apiResponse.getMessage()).isEqualTo("Was unable to find repository test");
assertThat(apiResponse.isSucessful()).isEqualTo(false);
}
use of spark.Request in project searchcode-server by boyter.
the class ApiRouteServiceTest method testRepositoryIndexApiNoRepositorySupplied.
public void testRepositoryIndexApiNoRepositorySupplied() {
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);
ApiRouteService apiRouteService = new ApiRouteService(null, mockJobService, mockRepo, null, null);
apiRouteService.apiEnabled = true;
ApiResponse apiResponse = apiRouteService.repositoryIndex(mockRequest, null);
assertThat(apiResponse.getMessage()).isEqualTo("Was unable to find repository null");
assertThat(apiResponse.isSucessful()).isEqualTo(false);
}
Aggregations