Search in sources :

Example 56 with Request

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

the class AdminRouteServiceTest method testGetStatValuesExpectEmpty.

public void testGetStatValuesExpectEmpty() {
    AdminRouteService adminRouteService = new AdminRouteService();
    Singleton.getLogger().clearAllLogs();
    List<String> statValue = Arrays.asList(null, "", "alllogs", "infologs", "warninglogs", "severelogs", "searchlogs");
    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).isEmpty();
    }
}
Also used : AdminRouteService(com.searchcode.app.service.route.AdminRouteService) Request(spark.Request)

Example 57 with Request

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

the class AdminRouteServiceTest method testGetStatValuesExpectNbspBecauseIntercoolerJS.

public void testGetStatValuesExpectNbspBecauseIntercoolerJS() {
    AdminRouteService adminRouteService = new AdminRouteService();
    Singleton.getLogger().clearAllLogs();
    Request mockRequest = mock(Request.class);
    Set<String> returnSet = new HashSet<>();
    returnSet.add("statname");
    when(mockRequest.queryParams()).thenReturn(returnSet);
    when(mockRequest.queryParams("statname")).thenReturn("runningjobs");
    String result = adminRouteService.getStat(mockRequest, null);
    assertThat(result).as("For value runningjobs").isEqualTo("&nbsp;");
}
Also used : AdminRouteService(com.searchcode.app.service.route.AdminRouteService) Request(spark.Request)

Example 58 with Request

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

the class AdminRouteServiceTest method testPostRepoMultipleRepo.

public void testPostRepoMultipleRepo() {
    SQLiteRepo mockSQLiteRepo = mock(SQLiteRepo.class);
    JobService mockJobService = mock(JobService.class);
    ValidatorService mockValidatorService = mock(ValidatorService.class);
    when(mockSQLiteRepo.saveRepo(any())).thenReturn(true);
    when(mockValidatorService.validate(any(), anyBoolean())).thenReturn(new ValidatorResult(true, ""));
    when(mockSQLiteRepo.getRepoByUrl(any())).thenReturn(Optional.of(new RepoResult()));
    AdminRouteService adminRouteService = new AdminRouteService(mockSQLiteRepo, null, mockJobService, null, null, null, mockValidatorService, null, Singleton.getLogger());
    Request mockRequest = 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("source,source".split(","));
    when(mockRequest.queryParamsValues("source")).thenReturn("source,source".split(","));
    when(mockRequest.queryParamsValues("sourceuser")).thenReturn("master,master".split(","));
    when(mockRequest.queryParamsValues("sourceproject")).thenReturn("master,master".split(","));
    adminRouteService.postRepo(mockRequest, null, false);
    verify(mockSQLiteRepo, times(2)).saveRepo(any());
    verify(mockJobService, times(2)).forceEnqueue(any());
    verify(mockValidatorService, times(2)).validate(any(), anyBoolean());
}
Also used : ValidatorResult(com.searchcode.app.model.ValidatorResult) SQLiteRepo(com.searchcode.app.dao.SQLiteRepo) AdminRouteService(com.searchcode.app.service.route.AdminRouteService) Request(spark.Request) RepoResult(com.searchcode.app.model.RepoResult)

Example 59 with Request

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

the class ApiRouteServiceTest method testRepoDeleteAuthReponameFailedAuth.

public void testRepoDeleteAuthReponameFailedAuth() {
    Request mockRequest = mock(Request.class);
    SQLiteRepo mockSQLiteRepo = mock(SQLiteRepo.class);
    UniqueRepoQueue uniqueRepoQueue = new UniqueRepoQueue(new ConcurrentLinkedQueue<>());
    ApiService mockApiService = mock(ApiService.class);
    when(mockApiService.validateRequest("test", "test", "pub=test", ApiService.HmacType.SHA1)).thenReturn(false);
    when(mockSQLiteRepo.getRepoByName("unit-test")).thenReturn(Optional.of(new RepoResult()));
    ApiRouteService apiRouteService = new ApiRouteService(mockApiService, null, mockSQLiteRepo, null, null, null, new Helpers(), new LoggerWrapper());
    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 : ApiRouteService(com.searchcode.app.service.route.ApiRouteService) Helpers(com.searchcode.app.util.Helpers) LoggerWrapper(com.searchcode.app.util.LoggerWrapper) Request(spark.Request) SQLiteRepo(com.searchcode.app.dao.SQLiteRepo) 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 60 with Request

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

the class ApiRouteServiceTest method testRepositoryReindexApiAuthEnabledInvalidSig.

public void testRepositoryReindexApiAuthEnabledInvalidSig() {
    JobService mockJobService = mock(JobService.class);
    ApiService mockApiService = mock(ApiService.class);
    Request mockRequest = mock(Request.class);
    when(mockRequest.queryParams("pub")).thenReturn("test");
    when(mockRequest.queryParams("sig")).thenReturn("test");
    when(mockApiService.validateRequest("test", "test", "pub=test", ApiService.HmacType.SHA1)).thenReturn(false);
    ApiRouteService apiRouteService = new ApiRouteService(mockApiService, mockJobService, null, null, null, null, new Helpers(), new LoggerWrapper());
    apiRouteService.apiEnabled = true;
    apiRouteService.apiAuth = true;
    ApiResponse apiResponse = apiRouteService.repositoryReindex(mockRequest, null);
    assertThat(apiResponse.getMessage()).isEqualTo("invalid signed url");
    assertThat(apiResponse.isSucessful()).isEqualTo(false);
}
Also used : ApiRouteService(com.searchcode.app.service.route.ApiRouteService) Helpers(com.searchcode.app.util.Helpers) LoggerWrapper(com.searchcode.app.util.LoggerWrapper) Request(spark.Request) ApiResponse(com.searchcode.app.dto.api.ApiResponse) RepoResultApiResponse(com.searchcode.app.dto.api.RepoResultApiResponse)

Aggregations

Request (spark.Request)70 ApiRouteService (com.searchcode.app.service.route.ApiRouteService)35 RepoResultApiResponse (com.searchcode.app.dto.api.RepoResultApiResponse)33 Helpers (com.searchcode.app.util.Helpers)31 LoggerWrapper (com.searchcode.app.util.LoggerWrapper)31 SQLiteRepo (com.searchcode.app.dao.SQLiteRepo)28 ApiResponse (com.searchcode.app.dto.api.ApiResponse)28 Response (spark.Response)17 RepoResult (com.searchcode.app.model.RepoResult)11 AdminRouteService (com.searchcode.app.service.route.AdminRouteService)8 CodeRouteService (com.searchcode.app.service.route.CodeRouteService)7 Collectors (java.util.stream.Collectors)5 IndexService (com.searchcode.app.service.index.IndexService)4 IOException (java.io.IOException)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 Spark (spark.Spark)4 ValidatorResult (com.searchcode.app.model.ValidatorResult)3 ApiController (com.thoughtworks.go.api.ApiController)3 ApiVersion (com.thoughtworks.go.api.ApiVersion)3 JsonReader (com.thoughtworks.go.api.representers.JsonReader)3