Search in sources :

Example 21 with SQLiteRepo

use of com.searchcode.app.dao.SQLiteRepo in project searchcode-server by boyter.

the class ApiRouteServiceTest method testRepoAddMissingRepoPassword.

public void testRepoAddMissingRepoPassword() {
    Request mockRequest = mock(Request.class);
    SQLiteRepo mockSQLiteRepo = mock(SQLiteRepo.class);
    ApiRouteService apiRouteService = new ApiRouteService(null, null, mockSQLiteRepo, null, null, null, new Helpers(), new LoggerWrapper());
    apiRouteService.apiEnabled = true;
    apiRouteService.apiAuth = false;
    when(mockRequest.queryParams("reponame")).thenReturn("test");
    when(mockRequest.queryParams("repourl")).thenReturn("test");
    when(mockRequest.queryParams("repotype")).thenReturn("test");
    when(mockRequest.queryParams("repousername")).thenReturn("test");
    ApiResponse apiResponse = apiRouteService.repoAdd(mockRequest, null);
    assertThat(apiResponse.getMessage()).isEqualTo("repopassword is a required parameter");
    assertThat(apiResponse.isSucessful()).isFalse();
}
Also used : ApiRouteService(com.searchcode.app.service.route.ApiRouteService) Helpers(com.searchcode.app.util.Helpers) LoggerWrapper(com.searchcode.app.util.LoggerWrapper) Request(spark.Request) SQLiteRepo(com.searchcode.app.dao.SQLiteRepo) ApiResponse(com.searchcode.app.dto.api.ApiResponse) RepoResultApiResponse(com.searchcode.app.dto.api.RepoResultApiResponse)

Example 22 with SQLiteRepo

use of com.searchcode.app.dao.SQLiteRepo in project searchcode-server by boyter.

the class CodeRouteServiceTest method testGetCodeWithParamsWithMatch.

public void testGetCodeWithParamsWithMatch() {
    var request = mock(Request.class);
    var response = mock(Response.class);
    var indexService = mock(IndexService.class);
    var highlight = mock(Highlight.class);
    var codeRouteService = new CodeRouteService(indexService, new Helpers(), new SQLiteRepo(), new Data(), null, null, null, null, highlight);
    var codeResult = new CodeResult(new ArrayList<>(), new ArrayList<>());
    codeResult.setLines("100");
    codeResult.setLanguageName("LanguageName");
    codeResult.setMd5hash("md5hash");
    codeResult.setRepoName("myRepo");
    codeResult.setRepoLocation("repoLocation");
    codeResult.setCodeOwner("codeOwner");
    codeResult.setDisplayLocation("myDisplayLocation");
    when(request.params(":codeid")).thenReturn("MATCH-MOCK");
    when(indexService.getCodeResultByCodeId("MATCH-MOCK")).thenReturn(codeResult);
    when(highlight.highlightCodeResult(any())).thenReturn(new HashMap<>() {

        {
            put("codeValue", "");
        }
    });
    var map = codeRouteService.getCode(request, response);
    assertThat(map.get("codePath")).isEqualTo("myDisplayLocation");
    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");
    // TODO depends on the highlighter being used
    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.IS_COMMUNITY);
    assertThat(map.get("estimatedCost")).isEqualTo(2395);
}
Also used : CodeRouteService(com.searchcode.app.service.route.CodeRouteService) Helpers(com.searchcode.app.util.Helpers) SQLiteRepo(com.searchcode.app.dao.SQLiteRepo) CodeResult(com.searchcode.app.dto.CodeResult) Data(com.searchcode.app.dao.Data)

Example 23 with SQLiteRepo

use of com.searchcode.app.dao.SQLiteRepo 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 24 with SQLiteRepo

use of com.searchcode.app.dao.SQLiteRepo 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)

Example 25 with SQLiteRepo

use of com.searchcode.app.dao.SQLiteRepo in project searchcode-server by boyter.

the class AdminRouteServiceTest method testPostRepoMultipleRepo.

public void testPostRepoMultipleRepo() {
    SQLiteRepo mockSQLiteRepo = mock(SQLiteRepo.class);
    JobService mockJobService = mock(JobService.class);
    ValidatorService mockValidatorService = mock(ValidatorService.class);
    when(mockSQLiteRepo.saveRepo(any())).thenReturn(true);
    when(mockValidatorService.validate(any(), anyBoolean())).thenReturn(new ValidatorResult(true, ""));
    when(mockSQLiteRepo.getRepoByUrl(any())).thenReturn(Optional.of(new RepoResult()));
    AdminRouteService adminRouteService = new AdminRouteService(mockSQLiteRepo, null, mockJobService, null, null, null, mockValidatorService, null, Singleton.getLogger());
    Request mockRequest = mock(Request.class);
    when(mockRequest.queryParamsValues("reponame")).thenReturn("name,name".split(","));
    when(mockRequest.queryParamsValues("reposcm")).thenReturn("git,git".split(","));
    when(mockRequest.queryParamsValues("repourl")).thenReturn("url,url".split(","));
    when(mockRequest.queryParamsValues("repousername")).thenReturn("username,username".split(","));
    when(mockRequest.queryParamsValues("repopassword")).thenReturn("password,password".split(","));
    when(mockRequest.queryParamsValues("reposource")).thenReturn("source,source".split(","));
    when(mockRequest.queryParamsValues("repobranch")).thenReturn("source,source".split(","));
    when(mockRequest.queryParamsValues("source")).thenReturn("source,source".split(","));
    when(mockRequest.queryParamsValues("sourceuser")).thenReturn("master,master".split(","));
    when(mockRequest.queryParamsValues("sourceproject")).thenReturn("master,master".split(","));
    adminRouteService.postRepo(mockRequest, null, false);
    verify(mockSQLiteRepo, times(2)).saveRepo(any());
    verify(mockJobService, times(2)).forceEnqueue(any());
    verify(mockValidatorService, times(2)).validate(any(), anyBoolean());
}
Also used : ValidatorResult(com.searchcode.app.model.ValidatorResult) SQLiteRepo(com.searchcode.app.dao.SQLiteRepo) AdminRouteService(com.searchcode.app.service.route.AdminRouteService) Request(spark.Request) RepoResult(com.searchcode.app.model.RepoResult)

Aggregations

SQLiteRepo (com.searchcode.app.dao.SQLiteRepo)31 Request (spark.Request)28 Helpers (com.searchcode.app.util.Helpers)27 ApiRouteService (com.searchcode.app.service.route.ApiRouteService)24 LoggerWrapper (com.searchcode.app.util.LoggerWrapper)24 RepoResultApiResponse (com.searchcode.app.dto.api.RepoResultApiResponse)22 ApiResponse (com.searchcode.app.dto.api.ApiResponse)20 RepoResult (com.searchcode.app.model.RepoResult)12 ValidatorResult (com.searchcode.app.model.ValidatorResult)5 AdminRouteService (com.searchcode.app.service.route.AdminRouteService)4 UniqueRepoQueue (com.searchcode.app.util.UniqueRepoQueue)3 Matchers.anyString (org.mockito.Matchers.anyString)2 SQLiteMemoryDatabaseConfig (com.searchcode.app.config.SQLiteMemoryDatabaseConfig)1 Data (com.searchcode.app.dao.Data)1 CodeResult (com.searchcode.app.dto.CodeResult)1 IIndexService (com.searchcode.app.service.index.IIndexService)1 IndexService (com.searchcode.app.service.index.IndexService)1 CodeRouteService (com.searchcode.app.service.route.CodeRouteService)1