Search in sources :

Example 21 with ApiRouteService

use of com.searchcode.app.service.route.ApiRouteService in project searchcode-server by boyter.

the class ApiRouteServiceTest method testRepoAddAuthValidSigned.

public void testRepoAddAuthValidSigned() {
    Request mockRequest = Mockito.mock(Request.class);
    Repo mockRepo = Mockito.mock(Repo.class);
    ApiService mockApiService = Mockito.mock(ApiService.class);
    ValidatorService mockValidatorService = Mockito.mock(ValidatorService.class);
    when(mockApiService.validateRequest("test", "test", "pub=test&reponame=test&repourl=test&repotype=test&repousername=test&repopassword=test&reposource=test&repobranch=test", ApiService.HmacType.SHA1)).thenReturn(true);
    when(mockValidatorService.validate(any())).thenReturn(new ValidatorResult(true, ""));
    ApiRouteService apiRouteService = new ApiRouteService(mockApiService, null, mockRepo, null, mockValidatorService);
    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");
    when(mockRequest.queryParams("sig")).thenReturn("test");
    ApiResponse apiResponse = apiRouteService.repoAdd(mockRequest, null);
    assertThat(apiResponse.getMessage()).isEqualTo("added repository successfully");
    assertThat(apiResponse.isSucessful()).isTrue();
    verify(mockRepo, times(1)).saveRepo(Matchers.<RepoResult>anyObject());
}
Also used : Repo(com.searchcode.app.dao.Repo) ApiRouteService(com.searchcode.app.service.route.ApiRouteService) ValidatorResult(com.searchcode.app.model.ValidatorResult) Request(spark.Request) ApiResponse(com.searchcode.app.dto.api.ApiResponse) RepoResultApiResponse(com.searchcode.app.dto.api.RepoResultApiResponse)

Example 22 with ApiRouteService

use of com.searchcode.app.service.route.ApiRouteService in project searchcode-server by boyter.

the class ApiRouteServiceTest method testRepoAddMissingRepotype.

public void testRepoAddMissingRepotype() {
    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");
    ApiResponse apiResponse = apiRouteService.repoAdd(mockRequest, null);
    assertThat(apiResponse.getMessage()).isEqualTo("repotype 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 23 with ApiRouteService

use of com.searchcode.app.service.route.ApiRouteService in project searchcode-server by boyter.

the class ApiRouteServiceTest method testGetIndexTime.

public void testGetIndexTime() {
    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", "\n" + "{\"rowId\":1,\"name\":\"test\",\"scm\":\"git\",\"url\":\"/test/\",\"username\":\"\",\"password\":\"\",\"source\":\"\",\"branch\":\"master\",\"data\":{\"averageIndexTimeSeconds\":9,\"indexStatus\":\"success\",\"jobRunTime\":{\"seconds\":1496356541,\"nanos\":188000000}}}"));
    ApiRouteService apiRouteService = new ApiRouteService(null, null, repoMock, null, null);
    String averageIndexTimeSeconds = apiRouteService.getIndexTime(mockRequest, null);
    assertThat(averageIndexTimeSeconds).isEqualTo("0 seconds ago");
}
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 24 with ApiRouteService

use of com.searchcode.app.service.route.ApiRouteService in project searchcode-server by boyter.

the class ApiRouteServiceTest method testRepoAddNoAuthSucessful.

public void testRepoAddNoAuthSucessful() {
    Request mockRequest = Mockito.mock(Request.class);
    Repo mockRepo = Mockito.mock(Repo.class);
    ValidatorService mockValidatorService = Mockito.mock(ValidatorService.class);
    when(mockValidatorService.validate(any())).thenReturn(new ValidatorResult(true, ""));
    ApiRouteService apiRouteService = new ApiRouteService(null, null, mockRepo, null, mockValidatorService);
    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");
    when(mockRequest.queryParams("repobranch")).thenReturn("test");
    ApiResponse apiResponse = apiRouteService.repoAdd(mockRequest, null);
    assertThat(apiResponse.getMessage()).isEqualTo("added repository successfully");
    assertThat(apiResponse.isSucessful()).isTrue();
    verify(mockRepo, times(1)).saveRepo(Matchers.<RepoResult>anyObject());
}
Also used : Repo(com.searchcode.app.dao.Repo) ApiRouteService(com.searchcode.app.service.route.ApiRouteService) ValidatorResult(com.searchcode.app.model.ValidatorResult) Request(spark.Request) ApiResponse(com.searchcode.app.dto.api.ApiResponse) RepoResultApiResponse(com.searchcode.app.dto.api.RepoResultApiResponse)

Example 25 with ApiRouteService

use of com.searchcode.app.service.route.ApiRouteService in project searchcode-server by boyter.

the class ApiRouteServiceTest method testRepoListApiEnabledAuthInvalidSigned.

public void testRepoListApiEnabledAuthInvalidSigned() {
    Request mockRequest = Mockito.mock(Request.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, null, null, null);
    apiRouteService.apiEnabled = true;
    apiRouteService.apiAuth = true;
    when(mockRequest.queryParams("pub")).thenReturn("test");
    when(mockRequest.queryParams("sig")).thenReturn("test");
    RepoResultApiResponse apiResponse = apiRouteService.repoList(mockRequest, null);
    assertThat(apiResponse.getMessage()).isEqualTo("invalid signed url");
    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

ApiRouteService (com.searchcode.app.service.route.ApiRouteService)39 RepoResultApiResponse (com.searchcode.app.dto.api.RepoResultApiResponse)37 Request (spark.Request)34 ApiResponse (com.searchcode.app.dto.api.ApiResponse)31 Repo (com.searchcode.app.dao.Repo)24 RepoResult (com.searchcode.app.model.RepoResult)8 UniqueRepoQueue (com.searchcode.app.util.UniqueRepoQueue)3 ValidatorResult (com.searchcode.app.model.ValidatorResult)2 SQLiteMemoryDatabaseConfig (com.searchcode.app.config.SQLiteMemoryDatabaseConfig)1 Helpers (com.searchcode.app.util.Helpers)1