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;
}
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;
.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)
return ShowWsResponse.newBuilder()
.setId(qualityGate.getId())
.setName(qualityGate.getName())
+ .setIsBuiltIn(qualityGate.isBuiltIn())
.addAllConditions(conditions.stream()
.map(toWsCondition(metricsById))
.collect(toList()))
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;
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));
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)
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();