]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-12512 SONAR-12514 SONAR-515 Add multipleAlmEnabled in the payload
authorPierre Guillot <pierre.guillot@sonarsource.com>
Wed, 4 Dec 2019 15:42:46 +0000 (16:42 +0100)
committerSonarTech <sonartech@sonarsource.com>
Mon, 9 Dec 2019 19:46:18 +0000 (20:46 +0100)
server/sonar-server-common/src/main/java/org/sonar/server/almsettings/MultipleAlmFeatureProvider.java [new file with mode: 0644]
server/sonar-server-common/src/test/java/org/sonar/server/almsettings/MultipleAlmFeatureProviderTest.java [new file with mode: 0644]
server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/GlobalAction.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/GlobalActionTest.java
server/sonar-webserver/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java

diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/almsettings/MultipleAlmFeatureProvider.java b/server/sonar-server-common/src/main/java/org/sonar/server/almsettings/MultipleAlmFeatureProvider.java
new file mode 100644 (file)
index 0000000..abbf1c2
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 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.almsettings;
+
+import java.util.Optional;
+import org.sonar.core.platform.EditionProvider;
+import org.sonar.core.platform.PlatformEditionProvider;
+
+public class MultipleAlmFeatureProvider {
+
+  private PlatformEditionProvider editionProvider;
+
+  public MultipleAlmFeatureProvider(PlatformEditionProvider editionProvider) {
+    this.editionProvider = editionProvider;
+  }
+
+  public boolean enabled() {
+    Optional<EditionProvider.Edition> edition = editionProvider.get();
+    if (!edition.isPresent()) {
+      return false;
+    }
+    switch (edition.get()) {
+      case ENTERPRISE:
+      case DATACENTER:
+        return true;
+      default:
+        return false;
+    }
+  }
+
+}
diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/almsettings/MultipleAlmFeatureProviderTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/almsettings/MultipleAlmFeatureProviderTest.java
new file mode 100644 (file)
index 0000000..b5d2505
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 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.almsettings;
+
+import java.util.Optional;
+import org.assertj.core.api.Assertions;
+import org.junit.Test;
+import org.sonar.core.platform.EditionProvider;
+import org.sonar.core.platform.PlatformEditionProvider;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class MultipleAlmFeatureProviderTest {
+
+  private PlatformEditionProvider editionProvider = mock(PlatformEditionProvider.class);
+  private final MultipleAlmFeatureProvider underTest = new MultipleAlmFeatureProvider(editionProvider);
+
+  @Test
+  public void is_enabled_on_CE() {
+    when(editionProvider.get()).thenReturn(Optional.of(EditionProvider.Edition.COMMUNITY));
+    Assertions.assertThat(underTest.enabled()).isFalse();
+  }
+
+  @Test
+  public void is_enabled_on_DE() {
+    when(editionProvider.get()).thenReturn(Optional.of(EditionProvider.Edition.DEVELOPER));
+    Assertions.assertThat(underTest.enabled()).isFalse();
+  }
+
+  @Test
+  public void is_enabled_on_EE() {
+    when(editionProvider.get()).thenReturn(Optional.of(EditionProvider.Edition.ENTERPRISE));
+    Assertions.assertThat(underTest.enabled()).isTrue();
+  }
+
+  @Test
+  public void is_enabled_on_DCE() {
+    when(editionProvider.get()).thenReturn(Optional.of(EditionProvider.Edition.DATACENTER));
+    Assertions.assertThat(underTest.enabled()).isTrue();
+  }
+}
index cd363fb12fd62bcc80c41c5210c86610ba94f105..2d00a78df9e07890999fc603671a3a6e5634e90d 100644 (file)
@@ -38,6 +38,7 @@ import org.sonar.core.platform.PlatformEditionProvider;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.dialect.H2;
+import org.sonar.server.almsettings.MultipleAlmFeatureProvider;
 import org.sonar.server.branch.BranchFeatureProxy;
 import org.sonar.server.organization.DefaultOrganizationProvider;
 import org.sonar.server.organization.OrganizationFlags;
