3 * Copyright (C) 2009-2021 SonarSource SA
4 * mailto:info AT sonarsource DOT com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package org.sonar.server.platform.monitoring;
22 import org.junit.Rule;
23 import org.junit.Test;
24 import org.sonar.db.DbTester;
25 import org.sonar.db.alm.setting.AlmSettingDto;
26 import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo;
27 import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo.Attribute;
29 import static org.assertj.core.api.Assertions.assertThat;
30 import static org.assertj.core.api.Assertions.tuple;
32 public class AlmConfigurationSectionTest {
35 public DbTester db = DbTester.create();
37 private AlmConfigurationSection underTest = new AlmConfigurationSection(db.getDbClient());
40 public void alm_are_listed() {
41 AlmSettingDto azure = db.almSettings().insertAzureAlmSetting();
42 AlmSettingDto github = db.almSettings().insertGitHubAlmSetting();
43 AlmSettingDto gitlab = db.almSettings().insertGitlabAlmSetting();
44 AlmSettingDto bitbucket = db.almSettings().insertBitbucketAlmSetting();
45 AlmSettingDto bitbucketCloud = db.almSettings().insertBitbucketCloudAlmSetting();
47 ProtobufSystemInfo.Section section = underTest.toProtobuf();
49 assertThat(section.getAttributesList()).hasSize(5);
50 assertThat(section.getAttributesList())
51 .extracting(Attribute::getKey, Attribute::getStringValue)
52 .containsExactlyInAnyOrder(
53 tuple(azure.getKey(), String.format("alm:%s, url:%s", azure.getRawAlm(), azure.getUrl())),
54 tuple(github.getKey(), String.format("alm:%s, url:%s, appId:%s, clientId:%s", github.getRawAlm(), github.getUrl(), github.getAppId(), github.getClientId())),
55 tuple(gitlab.getKey(), String.format("alm:%s, url:%s", gitlab.getRawAlm(), gitlab.getUrl())),
56 tuple(bitbucket.getKey(), String.format("alm:%s, url:%s", bitbucket.getRawAlm(), bitbucket.getUrl())),
57 tuple(bitbucketCloud.getKey(), String.format("alm:%s, workspace id:%s, OAuth Key:%s", bitbucketCloud.getRawAlm(), bitbucketCloud.getAppId(), bitbucketCloud.getClientId())));
61 public void several_alm_same_type() {
62 AlmSettingDto gitlab1 = db.almSettings().insertGitlabAlmSetting();
63 AlmSettingDto gitlab2 = db.almSettings().insertGitlabAlmSetting();
65 ProtobufSystemInfo.Section section = underTest.toProtobuf();
67 assertThat(section.getAttributesList()).hasSize(2);
68 assertThat(section.getAttributesList())
69 .extracting(Attribute::getKey, Attribute::getStringValue)
70 .containsExactlyInAnyOrder(
71 tuple(gitlab1.getKey(), String.format("alm:%s, url:%s", gitlab1.getRawAlm(), gitlab1.getUrl())),
72 tuple(gitlab2.getKey(), String.format("alm:%s, url:%s", gitlab2.getRawAlm(), gitlab2.getUrl())));
76 public void null_url_are_ignored() {
77 AlmSettingDto azure = db.almSettings().insertAzureAlmSetting(a -> a.setUrl(null));
79 ProtobufSystemInfo.Section section = underTest.toProtobuf();
81 assertThat(section.getAttributesList()).hasSize(1);
82 assertThat(section.getAttributesList())
83 .extracting(Attribute::getKey, Attribute::getStringValue)
84 .containsExactlyInAnyOrder(
85 tuple(azure.getKey(), String.format("alm:%s", azure.getRawAlm())));