Search in sources :

Example 1 with CodeRouteService

use of com.searchcode.app.service.route.CodeRouteService 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/");
}
Also used : Response(spark.Response) HaltException(spark.HaltException) CodeRouteService(com.searchcode.app.service.route.CodeRouteService) Request(spark.Request)

Example 2 with CodeRouteService

use of com.searchcode.app.service.route.CodeRouteService 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/");
}
Also used : Response(spark.Response) HaltException(spark.HaltException) CodeRouteService(com.searchcode.app.service.route.CodeRouteService) Request(spark.Request)

Example 3 with CodeRouteService

use of com.searchcode.app.service.route.CodeRouteService 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/");
}
Also used : Response(spark.Response) HaltException(spark.HaltException) CodeRouteService(com.searchcode.app.service.route.CodeRouteService) Request(spark.Request)

Example 4 with CodeRouteService

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

Example 5 with CodeRouteService

use of com.searchcode.app.service.route.CodeRouteService in project searchcode-server by boyter.

the class CodeRouteServiceTest method testHtmlNoQueryString.

public void testHtmlNoQueryString() {
    CodeRouteService codeRouteService = new CodeRouteService();
    Request request = Mockito.mock(Request.class);
    ModelAndView modelAndView = codeRouteService.html(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");
}
Also used : CodeRouteService(com.searchcode.app.service.route.CodeRouteService) Request(spark.Request) ModelAndView(spark.ModelAndView) Map(java.util.Map)

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