diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2017-12-07 12:24:11 +0100 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2017-12-14 17:03:35 +0100 |
commit | 1ed2b5a977bf6264a68da80338e4105bd145e844 (patch) | |
tree | cabeecda5aeac9a4daef61bc23cec5bdb64bcf75 | |
parent | 4a0c3a9d916533a9811452e5c7854bde34e469a4 (diff) | |
download | sonarqube-1ed2b5a977bf6264a68da80338e4105bd145e844.tar.gz sonarqube-1ed2b5a977bf6264a68da80338e4105bd145e844.zip |
SONAR-9962 Reset built-in quality gate as default between each IT
-rw-r--r-- | server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/QGateTester.java | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/QGateTester.java b/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/QGateTester.java index a90e2f36925..86c330bee29 100644 --- a/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/QGateTester.java +++ b/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/QGateTester.java @@ -24,13 +24,16 @@ import com.google.gson.annotations.SerializedName; import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Collectors; import org.sonarqube.ws.Projects.CreateWsResponse.Project; -import org.sonarqube.ws.Qualitygates; -import org.sonarqube.ws.client.GetRequest; -import org.sonarqube.ws.client.PostRequest; import org.sonarqube.ws.client.qualitygates.CreateRequest; +import org.sonarqube.ws.client.qualitygates.DestroyRequest; import org.sonarqube.ws.client.qualitygates.QualitygatesService; import org.sonarqube.ws.client.qualitygates.SelectRequest; +import org.sonarqube.ws.client.qualitygates.SetAsDefaultRequest; + +import static org.sonarqube.ws.Qualitygates.CreateResponse; +import static org.sonarqube.ws.Qualitygates.ListWsResponse; public class QGateTester { private static final AtomicInteger ID_GENERATOR = new AtomicInteger(); @@ -46,19 +49,23 @@ public class QGateTester { } void deleteAll() { - String json = session.wsClient().wsConnector().call(new GetRequest("api/qualitygates/list")).failIfNotSuccessful().content(); - ListResponse response = ListResponse.parse(json); - response.getQualityGates().stream() - .filter(qualityGate -> !qualityGate.getId().equals(response.getDefault())) - .forEach(qualityGate -> session.wsClient().wsConnector().call(new PostRequest("api/qualitygates/destroy").setParam("id", qualityGate.getId())).failIfNotSuccessful()); + List<ListWsResponse.QualityGate> builtInQualityGates = session.wsClient().qualitygates().list().getQualitygatesList().stream() + .filter(ListWsResponse.QualityGate::getIsBuiltIn) + .collect(Collectors.toList()); + if (builtInQualityGates.size() == 1) { + session.wsClient().qualitygates().setAsDefault(new SetAsDefaultRequest().setId(Long.toString(builtInQualityGates.get(0).getId()))); + } + session.wsClient().qualitygates().list().getQualitygatesList().stream() + .filter(qualityGate -> !qualityGate.getIsDefault()) + .forEach(qualityGate -> session.wsClient().qualitygates().destroy(new DestroyRequest().setId(Long.toString(qualityGate.getId())))); } - public Qualitygates.CreateResponse generate() { + public CreateResponse generate() { int id = ID_GENERATOR.getAndIncrement(); return session.wsClient().qualitygates().create(new CreateRequest().setName("QualityGate" + id)); } - public void associateProject(Qualitygates.CreateResponse qualityGate, Project project){ + public void associateProject(CreateResponse qualityGate, Project project) { service().select(new SelectRequest().setGateId(String.valueOf(qualityGate.getId())).setProjectKey(project.getKey())); } |