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;
}
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());
}
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());
}
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();
}
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();
}
Aggregations