aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2017-10-06 13:55:00 +0200
committerTeryk Bellahsene <teryk@users.noreply.github.com>2017-10-11 18:04:40 +0200
commitafac87bda0c0510d8c9315aa0c36dde8aa675419 (patch)
tree4745a2a3710fa828ab97b8d2603de65d70fde570 /tests
parent52f7e44133feff053d55569f17f06654822b821c (diff)
downloadsonarqube-afac87bda0c0510d8c9315aa0c36dde8aa675419.tar.gz
sonarqube-afac87bda0c0510d8c9315aa0c36dde8aa675419.zip
SONAR-9920 Quality gate administrators can do all qg related actions
Diffstat (limited to 'tests')
-rw-r--r--tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateTest.java27
-rw-r--r--tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateWithOrganizationsTest.java4
2 files changed, 29 insertions, 2 deletions
diff --git a/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateTest.java b/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateTest.java
index c9c13fc8814..75e6a897654 100644
--- a/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateTest.java
+++ b/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateTest.java
@@ -43,18 +43,25 @@ import org.sonar.wsclient.qualitygate.NewCondition;
import org.sonar.wsclient.qualitygate.QualityGate;
import org.sonar.wsclient.qualitygate.QualityGateClient;
import org.sonarqube.tests.Category1Suite;
+import org.sonarqube.tests.Session;
import org.sonarqube.tests.Tester;
import org.sonarqube.ws.MediaTypes;
+import org.sonarqube.ws.Organizations.Organization;
import org.sonarqube.ws.WsCe;
import org.sonarqube.ws.WsMeasures.Measure;
import org.sonarqube.ws.WsProjects.CreateWsResponse.Project;
import org.sonarqube.ws.WsQualityGates;
import org.sonarqube.ws.WsQualityGates.ProjectStatusWsResponse;
+import org.sonarqube.ws.WsUsers;
import org.sonarqube.ws.client.GetRequest;
import org.sonarqube.ws.client.PostRequest;
import org.sonarqube.ws.client.WsResponse;
+import org.sonarqube.ws.client.permission.AddUserWsRequest;
+import org.sonarqube.ws.client.qualitygate.CreateConditionRequest;
import org.sonarqube.ws.client.qualitygate.ProjectStatusWsRequest;
+import org.sonarqube.ws.client.qualitygate.QualityGatesService;
import org.sonarqube.ws.client.qualitygate.SelectWsRequest;
+import org.sonarqube.ws.client.qualitygate.UpdateConditionRequest;
import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
import static org.assertj.core.api.Assertions.assertThat;
@@ -280,6 +287,26 @@ public class QualityGateTest {
}
}
+ @Test
+ public void administrate_quality_gate_with_gateadmin_permission() {
+ // user is quality gate admin of default organization
+ Organization organization = tester.organizations().getDefaultOrganization();
+ WsUsers.CreateWsResponse.User user = tester.users().generateMember(organization);
+ tester.wsClient().permissions().addUser(new AddUserWsRequest().setLogin(user.getLogin()).setPermission("gateadmin").setOrganization(organization.getKey()));
+ Session qGateAdminTester = tester.as(user.getLogin());
+ QualityGatesService qGateService = qGateAdminTester.qGates().service();
+ // perform administration operations
+ WsQualityGates.CreateWsResponse qualityGate = qGateAdminTester.qGates().generate();
+ WsQualityGates.CreateConditionWsResponse condition = qGateService.createCondition(CreateConditionRequest.builder()
+ .setQualityGateId(qualityGate.getId()).setMetricKey("coverage").setOperator("LT").setError("90").build());
+ qGateService.updateCondition(UpdateConditionRequest.builder()
+ .setConditionId(condition.getId()).setMetricKey("coverage").setOperator("LT").setError("90").setWarning("80").build());
+ qGateAdminTester.wsClient().wsConnector().call(new PostRequest("api/qualitygates/set_as_default").setParam("id", qualityGate.getId()));
+ qGateAdminTester.wsClient().wsConnector().call(new PostRequest("api/qualitygates/delete_condition").setParam("id", condition.getId()));
+ qGateAdminTester.wsClient().wsConnector().call(new PostRequest("api/qualitygates/unset_default").setParam("id", qualityGate.getId()));
+ qGateAdminTester.wsClient().wsConnector().call(new PostRequest("api/qualitygates/destroy").setParam("id", qualityGate.getId()));
+ }
+
private BuildResult executeAnalysis(String projectKey, String... keyValueProperties) {
return orchestrator.executeBuild(SonarScanner.create(
projectDir("qualitygate/xoo-sample"), concat(keyValueProperties, "sonar.projectKey", projectKey)));
diff --git a/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateWithOrganizationsTest.java b/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateWithOrganizationsTest.java
index 4af85f7a8ea..226096b2189 100644
--- a/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateWithOrganizationsTest.java
+++ b/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateWithOrganizationsTest.java
@@ -27,7 +27,7 @@ import org.junit.Rule;
import org.junit.Test;
import org.sonarqube.tests.Category6Suite;
import org.sonarqube.tests.Tester;
-import org.sonarqube.ws.Organizations;
+import org.sonarqube.ws.Organizations.Organization;
import org.sonarqube.ws.WsProjects.CreateWsResponse.Project;
import org.sonarqube.ws.WsQualityGates.CreateWsResponse;
import org.sonarqube.ws.WsUsers;
@@ -49,7 +49,7 @@ public class QualityGateWithOrganizationsTest {
@Test
public void always_display_current_quality_gate_in_effect() throws Exception {
- Organizations.Organization organization = tester.organizations().generate();
+ Organization organization = tester.organizations().generate();
Project project = tester.projects().generate(organization);
CreateWsResponse qualityGate = tester.qGates().generate();
tester.qGates().associateProject(qualityGate, project);