Search in sources :

Example 6 with Project

use of org.sonar.alm.client.gitlab.Project in project sonarqube by SonarSource.

the class SearchGitlabReposActionTest method verify_response_example.

@Test
public void verify_response_example() {
    Project gitlabProject1 = new Project(1L, "Gitlab repo name 1", "Group / Gitlab repo name 1", "gitlab-repo-name-1", "group/gitlab-repo-name-1", "https://example.gitlab.com/group/gitlab-repo-name-1");
    Project gitlabProject2 = new Project(2L, "Gitlab repo name 2", "Group / Gitlab repo name 2", "gitlab-repo-name-2", "group/gitlab-repo-name-2", "https://example.gitlab.com/group/gitlab-repo-name-2");
    Project gitlabProject3 = new Project(3L, "Gitlab repo name 3", "Group / Gitlab repo name 3", "gitlab-repo-name-3", "group/gitlab-repo-name-3", "https://example.gitlab.com/group/gitlab-repo-name-3");
    when(gitlabHttpClient.searchProjects(any(), any(), any(), anyInt(), anyInt())).thenReturn(new ProjectList(Arrays.asList(gitlabProject1, gitlabProject2, gitlabProject3), 1, 3, 10));
    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);
    WebService.Action def = ws.getDef();
    String responseExample = def.responseExampleAsString();
    assertThat(responseExample).isNotBlank();
    ws.newRequest().setParam("almSetting", almSetting.getKey()).execute().assertJson(responseExample);
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) Project(org.sonar.alm.client.gitlab.Project) WebService(org.sonar.api.server.ws.WebService) ProjectList(org.sonar.alm.client.gitlab.ProjectList) UserDto(org.sonar.db.user.UserDto) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) Test(org.junit.Test)

Example 7 with Project

use of org.sonar.alm.client.gitlab.Project in project sonarqube by SonarSource.

the class ImportGitLabProjectActionTest method import_project.

@Test
public void import_project() {
    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("master", 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);
    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();
}
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 8 with Project

use of org.sonar.alm.client.gitlab.Project in project sonarqube by SonarSource.

the class ImportGitLabProjectActionTest method import_project_no_gitlab_default_branch.

@Test
public void import_project_no_gitlab_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(emptyList());
    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("master", 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) Test(org.junit.Test)

Aggregations

Project (org.sonar.alm.client.gitlab.Project)8 AlmSettingDto (org.sonar.db.alm.setting.AlmSettingDto)8 Test (org.junit.Test)6 ProjectDto (org.sonar.db.project.ProjectDto)6 UserDto (org.sonar.db.user.UserDto)6 ProjectList (org.sonar.alm.client.gitlab.ProjectList)4 AlmIntegrations (org.sonarqube.ws.AlmIntegrations)3 Projects (org.sonarqube.ws.Projects)3 GitLabBranch (org.sonar.alm.client.gitlab.GitLabBranch)2 WebService (org.sonar.api.server.ws.WebService)2 DbSession (org.sonar.db.DbSession)2 AlmPatDto (org.sonar.db.alm.pat.AlmPatDto)2 ProjectAlmSettingDto (org.sonar.db.alm.setting.ProjectAlmSettingDto)2 SearchGitlabReposWsResponse (org.sonarqube.ws.AlmIntegrations.SearchGitlabReposWsResponse)2 List (java.util.List)1 Map (java.util.Map)1 Objects.requireNonNull (java.util.Objects.requireNonNull)1 Optional (java.util.Optional)1 Set (java.util.Set)1 BinaryOperator (java.util.function.BinaryOperator)1