Search in sources :

Example 1 with GitLabBranch

use of org.sonar.alm.client.gitlab.GitLabBranch 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 2 with GitLabBranch

use of org.sonar.alm.client.gitlab.GitLabBranch 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)

Aggregations

Test (org.junit.Test)2 GitLabBranch (org.sonar.alm.client.gitlab.GitLabBranch)2 Project (org.sonar.alm.client.gitlab.Project)2 AlmSettingDto (org.sonar.db.alm.setting.AlmSettingDto)2 ProjectDto (org.sonar.db.project.ProjectDto)2 UserDto (org.sonar.db.user.UserDto)2 Projects (org.sonarqube.ws.Projects)2