Search in sources :

Example 6 with CodeRouteService

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();
}
Also used : Response(spark.Response) CodeRouteService(com.searchcode.app.service.route.CodeRouteService) Request(spark.Request) CodeResult(com.searchcode.app.dto.CodeResult) CodeMatchResult(com.searchcode.app.dto.CodeMatchResult)

Example 7 with CodeRouteService

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");
}
Also used : CodeRouteService(com.searchcode.app.service.route.CodeRouteService) Request(spark.Request) ModelAndView(spark.ModelAndView) Map(java.util.Map) HashSet(java.util.HashSet)

Example 8 with CodeRouteService

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");
}
Also used : CodeRouteService(com.searchcode.app.service.route.CodeRouteService) Request(spark.Request) ModelAndView(spark.ModelAndView) Map(java.util.Map) HashSet(java.util.HashSet)

Aggregations

CodeRouteService (com.searchcode.app.service.route.CodeRouteService)8 Request (spark.Request)8 Map (java.util.Map)4 ModelAndView (spark.ModelAndView)4 Response (spark.Response)4 HaltException (spark.HaltException)3 HashSet (java.util.HashSet)2 Data (com.searchcode.app.dao.Data)1 CodeMatchResult (com.searchcode.app.dto.CodeMatchResult)1 CodeResult (com.searchcode.app.dto.CodeResult)1