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);
}
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();
}
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));
}
Aggregations