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