]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10015 add standalone flag to api/navigation/global
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Fri, 20 Oct 2017 12:28:14 +0000 (14:28 +0200)
committerGrégoire Aubert <gregoire.aubert@sonarsource.com>
Mon, 23 Oct 2017 15:01:13 +0000 (08:01 -0700)
server/sonar-server/src/main/java/org/sonar/server/ui/ws/GlobalAction.java
server/sonar-server/src/main/resources/org/sonar/server/ui/ws/global-example.json
server/sonar-server/src/test/java/org/sonar/server/ui/ws/GlobalActionTest.java

index 6ff1646ac0291435f36a5b2629c44c8829208f4d..131925733899f10470a9f8dcb0f0f8c46d3c5580 100644 (file)
@@ -35,6 +35,7 @@ import org.sonar.db.dialect.H2;
 import org.sonar.server.branch.BranchFeatureProxy;
 import org.sonar.server.organization.DefaultOrganizationProvider;
 import org.sonar.server.organization.OrganizationFlags;
+import org.sonar.server.platform.WebServer;
 import org.sonar.server.ui.PageRepository;
 import org.sonar.server.ui.VersionFormatter;
 import org.sonar.server.user.UserSession;
@@ -64,6 +65,7 @@ public class GlobalAction implements NavigationWsAction {
   private final Configuration config;
   private final ResourceTypes resourceTypes;
   private final Server server;
+  private final WebServer webServer;
   private final DbClient dbClient;
   private final OrganizationFlags organizationFlags;
   private final DefaultOrganizationProvider defaultOrganizationProvider;
@@ -71,11 +73,13 @@ public class GlobalAction implements NavigationWsAction {
   private final UserSession userSession;
 
   public GlobalAction(PageRepository pageRepository, Configuration config, ResourceTypes resourceTypes, Server server,
-    DbClient dbClient, OrganizationFlags organizationFlags, DefaultOrganizationProvider defaultOrganizationProvider, BranchFeatureProxy branchFeature, UserSession userSession) {
+    WebServer webServer, DbClient dbClient, OrganizationFlags organizationFlags,
+    DefaultOrganizationProvider defaultOrganizationProvider, BranchFeatureProxy branchFeature, UserSession userSession) {
     this.pageRepository = pageRepository;
     this.config = config;
     this.resourceTypes = resourceTypes;
     this.server = server;
+    this.webServer = webServer;
     this.dbClient = dbClient;
     this.organizationFlags = organizationFlags;
     this.defaultOrganizationProvider = defaultOrganizationProvider;
@@ -106,6 +110,7 @@ public class GlobalAction implements NavigationWsAction {
       writeDatabaseProduction(json);
       writeOrganizationSupport(json);
       writeBranchSupport(json);
+      json.prop("standalone", webServer.isStandalone());
       json.endObject();
     }
   }
index 5deb92e4e4c8fe41e03d68c3f01f6133db323a51..ec18d44b485a471aa952a5099e2bd471dbd34614 100644 (file)
@@ -28,5 +28,6 @@
   "organizationsEnabled": false,
   "branchesEnabled": false,
   "defaultOrganization": "key_foo",
-  "canAdmin": false
+  "canAdmin": false,
+  "standalone": true
 }
index 1576a6429f904ed354adc31c17105ab6da497847..fa83772a3860d8d946f8dacbb8ee47d07e585270 100644 (file)
@@ -36,6 +36,7 @@ import org.sonar.server.branch.BranchFeatureRule;
 import org.sonar.server.organization.DefaultOrganizationProvider;
 import org.sonar.server.organization.TestDefaultOrganizationProvider;
 import org.sonar.server.organization.TestOrganizationFlags;
+import org.sonar.server.platform.WebServer;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.ui.PageRepository;
 import org.sonar.server.ws.WsActionTester;
@@ -55,6 +56,7 @@ public class GlobalActionTest {
   private MapSettings settings = new MapSettings();
 
   private Server server = mock(Server.class);
+  private WebServer webServer = mock(WebServer.class);
   private DbClient dbClient = mock(DbClient.class, RETURNS_DEEP_STUBS);
 
   private TestOrganizationFlags organizationFlags = TestOrganizationFlags.standalone();
@@ -225,6 +227,26 @@ public class GlobalActionTest {
     assertJson(call()).isSimilarTo("{\"canAdmin\":true}");
   }
 
+  @Test
+  public void standalone_flag() {
+    init();
+    userSession.logIn().setRoot();
+    when(webServer.isStandalone()).thenReturn(true);
+
+
+    assertJson(call()).isSimilarTo("{\"standalone\":true}");
+  }
+
+  @Test
+  public void not_standalone_flag() {
+    init();
+    userSession.logIn().setRoot();
+    when(webServer.isStandalone()).thenReturn(false);
+
+
+    assertJson(call()).isSimilarTo("{\"standalone\":false}");
+  }
+
   @Test
   public void test_example_response() throws Exception {
     init(createPages(), new ResourceTypeTree[] {
@@ -247,9 +269,10 @@ public class GlobalActionTest {
     settings.setProperty("sonar.technicalDebt.ratingGrid", "0.05,0.1,0.2,0.5");
     when(server.getVersion()).thenReturn("6.2");
     when(dbClient.getDatabase().getDialect()).thenReturn(new MySql());
+    when(webServer.isStandalone()).thenReturn(true);
 
     String result = call();
-    assertJson(ws.getDef().responseExampleAsString()).isSimilarTo(result);
+    assertJson(result).isSimilarTo(ws.getDef().responseExampleAsString());
   }
 
   private void init() {
@@ -268,7 +291,7 @@ public class GlobalActionTest {
     }});
     pageRepository.start();
     ws = new WsActionTester(new GlobalAction(pageRepository, settings.asConfig(), new ResourceTypes(resourceTypeTrees), server,
-      dbClient, organizationFlags, defaultOrganizationProvider, branchFeature, userSession));
+        webServer, dbClient, organizationFlags, defaultOrganizationProvider, branchFeature, userSession));
   }
 
   private String call() {