Search in sources :

Example 41 with Helpers

use of com.searchcode.app.util.Helpers in project searchcode-server by boyter.

the class ApiServiceTest method testValidateRequestInCorrectHmac.

public void testValidateRequestInCorrectHmac() {
    var apiMock = mock(Api.class);
    when(apiMock.getApiByPublicKey("publicKey")).thenReturn(Optional.of(new ApiResult(1, "publicKey", "privateKey", "", "")));
    var service = new ApiService(apiMock, new Helpers());
    var actual = service.validateRequest("publicKey", "incorrecthmac", "stringtohmac", ApiService.HmacType.SHA1);
    assertFalse(actual);
}
Also used : ApiResult(com.searchcode.app.model.ApiResult) Helpers(com.searchcode.app.util.Helpers)

Example 42 with Helpers

use of com.searchcode.app.util.Helpers in project searchcode-server by boyter.

the class StatsServiceTest method testIncrementSearchIntergerOverflow.

public void testIncrementSearchIntergerOverflow() {
    Data dataMock = Mockito.mock(Data.class);
    when(dataMock.getDataByName(Values.CACHE_TOTAL_SEARCH, "0")).thenReturn("" + Integer.MAX_VALUE);
    StatsService statsService = new StatsService(dataMock, new Helpers());
    statsService.incrementSearchCount();
    verify(dataMock, times(1)).saveData(Values.CACHE_TOTAL_SEARCH, "1");
}
Also used : Helpers(com.searchcode.app.util.Helpers) Data(com.searchcode.app.dao.Data)

Example 43 with Helpers

use of com.searchcode.app.util.Helpers in project searchcode-server by boyter.

the class StatsServiceTest method testIncrementSearchCountTwo.

public void testIncrementSearchCountTwo() {
    Data dataMock = Mockito.mock(Data.class);
    when(dataMock.getDataByName(Values.CACHE_TOTAL_SEARCH, "0")).thenReturn("100");
    StatsService statsService = new StatsService(dataMock, new Helpers());
    statsService.incrementSearchCount();
    verify(dataMock, times(1)).saveData(Values.CACHE_TOTAL_SEARCH, "101");
}
Also used : Helpers(com.searchcode.app.util.Helpers) Data(com.searchcode.app.dao.Data)

Example 44 with Helpers

use of com.searchcode.app.util.Helpers in project searchcode-server by boyter.

the class ValidatorServiceTest method testValidatorServiceExistingNameIgnored.

public void testValidatorServiceExistingNameIgnored() {
    SQLiteRepo mockSQLiteRepo = mock(SQLiteRepo.class);
    ValidatorService validatorService = new ValidatorService(mockSQLiteRepo, new Helpers());
    when(mockSQLiteRepo.getRepoByName("exists")).thenReturn(Optional.of(new RepoResult()));
    RepoResult repoResult = new RepoResult().setRowId(0).setName("exists").setScm("something").setUrl("url").setUsername("").setPassword("").setSource("source").setBranch("branch").setData("{}");
    ValidatorResult validate = validatorService.validate(repoResult, true);
    assertThat(validate.isValid).isTrue();
}
Also used : Helpers(com.searchcode.app.util.Helpers) ValidatorResult(com.searchcode.app.model.ValidatorResult) SQLiteRepo(com.searchcode.app.dao.SQLiteRepo) RepoResult(com.searchcode.app.model.RepoResult)

Example 45 with Helpers

use of com.searchcode.app.util.Helpers in project searchcode-server by boyter.

the class ValidatorServiceTest method testValidatorServiceExistingName.

public void testValidatorServiceExistingName() {
    SQLiteRepo mockSQLiteRepo = mock(SQLiteRepo.class);
    ValidatorService validatorService = new ValidatorService(mockSQLiteRepo, new Helpers());
    when(mockSQLiteRepo.getRepoByName("exists")).thenReturn(Optional.of(new RepoResult()));
    RepoResult repoResult = new RepoResult().setRowId(0).setName("exists").setScm("something").setUrl("url").setUsername("").setPassword("").setSource("source").setBranch("branch").setData("{}");
    ValidatorResult validate = validatorService.validate(repoResult, false);
    assertThat(validate.isValid).isFalse();
}
Also used : Helpers(com.searchcode.app.util.Helpers) ValidatorResult(com.searchcode.app.model.ValidatorResult) SQLiteRepo(com.searchcode.app.dao.SQLiteRepo) RepoResult(com.searchcode.app.model.RepoResult)

Aggregations

Helpers (com.searchcode.app.util.Helpers)53 LoggerWrapper (com.searchcode.app.util.LoggerWrapper)32 ApiRouteService (com.searchcode.app.service.route.ApiRouteService)31 Request (spark.Request)31 RepoResultApiResponse (com.searchcode.app.dto.api.RepoResultApiResponse)29 SQLiteRepo (com.searchcode.app.dao.SQLiteRepo)27 ApiResponse (com.searchcode.app.dto.api.ApiResponse)26 RepoResult (com.searchcode.app.model.RepoResult)12 ApiResult (com.searchcode.app.model.ApiResult)9 Data (com.searchcode.app.dao.Data)5 ValidatorResult (com.searchcode.app.model.ValidatorResult)4 IndexService (com.searchcode.app.service.index.IndexService)3 UniqueRepoQueue (com.searchcode.app.util.UniqueRepoQueue)3 SQLiteMemoryDatabaseConfig (com.searchcode.app.config.SQLiteMemoryDatabaseConfig)2 SourceResult (com.searchcode.app.model.SourceResult)2 Matchers.anyString (org.mockito.Matchers.anyString)2 CodeIndexDocument (com.searchcode.app.dto.CodeIndexDocument)1 CodeResult (com.searchcode.app.dto.CodeResult)1 SearchResult (com.searchcode.app.dto.SearchResult)1 CodeRouteService (com.searchcode.app.service.route.CodeRouteService)1