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