aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/ui/ws/GlobalNavigationAction.java50
-rw-r--r--server/sonar-server/src/main/resources/org/sonar/server/ui/ws/example-global.json33
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/ui/ws/GlobalNavigationActionTest.java109
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalNavigationActionTest/deprecated_logo_settings.json8
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalNavigationActionTest/empty.json4
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalNavigationActionTest/global_pages_for_admin.json (renamed from server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalNavigationActionTest/admin.json)4
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalNavigationActionTest/global_pages_for_anonymous.json (renamed from server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalNavigationActionTest/anonymous.json)4
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalNavigationActionTest/global_pages_for_user.json (renamed from server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalNavigationActionTest/user.json)4
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalNavigationActionTest/only_logo.json5
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalNavigationActionTest/production_database.json3
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalNavigationActionTest/qualifiers.json (renamed from server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalNavigationActionTest/with_qualifiers.json)1
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalNavigationActionTest/settings.json12
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalNavigationActionTest/version.json3
13 files changed, 183 insertions, 57 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/ui/ws/GlobalNavigationAction.java b/server/sonar-server/src/main/java/org/sonar/server/ui/ws/GlobalNavigationAction.java
index 6f5df35ff46..2340b2f1e45 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/ui/ws/GlobalNavigationAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/ui/ws/GlobalNavigationAction.java
@@ -19,7 +19,10 @@
*/
package org.sonar.server.ui.ws;
+import com.google.common.collect.ImmutableSet;
+import java.util.Set;
import org.sonar.api.config.Settings;
+import org.sonar.api.platform.Server;
import org.sonar.api.resources.ResourceType;
import org.sonar.api.resources.ResourceTypes;
import org.sonar.api.server.ws.Request;
@@ -28,22 +31,44 @@ import org.sonar.api.server.ws.WebService.NewController;
import org.sonar.api.utils.text.JsonWriter;
import org.sonar.api.web.NavigationSection;
import org.sonar.api.web.Page;
+import org.sonar.db.Database;
+import org.sonar.db.dialect.H2;
import org.sonar.server.ui.ViewProxy;
import org.sonar.server.ui.Views;
+import static org.sonar.api.CoreProperties.CORE_ALLOW_USERS_TO_SIGNUP_PROPERTY;
+import static org.sonar.api.CoreProperties.HOURS_IN_DAY;
+import static org.sonar.api.CoreProperties.RATING_GRID;
+import static org.sonar.core.config.WebConstants.SONAR_LF_ENABLE_GRAVATAR;
+import static org.sonar.core.config.WebConstants.SONAR_LF_GRAVATAR_SERVER_URL;
import static org.sonar.core.config.WebConstants.SONAR_LF_LOGO_URL;
import static org.sonar.core.config.WebConstants.SONAR_LF_LOGO_WIDTH_PX;
+import static org.sonar.core.config.WebConstants.SONAR_UPDATECENTER_ACTIVATE;
public class GlobalNavigationAction implements NavigationWsAction {
+ private static final Set<String> SETTING_KEYS = ImmutableSet.of(
+ SONAR_LF_LOGO_URL,
+ SONAR_LF_LOGO_WIDTH_PX,
+ SONAR_LF_ENABLE_GRAVATAR,
+ SONAR_LF_GRAVATAR_SERVER_URL,
+ SONAR_UPDATECENTER_ACTIVATE,
+ HOURS_IN_DAY,
+ RATING_GRID,
+ CORE_ALLOW_USERS_TO_SIGNUP_PROPERTY);
+
private final Views views;
private final Settings settings;
private final ResourceTypes resourceTypes;
+ private final Server server;
+ private final Database database;
- public GlobalNavigationAction(Views views, Settings settings, ResourceTypes resourceTypes) {
+ public GlobalNavigationAction(Views views, Settings settings, ResourceTypes resourceTypes, Server server, Database database) {
this.views = views;
this.settings = settings;
this.resourceTypes = resourceTypes;
+ this.server = server;
+ this.database = database;
}
@Override
@@ -60,8 +85,11 @@ public class GlobalNavigationAction implements NavigationWsAction {
public void handle(Request request, Response response) throws Exception {
JsonWriter json = response.newJsonWriter().beginObject();
writePages(json);
- writeLogoProperties(json);
+ writeSettings(json);
+ writeDeprecatedLogoProperties(json);
writeQualifiers(json);
+ writeVersion(json);
+ writeDatabaseProduction(json);
json.endObject().close();
}
@@ -78,7 +106,15 @@ public class GlobalNavigationAction implements NavigationWsAction {
json.endArray();
}
- private void writeLogoProperties(JsonWriter json) {
+ private void writeSettings(JsonWriter json) {
+ json.name("settings").beginObject();
+ for (String settingKey : SETTING_KEYS) {
+ json.prop(settingKey, settings.getString(settingKey));
+ }
+ json.endObject();
+ }
+
+ private void writeDeprecatedLogoProperties(JsonWriter json) {
json.prop("logoUrl", settings.getString(SONAR_LF_LOGO_URL));
json.prop("logoWidth", settings.getString(SONAR_LF_LOGO_WIDTH_PX));
}
@@ -90,4 +126,12 @@ public class GlobalNavigationAction implements NavigationWsAction {
}
json.endArray();
}
+
+ private void writeVersion(JsonWriter json) {
+ json.prop("version", server.getVersion());
+ }
+
+ private void writeDatabaseProduction(JsonWriter json) {
+ json.prop("productionDatabase", !database.getDialect().getId().equals(H2.ID));
+ }
}
diff --git a/server/sonar-server/src/main/resources/org/sonar/server/ui/ws/example-global.json b/server/sonar-server/src/main/resources/org/sonar/server/ui/ws/example-global.json
index 44dcbd3e24c..311f46af032 100644
--- a/server/sonar-server/src/main/resources/org/sonar/server/ui/ws/example-global.json
+++ b/server/sonar-server/src/main/resources/org/sonar/server/ui/ws/example-global.json
@@ -1,17 +1,30 @@
{
- "globalDashboards": [
- {
- "key": 51,
- "name": "Helicopter View"
- }
- ],
"globalPages": [
{
- "name": "My Plugin",
- "url": "/plugins/home/my-plugin"
+ "name": "My Plugin Page",
+ "url": "/plugins/home/my_plugin_page"
+ },
+ {
+ "name": "My Rails App",
+ "url": "/my_rails_app"
}
],
+ "settings": {
+ "sonar.lf.logoUrl": "http://example.com/my-custom-logo.png",
+ "sonar.lf.logoWidthPx": "135",
+ "sonar.lf.enableGravatar": "true",
+ "sonar.lf.gravatarServerUrl": "http://some-server.tld/logo.png",
+ "sonar.updatecenter.activate": "false",
+ "sonar.technicalDebt.hoursInDay": "10",
+ "sonar.technicalDebt.ratingGrid": "0.05,0.1,0.2,0.5",
+ "sonar.allowUsersToSignUp": "true"
+ },
"logoUrl": "http://example.com/my-custom-logo.png",
- "logoWidth": 135,
- "qualifiers": ["TRK", "VW"]
+ "logoWidth": "135",
+ "qualifiers": [
+ "PAL",
+ "POL"
+ ],
+ "version": "6.2",
+ "productionDatabase": true
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/ui/ws/GlobalNavigationActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/ui/ws/GlobalNavigationActionTest.java
index 759b091eac0..4419611cbfb 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/ui/ws/GlobalNavigationActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/ui/ws/GlobalNavigationActionTest.java
@@ -23,6 +23,7 @@ import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.config.MapSettings;
import org.sonar.api.config.Settings;
+import org.sonar.api.platform.Server;
import org.sonar.api.resources.ResourceType;
import org.sonar.api.resources.ResourceTypeTree;
import org.sonar.api.resources.ResourceTypes;
@@ -31,11 +32,17 @@ import org.sonar.api.web.Page;
import org.sonar.api.web.UserRole;
import org.sonar.api.web.View;
import org.sonar.core.permission.GlobalPermissions;
+import org.sonar.db.Database;
+import org.sonar.db.dialect.H2;
+import org.sonar.db.dialect.MySql;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ui.Views;
import org.sonar.server.ws.WsActionTester;
import org.sonar.test.JsonAssert;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
public class GlobalNavigationActionTest {
@Rule
@@ -43,6 +50,9 @@ public class GlobalNavigationActionTest {
private Settings settings = new MapSettings();
+ private Server server = mock(Server.class);
+ private Database database = mock(Database.class);
+
private WsActionTester ws;
@Test
@@ -53,7 +63,7 @@ public class GlobalNavigationActionTest {
}
@Test
- public void with_root_qualifiers() throws Exception {
+ public void return_qualifiers() throws Exception {
init(new View[] {}, new ResourceTypeTree[] {
ResourceTypeTree.builder()
.addType(ResourceType.builder("POL").build())
@@ -67,54 +77,101 @@ public class GlobalNavigationActionTest {
.build()
});
- executeAndVerify("with_qualifiers.json");
+ executeAndVerify("qualifiers.json");
+ }
+
+ @Test
+ public void return_settings() throws Exception {
+ init();
+ settings.setProperty("sonar.lf.logoUrl", "http://example.com/my-custom-logo.png");
+ settings.setProperty("sonar.lf.logoWidthPx", 135);
+ settings.setProperty("sonar.lf.gravatarServerUrl", "https://secure.gravatar.com/avatar/{EMAIL_MD5}.jpg?s={SIZE}&d=identicon");
+ settings.setProperty("sonar.lf.enableGravatar", true);
+ settings.setProperty("sonar.updatecenter.activate", false);
+ settings.setProperty("sonar.technicalDebt.hoursInDay", "10");
+ settings.setProperty("sonar.technicalDebt.ratingGrid", "0.05,0.1,0.2,0.5");
+ settings.setProperty("sonar.allowUsersToSignUp", true);
+ // This setting should be ignored as it's not needed
+ settings.setProperty("sonar.defaultGroup", "sonar-users");
+
+ executeAndVerify("settings.json");
}
@Test
- public void only_logo() throws Exception {
+ public void return_deprecated_logo_settings() throws Exception {
init();
- settings.setProperty("sonar.lf.logoUrl", "http://some-server.tld/logo.png");
- settings.setProperty("sonar.lf.logoWidthPx", "123");
+ settings.setProperty("sonar.lf.logoUrl", "http://example.com/my-custom-logo.png");
+ settings.setProperty("sonar.lf.logoWidthPx", 135);
- executeAndVerify("only_logo.json");
+ executeAndVerify("deprecated_logo_settings.json");
}
@Test
- public void nominal_call_for_anonymous() throws Exception {
+ public void return_global_pages_for_anonymous() throws Exception {
init(createViews(), new ResourceTypeTree[] {});
- addNominalSettings();
- executeAndVerify("anonymous.json");
+ executeAndVerify("global_pages_for_anonymous.json");
}
@Test
- public void nominal_call_for_user() throws Exception {
+ public void return_global_pages_for_user() throws Exception {
init(createViews(), new ResourceTypeTree[] {});
- addNominalSettings();
-
userSessionRule.login("obiwan");
- executeAndVerify("user.json");
+ executeAndVerify("global_pages_for_user.json");
}
@Test
- public void nominal_call_for_admin() throws Exception {
+ public void return_global_pages_for_admin() throws Exception {
init(createViews(), new ResourceTypeTree[] {});
- addNominalSettings();
-
userSessionRule.login("obiwan").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
- executeAndVerify("admin.json");
+ executeAndVerify("global_pages_for_admin.json");
}
@Test
- public void nominal_call_for_user_without_configured_dashboards() throws Exception {
- init(createViews(), new ResourceTypeTree[] {});
- addNominalSettings();
+ public void return_sonarqube_version() throws Exception {
+ init();
+ when(server.getVersion()).thenReturn("6.2");
+
+ executeAndVerify("version.json");
+ }
+
+ @Test
+ public void return_if_production_database_or_not() throws Exception {
+ init();
+ when(database.getDialect()).thenReturn(new MySql());
- userSessionRule.login("anakin");
+ executeAndVerify("production_database.json");
+ }
- executeAndVerify("anonymous.json");
+ @Test
+ public void test_example_response() throws Exception {
+ init(createViews(), new ResourceTypeTree[] {
+ ResourceTypeTree.builder()
+ .addType(ResourceType.builder("POL").build())
+ .addType(ResourceType.builder("LOP").build())
+ .addRelations("POL", "LOP")
+ .build(),
+ ResourceTypeTree.builder()
+ .addType(ResourceType.builder("PAL").build())
+ .addType(ResourceType.builder("LAP").build())
+ .addRelations("PAL", "LAP")
+ .build()
+ });
+ settings.setProperty("sonar.lf.logoUrl", "http://example.com/my-custom-logo.png");
+ settings.setProperty("sonar.lf.logoWidthPx", 135);
+ settings.setProperty("sonar.lf.gravatarServerUrl", "http://some-server.tld/logo.png");
+ settings.setProperty("sonar.lf.enableGravatar", true);
+ settings.setProperty("sonar.updatecenter.activate", false);
+ settings.setProperty("sonar.technicalDebt.hoursInDay", "10");
+ settings.setProperty("sonar.technicalDebt.ratingGrid", "0.05,0.1,0.2,0.5");
+ settings.setProperty("sonar.allowUsersToSignUp", true);
+ when(server.getVersion()).thenReturn("6.2");
+ when(database.getDialect()).thenReturn(new MySql());
+
+ String result = ws.newRequest().execute().getInput();
+ JsonAssert.assertJson(ws.getDef().responseExampleAsString()).isSimilarTo(result);
}
private void init() {
@@ -122,18 +179,14 @@ public class GlobalNavigationActionTest {
}
private void init(View[] views, ResourceTypeTree[] resourceTypeTrees) {
- ws = new WsActionTester(new GlobalNavigationAction(new Views(userSessionRule, views), settings, new ResourceTypes(resourceTypeTrees)));
+ when(database.getDialect()).thenReturn(new H2());
+ ws = new WsActionTester(new GlobalNavigationAction(new Views(userSessionRule, views), settings, new ResourceTypes(resourceTypeTrees), server, database));
}
private void executeAndVerify(String json) {
JsonAssert.assertJson(ws.newRequest().execute().getInput()).isSimilarTo(getClass().getResource(GlobalNavigationActionTest.class.getSimpleName() + "/" + json));
}
- private void addNominalSettings() {
- settings.setProperty("sonar.lf.logoUrl", "http://some-server.tld/logo.png");
- settings.setProperty("sonar.lf.logoWidthPx", "123");
- }
-
private View[] createViews() {
Page page = new Page() {
@Override
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalNavigationActionTest/deprecated_logo_settings.json b/server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalNavigationActionTest/deprecated_logo_settings.json
new file mode 100644
index 00000000000..13930da3fd2
--- /dev/null
+++ b/server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalNavigationActionTest/deprecated_logo_settings.json
@@ -0,0 +1,8 @@
+{
+ "settings": {
+ "sonar.lf.logoUrl": "http://example.com/my-custom-logo.png",
+ "sonar.lf.logoWidthPx": "135"
+ },
+ "logoUrl": "http://example.com/my-custom-logo.png",
+ "logoWidth": "135"
+}
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalNavigationActionTest/empty.json b/server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalNavigationActionTest/empty.json
index 64ac56232fc..cc5448c6cf3 100644
--- a/server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalNavigationActionTest/empty.json
+++ b/server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalNavigationActionTest/empty.json
@@ -1,3 +1,5 @@
{
- "globalPages": []
+ "globalPages": [],
+ "settings": {},
+ "qualifiers": []
}
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalNavigationActionTest/admin.json b/server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalNavigationActionTest/global_pages_for_admin.json
index 1ad7b80b091..019342bd220 100644
--- a/server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalNavigationActionTest/admin.json
+++ b/server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalNavigationActionTest/global_pages_for_admin.json
@@ -12,7 +12,5 @@
"name": "Admin Page",
"url": "/plugins/home/admin_page"
}
- ],
- "logoUrl": "http://some-server.tld/logo.png",
- "logoWidth": "123"
+ ]
}
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalNavigationActionTest/anonymous.json b/server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalNavigationActionTest/global_pages_for_anonymous.json
index 4bb69ea6b3d..b2783b5e528 100644
--- a/server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalNavigationActionTest/anonymous.json
+++ b/server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalNavigationActionTest/global_pages_for_anonymous.json
@@ -8,7 +8,5 @@
"name": "My Rails App",
"url": "/my_rails_app"
}
- ],
- "logoUrl": "http://some-server.tld/logo.png",
- "logoWidth": "123"
+ ]
}
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalNavigationActionTest/user.json b/server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalNavigationActionTest/global_pages_for_user.json
index 4bb69ea6b3d..b2783b5e528 100644
--- a/server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalNavigationActionTest/user.json
+++ b/server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalNavigationActionTest/global_pages_for_user.json
@@ -8,7 +8,5 @@
"name": "My Rails App",
"url": "/my_rails_app"
}
- ],
- "logoUrl": "http://some-server.tld/logo.png",
- "logoWidth": "123"
+ ]
}
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalNavigationActionTest/only_logo.json b/server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalNavigationActionTest/only_logo.json
deleted file mode 100644
index 08dfe170880..00000000000
--- a/server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalNavigationActionTest/only_logo.json
+++ /dev/null
@@ -1,5 +0,0 @@
-{
- "globalPages": [],
- "logoUrl": "http://some-server.tld/logo.png",
- "logoWidth": "123"
-}
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalNavigationActionTest/production_database.json b/server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalNavigationActionTest/production_database.json
new file mode 100644
index 00000000000..ae8359cc59d
--- /dev/null
+++ b/server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalNavigationActionTest/production_database.json
@@ -0,0 +1,3 @@
+{
+ "productionDatabase": true
+}
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalNavigationActionTest/with_qualifiers.json b/server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalNavigationActionTest/qualifiers.json
index 3e5658321bc..ef2107cd9b3 100644
--- a/server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalNavigationActionTest/with_qualifiers.json
+++ b/server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalNavigationActionTest/qualifiers.json
@@ -1,4 +1,3 @@
{
- "globalPages": [],
"qualifiers": ["POL", "PAL"]
}
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalNavigationActionTest/settings.json b/server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalNavigationActionTest/settings.json
new file mode 100644
index 00000000000..d6d1fd25d9a
--- /dev/null
+++ b/server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalNavigationActionTest/settings.json
@@ -0,0 +1,12 @@
+{
+ "settings": {
+ "sonar.lf.logoUrl": "http://example.com/my-custom-logo.png",
+ "sonar.lf.logoWidthPx": "135",
+ "sonar.lf.gravatarServerUrl": "https://secure.gravatar.com/avatar/{EMAIL_MD5}.jpg?s={SIZE}&d=identicon",
+ "sonar.lf.enableGravatar": "true",
+ "sonar.updatecenter.activate": "false",
+ "sonar.technicalDebt.hoursInDay": "10",
+ "sonar.technicalDebt.ratingGrid": "0.05,0.1,0.2,0.5",
+ "sonar.allowUsersToSignUp": "true"
+ }
+}
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalNavigationActionTest/version.json b/server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalNavigationActionTest/version.json
new file mode 100644
index 00000000000..21cd1393d5c
--- /dev/null
+++ b/server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalNavigationActionTest/version.json
@@ -0,0 +1,3 @@
+{
+ "version": "6.2"
+}