Search in sources :

Example 51 with Request

use of spark.Request in project searchcode-server by boyter.

the class CodeRouteServiceTest method testHtmlNoQueryString.

public void testHtmlNoQueryString() {
    CodeRouteService codeRouteService = new CodeRouteService();
    Request request = Mockito.mock(Request.class);
    var model = codeRouteService.html(request, null);
    assertThat(model.get("photoId")).isInstanceOf(Integer.class);
    assertThat((int) model.get("photoId")).isGreaterThanOrEqualTo(0);
    assertThat((int) model.get("photoId")).isLessThanOrEqualTo(42);
    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.IS_COMMUNITY);
}
Also used : CodeRouteService(com.searchcode.app.service.route.CodeRouteService) Request(spark.Request)

Example 52 with Request

use of spark.Request 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.IS_COMMUNITY);
    assertThat(viewName).isEqualTo("search_ajax.ftl");
}
Also used : CodeRouteService(com.searchcode.app.service.route.CodeRouteService) Request(spark.Request) ModelAndView(spark.ModelAndView)

Example 53 with Request

use of spark.Request 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");
    var model = codeRouteService.html(request, null);
    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.IS_COMMUNITY);
}
Also used : CodeRouteService(com.searchcode.app.service.route.CodeRouteService) Request(spark.Request)

Example 54 with Request

use of spark.Request in project searchcode-server by boyter.

the class AdminRouteServiceTest method testGetStatValuesExpectValue.

public void testGetStatValuesExpectValue() {
    SQLiteRepo SQLiteRepoMock = mock(SQLiteRepo.class);
    StatsService statsServiceMock = mock(StatsService.class);
    IndexService indexServiceMock = mock(IndexService.class);
    when(statsServiceMock.getMemoryUsage(any())).thenReturn("Yep");
    when(statsServiceMock.getLoadAverage()).thenReturn("Yep");
    when(statsServiceMock.getUpTime()).thenReturn("Yep");
    when(SQLiteRepoMock.getRepoCount()).thenReturn(1);
    when(indexServiceMock.getIndexedDocumentCount()).thenReturn(100);
    when(indexServiceMock.shouldPause(IIndexService.JobType.REPO_PARSER)).thenReturn(false);
    AdminRouteService adminRouteService = new AdminRouteService(SQLiteRepoMock, null, null, null, indexServiceMock, statsServiceMock, null, null, Singleton.getLogger());
    List<String> statValue = Arrays.asList("memoryusage", "loadaverage", "uptime", "searchcount", "spellingcount", "repocount", "numdocs", "servertime", "deletionqueue");
    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).isNotEmpty();
    }
}
Also used : IndexService(com.searchcode.app.service.index.IndexService) IIndexService(com.searchcode.app.service.index.IIndexService) SQLiteRepo(com.searchcode.app.dao.SQLiteRepo) AdminRouteService(com.searchcode.app.service.route.AdminRouteService) Request(spark.Request)

Example 55 with Request

use of spark.Request in project searchcode-server by boyter.

the class AdminRouteServiceTest method testDeleteRepo.

public void testDeleteRepo() {
    SQLiteRepo mockSQLiteRepo = Mockito.mock(SQLiteRepo.class);
    JobService mockJobService = Mockito.mock(JobService.class);
    DataService mockDataService = Mockito.mock(DataService.class);
    AdminRouteService adminRouteService = new AdminRouteService(mockSQLiteRepo, null, mockJobService, mockDataService, null, null, null, null, Singleton.getLogger());
    Request mockRequest = Mockito.mock(Request.class);
    when(mockRequest.queryParams("repoName")).thenReturn("myRepo");
    when(mockSQLiteRepo.getRepoByName("myRepo")).thenReturn(Optional.of(new RepoResult()));
    adminRouteService.deleteRepo(mockRequest, null);
    verify(mockDataService, times(1)).addToPersistentDelete("");
}
Also used : SQLiteRepo(com.searchcode.app.dao.SQLiteRepo) AdminRouteService(com.searchcode.app.service.route.AdminRouteService) Request(spark.Request) RepoResult(com.searchcode.app.model.RepoResult)

Aggregations

Request (spark.Request)70 ApiRouteService (com.searchcode.app.service.route.ApiRouteService)35 RepoResultApiResponse (com.searchcode.app.dto.api.RepoResultApiResponse)33 Helpers (com.searchcode.app.util.Helpers)31 LoggerWrapper (com.searchcode.app.util.LoggerWrapper)31 SQLiteRepo (com.searchcode.app.dao.SQLiteRepo)28 ApiResponse (com.searchcode.app.dto.api.ApiResponse)28 Response (spark.Response)17 RepoResult (com.searchcode.app.model.RepoResult)11 AdminRouteService (com.searchcode.app.service.route.AdminRouteService)8 CodeRouteService (com.searchcode.app.service.route.CodeRouteService)7 Collectors (java.util.stream.Collectors)5 IndexService (com.searchcode.app.service.index.IndexService)4 IOException (java.io.IOException)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 Spark (spark.Spark)4 ValidatorResult (com.searchcode.app.model.ValidatorResult)3 ApiController (com.thoughtworks.go.api.ApiController)3 ApiVersion (com.thoughtworks.go.api.ApiVersion)3 JsonReader (com.thoughtworks.go.api.representers.JsonReader)3