Search in sources :

Example 1 with AdminRouteService

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

the class AdminRouteServiceTest method testGetStatLogs.

public void testGetStatLogs() {
    AdminRouteService adminRouteService = new AdminRouteService();
    Singleton.getLogger().apiLog("test");
    Singleton.getLogger().warning("test");
    Singleton.getLogger().searchLog("test");
    Singleton.getLogger().severe("test");
    Singleton.getLogger().info("test");
    List<String> statValue = Arrays.asList("alllogs", "infologs", "warninglogs", "severelogs", "searchlogs", "apilogs");
    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 : AdminRouteService(com.searchcode.app.service.route.AdminRouteService) Request(spark.Request) HashSet(java.util.HashSet)

Example 2 with AdminRouteService

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

the class AdminRouteServiceTest method testPostRepoRepoNamesEmptyNothing.

public void testPostRepoRepoNamesEmptyNothing() {
    Repo mockRepo = Mockito.mock(Repo.class);
    JobService mockJobService = Mockito.mock(JobService.class);
    AdminRouteService adminRouteService = new AdminRouteService(mockRepo, mockJobService, null, null, null, null);
    Request mockRequest = Mockito.mock(Request.class);
    when(mockRequest.queryParamsValues("reponame")).thenReturn(new String[0]);
    when(mockRequest.queryParamsValues("reposcm")).thenReturn(new String[0]);
    when(mockRequest.queryParamsValues("repourl")).thenReturn(new String[0]);
    when(mockRequest.queryParamsValues("repousername")).thenReturn(new String[0]);
    when(mockRequest.queryParamsValues("repopassword")).thenReturn(new String[0]);
    when(mockRequest.queryParamsValues("reposource")).thenReturn(new String[0]);
    when(mockRequest.queryParamsValues("repobranch")).thenReturn(new String[0]);
    adminRouteService.postRepo(mockRequest, null);
}
Also used : Repo(com.searchcode.app.dao.Repo) AdminRouteService(com.searchcode.app.service.route.AdminRouteService) Request(spark.Request)

Example 3 with AdminRouteService

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

the class AdminRouteServiceTest method testCheckIndexStatus.

public void testCheckIndexStatus() {
    AdminRouteService adminRouteService = new AdminRouteService();
    Request mockRequest = Mockito.mock(Request.class);
    Set<String> returnSet = new HashSet<>();
    returnSet.add("reponame");
    when(mockRequest.queryParams()).thenReturn(returnSet);
    when(mockRequest.queryParams("reponame")).thenReturn("hopefullyarandomnamethatdoesnotexist");
    String result = adminRouteService.checkIndexStatus(mockRequest, null);
    assertThat(result).isEmpty();
}
Also used : AdminRouteService(com.searchcode.app.service.route.AdminRouteService) Request(spark.Request) HashSet(java.util.HashSet)

Example 4 with AdminRouteService

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

the class AdminRouteServiceTest method testGetStatValuesExpectEmpty.

public void testGetStatValuesExpectEmpty() {
    AdminRouteService adminRouteService = new AdminRouteService();
    Singleton.getLogger().clearAllLogs();
    List<String> statValue = Arrays.asList(null, "", "runningjobs", "alllogs", "infologs", "warninglogs", "severelogs", "searchlogs");
    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).isEmpty();
    }
}
Also used : AdminRouteService(com.searchcode.app.service.route.AdminRouteService) Request(spark.Request) HashSet(java.util.HashSet)

Example 5 with AdminRouteService

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

the class AdminRouteServiceTest method testGetStatValuesExpectValue.

public void testGetStatValuesExpectValue() {
    SharedService sharedServiceMock = Mockito.mock(SharedService.class);
    StatsService statsServiceMock = Mockito.mock(StatsService.class);
    when(statsServiceMock.getMemoryUsage(any())).thenReturn("Yep");
    when(statsServiceMock.getLoadAverage()).thenReturn("Yep");
    when(statsServiceMock.getUptime()).thenReturn("Yep");
    AdminRouteService adminRouteService = new AdminRouteService(null, null, null, sharedServiceMock, statsServiceMock, null);
    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 : AdminRouteService(com.searchcode.app.service.route.AdminRouteService) Request(spark.Request) HashSet(java.util.HashSet)

Aggregations

AdminRouteService (com.searchcode.app.service.route.AdminRouteService)7 Request (spark.Request)7 HashSet (java.util.HashSet)4 Repo (com.searchcode.app.dao.Repo)3 RepoResult (com.searchcode.app.model.RepoResult)1 ValidatorResult (com.searchcode.app.model.ValidatorResult)1