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;
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 {
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) {
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 {
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