use of org.sonar.alm.client.azure.GsonAzureRepoList in project sonarqube by SonarSource.
the class SearchAzureReposActionTest method search_repos_with_same_name_and_different_project.
@Test
public void search_repos_with_same_name_and_different_project() {
mockClient(new GsonAzureRepoList(ImmutableList.of(getGsonAzureRepo("project-1", "repoName-1"), getGsonAzureRepo("project-2", "repoName-1"))));
AlmSettingDto almSetting = insertAlmSetting();
ProjectDto projectDto1 = insertProject(almSetting, "repoName-1", "project-1");
ProjectDto projectDto2 = insertProject(almSetting, "repoName-1", "project-2");
SearchAzureReposWsResponse response = ws.newRequest().setParam("almSetting", almSetting.getKey()).executeProtobuf(SearchAzureReposWsResponse.class);
assertThat(response.getRepositoriesCount()).isEqualTo(2);
assertThat(response.getRepositoriesList()).extracting(AzureRepo::getName, AzureRepo::getProjectName, AzureRepo::getSqProjectKey, AzureRepo::getSqProjectName).containsExactlyInAnyOrder(tuple("repoName-1", "project-1", projectDto1.getKey(), projectDto1.getName()), tuple("repoName-1", "project-2", projectDto2.getKey(), projectDto2.getName()));
}
use of org.sonar.alm.client.azure.GsonAzureRepoList in project sonarqube by SonarSource.
the class SearchAzureReposActionTest method return_empty_list_when_there_are_no_azure_repos.
@Test
public void return_empty_list_when_there_are_no_azure_repos() {
when(azureDevOpsHttpClient.getRepos(any(), any(), any())).thenReturn(new GsonAzureRepoList(emptyList()));
AlmSettingDto almSetting = insertAlmSetting();
SearchAzureReposWsResponse response = ws.newRequest().setParam("almSetting", almSetting.getKey()).executeProtobuf(SearchAzureReposWsResponse.class);
assertThat(response.getRepositoriesList()).isEmpty();
}
use of org.sonar.alm.client.azure.GsonAzureRepoList in project sonarqube by SonarSource.
the class SearchAzureReposActionTest method search_and_filter_repos_with_matching_repo_and_project_name.
@Test
public void search_and_filter_repos_with_matching_repo_and_project_name() {
mockClient(new GsonAzureRepoList(ImmutableList.of(getGsonAzureRepo("big-project", "repo-1"), getGsonAzureRepo("big-project", "repo-2"), getGsonAzureRepo("big-project", "big-repo"), getGsonAzureRepo("project", "big-repo"), getGsonAzureRepo("project", "small-repo"))));
AlmSettingDto almSetting = insertAlmSetting();
SearchAzureReposWsResponse response = ws.newRequest().setParam("almSetting", almSetting.getKey()).setParam("searchQuery", "big").executeProtobuf(SearchAzureReposWsResponse.class);
assertThat(response.getRepositoriesList()).extracting(AzureRepo::getName, AzureRepo::getProjectName).containsExactlyInAnyOrder(tuple("repo-1", "big-project"), tuple("repo-2", "big-project"), tuple("big-repo", "big-project"), tuple("big-repo", "project"));
}
use of org.sonar.alm.client.azure.GsonAzureRepoList in project sonarqube by SonarSource.
the class SearchAzureReposAction method doHandle.
private SearchAzureReposWsResponse doHandle(Request request) {
try (DbSession dbSession = dbClient.openSession(false)) {
userSession.checkLoggedIn().checkPermission(PROVISION_PROJECTS);
String almSettingKey = request.mandatoryParam(PARAM_ALM_SETTING);
String userUuid = requireNonNull(userSession.getUuid(), "User UUID cannot be null");
AlmSettingDto almSettingDto = dbClient.almSettingDao().selectByKey(dbSession, almSettingKey).orElseThrow(() -> new NotFoundException(String.format("ALM Setting '%s' not found", almSettingKey)));
Optional<AlmPatDto> almPatDto = dbClient.almPatDao().selectByUserAndAlmSetting(dbSession, userUuid, almSettingDto);
String projectKey = request.param(PARAM_PROJECT_NAME);
String searchQuery = request.param(PARAM_SEARCH_QUERY);
String pat = almPatDto.map(AlmPatDto::getPersonalAccessToken).orElseThrow(() -> new IllegalArgumentException("No personal access token found"));
String url = requireNonNull(almSettingDto.getUrl(), "ALM url cannot be null");
GsonAzureRepoList gsonAzureRepoList = azureDevOpsHttpClient.getRepos(url, pat, projectKey);
Map<ProjectKeyName, ProjectDto> sqProjectsKeyByAzureKey = getSqProjectsKeyByCustomKey(dbSession, almSettingDto, gsonAzureRepoList);
List<AzureRepo> repositories = gsonAzureRepoList.getValues().stream().filter(r -> isSearchOnlyByProjectName(searchQuery) || doesSearchCriteriaMatchProjectOrRepo(r, searchQuery)).map(repo -> toAzureRepo(repo, sqProjectsKeyByAzureKey)).sorted(comparing(AzureRepo::getName, String::compareToIgnoreCase)).collect(toList());
LOG.debug(repositories.toString());
return SearchAzureReposWsResponse.newBuilder().addAllRepositories(repositories).build();
}
}
use of org.sonar.alm.client.azure.GsonAzureRepoList in project sonarqube by SonarSource.
the class SearchAzureReposActionTest method search_repos_alphabetically_sorted.
@Test
public void search_repos_alphabetically_sorted() {
mockClient(new GsonAzureRepoList(ImmutableList.of(getGsonAzureRepo("project-1", "Z-repo"), getGsonAzureRepo("project-1", "A-repo-1"), getGsonAzureRepo("project-1", "a-repo"), getGsonAzureRepo("project-1", "b-repo"))));
AlmSettingDto almSetting = insertAlmSetting();
SearchAzureReposWsResponse response = ws.newRequest().setParam("almSetting", almSetting.getKey()).executeProtobuf(SearchAzureReposWsResponse.class);
assertThat(response.getRepositoriesList()).extracting(AzureRepo::getName, AzureRepo::getProjectName).containsExactly(tuple("a-repo", "project-1"), tuple("A-repo-1", "project-1"), tuple("b-repo", "project-1"), tuple("Z-repo", "project-1"));
}
Aggregations