From: Julien Lancelot Date: Wed, 22 Nov 2017 17:00:31 +0000 (+0100) Subject: SONAR-10087 Add built-in field in api/qualitygates/list X-Git-Tag: 7.0-RC1~238 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f7ac66cac58e254e501ff5f381ce484cfbdda285;p=sonarqube.git SONAR-10087 Add built-in field in api/qualitygates/list --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/ListAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/ListAction.java index 7b1a67bdebd..fe9e93dfd13 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/ListAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/ListAction.java @@ -54,8 +54,9 @@ public class ListAction implements QualityGatesWsAction { .setSince("4.3") .setResponseExample(Resources.getResource(this.getClass(), "list-example.json")) .setChangelog( - new Change("7.0", "'isDefault' field is added on quality gate level"), - new Change("7.0", "'default' field on root level is deprecated")) + new Change("7.0", "'isDefault' field is added on quality gate"), + new Change("7.0", "'default' field on root level is deprecated"), + new Change("7.0", "'isBuiltIn' field is added in the response")) .setHandler(this); } @@ -76,6 +77,7 @@ public class ListAction implements QualityGatesWsAction { .setId(qualityGate.getId()) .setName(qualityGate.getName()) .setIsDefault(qualityGate.getId().equals(defaultId)) + .setIsBuiltIn(qualityGate.isBuiltIn()) .build()) .collect(toList())); setNullable(defaultId, builder::setDefault); diff --git a/server/sonar-server/src/main/resources/org/sonar/server/qualitygate/ws/list-example.json b/server/sonar-server/src/main/resources/org/sonar/server/qualitygate/ws/list-example.json index 7e5b5f5a625..547b8d4e863 100644 --- a/server/sonar-server/src/main/resources/org/sonar/server/qualitygate/ws/list-example.json +++ b/server/sonar-server/src/main/resources/org/sonar/server/qualitygate/ws/list-example.json @@ -3,12 +3,14 @@ { "id": 2, "name": "Sonar way", - "isDefault": true + "isDefault": true, + "isBuiltIn": true }, { "id": 4, "name": "Sonar way - Without Coverage", - "isDefault": false + "isDefault": false, + "isBuiltIn": false } ], "default": 2 diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/ListActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/ListActionTest.java index 0723d6d2cd8..83f27cd2025 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/ListActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/ListActionTest.java @@ -56,15 +56,16 @@ public class ListActionTest { assertThat(action.isInternal()).isFalse(); assertThat(action.changelog()).extracting(Change::getVersion, Change::getDescription) .containsExactlyInAnyOrder( - tuple("7.0", "'isDefault' field is added on quality gate level"), - tuple("7.0", "'default' field on root level is deprecated")); + tuple("7.0", "'isDefault' field is added on quality gate"), + tuple("7.0", "'default' field on root level is deprecated"), + tuple("7.0", "'isBuiltIn' field is added in the response")); assertThat(action.params()).isEmpty(); } @Test public void json_example() { - QualityGateDto defaultQualityGate = db.qualityGates().insertQualityGate("Sonar way"); - db.qualityGates().insertQualityGate("Sonar way - Without Coverage"); + QualityGateDto defaultQualityGate = db.qualityGates().insertQualityGate(qualityGate -> qualityGate.setName("Sonar way").setBuiltIn(true)); + db.qualityGates().insertQualityGate(qualityGate -> qualityGate.setName("Sonar way - Without Coverage").setBuiltIn(false)); db.qualityGates().setDefaultQualityGate(defaultQualityGate); String response = ws.newRequest() @@ -85,9 +86,23 @@ public class ListActionTest { assertThat(response.getQualitygatesList()) .extracting(QualityGate::getId, QualityGate::getName, QualityGate::getIsDefault) - .containsExactlyInAnyOrder( - tuple(defaultQualityGate.getId(), defaultQualityGate.getName(), true), - tuple(otherQualityGate.getId(), otherQualityGate.getName(), false)); + .containsExactlyInAnyOrder( + tuple(defaultQualityGate.getId(), defaultQualityGate.getName(), true), + tuple(otherQualityGate.getId(), otherQualityGate.getName(), false)); + } + + @Test + public void test_built_in_flag() { + QualityGateDto qualityGate1 = db.qualityGates().insertQualityGate(qualityGate -> qualityGate.setBuiltIn(true)); + QualityGateDto qualityGate2 = db.qualityGates().insertQualityGate(qualityGate -> qualityGate.setBuiltIn(false)); + + ListWsResponse response = ws.newRequest().executeProtobuf(ListWsResponse.class); + + assertThat(response.getQualitygatesList()) + .extracting(QualityGate::getId, QualityGate::getIsBuiltIn) + .containsExactlyInAnyOrder( + tuple(qualityGate1.getId(), true), + tuple(qualityGate2.getId(), false)); } @Test diff --git a/sonar-ws/src/main/protobuf/ws-qualitygates.proto b/sonar-ws/src/main/protobuf/ws-qualitygates.proto index e8f322a112e..57658d9996f 100644 --- a/sonar-ws/src/main/protobuf/ws-qualitygates.proto +++ b/sonar-ws/src/main/protobuf/ws-qualitygates.proto @@ -145,6 +145,7 @@ message ListWsResponse { optional int64 id = 1; optional string name = 2; optional bool isDefault = 3; + optional bool isBuiltIn = 4; } }