aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-webserver-common
diff options
context:
space:
mode:
authorWojtek Wajerowicz <115081248+wojciech-wajerowicz-sonarsource@users.noreply.github.com>2024-04-11 09:55:12 +0200
committersonartech <sonartech@sonarsource.com>2024-04-11 20:02:47 +0000
commit819c96c042e6bfafb924cc40329e59f85a80d2d7 (patch)
tree93340f294c9d89317b46a3ab50f86f1dbefaa10d /server/sonar-webserver-common
parentef0cf89eccf70533372c46d150e38ee05ac70d3e (diff)
downloadsonarqube-819c96c042e6bfafb924cc40329e59f85a80d2d7.tar.gz
sonarqube-819c96c042e6bfafb924cc40329e59f85a80d2d7.zip
SONAR-21898 make ALM/DOP types consistent between v1 and v2 endpoints.
Diffstat (limited to 'server/sonar-webserver-common')
-rw-r--r--server/sonar-webserver-common/src/main/java/org/sonar/server/common/AlmSettingMapper.java39
-rw-r--r--server/sonar-webserver-common/src/test/java/org/sonar/server/common/AlmSettingMapperTest.java40
2 files changed, 79 insertions, 0 deletions
diff --git a/server/sonar-webserver-common/src/main/java/org/sonar/server/common/AlmSettingMapper.java b/server/sonar-webserver-common/src/main/java/org/sonar/server/common/AlmSettingMapper.java
new file mode 100644
index 00000000000..e6397e58fbc
--- /dev/null
+++ b/server/sonar-webserver-common/src/main/java/org/sonar/server/common/AlmSettingMapper.java
@@ -0,0 +1,39 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.common;
+
+import org.sonar.db.alm.setting.ALM;
+import org.sonarqube.ws.AlmSettings;
+
+public class AlmSettingMapper {
+
+ private AlmSettingMapper() {
+ }
+
+ public static AlmSettings.Alm toResponseAlm(ALM alm) {
+ return switch (alm) {
+ case GITHUB -> AlmSettings.Alm.github;
+ case BITBUCKET -> AlmSettings.Alm.bitbucket;
+ case BITBUCKET_CLOUD -> AlmSettings.Alm.bitbucketcloud;
+ case AZURE_DEVOPS -> AlmSettings.Alm.azure;
+ case GITLAB -> AlmSettings.Alm.gitlab;
+ };
+ }
+}
diff --git a/server/sonar-webserver-common/src/test/java/org/sonar/server/common/AlmSettingMapperTest.java b/server/sonar-webserver-common/src/test/java/org/sonar/server/common/AlmSettingMapperTest.java
new file mode 100644
index 00000000000..0d14b2e9126
--- /dev/null
+++ b/server/sonar-webserver-common/src/test/java/org/sonar/server/common/AlmSettingMapperTest.java
@@ -0,0 +1,40 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.common;
+
+import org.junit.jupiter.api.Test;
+import org.sonar.db.alm.setting.ALM;
+import org.sonarqube.ws.AlmSettings;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+class AlmSettingMapperTest {
+
+
+ @Test
+ void toResponseAlm_shouldCorrectlyMapAlms() {
+ assertThat(AlmSettingMapper.toResponseAlm(ALM.GITHUB)).isEqualTo(AlmSettings.Alm.github);
+ assertThat(AlmSettingMapper.toResponseAlm(ALM.BITBUCKET)).isEqualTo(AlmSettings.Alm.bitbucket);
+ assertThat(AlmSettingMapper.toResponseAlm(ALM.BITBUCKET_CLOUD)).isEqualTo(AlmSettings.Alm.bitbucketcloud);
+ assertThat(AlmSettingMapper.toResponseAlm(ALM.AZURE_DEVOPS)).isEqualTo(AlmSettings.Alm.azure);
+ assertThat(AlmSettingMapper.toResponseAlm(ALM.GITLAB)).isEqualTo(AlmSettings.Alm.gitlab);
+ }
+
+} \ No newline at end of file