use of org.sonar.db.alm.setting.AlmSettingDto in project sonarqube by SonarSource.
the class AlmConfigurationSectionTest method several_alm_same_type.
@Test
public void several_alm_same_type() {
AlmSettingDto gitlab1 = db.almSettings().insertGitlabAlmSetting();
AlmSettingDto gitlab2 = db.almSettings().insertGitlabAlmSetting();
ProtobufSystemInfo.Section section = underTest.toProtobuf();
assertThat(section.getAttributesList()).hasSize(2);
assertThat(section.getAttributesList()).extracting(Attribute::getKey, Attribute::getStringValue).containsExactlyInAnyOrder(tuple(gitlab1.getKey(), String.format("Alm:%s, Url:%s", gitlab1.getRawAlm(), gitlab1.getUrl())), tuple(gitlab2.getKey(), String.format("Alm:%s, Url:%s", gitlab2.getRawAlm(), gitlab2.getUrl())));
}
use of org.sonar.db.alm.setting.AlmSettingDto in project sonarqube by SonarSource.
the class SetPatActionTest method set_new_bitbucketcloud_pat.
@Test
public void set_new_bitbucketcloud_pat() {
UserDto user = db.users().insertUser();
AlmSettingDto almSetting = db.almSettings().insertBitbucketCloudAlmSetting();
userSession.logIn(user).addPermission(PROVISION_PROJECTS);
String pat = "12345678987654321";
String username = "test-user";
ws.newRequest().setParam("almSetting", almSetting.getKey()).setParam("pat", pat).setParam("username", username).execute();
Optional<AlmPatDto> actualAlmPat = db.getDbClient().almPatDao().selectByUserAndAlmSetting(db.getSession(), user.getUuid(), almSetting);
assertThat(actualAlmPat).isPresent();
assertThat(actualAlmPat.get().getPersonalAccessToken()).isEqualTo(CredentialsEncoderHelper.encodeCredentials(ALM.BITBUCKET_CLOUD, pat, username));
assertThat(actualAlmPat.get().getUserUuid()).isEqualTo(user.getUuid());
assertThat(actualAlmPat.get().getAlmSettingUuid()).isEqualTo(almSetting.getUuid());
}
use of org.sonar.db.alm.setting.AlmSettingDto in project sonarqube by SonarSource.
the class ListAzureProjectsActionTest method list_projects.
@Test
public void list_projects() {
AlmSettingDto almSetting = insertAlmSetting();
ListAzureProjectsWsResponse response = ws.newRequest().setParam("almSetting", almSetting.getKey()).executeProtobuf(ListAzureProjectsWsResponse.class);
assertThat(response.getProjectsCount()).isEqualTo(2);
assertThat(response.getProjectsList()).extracting(AzureProject::getName, AzureProject::getDescription).containsExactly(tuple("name", "description"), tuple("name", ""));
}
use of org.sonar.db.alm.setting.AlmSettingDto in project sonarqube by SonarSource.
the class ImportBitbucketCloudRepoActionTest method import_project.
@Test
public void import_project() {
UserDto user = db.users().insertUser();
userSession.logIn(user).addPermission(PROVISION_PROJECTS);
AlmSettingDto almSetting = db.almSettings().insertBitbucketCloudAlmSetting();
db.almPats().insert(dto -> {
dto.setAlmSettingUuid(almSetting.getUuid());
dto.setUserUuid(user.getUuid());
});
Repository repo = getGsonBBCRepo();
when(bitbucketCloudRestClient.getRepo(any(), any(), any())).thenReturn(repo);
Projects.CreateWsResponse response = ws.newRequest().setParam("almSetting", almSetting.getKey()).setParam("repositorySlug", "repo-slug-1").executeProtobuf(Projects.CreateWsResponse.class);
Projects.CreateWsResponse.Project result = response.getProject();
assertThat(result.getKey()).isEqualTo(almSetting.getAppId() + "_" + repo.getSlug());
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).isPresent();
assertThat(projectAlmSettingDto.get().getAlmRepo()).isEqualTo("repo-slug-1");
Optional<BranchDto> branchDto = db.getDbClient().branchDao().selectByBranchKey(db.getSession(), projectDto.get().getUuid(), "develop");
assertThat(branchDto).isPresent();
assertThat(branchDto.get().isMain()).isTrue();
}
use of org.sonar.db.alm.setting.AlmSettingDto in project sonarqube by SonarSource.
the class ImportBitbucketCloudRepoActionTest method fail_project_already_exist.
@Test
public void fail_project_already_exist() {
UserDto user = db.users().insertUser();
userSession.logIn(user).addPermission(PROVISION_PROJECTS);
AlmSettingDto almSetting = db.almSettings().insertGitHubAlmSetting();
db.almPats().insert(dto -> {
dto.setAlmSettingUuid(almSetting.getUuid());
dto.setUserUuid(user.getUuid());
});
Repository repo = getGsonBBCRepo();
String projectKey = almSetting.getAppId() + "_" + repo.getSlug();
db.components().insertPublicProject(p -> p.setDbKey(projectKey));
when(bitbucketCloudRestClient.getRepo(any(), any(), any())).thenReturn(repo);
TestRequest request = ws.newRequest().setParam("almSetting", almSetting.getKey()).setParam("repositorySlug", "repo-slug-1");
assertThatThrownBy(request::execute).isInstanceOf(BadRequestException.class).hasMessageContaining("Could not create null, key already exists: " + projectKey);
}
Aggregations