use of org.sonarqube.ws.AlmIntegrations.ListGithubRepositoriesWsResponse in project sonarqube by SonarSource.
the class ListGithubRepositoriesActionTest method return_repositories_using_existing_personal_access_token.
@Test
public void return_repositories_using_existing_personal_access_token() {
AlmSettingDto githubAlmSettings = setupAlm();
AlmPatDto pat = db.almPats().insert(p -> p.setAlmSettingUuid(githubAlmSettings.getUuid()).setUserUuid(userSession.getUuid()));
when(appClient.listRepositories(eq(githubAlmSettings.getUrl()), argThat(token -> token.getValue().equals(pat.getPersonalAccessToken())), eq("github"), isNull(), eq(1), eq(100))).thenReturn(new GithubApplicationClient.Repositories().setTotal(2).setRepositories(Stream.of("HelloWorld", "HelloUniverse").map(name -> new GithubApplicationClient.Repository(name.length(), name, false, "github/" + name, "https://github-enterprise.sonarqube.com/api/v3/github/HelloWorld", "main")).collect(Collectors.toList())));
ProjectDto project = db.components().insertPrivateProjectDto(componentDto -> componentDto.setDbKey("github_HelloWorld"));
db.almSettings().insertGitHubProjectAlmSetting(githubAlmSettings, project, projectAlmSettingDto -> projectAlmSettingDto.setAlmRepo("github/HelloWorld"));
ProjectDto project2 = db.components().insertPrivateProjectDto(componentDto -> componentDto.setDbKey("github_HelloWorld2"));
db.almSettings().insertGitHubProjectAlmSetting(githubAlmSettings, project2, projectAlmSettingDto -> projectAlmSettingDto.setAlmRepo("github/HelloWorld"));
ListGithubRepositoriesWsResponse response = ws.newRequest().setParam(ListGithubRepositoriesAction.PARAM_ALM_SETTING, githubAlmSettings.getKey()).setParam(ListGithubRepositoriesAction.PARAM_ORGANIZATION, "github").executeProtobuf(ListGithubRepositoriesWsResponse.class);
assertThat(response.getPaging()).extracting(Common.Paging::getPageIndex, Common.Paging::getPageSize, Common.Paging::getTotal).containsOnly(1, 100, 2);
assertThat(response.getRepositoriesCount()).isEqualTo(2);
assertThat(response.getRepositoriesList()).extracting(GithubRepository::getKey, GithubRepository::getName, GithubRepository::getSqProjectKey).containsOnly(tuple("github/HelloWorld", "HelloWorld", project.getKey()), tuple("github/HelloUniverse", "HelloUniverse", ""));
verify(appClient).listRepositories(eq(githubAlmSettings.getUrl()), argThat(token -> token.getValue().equals(pat.getPersonalAccessToken())), eq("github"), isNull(), eq(1), eq(100));
}
Aggregations