Search in sources :

Example 6 with Request

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("");
}
Also used : Repo(com.searchcode.app.dao.Repo) ApiRouteService(com.searchcode.app.service.route.ApiRouteService) Request(spark.Request) ApiResponse(com.searchcode.app.dto.api.ApiResponse) RepoResultApiResponse(com.searchcode.app.dto.api.RepoResultApiResponse) RepoResult(com.searchcode.app.model.RepoResult)

Example 7 with Request

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();
}
Also used : Repo(com.searchcode.app.dao.Repo) ApiRouteService(com.searchcode.app.service.route.ApiRouteService) Request(spark.Request) ApiResponse(com.searchcode.app.dto.api.ApiResponse) RepoResultApiResponse(com.searchcode.app.dto.api.RepoResultApiResponse)

Example 8 with Request

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);
}
Also used : Repo(com.searchcode.app.dao.Repo) ApiRouteService(com.searchcode.app.service.route.ApiRouteService) Request(spark.Request) UniqueRepoQueue(com.searchcode.app.util.UniqueRepoQueue) ApiResponse(com.searchcode.app.dto.api.ApiResponse) RepoResultApiResponse(com.searchcode.app.dto.api.RepoResultApiResponse) RepoResult(com.searchcode.app.model.RepoResult)

Example 9 with Request

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();
}
Also used : Repo(com.searchcode.app.dao.Repo) ApiRouteService(com.searchcode.app.service.route.ApiRouteService) Helpers(com.searchcode.app.util.Helpers) Request(spark.Request) SQLiteMemoryDatabaseConfig(com.searchcode.app.config.SQLiteMemoryDatabaseConfig) RepoResultApiResponse(com.searchcode.app.dto.api.RepoResultApiResponse)

Example 10 with Request

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();
}
Also used : ApiRouteService(com.searchcode.app.service.route.ApiRouteService) Request(spark.Request) RepoResultApiResponse(com.searchcode.app.dto.api.RepoResultApiResponse)

Aggregations

Request (spark.Request)57 ApiRouteService (com.searchcode.app.service.route.ApiRouteService)34 RepoResultApiResponse (com.searchcode.app.dto.api.RepoResultApiResponse)32 Repo (com.searchcode.app.dao.Repo)28 ApiResponse (com.searchcode.app.dto.api.ApiResponse)27 RepoResult (com.searchcode.app.model.RepoResult)10 CodeRouteService (com.searchcode.app.service.route.CodeRouteService)8 Response (spark.Response)8 AdminRouteService (com.searchcode.app.service.route.AdminRouteService)7 HashSet (java.util.HashSet)6 Map (java.util.Map)5 ModelAndView (spark.ModelAndView)5 RouteMatch (spark.routematch.RouteMatch)4 ValidatorResult (com.searchcode.app.model.ValidatorResult)3 UniqueRepoQueue (com.searchcode.app.util.UniqueRepoQueue)3 FilterImpl (spark.FilterImpl)3 HaltException (spark.HaltException)3 Values (com.searchcode.app.config.Values)2 Data (com.searchcode.app.dao.Data)2 CodeResult (com.searchcode.app.dto.CodeResult)2