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);
}
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");
}
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);
}
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();
}
}
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("");
}
Aggregations