use of com.searchcode.app.service.route.CodeRouteService in project searchcode-server by boyter.
the class CodeRouteServiceTest method testGetCodeWithParamsWithMatch.
public void testGetCodeWithParamsWithMatch() {
Request request = Mockito.mock(Request.class);
Response response = Mockito.mock(Response.class);
CodeSearcher codeSearcher = Mockito.mock(CodeSearcher.class);
CodeRouteService codeRouteService = new CodeRouteService(codeSearcher);
CodeResult codeResult = new CodeResult(new ArrayList<String>(), new ArrayList<CodeMatchResult>());
codeResult.setCodeLines("100");
codeResult.setLanguageName("LanguageName");
codeResult.setMd5hash("md5hash");
codeResult.setRepoName("myRepo");
codeResult.setRepoLocation("repoLocation");
codeResult.setCodeOwner("codeOwner");
when(request.params(":codeid")).thenReturn("MATCH-MOCK");
when(codeSearcher.getByCodeId("MATCH-MOCK")).thenReturn(codeResult);
Map<String, Object> map = codeRouteService.getCode(request, response);
assertThat(map.get("codePath")).isEqualTo("/");
assertThat(map.get("codeLength")).isEqualTo("100");
assertThat(map.get("languageName")).isEqualTo("LanguageName");
assertThat(map.get("md5Hash")).isEqualTo("md5hash");
assertThat(map.get("repoName")).isEqualTo("myRepo");
assertThat(map.get("highlight")).isEqualTo(true);
assertThat(map.get("repoLocation")).isEqualTo("repoLocation");
assertThat(map.get("codeValue")).isEqualTo("");
assertThat(map.get("highligher")).isNotNull();
assertThat(map.get("codeOwner")).isEqualTo("codeOwner");
assertThat(map.get("owaspResults")).isNotNull();
assertThat(map.get("logoImage")).isNotNull();
assertThat(map.get("isCommunity")).isEqualTo(App.ISCOMMUNITY);
assertThat(map.get("estimatedCost")).isNull();
}
use of com.searchcode.app.service.route.CodeRouteService in project searchcode-server by boyter.
the class CodeRouteServiceTest method testHtmlQueryString.
public void testHtmlQueryString() {
CodeRouteService codeRouteService = new CodeRouteService();
Request request = Mockito.mock(Request.class);
Set<String> hashSet = new HashSet<>();
hashSet.add("q");
when(request.queryParams()).thenReturn(hashSet);
when(request.queryParams("q")).thenReturn("test");
ModelAndView modelAndView = codeRouteService.html(request, null);
Map<String, Object> model = (Map<String, Object>) modelAndView.getModel();
String viewName = modelAndView.getViewName();
assertThat(model.get("searchValue")).isEqualTo("test");
assertThat(model.get("searchResult")).isNotNull();
assertThat(model.get("reposQueryString")).isNotNull();
assertThat(model.get("langsQueryString")).isNotNull();
assertThat(model.get("ownsQueryString")).isNotNull();
assertThat(model.get("altQuery")).isNotNull();
assertThat((int) model.get("totalPages")).isGreaterThanOrEqualTo(0);
assertThat((boolean) model.get("isHtml")).isTrue();
assertThat(model.get("logoImage")).isNotNull();
assertThat(model.get("isCommunity")).isEqualTo(App.ISCOMMUNITY);
assertThat(viewName).isEqualTo("searchresults.ftl");
}
use of com.searchcode.app.service.route.CodeRouteService in project searchcode-server by boyter.
the class CodeRouteServiceTest method testRootQueryString.
public void testRootQueryString() {
CodeRouteService codeRouteService = new CodeRouteService();
Request request = Mockito.mock(Request.class);
Set<String> hashSet = new HashSet<>();
hashSet.add("q");
when(request.queryParams()).thenReturn(hashSet);
when(request.queryParams("q")).thenReturn("test");
ModelAndView modelAndView = codeRouteService.root(request, null);
Map<String, Object> model = (Map<String, Object>) modelAndView.getModel();
String viewName = modelAndView.getViewName();
assertThat(model.get("searchValue")).isEqualTo("test");
assertThat(model.get("searchResultJson")).isNotNull();
assertThat(model.get("logoImage")).isNotNull();
assertThat(model.get("isCommunity")).isEqualTo(App.ISCOMMUNITY);
assertThat(viewName).isEqualTo("search_ajax.ftl");
}
Aggregations