Search in sources :

Example 11 with ValidatorResult

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

the class AdminRouteService method postRepo.

public ValidatorResult postRepo(Request request, Response response) {
    String[] reponames = request.queryParamsValues("reponame");
    String[] reposcms = request.queryParamsValues("reposcm");
    String[] repourls = request.queryParamsValues("repourl");
    String[] repousername = request.queryParamsValues("repousername");
    String[] repopassword = request.queryParamsValues("repopassword");
    String[] reposource = request.queryParamsValues("reposource");
    String[] repobranch = request.queryParamsValues("repobranch");
    ValidatorResult validate = new ValidatorResult(true, Values.EMPTYSTRING);
    for (int i = 0; i < reponames.length; i++) {
        String branch = repobranch[i].trim();
        if (branch.equals(Values.EMPTYSTRING)) {
            branch = "master";
        }
        RepoResult repoResult = new RepoResult(-1, reponames[i], reposcms[i], repourls[i], repousername[i], repopassword[i], reposource[i], branch, "{}");
        validate = this.validatorService.validate(repoResult);
        if (!validate.isValid) {
            validate.setRepoResult(repoResult);
            return validate;
        }
        this.repo.saveRepo(repoResult);
        this.jobService.forceEnqueue(this.repo.getRepoByUrl(repourls[i]));
    }
    return validate;
}
Also used : ValidatorResult(com.searchcode.app.model.ValidatorResult) RepoResult(com.searchcode.app.model.RepoResult)

Example 12 with ValidatorResult

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

the class ApiRouteServiceTest method testRepoAddNoAuthSucessful.

public void testRepoAddNoAuthSucessful() {
    Request mockRequest = mock(Request.class);
    SQLiteRepo mockSQLiteRepo = mock(SQLiteRepo.class);
    ValidatorService mockValidatorService = mock(ValidatorService.class);
    when(mockValidatorService.validate(any(), anyBoolean())).thenReturn(new ValidatorResult(true, ""));
    when(mockSQLiteRepo.getRepoByName(anyString())).thenReturn(Optional.empty());
    ApiRouteService apiRouteService = new ApiRouteService(null, null, mockSQLiteRepo, null, mockValidatorService, null, new Helpers(), new LoggerWrapper());
    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(mockSQLiteRepo, times(1)).saveRepo(Matchers.anyObject());
}
Also used : ApiRouteService(com.searchcode.app.service.route.ApiRouteService) ValidatorResult(com.searchcode.app.model.ValidatorResult) Helpers(com.searchcode.app.util.Helpers) LoggerWrapper(com.searchcode.app.util.LoggerWrapper) Request(spark.Request) SQLiteRepo(com.searchcode.app.dao.SQLiteRepo) ApiResponse(com.searchcode.app.dto.api.ApiResponse) RepoResultApiResponse(com.searchcode.app.dto.api.RepoResultApiResponse)

Example 13 with ValidatorResult

use of com.searchcode.app.model.ValidatorResult 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 14 with ValidatorResult

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

the class ValidatorServiceTest method testValidatorServiceExistingNameIgnored.

public void testValidatorServiceExistingNameIgnored() {
    SQLiteRepo mockSQLiteRepo = mock(SQLiteRepo.class);
    ValidatorService validatorService = new ValidatorService(mockSQLiteRepo, new Helpers());
    when(mockSQLiteRepo.getRepoByName("exists")).thenReturn(Optional.of(new RepoResult()));
    RepoResult repoResult = new RepoResult().setRowId(0).setName("exists").setScm("something").setUrl("url").setUsername("").setPassword("").setSource("source").setBranch("branch").setData("{}");
    ValidatorResult validate = validatorService.validate(repoResult, true);
    assertThat(validate.isValid).isTrue();
}
Also used : Helpers(com.searchcode.app.util.Helpers) ValidatorResult(com.searchcode.app.model.ValidatorResult) SQLiteRepo(com.searchcode.app.dao.SQLiteRepo) RepoResult(com.searchcode.app.model.RepoResult)

Example 15 with ValidatorResult

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

the class ValidatorServiceTest method testValidatorServiceExistingName.

public void testValidatorServiceExistingName() {
    SQLiteRepo mockSQLiteRepo = mock(SQLiteRepo.class);
    ValidatorService validatorService = new ValidatorService(mockSQLiteRepo, new Helpers());
    when(mockSQLiteRepo.getRepoByName("exists")).thenReturn(Optional.of(new RepoResult()));
    RepoResult repoResult = new RepoResult().setRowId(0).setName("exists").setScm("something").setUrl("url").setUsername("").setPassword("").setSource("source").setBranch("branch").setData("{}");
    ValidatorResult validate = validatorService.validate(repoResult, false);
    assertThat(validate.isValid).isFalse();
}
Also used : Helpers(com.searchcode.app.util.Helpers) ValidatorResult(com.searchcode.app.model.ValidatorResult) SQLiteRepo(com.searchcode.app.dao.SQLiteRepo) RepoResult(com.searchcode.app.model.RepoResult)

Aggregations

ValidatorResult (com.searchcode.app.model.ValidatorResult)16 RepoResult (com.searchcode.app.model.RepoResult)12 SQLiteRepo (com.searchcode.app.dao.SQLiteRepo)5 Helpers (com.searchcode.app.util.Helpers)4 ApiResponse (com.searchcode.app.dto.api.ApiResponse)3 RepoResultApiResponse (com.searchcode.app.dto.api.RepoResultApiResponse)3 Request (spark.Request)3 ApiRouteService (com.searchcode.app.service.route.ApiRouteService)2 LoggerWrapper (com.searchcode.app.util.LoggerWrapper)2 AdminRouteService (com.searchcode.app.service.route.AdminRouteService)1 JsonTransformer (com.searchcode.app.util.JsonTransformer)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 HashMap (java.util.HashMap)1 ModelAndView (spark.ModelAndView)1 FreeMarkerEngine (spark.template.freemarker.FreeMarkerEngine)1