Search in sources :

Example 51 with RepoResult

use of com.searchcode.app.model.RepoResult in project searchcode-server by boyter.

the class AdminRouteServiceTest method testDeleteRepo.

public void testDeleteRepo() {
    Repo mockRepo = Mockito.mock(Repo.class);
    JobService mockJobService = Mockito.mock(JobService.class);
    DataService mockDataService = Mockito.mock(DataService.class);
    AdminRouteService adminRouteService = new AdminRouteService(mockRepo, mockJobService, mockDataService, null, null, null);
    Request mockRequest = Mockito.mock(Request.class);
    when(mockRequest.queryParams("repoName")).thenReturn("myRepo");
    when(mockRepo.getRepoByName("myRepo")).thenReturn(new RepoResult());
    adminRouteService.deleteRepo(mockRequest, null);
    verify(mockDataService, times(1)).addToPersistentDelete("");
}
Also used : Repo(com.searchcode.app.dao.Repo) AdminRouteService(com.searchcode.app.service.route.AdminRouteService) Request(spark.Request) RepoResult(com.searchcode.app.model.RepoResult)

Example 52 with RepoResult

use of com.searchcode.app.model.RepoResult in project searchcode-server by boyter.

the class ApiRouteServiceTest method testRepoDeleteAuthReponameAuth.

public void testRepoDeleteAuthReponameAuth() {
    Request mockRequest = mock(Request.class);
    Repo mockRepo = mock(Repo.class);
    DataService dataServiceMock = mock(DataService.class);
    ApiService mockApiService = mock(ApiService.class);
    when(mockApiService.validateRequest("test", "test", "pub=test&reponame=unit-test", ApiService.HmacType.SHA1)).thenReturn(true);
    when(mockRepo.getRepoByName("unit-test")).thenReturn(new RepoResult());
    ApiRouteService apiRouteService = new ApiRouteService(mockApiService, null, mockRepo, dataServiceMock, null);
    apiRouteService.apiEnabled = true;
    apiRouteService.apiAuth = true;
    when(mockRequest.queryParams("pub")).thenReturn("test");
    when(mockRequest.queryParams("sig")).thenReturn("test");
    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 53 with RepoResult

use of com.searchcode.app.model.RepoResult in project searchcode-server by boyter.

the class ApiRouteServiceTest method testRepoDeleteAuthReponameFailedAuth.

public void testRepoDeleteAuthReponameFailedAuth() {
    Request mockRequest = Mockito.mock(Request.class);
    Repo mockRepo = Mockito.mock(Repo.class);
    UniqueRepoQueue uniqueRepoQueue = new UniqueRepoQueue(new ConcurrentLinkedQueue<>());
    ApiService mockApiService = Mockito.mock(ApiService.class);
    when(mockApiService.validateRequest("test", "test", "pub=test", ApiService.HmacType.SHA1)).thenReturn(false);
    when(mockRepo.getRepoByName("unit-test")).thenReturn(new RepoResult());
    ApiRouteService apiRouteService = new ApiRouteService(mockApiService, null, mockRepo, null, null);
    apiRouteService.apiEnabled = true;
    apiRouteService.apiAuth = true;
    when(mockRequest.queryParams("pub")).thenReturn("test");
    when(mockRequest.queryParams("sig")).thenReturn("test");
    when(mockRequest.queryParams("reponame")).thenReturn("unit-test");
    ApiResponse apiResponse = apiRouteService.repoDelete(mockRequest, null);
    assertThat(apiResponse.getMessage()).isEqualTo("invalid signed url");
    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 54 with RepoResult

use of com.searchcode.app.model.RepoResult in project searchcode-server by boyter.

the class RepoTest method testRepoSaveGetCacheBug.

public void testRepoSaveGetCacheBug() {
    this.repo.saveRepo(new RepoResult(-1, "myname", "git", "myurl", "username", "password", "mysource", "mybranch", "{}"));
    for (int i = 0; i < 200; i++) {
        assertThat(repo.getRepoByName("myname")).isNotNull();
    }
    this.repo.deleteRepoByName("myname");
}
Also used : RepoResult(com.searchcode.app.model.RepoResult)

Example 55 with RepoResult

use of com.searchcode.app.model.RepoResult in project searchcode-server by boyter.

the class RepoTest method testGetRepoByNameUsingNull.

public void testGetRepoByNameUsingNull() {
    RepoResult repoResult = this.repo.getRepoByName(null);
    assertThat(repoResult).isNull();
}
Also used : RepoResult(com.searchcode.app.model.RepoResult)

Aggregations

RepoResult (com.searchcode.app.model.RepoResult)59 Repo (com.searchcode.app.dao.Repo)13 ApiResponse (com.searchcode.app.dto.api.ApiResponse)9 RepoResultApiResponse (com.searchcode.app.dto.api.RepoResultApiResponse)9 Request (spark.Request)9 ValidatorResult (com.searchcode.app.model.ValidatorResult)8 ApiRouteService (com.searchcode.app.service.route.ApiRouteService)8 UniqueRepoQueue (com.searchcode.app.util.UniqueRepoQueue)8 Connection (java.sql.Connection)5 PreparedStatement (java.sql.PreparedStatement)5 SQLException (java.sql.SQLException)5 ResultSet (java.sql.ResultSet)4 ArrayList (java.util.ArrayList)3 RepositoryChanged (com.searchcode.app.dto.RepositoryChanged)2 RunningIndexJob (com.searchcode.app.dto.RunningIndexJob)2 File (java.io.File)2 Gson (com.google.gson.Gson)1 Data (com.searchcode.app.dao.Data)1 IndexBaseRepoJob (com.searchcode.app.jobs.repository.IndexBaseRepoJob)1 IndexFileRepoJob (com.searchcode.app.jobs.repository.IndexFileRepoJob)1