From: Sébastien Lesaint Date: Fri, 20 Oct 2017 12:28:14 +0000 (+0200) Subject: SONAR-10015 add standalone flag to api/navigation/global X-Git-Tag: 6.7-RC1~55 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=3c54405e43bed45afa8ad18770140335c726c54d;p=sonarqube.git SONAR-10015 add standalone flag to api/navigation/global --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/ui/ws/GlobalAction.java b/server/sonar-server/src/main/java/org/sonar/server/ui/ws/GlobalAction.java index 6ff1646ac02..13192573389 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/ui/ws/GlobalAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/ui/ws/GlobalAction.java @@ -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(); } } diff --git a/server/sonar-server/src/main/resources/org/sonar/server/ui/ws/global-example.json b/server/sonar-server/src/main/resources/org/sonar/server/ui/ws/global-example.json index 5deb92e4e4c..ec18d44b485 100644 --- a/server/sonar-server/src/main/resources/org/sonar/server/ui/ws/global-example.json +++ b/server/sonar-server/src/main/resources/org/sonar/server/ui/ws/global-example.json @@ -28,5 +28,6 @@ "organizationsEnabled": false, "branchesEnabled": false, "defaultOrganization": "key_foo", - "canAdmin": false + "canAdmin": false, + "standalone": true } diff --git a/server/sonar-server/src/test/java/org/sonar/server/ui/ws/GlobalActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/ui/ws/GlobalActionTest.java index 1576a6429f9..fa83772a386 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/ui/ws/GlobalActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/ui/ws/GlobalActionTest.java @@ -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() {