aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-server
diff options
context:
space:
mode:
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2017-06-29 15:16:16 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2017-07-04 16:29:36 +0200
commit82e6624f67a8cb93aea2a2517db879801b8e9346 (patch)
treef9fdec89dc3837d47b9741f81b8c8136a9dd9b9f /server/sonar-server
parenta756c3bc2cd74b77ec0ae9c7e0401932c408c7bb (diff)
downloadsonarqube-82e6624f67a8cb93aea2a2517db879801b8e9346.tar.gz
sonarqube-82e6624f67a8cb93aea2a2517db879801b8e9346.zip
SONAR-9482 Add WS client for api/qualityprofiles/show
Diffstat (limited to 'server/sonar-server')
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ShowAction.java16
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ShowActionTest.java29
2 files changed, 24 insertions, 21 deletions
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
index cff1902a7b4..9a293eeb25d 100644
--- 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
@@ -38,9 +38,10 @@ import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.es.SearchOptions;
import org.sonar.server.rule.index.RuleIndex;
import org.sonar.server.rule.index.RuleQuery;
-import org.sonarqube.ws.QualityProfiles.ShowWsResponse;
-import org.sonarqube.ws.QualityProfiles.ShowWsResponse.CompareToSonarWay;
-import org.sonarqube.ws.QualityProfiles.ShowWsResponse.QualityProfile;
+import org.sonarqube.ws.QualityProfiles;
+import org.sonarqube.ws.QualityProfiles.ShowResponse;
+import org.sonarqube.ws.QualityProfiles.ShowResponse.CompareToSonarWay;
+import org.sonarqube.ws.QualityProfiles.ShowResponse.QualityProfile;
import static java.util.Collections.singletonList;
import static org.sonar.api.rule.RuleStatus.DEPRECATED;
@@ -49,6 +50,7 @@ import static org.sonar.core.util.Protobuf.setNullable;
import static org.sonar.core.util.Uuids.UUID_EXAMPLE_01;
import static org.sonar.server.ws.WsUtils.checkFound;
import static org.sonar.server.ws.WsUtils.writeProtobuf;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.ACTION_SHOW;
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_COMPARE_TO_SONAR_WAY;
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PROFILE;
@@ -71,7 +73,7 @@ public class ShowAction implements QProfileWsAction {
@Override
public void define(WebService.NewController controller) {
- NewAction show = controller.createAction("show")
+ NewAction show = controller.createAction(ACTION_SHOW)
.setSince("6.5")
.setDescription("Show a quality profile")
.setResponseExample(getClass().getResource("show-example.json"))
@@ -149,9 +151,9 @@ public class ShowAction implements QProfileWsAction {
.build();
}
- private static ShowWsResponse buildResponse(QProfileDto profile, boolean isDefault, Language language, long activeRules, long deprecatedActiveRules, long projects,
- @Nullable CompareToSonarWay compareToSonarWay) {
- ShowWsResponse.Builder showResponseBuilder = ShowWsResponse.newBuilder();
+ private static ShowResponse buildResponse(QProfileDto profile, boolean isDefault, Language language, long activeRules, long deprecatedActiveRules, long projects,
+ @Nullable CompareToSonarWay compareToSonarWay) {
+ ShowResponse.Builder showResponseBuilder = QualityProfiles.ShowResponse.newBuilder();
QualityProfile.Builder profileBuilder = QualityProfile.newBuilder()
.setKey(profile.getKee())
.setName(profile.getName())
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
index 4d06ff2ff1b..5e133f330c9 100644
--- 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
@@ -43,8 +43,9 @@ import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ws.TestRequest;
import org.sonar.server.ws.WsActionTester;
import org.sonarqube.ws.MediaTypes;
-import org.sonarqube.ws.QualityProfiles.ShowWsResponse;
-import org.sonarqube.ws.QualityProfiles.ShowWsResponse.CompareToSonarWay;
+import org.sonarqube.ws.QualityProfiles;
+import org.sonarqube.ws.QualityProfiles.ShowResponse;
+import org.sonarqube.ws.QualityProfiles.ShowResponse.CompareToSonarWay;
import static java.util.stream.IntStream.range;
import static org.assertj.core.api.Assertions.assertThat;
@@ -52,7 +53,7 @@ import static org.sonar.api.rule.RuleStatus.DEPRECATED;
import static org.sonar.api.utils.DateUtils.parseDateTime;
import static org.sonar.server.language.LanguageTesting.newLanguage;
import static org.sonar.test.JsonAssert.assertJson;
-import static org.sonarqube.ws.QualityProfiles.ShowWsResponse.QualityProfile;
+import static org.sonarqube.ws.QualityProfiles.ShowResponse.QualityProfile;
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_COMPARE_TO_SONAR_WAY;
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PROFILE;
@@ -103,7 +104,7 @@ public class ShowActionTest {
public void profile_info() {
QProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setLanguage(XOO1.getKey()));
- ShowWsResponse result = call(ws.newRequest().setParam(PARAM_PROFILE, profile.getKee()));
+ QualityProfiles.ShowResponse result = call(ws.newRequest().setParam(PARAM_PROFILE, profile.getKee()));
assertThat(result.getProfile())
.extracting(QualityProfile::getKey, QualityProfile::getName, QualityProfile::getIsBuiltIn, QualityProfile::getLanguage, QualityProfile::getLanguageName,
@@ -116,7 +117,7 @@ public class ShowActionTest {
QProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setLanguage(XOO1.getKey()));
db.qualityProfiles().setAsDefault(profile);
- ShowWsResponse result = call(ws.newRequest().setParam(PARAM_PROFILE, profile.getKee()));
+ QualityProfiles.ShowResponse result = call(ws.newRequest().setParam(PARAM_PROFILE, profile.getKee()));
assertThat(result.getProfile().getIsDefault()).isTrue();
}
@@ -127,7 +128,7 @@ public class ShowActionTest {
QProfileDto defaultProfile = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setLanguage(XOO1.getKey()));
db.qualityProfiles().setAsDefault(defaultProfile);
- ShowWsResponse result = call(ws.newRequest().setParam(PARAM_PROFILE, profile.getKee()));
+ ShowResponse result = call(ws.newRequest().setParam(PARAM_PROFILE, profile.getKee()));
assertThat(result.getProfile().getIsDefault()).isFalse();
}
@@ -141,7 +142,7 @@ public class ShowActionTest {
.setLastUsed(time)
.setUserUpdatedAt(time));
- ShowWsResponse result = call(ws.newRequest().setParam(PARAM_PROFILE, profile.getKee()));
+ QualityProfiles.ShowResponse result = call(ws.newRequest().setParam(PARAM_PROFILE, profile.getKee()));
assertThat(result.getProfile().getRulesUpdatedAt()).isEqualTo("2016-12-21T19:10:03+0100");
assertThat(parseDateTime(result.getProfile().getLastUsed()).getTime()).isEqualTo(time);
@@ -164,7 +165,7 @@ public class ShowActionTest {
.mapToObj(i -> db.components().insertPrivateProject())
.forEach(project -> db.qualityProfiles().associateWithProject(project, profile));
- ShowWsResponse result = call(ws.newRequest().setParam(PARAM_PROFILE, profile.getKee()));
+ QualityProfiles.ShowResponse result = call(ws.newRequest().setParam(PARAM_PROFILE, profile.getKee()));
assertThat(result.getProfile())
.extracting(QualityProfile::getActiveRuleCount, QualityProfile::getActiveDeprecatedRuleCount, QualityProfile::getProjectCount)
@@ -227,7 +228,7 @@ public class ShowActionTest {
p -> p.setIsBuiltIn(true).setName("Another Sonar way").setLanguage(XOO1.getKey()));
QProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setLanguage(XOO1.getKey()));
- ShowWsResponse result = call(ws.newRequest()
+ ShowResponse result = call(ws.newRequest()
.setParam(PARAM_PROFILE, profile.getKee())
.setParam(PARAM_COMPARE_TO_SONAR_WAY, "true"));
@@ -239,7 +240,7 @@ public class ShowActionTest {
QProfileDto sonarWayProfile = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setIsBuiltIn(true).setName("Sonar way").setLanguage(XOO1.getKey()));
QProfileDto anotherBuiltInProfile = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setIsBuiltIn(true).setLanguage(XOO1.getKey()));
- ShowWsResponse result = call(ws.newRequest()
+ QualityProfiles.ShowResponse result = call(ws.newRequest()
.setParam(PARAM_PROFILE, anotherBuiltInProfile.getKee())
.setParam(PARAM_COMPARE_TO_SONAR_WAY, "true"));
@@ -251,7 +252,7 @@ public class ShowActionTest {
QProfileDto sonarWayProfile = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setIsBuiltIn(false).setName("Sonar way").setLanguage(XOO1.getKey()));
QProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setLanguage(XOO1.getKey()));
- ShowWsResponse result = call(ws.newRequest()
+ QualityProfiles.ShowResponse result = call(ws.newRequest()
.setParam(PARAM_PROFILE, profile.getKee())
.setParam(PARAM_COMPARE_TO_SONAR_WAY, "true"));
@@ -263,7 +264,7 @@ public class ShowActionTest {
QProfileDto sonarWayProfile = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setIsBuiltIn(true).setName("Sonar way").setLanguage(XOO1.getKey()));
QProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setLanguage(XOO1.getKey()));
- ShowWsResponse result = call(ws.newRequest()
+ QualityProfiles.ShowResponse result = call(ws.newRequest()
.setParam(PARAM_PROFILE, profile.getKee())
.setParam(PARAM_COMPARE_TO_SONAR_WAY, "false"));
@@ -349,8 +350,8 @@ public class ShowActionTest {
assertJson(result).ignoreFields("rulesUpdatedAt", "lastUsed", "userUpdatedAt").isSimilarTo(ws.getDef().responseExampleAsString());
}
- private ShowWsResponse call(TestRequest request) {
+ private ShowResponse call(TestRequest request) {
TestRequest wsRequest = request.setMediaType(MediaTypes.PROTOBUF);
- return wsRequest.executeProtobuf(ShowWsResponse.class);
+ return wsRequest.executeProtobuf(QualityProfiles.ShowResponse.class);
}
}