]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10087 Add built-in field in api/qualitygates/list
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 22 Nov 2017 17:00:31 +0000 (18:00 +0100)
committerEric Hartmann <hartmann.eric@gmail.Com>
Mon, 4 Dec 2017 12:44:55 +0000 (13:44 +0100)
server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/ListAction.java
server/sonar-server/src/main/resources/org/sonar/server/qualitygate/ws/list-example.json
server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/ListActionTest.java
sonar-ws/src/main/protobuf/ws-qualitygates.proto

index 7b1a67bdebd979411f492bca87465ce7ddcda58e..fe9e93dfd13049ab0c17a00ddbc0c199c652c1a8 100644 (file)
@@ -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);
index 7e5b5f5a62510cb7b6307ccff552989c9227b3c1..547b8d4e8634d9ac9ba4087fdf27d83525d7f9cb 100644 (file)
@@ -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
index 0723d6d2cd8dd2fed17087903c5491b14bbad0fb..83f27cd202509824fba4a9ca43c5daf7166f0a0d 100644 (file)
@@ -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
index e8f322a112ee40b79723601299ea0aabe39de69b..57658d9996f4509084225c6d323f0b647d3e3377 100644 (file)
@@ -145,6 +145,7 @@ message ListWsResponse {
     optional int64 id = 1;
     optional string name = 2;
     optional bool isDefault = 3;
+    optional bool isBuiltIn = 4;
   }
 }