aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2017-06-27 18:18:08 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2017-07-04 16:29:36 +0200
commit1308b6801babb7d64bec4ffe2e619ea0e4c5cdef (patch)
tree022b21a68ca9035adcd55e9b8a643a3797aed8e5 /server
parent72f20e1066197e64b7e5d348d9f1bc2466073f2e (diff)
downloadsonarqube-1308b6801babb7d64bec4ffe2e619ea0e4c5cdef.tar.gz
sonarqube-1308b6801babb7d64bec4ffe2e619ea0e4c5cdef.zip
SONAR-9482 Create api/qualityprofile/show WS returning stub
Diffstat (limited to 'server')
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfilesWsModule.java3
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ShowAction.java83
-rw-r--r--server/sonar-server/src/main/resources/org/sonar/server/qualityprofile/ws/show-example.json23
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsModuleTest.java2
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ShowActionTest.java89
5 files changed, 198 insertions, 2 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfilesWsModule.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfilesWsModule.java
index 3708ce600ea..f3362d94a61 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfilesWsModule.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfilesWsModule.java
@@ -50,7 +50,8 @@ public class QProfilesWsModule extends Module {
ActivateRuleAction.class,
DeactivateRuleAction.class,
SearchAction.class,
- SetDefaultAction.class
+ SetDefaultAction.class,
+ ShowAction.class
);
}
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ShowAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ShowAction.java
new file mode 100644
index 00000000000..7b4020baf94
--- /dev/null
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ShowAction.java
@@ -0,0 +1,83 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 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.qualityprofile.ws;
+
+import org.sonar.api.server.ws.Request;
+import org.sonar.api.server.ws.Response;
+import org.sonar.api.server.ws.WebService;
+import org.sonar.api.server.ws.WebService.NewAction;
+import org.sonarqube.ws.QualityProfiles.ShowWsResponse;
+import org.sonarqube.ws.QualityProfiles.ShowWsResponse.CompareToSonarWay;
+
+import static org.sonar.core.util.Uuids.UUID_EXAMPLE_01;
+import static org.sonar.server.ws.WsUtils.writeProtobuf;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_COMPARE_TO_SONAR_WAY;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PROFILE;
+
+public class ShowAction implements QProfileWsAction {
+
+ @Override
+ public void define(WebService.NewController controller) {
+ NewAction show = controller.createAction("show")
+ .setSince("6.5")
+ .setDescription("Show a quality profile")
+ .setResponseExample(getClass().getResource("show-example.json"))
+ .setInternal(true)
+ .setHandler(this);
+
+ show.createParam(PARAM_PROFILE)
+ .setDescription("Quality profile key")
+ .setExampleValue(UUID_EXAMPLE_01)
+ .setRequired(true);
+
+ show.createParam(PARAM_COMPARE_TO_SONAR_WAY)
+ .setDescription("Add the number of missing rules from the related Sonar way profile in the response")
+ .setInternal(true)
+ .setBooleanPossibleValues();
+ }
+
+ @Override
+ public void handle(Request request, Response response) throws Exception {
+ ShowWsResponse showWsResponse = ShowWsResponse.newBuilder()
+ .setProfile(ShowWsResponse.QualityProfile.newBuilder()
+ .setKey("AU-TpxcA-iU5OvuD2FL3")
+ .setName("My Company Profile")
+ .setLanguage("cs")
+ .setLanguageName("C#")
+ .setIsInherited(true)
+ .setIsBuiltIn(false)
+ .setIsDefault(false)
+ .setParentKey("AU-TpxcA-iU5OvuD2FL1")
+ .setParentName("Parent Company Profile")
+ .setActiveRuleCount(10)
+ .setActiveDeprecatedRuleCount(0)
+ .setProjectCount(7)
+ .setRuleUpdatedAt("2016-12-22T19:10:03+0100")
+ .setLastUsed("2016-12-01T19:10:03+0100"))
+ .setCompareToSonarWay(CompareToSonarWay.newBuilder()
+ .setProfile("iU5OvuD2FLz")
+ .setProfileName("Sonar way")
+ .setMissingRuleCount(4)
+ .build())
+ .build();
+ writeProtobuf(showWsResponse, request, response);
+ }
+
+}
diff --git a/server/sonar-server/src/main/resources/org/sonar/server/qualityprofile/ws/show-example.json b/server/sonar-server/src/main/resources/org/sonar/server/qualityprofile/ws/show-example.json
new file mode 100644
index 00000000000..60f03aaf168
--- /dev/null
+++ b/server/sonar-server/src/main/resources/org/sonar/server/qualityprofile/ws/show-example.json
@@ -0,0 +1,23 @@
+{
+ "profile": {
+ "key": "AU-TpxcA-iU5OvuD2FL3",
+ "name": "My Company Profile",
+ "language": "cs",
+ "languageName": "C#",
+ "isInherited": true,
+ "isBuiltIn": false,
+ "isDefault": false,
+ "parentKey": "AU-TpxcA-iU5OvuD2FL1",
+ "parentName": "Parent Company Profile",
+ "activeRuleCount": 10,
+ "activeDeprecatedRuleCount": 0,
+ "projectCount": 7,
+ "ruleUpdatedAt": "2016-12-22T19:10:03+0100",
+ "lastUsed": "2016-12-01T19:10:03+0100"
+ },
+ "compareToSonarWay": {
+ "profile": "iU5OvuD2FLz",
+ "profileName": "Sonar way",
+ "missingRuleCount": 4
+ }
+}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsModuleTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsModuleTest.java
index 60f84b6d05c..1764e6cafcc 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsModuleTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsModuleTest.java
@@ -29,6 +29,6 @@ public class QProfilesWsModuleTest {
public void verify_count_of_added_components() {
ComponentContainer container = new ComponentContainer();
new QProfilesWsModule().configure(container);
- assertThat(container.size()).isEqualTo(26 + 2);
+ assertThat(container.size()).isEqualTo(27 + 2);
}
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ShowActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ShowActionTest.java
new file mode 100644
index 00000000000..b7f9b98f35d
--- /dev/null
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ShowActionTest.java
@@ -0,0 +1,89 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 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.qualityprofile.ws;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.api.resources.Language;
+import org.sonar.api.server.ws.WebService;
+import org.sonar.db.DbTester;
+import org.sonar.db.qualityprofile.QProfileDto;
+import org.sonar.server.ws.WsActionTester;
+
+import static java.util.stream.IntStream.range;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.sonar.server.language.LanguageTesting.newLanguage;
+import static org.sonar.test.JsonAssert.assertJson;
+
+public class ShowActionTest {
+
+ @Rule
+ public DbTester db = DbTester.create();
+
+ private WsActionTester ws = new WsActionTester(new ShowAction());
+
+ @Test
+ public void test_definition() {
+ WebService.Action action = ws.getDef();
+ assertThat(action.key()).isEqualTo("show");
+ assertThat(action.responseExampleAsString()).isNotEmpty();
+ assertThat(action.isPost()).isFalse();
+ assertThat(action.since()).isEqualTo("6.5");
+
+ WebService.Param profile = action.param("profile");
+ assertThat(profile).isNotNull();
+ assertThat(profile.isRequired()).isTrue();
+ assertThat(profile.isInternal()).isFalse();
+ assertThat(profile.description()).isNotEmpty();
+
+ WebService.Param compareToSonarWay = action.param("compareToSonarWay");
+ assertThat(compareToSonarWay).isNotNull();
+ assertThat(compareToSonarWay.isRequired()).isFalse();
+ assertThat(compareToSonarWay.isInternal()).isTrue();
+ assertThat(compareToSonarWay.description()).isNotEmpty();
+ assertThat(compareToSonarWay.possibleValues()).contains("true", "false");
+ }
+
+ @Test
+ public void test_example() {
+ Language cs = newLanguage("cs", "C#");
+ QProfileDto parentProfile = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setKee("AU-TpxcA-iU5OvuD2FL1").setName("Parent Company Profile"));
+ QProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p
+ .setKee("AU-TpxcA-iU5OvuD2FL3")
+ .setName("My Company Profile")
+ .setLanguage(cs.getKey())
+ .setIsBuiltIn(false)
+ .setRulesUpdatedAt("2016-12-22T19:10:03+0100")
+ .setParentKee(parentProfile.getKee()));
+ // Active rules
+ range(0, 10)
+ .mapToObj(i -> db.rules().insertRule(r -> r.setLanguage(cs.getKey())).getDefinition())
+ .forEach(r -> db.qualityProfiles().activateRule(profile, r));
+ // Projects
+ range(0, 7)
+ .mapToObj(i -> db.components().insertPrivateProject())
+ .forEach(project -> db.qualityProfiles().associateWithProject(project, profile));
+
+ String result = ws.newRequest().execute().getInput();
+
+ assertJson(result).isSimilarTo(ws.getDef().responseExampleAsString());
+ }
+}