Search in sources :

Example 31 with AlmSettingDto

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())));
}
Also used : ProtobufSystemInfo(org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) Test(org.junit.Test)

Example 32 with AlmSettingDto

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());
}
Also used : UserDto(org.sonar.db.user.UserDto) AlmPatDto(org.sonar.db.alm.pat.AlmPatDto) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) Test(org.junit.Test)

Example 33 with AlmSettingDto

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", ""));
}
Also used : ListAzureProjectsWsResponse(org.sonarqube.ws.AlmIntegrations.ListAzureProjectsWsResponse) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) Test(org.junit.Test)

Example 34 with AlmSettingDto

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();
}
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) Repository(org.sonar.alm.client.bitbucket.bitbucketcloud.Repository) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) ProjectAlmSettingDto(org.sonar.db.alm.setting.ProjectAlmSettingDto) Test(org.junit.Test)

Example 35 with AlmSettingDto

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);
}
Also used : Repository(org.sonar.alm.client.bitbucket.bitbucketcloud.Repository) UserDto(org.sonar.db.user.UserDto) BadRequestException(org.sonar.server.exceptions.BadRequestException) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) ProjectAlmSettingDto(org.sonar.db.alm.setting.ProjectAlmSettingDto) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test)

Aggregations

AlmSettingDto (org.sonar.db.alm.setting.AlmSettingDto)217 Test (org.junit.Test)175 UserDto (org.sonar.db.user.UserDto)113 TestRequest (org.sonar.server.ws.TestRequest)48 ProjectDto (org.sonar.db.project.ProjectDto)40 NotFoundException (org.sonar.server.exceptions.NotFoundException)37 DbSession (org.sonar.db.DbSession)36 WebService (org.sonar.api.server.ws.WebService)31 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)28 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)28 Rule (org.junit.Rule)28 Mockito.mock (org.mockito.Mockito.mock)28 DbTester (org.sonar.db.DbTester)28 UserSessionRule (org.sonar.server.tester.UserSessionRule)28 WsActionTester (org.sonar.server.ws.WsActionTester)28 Encryption (org.sonar.api.config.internal.Encryption)27 ForbiddenException (org.sonar.server.exceptions.ForbiddenException)27 ComponentFinder (org.sonar.server.component.ComponentFinder)26 Tuple.tuple (org.assertj.core.groups.Tuple.tuple)25 ProjectAlmSettingDto (org.sonar.db.alm.setting.ProjectAlmSettingDto)25