]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10087 Use protobuf in api/qualitygates/rename
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 23 Nov 2017 15:38:24 +0000 (16:38 +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/GetByProjectAction.java
server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/RenameAction.java
server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/RenameActionTest.java
sonar-ws/src/main/protobuf/ws-qualitygates.proto

index 23d7bb84ea7f0e8be071933af2f67d8136fde001..1d69b4a4c9bd755bb6bead214d1018c7f484f81a 100644 (file)
@@ -106,7 +106,7 @@ public class GetByProjectAction implements QualityGatesWsAction {
     GetByProjectResponse.Builder response = GetByProjectResponse.newBuilder();
 
     response.getQualityGateBuilder()
-      .setId(String.valueOf(qualityGate.getId()))
+      .setId(qualityGate.getId())
       .setName(qualityGate.getName())
       .setDefault(data.get().isDefault());
 
index deb2a084a861e8e0b027d5a481c526fada841dd9..c438e00e7fdefa145ba30d48392890c50117748d 100644 (file)
@@ -22,11 +22,11 @@ package org.sonar.server.qualitygate.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.utils.text.JsonWriter;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.qualitygate.QualityGateDto;
 import org.sonar.server.qualitygate.QualityGateFinder;
+import org.sonarqube.ws.Qualitygates.QualityGate;
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Strings.isNullOrEmpty;
@@ -34,6 +34,7 @@ import static org.sonar.server.qualitygate.ws.CreateAction.NAME_MAXIMUM_LENGTH;
 import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_ID;
 import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_NAME;
 import static org.sonar.server.util.Validation.CANT_BE_EMPTY_MESSAGE;
+import static org.sonar.server.ws.WsUtils.writeProtobuf;
 
 public class RenameAction implements QualityGatesWsAction {
 
@@ -72,9 +73,11 @@ public class RenameAction implements QualityGatesWsAction {
   public void handle(Request request, Response response) {
     wsSupport.checkCanEdit();
     long id = QualityGatesWs.parseId(request, PARAM_ID);
-    QualityGateDto renamedQualityGate = rename(id, request.mandatoryParam(PARAM_NAME));
-    JsonWriter writer = response.newJsonWriter();
-    QualityGatesWs.writeQualityGate(renamedQualityGate, writer).close();
+    QualityGateDto qualityGate = rename(id, request.mandatoryParam(PARAM_NAME));
+    writeProtobuf(QualityGate.newBuilder()
+      .setId(qualityGate.getId())
+      .setName(qualityGate.getName())
+      .build(), request, response);
   }
 
   private QualityGateDto rename(long id, String name) {
index 59d733bb0551349a23916e846310f014ae58ae0c..546ddfc86c87975bee83441ad39e2fbbe3fe8dc3 100644 (file)
@@ -34,13 +34,13 @@ import org.sonar.server.organization.TestDefaultOrganizationProvider;
 import org.sonar.server.qualitygate.QualityGateFinder;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.ws.WsActionTester;
+import org.sonarqube.ws.Qualitygates.QualityGate;
 
 import static java.lang.String.format;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.AssertionsForClassTypes.tuple;
 import static org.sonar.db.permission.OrganizationPermission.ADMINISTER_QUALITY_GATES;
 import static org.sonar.db.permission.OrganizationPermission.ADMINISTER_QUALITY_PROFILES;
-import static org.sonar.test.JsonAssert.assertJson;
 
 public class RenameActionTest {
 
@@ -85,18 +85,13 @@ public class RenameActionTest {
     logAsQualityGateAdminister();
     QualityGateDto qualityGate = db.qualityGates().insertQualityGate(qg -> qg.setName("old name"));
 
-    String result = ws.newRequest()
+    QualityGate result = ws.newRequest()
       .setParam("id", qualityGate.getId().toString())
       .setParam("name", "new name")
-      .execute()
-      .getInput();
-
-    assertJson(result).isSimilarTo(
-      format("{\n" +
-        "  \"id\": %s,\n" +
-        "  \"name\": \"new name\"\n" +
-        "}",
-        qualityGate.getId()));
+      .executeProtobuf(QualityGate.class);
+
+    assertThat(result.getId()).isEqualTo(qualityGate.getId());
+    assertThat(result.getName()).isEqualTo("new name");
   }
 
   @Test
index 16b4d7e96717273f3ebb9b468fbc05038fa9b975..e7355755459b6a6ab4c0766026f306252a7a1184 100644 (file)
@@ -73,7 +73,7 @@ message GetByProjectResponse {
 }
 
 message QualityGate {
-  optional string id = 1;
+  optional int64 id = 1;
   optional string name = 2;
   optional bool default = 3;
 }