aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDaniel Schwarz <daniel.schwarz@sonarsource.com>2017-10-04 09:42:38 +0200
committerDaniel Schwarz <bartfastiel@users.noreply.github.com>2017-10-07 09:06:25 +0200
commit454f14e4688f677877ce61bb0c9c5256638375a9 (patch)
tree652622b3302461388c93511de46e2c2db9e67b34 /tests
parent6dbe83f15f431bc1f5a609040767ef7e0a4ba79c (diff)
downloadsonarqube-454f14e4688f677877ce61bb0c9c5256638375a9.tar.gz
sonarqube-454f14e4688f677877ce61bb0c9c5256638375a9.zip
SONAR-9352 add "ignoredConditions" to response example of api/qualitygates/project_status
Diffstat (limited to 'tests')
-rw-r--r--tests/projects/qualitygate/small-changesets/v2-1020-lines/src/sample/Sample.xoo.scm2
-rw-r--r--tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateForSmallChangesetsTest.java81
2 files changed, 81 insertions, 2 deletions
diff --git a/tests/projects/qualitygate/small-changesets/v2-1020-lines/src/sample/Sample.xoo.scm b/tests/projects/qualitygate/small-changesets/v2-1020-lines/src/sample/Sample.xoo.scm
index 07c227857e1..98fd9a53dda 100644
--- a/tests/projects/qualitygate/small-changesets/v2-1020-lines/src/sample/Sample.xoo.scm
+++ b/tests/projects/qualitygate/small-changesets/v2-1020-lines/src/sample/Sample.xoo.scm
@@ -1017,4 +1017,4 @@
2,user2,2014-04-01
2,user2,2014-04-01
2,user2,2014-04-01
-3,user3,2014-04-02 \ No newline at end of file
+3,user3,2014-04-03 \ No newline at end of file
diff --git a/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateForSmallChangesetsTest.java b/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateForSmallChangesetsTest.java
index 715b80cab80..ca4c99e47dc 100644
--- a/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateForSmallChangesetsTest.java
+++ b/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateForSmallChangesetsTest.java
@@ -21,17 +21,29 @@ package org.sonarqube.tests.qualityGate;
import com.sonar.orchestrator.Orchestrator;
import com.sonar.orchestrator.build.SonarScanner;
+import java.io.File;
+import java.io.IOException;
+import java.io.StringReader;
+import java.nio.charset.StandardCharsets;
+import java.util.Properties;
+import org.apache.commons.io.FileUtils;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.sonarqube.tests.Category6Suite;
import org.sonarqube.tests.Tester;
+import org.sonarqube.ws.MediaTypes;
import org.sonarqube.ws.Organizations;
+import org.sonarqube.ws.WsCe;
import org.sonarqube.ws.WsProjects.CreateWsResponse.Project;
import org.sonarqube.ws.WsQualityGates;
import org.sonarqube.ws.WsQualityGates.CreateWsResponse;
import org.sonarqube.ws.WsUsers;
+import org.sonarqube.ws.client.GetRequest;
+import org.sonarqube.ws.client.WsResponse;
import org.sonarqube.ws.client.qualitygate.CreateConditionRequest;
+import org.sonarqube.ws.client.qualitygate.ProjectStatusWsRequest;
+import org.sonarqube.ws.client.qualitygate.UpdateConditionRequest;
import static org.assertj.core.api.Assertions.assertThat;
import static util.ItUtils.getMeasure;
@@ -64,6 +76,7 @@ public class QualityGateForSmallChangesetsTest {
String password = "password1";
WsUsers.CreateWsResponse.User user = tester.users().generateAdministrator(organization, u -> u.setPassword(password));
+ // no leak => use usual behaviour
SonarScanner analysis = SonarScanner
.create(projectDir("qualitygate/small-changesets/v1-1000-lines"))
.setProperty("sonar.projectKey", project.getKey())
@@ -76,7 +89,9 @@ public class QualityGateForSmallChangesetsTest {
.setDebugLogs(true);
orchestrator.executeBuild(analysis);
assertThat(getMeasure(orchestrator, project.getKey(), "alert_status").getValue()).isEqualTo("OK");
+ assertIgnoredConditions(project, "qualitygate/small-changesets/v1-1000-lines", false);
+ // small leak => ignore coverage warning or error
SonarScanner analysis2 = SonarScanner
.create(projectDir("qualitygate/small-changesets/v2-1019-lines"))
.setProperty("sonar.projectKey", project.getKey())
@@ -89,7 +104,40 @@ public class QualityGateForSmallChangesetsTest {
.setDebugLogs(true);
orchestrator.executeBuild(analysis2);
assertThat(getMeasure(orchestrator, project.getKey(), "alert_status").getValue()).isEqualTo("OK");
+ assertIgnoredConditions(project, "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(UpdateConditionRequest.builder()
+ .setConditionId(condition.getId())
+ .setMetricKey("new_coverage")
+ .setOperator("LT")
+ .setWarning("10")
+ .setError("20")
+ .setPeriod(1)
+ .build());
+ SonarScanner analysis3 = SonarScanner
+ .create(projectDir("qualitygate/small-changesets/v2-1019-lines"))
+ .setProperty("sonar.projectKey", project.getKey())
+ .setProperty("sonar.organization", organization.getKey())
+ .setProperty("sonar.login", user.getLogin())
+ .setProperty("sonar.password", password)
+ .setProperty("sonar.scm.provider", "xoo")
+ .setProperty("sonar.scm.disabled", "false")
+ .setProperty("sonar.projectDate", "2014-04-02")
+ .setDebugLogs(true);
+ orchestrator.executeBuild(analysis3);
+ assertThat(getMeasure(orchestrator, project.getKey(), "alert_status").getValue()).isEqualTo("OK");
+ assertIgnoredConditions(project, "qualitygate/small-changesets/v2-1019-lines", false);
+
+ // big leak => use usual behaviour
+ tester.wsClient().qualityGates().updateCondition(UpdateConditionRequest.builder()
+ .setConditionId(condition.getId())
+ .setMetricKey("new_coverage")
+ .setOperator("LT")
+ .setWarning(null)
+ .setError("70")
+ .setPeriod(1)
+ .build());
SonarScanner analysis4 = SonarScanner
.create(projectDir("qualitygate/small-changesets/v2-1020-lines"))
.setProperty("sonar.projectKey", project.getKey())
@@ -98,9 +146,40 @@ public class QualityGateForSmallChangesetsTest {
.setProperty("sonar.password", password)
.setProperty("sonar.scm.provider", "xoo")
.setProperty("sonar.scm.disabled", "false")
- .setProperty("sonar.projectDate", "2014-04-02")
+ .setProperty("sonar.projectDate", "2014-04-03")
.setDebugLogs(true);
orchestrator.executeBuild(analysis4);
assertThat(getMeasure(orchestrator, project.getKey(), "alert_status").getValue()).isEqualTo("ERROR");
+ assertIgnoredConditions(project, "qualitygate/small-changesets/v2-1020-lines", false);
+ }
+
+ private void assertIgnoredConditions(Project project, String projectDir, boolean expected) throws IOException {
+ String analysisId = getAnalysisId(getTaskIdInLocalReport(projectDir(projectDir)));
+ boolean ignoredConditions = tester.wsClient().qualityGates()
+ .projectStatus(new ProjectStatusWsRequest().setAnalysisId(analysisId))
+ .getProjectStatus()
+ .getIgnoredConditions();
+ assertThat(ignoredConditions).isEqualTo(expected);
+ }
+
+ private String getAnalysisId(String taskId) throws IOException {
+ WsResponse activity = tester.wsClient()
+ .wsConnector()
+ .call(new GetRequest("api/ce/task")
+ .setParam("id", taskId)
+ .setMediaType(MediaTypes.PROTOBUF));
+ WsCe.TaskResponse activityWsResponse = WsCe.TaskResponse.parseFrom(activity.contentStream());
+ return activityWsResponse.getTask().getAnalysisId();
+ }
+
+ private String getTaskIdInLocalReport(File projectDirectory) throws IOException {
+ File metadata = new File(projectDirectory, ".sonar/report-task.txt");
+ assertThat(metadata).exists().isFile();
+ // verify properties
+ Properties props = new Properties();
+ props.load(new StringReader(FileUtils.readFileToString(metadata, StandardCharsets.UTF_8)));
+ assertThat(props.getProperty("ceTaskId")).isNotEmpty();
+
+ return props.getProperty("ceTaskId");
}
}