Search in sources :

Example 16 with RepoResult

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);
}
Also used : UniqueRepoQueue(com.searchcode.app.util.UniqueRepoQueue) RepoResult(com.searchcode.app.model.RepoResult)

Example 17 with RepoResult

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);
}
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 18 with RepoResult

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

Example 19 with RepoResult

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);
}
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 20 with RepoResult

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();
}
Also used : ValidatorResult(com.searchcode.app.model.ValidatorResult) 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