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

index 38b3ab546de9c40e461fee80cd685b55caca55c2..84e53e052fd1e6b2f316f575360c0978de6e3f4c 100644 (file)
@@ -43,12 +43,17 @@ public class QualityGateDbTester {
     this.dbSession = db.getSession();
   }
 
-  public QualityGateDto insertQualityGate() {
-    return insertQualityGate(randomAlphanumeric(30));
+  public QualityGateDto insertQualityGate(String name) {
+    return insertQualityGate(qualityGate -> qualityGate.setName(name));
   }
 
-  public QualityGateDto insertQualityGate(String name) {
-    QualityGateDto updatedUser = dbClient.qualityGateDao().insert(dbSession, new QualityGateDto().setName(name).setBuiltIn(false));
+  @SafeVarargs
+  public final QualityGateDto insertQualityGate(Consumer<QualityGateDto>... dtoPopulators) {
+    QualityGateDto qualityGate = new QualityGateDto()
+      .setName(randomAlphanumeric(30))
+      .setBuiltIn(false);
+    Arrays.stream(dtoPopulators).forEach(dtoPopulator -> dtoPopulator.accept(qualityGate));
+    QualityGateDto updatedUser = dbClient.qualityGateDao().insert(dbSession, qualityGate);
     db.commit();
     return updatedUser;
   }
index d9d9d1efcc1e78826da85c562623662789ed3e85..53eb74529be3789821702d153a3b74a6f3e3b198 100644 (file)
@@ -25,6 +25,7 @@ import java.util.Map;
 import java.util.Set;
 import java.util.function.Function;
 import javax.annotation.Nullable;
+import org.sonar.api.server.ws.Change;
 import org.sonar.api.server.ws.Request;
 import org.sonar.api.server.ws.Response;
 import org.sonar.api.server.ws.WebService;
@@ -62,6 +63,7 @@ public class ShowAction implements QualityGatesWsAction {
       .setDescription("Display the details of a quality gate")
       .setSince("4.3")
       .setResponseExample(Resources.getResource(this.getClass(), "show-example.json"))
+      .setChangelog(new Change("7.0", "'isBuiltIn' field is added to the response"))
       .setHandler(this);
 
     action.createParam(PARAM_ID)
@@ -102,6 +104,7 @@ public class ShowAction implements QualityGatesWsAction {
     return ShowWsResponse.newBuilder()
       .setId(qualityGate.getId())
       .setName(qualityGate.getName())
+      .setIsBuiltIn(qualityGate.isBuiltIn())
       .addAllConditions(conditions.stream()
         .map(toWsCondition(metricsById))
         .collect(toList()))
index 7bca1004eb3b12bee82359ab47626e12d938805e..f01a2079fe6262d0fe56789cbe27ec9f9fee19f2 100644 (file)
@@ -1,6 +1,7 @@
 {
   "id": 2,
   "name": "My Quality Gate",
+  "isBuiltIn": false,
   "conditions": [
     {
       "id": 9,
index 3be7de287f3ed94077f0c60502ee85fdad38eb6a..ddb3b8b57a2c10c50e5a6e4b7fd3c6377a3bbdfb 100644 (file)
@@ -22,6 +22,7 @@ package org.sonar.server.qualitygate.ws;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
+import org.sonar.api.server.ws.Change;
 import org.sonar.api.server.ws.WebService;
 import org.sonar.api.server.ws.WebService.Param;
 import org.sonar.api.utils.System2;
@@ -55,7 +56,8 @@ public class ShowActionTest {
   public void verify_definition() {
     WebService.Action action = ws.getDef();
     assertThat(action.since()).isEqualTo("4.3");
-    assertThat(action.changelog()).isEmpty();
+    assertThat(action.changelog()).extracting(Change::getVersion, Change::getDescription)
+      .containsExactlyInAnyOrder(tuple("7.0", "'isBuiltIn' field is added to the response"));
     assertThat(action.params())
       .extracting(Param::key, Param::isRequired)
       .containsExactlyInAnyOrder(tuple("id", false), tuple("name", false));
@@ -90,6 +92,7 @@ public class ShowActionTest {
 
     assertThat(response.getId()).isEqualTo(qualityGate.getId());
     assertThat(response.getName()).isEqualTo(qualityGate.getName());
+    assertThat(response.getIsBuiltIn()).isFalse();
     assertThat(response.getConditionsList()).hasSize(2);
     assertThat(response.getConditionsList())
       .extracting(Condition::getId, Condition::getMetric, Condition::hasPeriod, Condition::getPeriod, Condition::getOp, Condition::getError, Condition::getWarning)
@@ -98,6 +101,16 @@ public class ShowActionTest {
         tuple(condition2.getId(), metric.getKey(), true, 1, "LT", condition2.getErrorThreshold(), condition2.getWarningThreshold()));
   }
 
+  @Test
+  public void show_built_in() {
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate(qg -> qg.setBuiltIn(true));
+
+    ShowWsResponse response = ws.newRequest().setParam("name", qualityGate.getName())
+      .executeProtobuf(ShowWsResponse.class);
+
+    assertThat(response.getIsBuiltIn()).isTrue();
+  }
+
   @Test
   public void show_by_id() {
     QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
index ef51ba14a3964e2ebcd2ced07b3c8bd84b85ae14..36998c537ffa372a24f18960f46ee8e7e3fef513 100644 (file)
@@ -123,6 +123,7 @@ message ShowWsResponse {
   optional int64 id = 1;
   optional string name = 2;
   repeated Condition conditions = 3;
+  optional bool isBuiltIn = 4;
 
   message Condition {
     optional int64 id = 1;