Search in sources :

Example 76 with ProjectDto

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));
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) Project(org.sonar.alm.client.gitlab.Project) ProjectList(org.sonar.alm.client.gitlab.ProjectList) UserDto(org.sonar.db.user.UserDto) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) SearchGitlabReposWsResponse(org.sonarqube.ws.AlmIntegrations.SearchGitlabReposWsResponse) AlmIntegrations(org.sonarqube.ws.AlmIntegrations) Test(org.junit.Test)

Example 77 with ProjectDto

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();
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) ProjectList(org.sonar.alm.client.gitlab.ProjectList) UserDto(org.sonar.db.user.UserDto) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) SearchGitlabReposWsResponse(org.sonarqube.ws.AlmIntegrations.SearchGitlabReposWsResponse) LinkedList(java.util.LinkedList) AlmIntegrations(org.sonarqube.ws.AlmIntegrations) Test(org.junit.Test)

Example 78 with ProjectDto

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);
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) UserDto(org.sonar.db.user.UserDto) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) CountBindingWsResponse(org.sonarqube.ws.AlmSettings.CountBindingWsResponse) Test(org.junit.Test)

Example 79 with ProjectDto

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));
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) Project(org.sonar.alm.client.gitlab.Project) UserDto(org.sonar.db.user.UserDto) Projects(org.sonarqube.ws.Projects) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) GitLabBranch(org.sonar.alm.client.gitlab.GitLabBranch) Test(org.junit.Test)

Example 80 with ProjectDto

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");
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) BranchDto(org.sonar.db.component.BranchDto) ProjectAlmSettingDto(org.sonar.db.alm.setting.ProjectAlmSettingDto) UserDto(org.sonar.db.user.UserDto) Projects(org.sonarqube.ws.Projects) GsonAzureRepo(org.sonar.alm.client.azure.GsonAzureRepo) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) ProjectAlmSettingDto(org.sonar.db.alm.setting.ProjectAlmSettingDto) Test(org.junit.Test)

Aggregations

ProjectDto (org.sonar.db.project.ProjectDto)283 Test (org.junit.Test)215 DbSession (org.sonar.db.DbSession)49 BranchDto (org.sonar.db.component.BranchDto)42 UserDto (org.sonar.db.user.UserDto)39 AlmSettingDto (org.sonar.db.alm.setting.AlmSettingDto)38 QProfileDto (org.sonar.db.qualityprofile.QProfileDto)31 SnapshotDto (org.sonar.db.component.SnapshotDto)27 QualityGateDto (org.sonar.db.qualitygate.QualityGateDto)26 ComponentDto (org.sonar.db.component.ComponentDto)23 ComponentTesting.newPrivateProjectDto (org.sonar.db.component.ComponentTesting.newPrivateProjectDto)20 NotFoundException (org.sonar.server.exceptions.NotFoundException)17 WebhookDto (org.sonar.db.webhook.WebhookDto)15 ApplicationProjectDto (org.sonar.db.project.ApplicationProjectDto)14 WebService (org.sonar.api.server.ws.WebService)13 DbClient (org.sonar.db.DbClient)12 PortfolioProjectDto (org.sonar.db.portfolio.PortfolioProjectDto)12 TestRequest (org.sonar.server.ws.TestRequest)11 TestResponse (org.sonar.server.ws.TestResponse)10 Projects (org.sonarqube.ws.Projects)10