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