Search in sources :

Example 41 with Request

use of spark.Request in project searchcode-server by boyter.

the class AdminRouteServiceTest method testGetStatValuesExpectValue.

public void testGetStatValuesExpectValue() {
    SharedService sharedServiceMock = Mockito.mock(SharedService.class);
    StatsService statsServiceMock = Mockito.mock(StatsService.class);
    when(statsServiceMock.getMemoryUsage(any())).thenReturn("Yep");
    when(statsServiceMock.getLoadAverage()).thenReturn("Yep");
    when(statsServiceMock.getUptime()).thenReturn("Yep");
    AdminRouteService adminRouteService = new AdminRouteService(null, null, null, sharedServiceMock, statsServiceMock, null);
    List<String> statValue = Arrays.asList("memoryusage", "loadaverage", "uptime", "searchcount", "spellingcount", "repocount", "numdocs", "servertime", "deletionqueue");
    for (String stat : statValue) {
        Request mockRequest = Mockito.mock(Request.class);
        Set<String> returnSet = new HashSet<>();
        returnSet.add("statname");
        when(mockRequest.queryParams()).thenReturn(returnSet);
        when(mockRequest.queryParams("statname")).thenReturn(stat);
        String result = adminRouteService.getStat(mockRequest, null);
        assertThat(result).as("For value %s", stat).isNotEmpty();
    }
}
Also used : AdminRouteService(com.searchcode.app.service.route.AdminRouteService) Request(spark.Request) HashSet(java.util.HashSet)

Example 42 with Request

use of spark.Request 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 43 with Request

use of spark.Request in project searchcode-server by boyter.

the class AdminRouteServiceTest method testPostRepoMultipleRepo.

public void testPostRepoMultipleRepo() {
    Repo mockRepo = Mockito.mock(Repo.class);
    JobService mockJobService = Mockito.mock(JobService.class);
    ValidatorService mockValidatorService = Mockito.mock(ValidatorService.class);
    when(mockRepo.saveRepo(any())).thenReturn(true);
    when(mockValidatorService.validate(any())).thenReturn(new ValidatorResult(true, ""));
    AdminRouteService adminRouteService = new AdminRouteService(mockRepo, mockJobService, null, null, null, mockValidatorService);
    Request mockRequest = Mockito.mock(Request.class);
    when(mockRequest.queryParamsValues("reponame")).thenReturn("name,name".split(","));
    when(mockRequest.queryParamsValues("reposcm")).thenReturn("git,git".split(","));
    when(mockRequest.queryParamsValues("repourl")).thenReturn("url,url".split(","));
    when(mockRequest.queryParamsValues("repousername")).thenReturn("username,username".split(","));
    when(mockRequest.queryParamsValues("repopassword")).thenReturn("password,password".split(","));
    when(mockRequest.queryParamsValues("reposource")).thenReturn("source,source".split(","));
    when(mockRequest.queryParamsValues("repobranch")).thenReturn("master,master".split(","));
    adminRouteService.postRepo(mockRequest, null);
    verify(mockRepo, times(2)).saveRepo(any());
    verify(mockJobService, times(2)).forceEnqueue(any());
    verify(mockValidatorService, times(2)).validate(any());
}
Also used : Repo(com.searchcode.app.dao.Repo) ValidatorResult(com.searchcode.app.model.ValidatorResult) AdminRouteService(com.searchcode.app.service.route.AdminRouteService) Request(spark.Request)

Example 44 with Request

use of spark.Request 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)

Example 45 with Request

use of spark.Request in project searchcode-server by boyter.

the class ApiRouteServiceTest method testRepoAddAuthInvalidSigned.

public void testRepoAddAuthInvalidSigned() {
    Request mockRequest = Mockito.mock(Request.class);
    Repo mockRepo = Mockito.mock(Repo.class);
    ApiService mockApiService = Mockito.mock(ApiService.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(false);
    ApiRouteService apiRouteService = new ApiRouteService(mockApiService, null, mockRepo, null, null);
    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("invalid signed url");
    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)

Aggregations

Request (spark.Request)58 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 Response (spark.Response)9 CodeRouteService (com.searchcode.app.service.route.CodeRouteService)8 AdminRouteService (com.searchcode.app.service.route.AdminRouteService)7 HashSet (java.util.HashSet)6 Map (java.util.Map)6 ModelAndView (spark.ModelAndView)5 RouteMatch (spark.routematch.RouteMatch)4 ValidatorResult (com.searchcode.app.model.ValidatorResult)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 CodeMatcher (com.searchcode.app.service.CodeMatcher)2