use of org.sonar.db.project.ProjectDto in project sonarqube by SonarSource.
the class SearchGitlabReposActionTest method list_gitlab_repos.
@Test
public void list_gitlab_repos() {
Project gitlabProject1 = new Project(1L, "repoName1", "repoNamePath1", "repo-slug-1", "repo-path-slug-1", "url-1");
Project gitlabProject2 = new Project(2L, "repoName2", "path1 / repoName2", "repo-slug-2", "path-1/repo-slug-2", "url-2");
Project gitlabProject3 = new Project(3L, "repoName3", "repoName3 / repoName3", "repo-slug-3", "repo-slug-3/repo-slug-3", "url-3");
Project gitlabProject4 = new Project(4L, "repoName4", "repoName4 / repoName4 / repoName4", "repo-slug-4", "repo-slug-4/repo-slug-4/repo-slug-4", "url-4");
when(gitlabHttpClient.searchProjects(any(), any(), any(), anyInt(), anyInt())).thenReturn(new ProjectList(Arrays.asList(gitlabProject1, gitlabProject2, gitlabProject3, gitlabProject4), 1, 10, 4));
UserDto user = db.users().insertUser();
userSession.logIn(user).addPermission(PROVISION_PROJECTS);
AlmSettingDto almSetting = db.almSettings().insertGitlabAlmSetting();
db.almPats().insert(dto -> {
dto.setAlmSettingUuid(almSetting.getUuid());
dto.setUserUuid(user.getUuid());
dto.setPersonalAccessToken("some-pat");
});
ProjectDto projectDto = db.components().insertPrivateProjectDto();
db.almSettings().insertGitlabProjectAlmSetting(almSetting, projectDto);
AlmIntegrations.SearchGitlabReposWsResponse response = ws.newRequest().setParam("almSetting", almSetting.getKey()).executeProtobuf(SearchGitlabReposWsResponse.class);
assertThat(response.getRepositoriesCount()).isEqualTo(4);
assertThat(response.getRepositoriesList()).extracting(GitlabRepository::getId, GitlabRepository::getName, GitlabRepository::getPathName, GitlabRepository::getSlug, GitlabRepository::getPathSlug, GitlabRepository::getUrl, GitlabRepository::hasSqProjectKey, GitlabRepository::hasSqProjectName).containsExactlyInAnyOrder(tuple(1L, "repoName1", "repoNamePath1", "repo-slug-1", "repo-path-slug-1", "url-1", false, false), tuple(2L, "repoName2", "path1", "repo-slug-2", "path-1", "url-2", false, false), tuple(3L, "repoName3", "repoName3", "repo-slug-3", "repo-slug-3", "url-3", false, false), tuple(4L, "repoName4", "repoName4 / repoName4", "repo-slug-4", "repo-slug-4/repo-slug-4", "url-4", false, false));
}
use of org.sonar.db.project.ProjectDto in project sonarqube by SonarSource.
the class SearchGitlabReposActionTest method return_empty_list_when_no_gitlab_projects.
@Test
public void return_empty_list_when_no_gitlab_projects() {
when(gitlabHttpClient.searchProjects(any(), any(), any(), anyInt(), anyInt())).thenReturn(new ProjectList(new LinkedList<>(), 1, 10, 0));
UserDto user = db.users().insertUser();
userSession.logIn(user).addPermission(PROVISION_PROJECTS);
AlmSettingDto almSetting = db.almSettings().insertBitbucketAlmSetting();
db.almPats().insert(dto -> {
dto.setAlmSettingUuid(almSetting.getUuid());
dto.setUserUuid(user.getUuid());
});
ProjectDto projectDto = db.components().insertPrivateProjectDto();
db.almSettings().insertGitlabProjectAlmSetting(almSetting, projectDto);
AlmIntegrations.SearchGitlabReposWsResponse response = ws.newRequest().setParam("almSetting", almSetting.getKey()).executeProtobuf(SearchGitlabReposWsResponse.class);
assertThat(response.getRepositoriesList()).isEmpty();
}
use of org.sonar.db.project.ProjectDto in project sonarqube by SonarSource.
the class CountBindingActionTest method count_github_binding.
@Test
public void count_github_binding() {
UserDto user = db.users().insertUser();
userSession.logIn(user).setSystemAdministrator();
AlmSettingDto almSetting = db.almSettings().insertGitHubAlmSetting();
ProjectDto project1 = db.components().insertPrivateProjectDto();
ProjectDto project2 = db.components().insertPrivateProjectDto();
db.almSettings().insertGitHubProjectAlmSetting(almSetting, project1);
db.almSettings().insertGitHubProjectAlmSetting(almSetting, project2);
CountBindingWsResponse response = ws.newRequest().setParam("almSetting", almSetting.getKey()).executeProtobuf(CountBindingWsResponse.class);
assertThat(response.getKey()).isEqualTo(almSetting.getKey());
assertThat(response.getProjects()).isEqualTo(2);
}
use of org.sonar.db.project.ProjectDto in project sonarqube by SonarSource.
the class ImportGitLabProjectActionTest method import_project_with_specific_different_default_branch.
@Test
public void import_project_with_specific_different_default_branch() {
UserDto user = db.users().insertUser();
userSession.logIn(user).addPermission(PROVISION_PROJECTS);
AlmSettingDto almSetting = db.almSettings().insertGitlabAlmSetting();
db.almPats().insert(dto -> {
dto.setAlmSettingUuid(almSetting.getUuid());
dto.setUserUuid(user.getUuid());
dto.setPersonalAccessToken("PAT");
});
Project project = getGitlabProject();
when(gitlabHttpClient.getProject(any(), any(), any())).thenReturn(project);
when(gitlabHttpClient.getBranches(any(), any(), any())).thenReturn(singletonList(new GitLabBranch("main", true)));
when(uuidFactory.create()).thenReturn("uuid");
Projects.CreateWsResponse response = ws.newRequest().setParam("almSetting", almSetting.getKey()).setParam("gitlabProjectId", "12345").executeProtobuf(Projects.CreateWsResponse.class);
verify(gitlabHttpClient).getProject(almSetting.getUrl(), "PAT", 12345L);
verify(gitlabHttpClient).getBranches(almSetting.getUrl(), "PAT", 12345L);
Projects.CreateWsResponse.Project result = response.getProject();
assertThat(result.getKey()).isEqualTo(project.getPathWithNamespace() + "_uuid");
assertThat(result.getName()).isEqualTo(project.getName());
Optional<ProjectDto> projectDto = db.getDbClient().projectDao().selectProjectByKey(db.getSession(), result.getKey());
assertThat(projectDto).isPresent();
assertThat(db.getDbClient().projectAlmSettingDao().selectByProject(db.getSession(), projectDto.get())).isPresent();
Assertions.assertThat(db.getDbClient().branchDao().selectByProject(db.getSession(), projectDto.get())).extracting(BranchDto::getKey, BranchDto::isMain).containsExactlyInAnyOrder(tuple("main", true));
}
use of org.sonar.db.project.ProjectDto in project sonarqube by SonarSource.
the class ImportAzureProjectActionTest method import_project.
@Test
public void import_project() {
UserDto user = db.users().insertUser();
userSession.logIn(user).addPermission(PROVISION_PROJECTS);
AlmSettingDto almSetting = db.almSettings().insertAzureAlmSetting();
db.almPats().insert(dto -> {
dto.setAlmSettingUuid(almSetting.getUuid());
dto.setPersonalAccessToken(almSetting.getDecryptedPersonalAccessToken(encryption));
dto.setUserUuid(user.getUuid());
});
GsonAzureRepo repo = getGsonAzureRepo();
when(azureDevOpsHttpClient.getRepo(almSetting.getUrl(), almSetting.getDecryptedPersonalAccessToken(encryption), "project-name", "repo-name")).thenReturn(repo);
Projects.CreateWsResponse response = ws.newRequest().setParam("almSetting", almSetting.getKey()).setParam("projectName", "project-name").setParam("repositoryName", "repo-name").executeProtobuf(Projects.CreateWsResponse.class);
Projects.CreateWsResponse.Project result = response.getProject();
assertThat(result.getKey()).isEqualTo(repo.getProject().getName() + "_" + repo.getName());
assertThat(result.getName()).isEqualTo(repo.getName());
Optional<ProjectDto> projectDto = db.getDbClient().projectDao().selectProjectByKey(db.getSession(), result.getKey());
assertThat(projectDto).isPresent();
Optional<ProjectAlmSettingDto> projectAlmSettingDto = db.getDbClient().projectAlmSettingDao().selectByProject(db.getSession(), projectDto.get());
assertThat(projectAlmSettingDto.get().getAlmRepo()).isEqualTo("repo-name");
assertThat(projectAlmSettingDto.get().getAlmSettingUuid()).isEqualTo(almSetting.getUuid());
assertThat(projectAlmSettingDto.get().getAlmSlug()).isEqualTo("project-name");
Optional<BranchDto> mainBranch = db.getDbClient().branchDao().selectByProject(db.getSession(), projectDto.get()).stream().filter(BranchDto::isMain).findFirst();
assertThat(mainBranch).isPresent();
assertThat(mainBranch.get().getKey()).hasToString("repo-default-branch");
}
Aggregations