use of spark.Request in project searchcode-server by boyter.
the class ApiRouteServiceTest method testRepoDeleteNoAuthReponame.
public void testRepoDeleteNoAuthReponame() {
Request mockRequest = Mockito.mock(Request.class);
Repo mockRepo = Mockito.mock(Repo.class);
DataService dataServiceMock = Mockito.mock(DataService.class);
when(mockRepo.getRepoByName("unit-test")).thenReturn(new RepoResult());
ApiRouteService apiRouteService = new ApiRouteService(null, null, mockRepo, dataServiceMock, null);
apiRouteService.apiEnabled = true;
apiRouteService.apiAuth = false;
when(mockRequest.queryParams("reponame")).thenReturn("unit-test");
ApiResponse apiResponse = apiRouteService.repoDelete(mockRequest, null);
assertThat(apiResponse.getMessage()).isEqualTo("repository queued for deletion");
assertThat(apiResponse.isSucessful()).isTrue();
verify(dataServiceMock, times(1)).addToPersistentDelete("");
}
use of spark.Request in project searchcode-server by boyter.
the class ApiRouteServiceTest method testRepoAddMissingRepoBranch.
public void testRepoAddMissingRepoBranch() {
Request mockRequest = Mockito.mock(Request.class);
Repo mockRepo = Mockito.mock(Repo.class);
ApiRouteService apiRouteService = new ApiRouteService(null, null, mockRepo, null, null);
apiRouteService.apiEnabled = true;
apiRouteService.apiAuth = false;
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");
ApiResponse apiResponse = apiRouteService.repoAdd(mockRequest, null);
assertThat(apiResponse.getMessage()).isEqualTo("repobranch is a required parameter");
assertThat(apiResponse.isSucessful()).isFalse();
}
use of spark.Request 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 spark.Request in project searchcode-server by boyter.
the class ApiRouteServiceTest method testRepoListApiEnabledNoAuth.
public void testRepoListApiEnabledNoAuth() {
Request mockRequest = Mockito.mock(Request.class);
Repo repo = new Repo(new SQLiteMemoryDatabaseConfig(), new Helpers());
repo.createTableIfMissing();
ApiRouteService apiRouteService = new ApiRouteService(null, null, repo, null, null);
apiRouteService.apiEnabled = true;
apiRouteService.apiAuth = false;
RepoResultApiResponse apiResponse = apiRouteService.repoList(mockRequest, null);
assertThat(apiResponse.getMessage()).isEmpty();
assertThat(apiResponse.getRepoResultList()).hasSize(0);
assertThat(apiResponse.isSucessful()).isTrue();
}
use of spark.Request in project searchcode-server by boyter.
the class ApiRouteServiceTest method testRepoListApiEnabledAuthMissingPub.
public void testRepoListApiEnabledAuthMissingPub() {
Request mockRequest = Mockito.mock(Request.class);
ApiRouteService apiRouteService = new ApiRouteService();
apiRouteService.apiEnabled = true;
apiRouteService.apiAuth = true;
RepoResultApiResponse apiResponse = apiRouteService.repoList(mockRequest, null);
assertThat(apiResponse.getMessage()).isEqualTo("pub is a required parameter");
assertThat(apiResponse.getRepoResultList()).isNull();
assertThat(apiResponse.isSucessful()).isFalse();
}
Aggregations