use of spark.Request in project searchcode-server by boyter.
the class CodeRouteServiceTest method testGetCodeNoParams.
public void testGetCodeNoParams() {
CodeRouteService codeRouteService = new CodeRouteService();
Request request = Mockito.mock(Request.class);
Response response = Mockito.mock(Response.class);
try {
codeRouteService.getCode(request, response);
} catch (HaltException ex) {
}
verify(response, times(1)).redirect("/404/");
}
use of spark.Request in project searchcode-server by boyter.
the class CodeRouteServiceTest method testGetCodeWithParamsNoMatch.
public void testGetCodeWithParamsNoMatch() {
CodeRouteService codeRouteService = new CodeRouteService();
Request request = Mockito.mock(Request.class);
Response response = Mockito.mock(Response.class);
when(request.params(":codeid")).thenReturn("NOTHING-SHOULD-MATCH-THIS-EVER");
try {
codeRouteService.getCode(request, response);
} catch (HaltException ex) {
}
verify(response, times(1)).redirect("/404/");
}
use of spark.Request in project searchcode-server by boyter.
the class CodeRouteServiceTest method testGetProject.
public void testGetProject() {
CodeRouteService codeRouteService = new CodeRouteService();
Request request = Mockito.mock(Request.class);
Response response = Mockito.mock(Response.class);
try {
codeRouteService.getProject(request, response);
} catch (HaltException ex) {
}
verify(response, times(1)).redirect("/404/");
}
use of spark.Request in project searchcode-server by boyter.
the class CodeRouteServiceTest method testRootNoQueryString.
public void testRootNoQueryString() {
CodeRouteService codeRouteService = new CodeRouteService();
Request request = Mockito.mock(Request.class);
Data mockData = Mockito.mock(Data.class);
when(mockData.getDataByName(Values.LOGO, Values.EMPTYSTRING)).thenReturn(Values.EMPTYSTRING);
Singleton.setData(mockData);
ModelAndView modelAndView = codeRouteService.root(request, null);
Map<String, Object> model = (Map<String, Object>) modelAndView.getModel();
String viewName = modelAndView.getViewName();
assertThat(model.get("photoId")).isInstanceOf(Integer.class);
assertThat((int) model.get("photoId")).isGreaterThanOrEqualTo(0);
assertThat((int) model.get("photoId")).isLessThanOrEqualTo(4);
assertThat(model.get("numDocs")).isInstanceOf(Integer.class);
assertThat((int) model.get("numDocs")).isGreaterThanOrEqualTo(0);
assertThat(model.get("logoImage")).isNotNull();
assertThat(model.get("isCommunity")).isEqualTo(App.ISCOMMUNITY);
assertThat(viewName).isEqualTo("index.ftl");
}
use of spark.Request in project searchcode-server by boyter.
the class ApiRouteServiceTest method testRepoAddAuthValidSigned.
public void testRepoAddAuthValidSigned() {
Request mockRequest = Mockito.mock(Request.class);
Repo mockRepo = Mockito.mock(Repo.class);
ApiService mockApiService = Mockito.mock(ApiService.class);
ValidatorService mockValidatorService = Mockito.mock(ValidatorService.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(true);
when(mockValidatorService.validate(any())).thenReturn(new ValidatorResult(true, ""));
ApiRouteService apiRouteService = new ApiRouteService(mockApiService, null, mockRepo, null, mockValidatorService);
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("added repository successfully");
assertThat(apiResponse.isSucessful()).isTrue();
verify(mockRepo, times(1)).saveRepo(Matchers.<RepoResult>anyObject());
}
Aggregations