aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2017-12-12 14:48:23 +0100
committerJulien Lancelot <julien.lancelot@sonarsource.com>2017-12-14 17:03:35 +0100
commit8314b7211794df1db779f56c70b3618d9de523e8 (patch)
tree83047d9ae20638600eda804665b7b7a97b10490c
parenta93fdfcffa23c125376d3e1f9e2e4abbc6b61a19 (diff)
downloadsonarqube-8314b7211794df1db779f56c70b3618d9de523e8.tar.gz
sonarqube-8314b7211794df1db779f56c70b3618d9de523e8.zip
SONAR-10134 Fix ITs on quality gates by setting organization
-rw-r--r--server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/QGateTester.java24
-rw-r--r--tests/src/test/java/org/sonarqube/tests/qualityGate/OrganizationQualityGateForSmallChangesetsTest.java19
-rw-r--r--tests/src/test/java/org/sonarqube/tests/qualityGate/OrganizationQualityGateTest.java12
3 files changed, 40 insertions, 15 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 3383f355d09..8860d32eb2b 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,7 +24,10 @@ import com.google.gson.annotations.SerializedName;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.Consumer;
import java.util.stream.Collectors;
+import javax.annotation.Nullable;
+import org.sonarqube.ws.Organizations;
import org.sonarqube.ws.Projects.CreateWsResponse.Project;
import org.sonarqube.ws.client.qualitygates.CreateRequest;
import org.sonarqube.ws.client.qualitygates.DestroyRequest;
@@ -33,6 +36,7 @@ import org.sonarqube.ws.client.qualitygates.QualitygatesService;
import org.sonarqube.ws.client.qualitygates.SelectRequest;
import org.sonarqube.ws.client.qualitygates.SetAsDefaultRequest;
+import static java.util.Arrays.stream;
import static org.sonarqube.ws.Qualitygates.CreateResponse;
import static org.sonarqube.ws.Qualitygates.ListWsResponse;
@@ -63,12 +67,28 @@ public class QGateTester {
}
public CreateResponse generate() {
+ return generate(null);
+ }
+
+ @SafeVarargs
+ public final CreateResponse generate(@Nullable Organizations.Organization organization, Consumer<CreateRequest>... populators) {
int id = ID_GENERATOR.getAndIncrement();
- return session.wsClient().qualitygates().create(new CreateRequest().setName("QualityGate" + id));
+ CreateRequest request = new CreateRequest()
+ .setName("QualityGate " + id)
+ .setOrganization(organization != null ? organization.getKey() : null);
+ stream(populators).forEach(p -> p.accept(request));
+ return session.wsClient().qualitygates().create(request);
}
public void associateProject(CreateResponse qualityGate, Project project) {
- service().select(new SelectRequest().setGateId(String.valueOf(qualityGate.getId())).setProjectKey(project.getKey()));
+ associateProject(null, qualityGate, project);
+ }
+
+ public void associateProject(@Nullable Organizations.Organization organization, CreateResponse qualityGate, Project project) {
+ service().select(new SelectRequest()
+ .setOrganization(organization != null ? organization.getKey() : null)
+ .setGateId(String.valueOf(qualityGate.getId()))
+ .setProjectKey(project.getKey()));
}
public static class ListResponse {
diff --git a/tests/src/test/java/org/sonarqube/tests/qualityGate/OrganizationQualityGateForSmallChangesetsTest.java b/tests/src/test/java/org/sonarqube/tests/qualityGate/OrganizationQualityGateForSmallChangesetsTest.java
index d0f2190c111..717e26d888f 100644
--- a/tests/src/test/java/org/sonarqube/tests/qualityGate/OrganizationQualityGateForSmallChangesetsTest.java
+++ b/tests/src/test/java/org/sonarqube/tests/qualityGate/OrganizationQualityGateForSmallChangesetsTest.java
@@ -59,9 +59,10 @@ public class OrganizationQualityGateForSmallChangesetsTest {
public void do_not_fail_quality_gate_with_poor_LEAK_coverage_and_a_max_of_19_lines_of_NEW_code() throws Exception {
Organizations.Organization organization = tester.organizations().generate();
Project project = tester.projects().provision(organization);
- Qualitygates.CreateResponse qualityGate = tester.qGates().generate();
- tester.qGates().associateProject(qualityGate, project);
+ Qualitygates.CreateResponse qualityGate = tester.qGates().generate(organization);
+ tester.qGates().associateProject(organization, qualityGate, project);
Qualitygates.CreateConditionResponse condition = tester.wsClient().qualitygates().createCondition(new CreateConditionRequest()
+ .setOrganization(organization.getKey())
.setGateId(String.valueOf(qualityGate.getId()))
.setMetric("new_coverage")
.setOp("LT")
@@ -86,7 +87,7 @@ public class OrganizationQualityGateForSmallChangesetsTest {
.setDebugLogs(true);
orchestrator.executeBuild(analysis);
assertThat(getMeasure(orchestrator, project.getKey(), "alert_status").getValue()).isEqualTo("OK");
- assertIgnoredConditions("qualitygate/small-changesets/v1-1000-lines", false);
+ assertIgnoredConditions(organization,"qualitygate/small-changesets/v1-1000-lines", false);
// small leak => ignore coverage warning or error
SonarScanner analysis2 = SonarScanner
@@ -101,10 +102,11 @@ public class OrganizationQualityGateForSmallChangesetsTest {
.setDebugLogs(true);
orchestrator.executeBuild(analysis2);
assertThat(getMeasure(orchestrator, project.getKey(), "alert_status").getValue()).isEqualTo("OK");
- assertIgnoredConditions("qualitygate/small-changesets/v2-1019-lines", true);
+ assertIgnoredConditions(organization, "qualitygate/small-changesets/v2-1019-lines", true);
// small leak => if coverage is OK anyways, we do not have to ignore anything
tester.wsClient().qualitygates().updateCondition(new UpdateConditionRequest()
+ .setOrganization(organization.getKey())
.setId(String.valueOf(condition.getId()))
.setMetric("new_coverage")
.setOp("LT")
@@ -123,10 +125,11 @@ public class OrganizationQualityGateForSmallChangesetsTest {
.setDebugLogs(true);
orchestrator.executeBuild(analysis3);
assertThat(getMeasure(orchestrator, project.getKey(), "alert_status").getValue()).isEqualTo("OK");
- assertIgnoredConditions("qualitygate/small-changesets/v2-1019-lines", false);
+ assertIgnoredConditions(organization, "qualitygate/small-changesets/v2-1019-lines", false);
// big leak => use usual behaviour
tester.wsClient().qualitygates().updateCondition(new UpdateConditionRequest()
+ .setOrganization(organization.getKey())
.setId(String.valueOf(condition.getId()))
.setMetric("new_coverage")
.setOp("LT")
@@ -145,13 +148,13 @@ public class OrganizationQualityGateForSmallChangesetsTest {
.setDebugLogs(true);
orchestrator.executeBuild(analysis4);
assertThat(getMeasure(orchestrator, project.getKey(), "alert_status").getValue()).isEqualTo("ERROR");
- assertIgnoredConditions("qualitygate/small-changesets/v2-1020-lines", false);
+ assertIgnoredConditions(organization, "qualitygate/small-changesets/v2-1020-lines", false);
}
- private void assertIgnoredConditions(String projectDir, boolean expected) throws IOException {
+ private void assertIgnoredConditions(Organizations.Organization organization, String projectDir, boolean expected) throws IOException {
String analysisId = getAnalysisId(getTaskIdInLocalReport(projectDir(projectDir)));
boolean ignoredConditions = tester.wsClient().qualitygates()
- .projectStatus(new ProjectStatusRequest().setAnalysisId(analysisId))
+ .projectStatus(new ProjectStatusRequest().setOrganization(organization.getKey()).setAnalysisId(analysisId))
.getProjectStatus()
.getIgnoredConditions();
assertThat(ignoredConditions).isEqualTo(expected);
diff --git a/tests/src/test/java/org/sonarqube/tests/qualityGate/OrganizationQualityGateTest.java b/tests/src/test/java/org/sonarqube/tests/qualityGate/OrganizationQualityGateTest.java
index bfaba6cc19b..155ba21efaa 100644
--- a/tests/src/test/java/org/sonarqube/tests/qualityGate/OrganizationQualityGateTest.java
+++ b/tests/src/test/java/org/sonarqube/tests/qualityGate/OrganizationQualityGateTest.java
@@ -47,12 +47,13 @@ public class OrganizationQualityGateTest {
public Tester tester = new Tester(orchestrator);
@Test
- public void always_display_current_quality_gate_in_effect() throws Exception {
+ public void always_display_current_quality_gate_in_effect() {
Organization organization = tester.organizations().generate();
Project project = tester.projects().provision(organization);
- Qualitygates.CreateResponse qualityGate = tester.qGates().generate();
- tester.qGates().associateProject(qualityGate, project);
+ Qualitygates.CreateResponse qualityGate = tester.qGates().generate(organization);
+ tester.qGates().associateProject(organization, qualityGate, project);
tester.wsClient().qualitygates().createCondition(new CreateConditionRequest()
+ .setOrganization(organization.getKey())
.setGateId(String.valueOf(qualityGate.getId()))
.setMetric("new_coverage")
.setOp("LT")
@@ -80,9 +81,10 @@ public class OrganizationQualityGateTest {
Map currentQualityGate2 = (Map) ItUtils.jsonToMap(response2.content()).get("qualityGate");
assertThat((long) (double) (Double) currentQualityGate2.get("key")).isEqualTo(qualityGate.getId());
- Qualitygates.CreateResponse qualityGate2 = tester.qGates().generate();
- tester.qGates().associateProject(qualityGate2, project);
+ Qualitygates.CreateResponse qualityGate2 = tester.qGates().generate(organization);
+ tester.qGates().associateProject(organization, qualityGate2, project);
tester.wsClient().qualitygates().createCondition(new CreateConditionRequest()
+ .setOrganization(organization.getKey())
.setGateId(String.valueOf(qualityGate2.getId()))
.setMetric("new_coverage")
.setOp("LT")