@@ -80,12 +81,13 @@ public class GlobalAction implements NavigationWsAction, Startable {
   private final BranchFeatureProxy branchFeature;
   private final UserSession userSession;
   private final PlatformEditionProvider editionProvider;
+  private final MultipleAlmFeatureProvider multipleAlmFeatureProvider;
   private final WebAnalyticsLoader webAnalyticsLoader;
 
   public GlobalAction(PageRepository pageRepository, Configuration config, ResourceTypes resourceTypes, Server server,
     WebServer webServer, DbClient dbClient, OrganizationFlags organizationFlags,
     DefaultOrganizationProvider defaultOrganizationProvider, BranchFeatureProxy branchFeature, UserSession userSession, PlatformEditionProvider editionProvider,
-    WebAnalyticsLoader webAnalyticsLoader) {
+    MultipleAlmFeatureProvider multipleAlmFeatureProvider, WebAnalyticsLoader webAnalyticsLoader) {
     this.pageRepository = pageRepository;
     this.config = config;
     this.resourceTypes = resourceTypes;
@@ -97,6 +99,7 @@ public class GlobalAction implements NavigationWsAction, Startable {
     this.branchFeature = branchFeature;
     this.userSession = userSession;
     this.editionProvider = editionProvider;
+    this.multipleAlmFeatureProvider = multipleAlmFeatureProvider;
     this.webAnalyticsLoader = webAnalyticsLoader;
     this.systemSettingValuesByKey = new HashMap<>();
   }
@@ -140,6 +143,7 @@ public class GlobalAction implements NavigationWsAction, Startable {
       writeDatabaseProduction(json);
       writeOrganizationSupport(json);
       writeBranchSupport(json);
+      writeMultipleAlmEnabled(json);
       editionProvider.get().ifPresent(e -> json.prop("edition", e.name().toLowerCase(Locale.ENGLISH)));
       json.prop("standalone", webServer.isStandalone());
       writeWebAnalytics(json);
@@ -202,6 +206,10 @@ public class GlobalAction implements NavigationWsAction, Startable {
     json.prop("branchesEnabled", branchFeature.isEnabled());
   }
 
+  private void writeMultipleAlmEnabled(JsonWriter json) {
+    json.prop("multipleAlmEnabled", multipleAlmFeatureProvider.enabled());
+  }
+
   private void writeWebAnalytics(JsonWriter json) {
     webAnalyticsLoader.getUrlPathToJs().ifPresent(p -> json.prop("webAnalyticsJsPath", p));
   }
index 0d4a2a29cd2c90b43bb494b349edebdc5f5be067..1bb8865d9d40fdac9fa4f6c9f73a6ad9f18b86af 100644 (file)
@@ -37,6 +37,7 @@ import org.sonar.core.platform.PluginRepository;
 import org.sonar.db.DbClient;
 import org.sonar.db.dialect.H2;
 import org.sonar.db.dialect.PostgreSql;
+import org.sonar.server.almsettings.MultipleAlmFeatureProvider;
 import org.sonar.server.organization.DefaultOrganizationProvider;
 import org.sonar.server.organization.TestDefaultOrganizationProvider;
 import org.sonar.server.organization.TestOrganizationFlags;
@@ -68,6 +69,7 @@ public class GlobalActionTest {
   private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.fromUuid("foo");
   private BranchFeatureRule branchFeature = new BranchFeatureRule();
   private PlatformEditionProvider editionProvider = mock(PlatformEditionProvider.class);
+  private MultipleAlmFeatureProvider multipleAlmFeatureProvider = mock(MultipleAlmFeatureProvider.class);
   private WebAnalyticsLoader webAnalyticsLoader = mock(WebAnalyticsLoader.class);
 
   private WsActionTester ws;
@@ -239,6 +241,17 @@ public class GlobalActionTest {
     assertJson(call()).isSimilarTo("{\"branchesEnabled\":false}");
   }
 
+  @Test
+  public void multiple_alm_enabled() {
+    init();
+    when(multipleAlmFeatureProvider.enabled()).thenReturn(true);
+    assertJson(call()).isSimilarTo("{\"multipleAlmEnabled\":true}");
+
+    when(multipleAlmFeatureProvider.enabled()).thenReturn(false);
+    assertJson(call()).isSimilarTo("{\"multipleAlmEnabled\":false}");
+
+  }
+
   @Test
   public void can_admin_on_global_level() {
     init();
@@ -350,7 +363,7 @@ public class GlobalActionTest {
     }});
     pageRepository.start();
     GlobalAction wsAction = new GlobalAction(pageRepository, settings.asConfig(), new ResourceTypes(resourceTypeTrees), server,
-      webServer, dbClient, organizationFlags, defaultOrganizationProvider, branchFeature, userSession, editionProvider, webAnalyticsLoader);
+      webServer, dbClient, organizationFlags, defaultOrganizationProvider, branchFeature, userSession, editionProvider, multipleAlmFeatureProvider, webAnalyticsLoader);
     ws = new WsActionTester(wsAction);
     wsAction.start();
   }
index 2c91bda2dd3a7cd48d5faeb90a099e17e47b668a..0c12f143a4c315f83858b76db7fba55164f3cf5e 100644 (file)
@@ -38,6 +38,7 @@ import org.sonar.core.component.DefaultResourceTypes;
 import org.sonar.core.extension.CoreExtensionsInstaller;
 import org.sonar.core.platform.ComponentContainer;
 import org.sonar.core.platform.PlatformEditionProvider;
+import org.sonar.server.almsettings.MultipleAlmFeatureProvider;
 import org.sonar.server.authentication.AuthenticationModule;
 import org.sonar.server.authentication.LogOAuthWarning;
 import org.sonar.server.authentication.ws.AuthenticationWsModule;
@@ -503,6 +504,8 @@ public class PlatformLevel4 extends PlatformLevel {
       CoreExtensionBootstraper.class,
       CoreExtensionStopper.class,
 
+      MultipleAlmFeatureProvider.class,
+
       // Compute engine (must be after Views and Developer Cockpit)
       ReportAnalysisFailureNotificationModule.class,
       CeModule.class,