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