-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
OrganizationQualityGateTest.java
99 lines (88 loc) · 4.4 KB
/
OrganizationQualityGateTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
* SonarQube
* Copyright (C) 2009-2017 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonarqube.tests.qualityGate;
import com.sonar.orchestrator.Orchestrator;
import com.sonar.orchestrator.build.SonarScanner;
import java.util.Map;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.sonarqube.qa.util.Tester;
import org.sonarqube.ws.Organizations.Organization;
import org.sonarqube.ws.WsProjects.CreateWsResponse.Project;
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 util.ItUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static util.ItUtils.projectDir;
public class OrganizationQualityGateTest {
@ClassRule
public static Orchestrator orchestrator = OrganizationQualityGateSuite.ORCHESTRATOR;
@Rule
public Tester tester = new Tester(orchestrator);
@Test
public void always_display_current_quality_gate_in_effect() throws Exception {
Organization organization = tester.organizations().generate();
Project project = tester.projects().generate(organization);
CreateWsResponse qualityGate = tester.qGates().generate();
tester.qGates().associateProject(qualityGate, project);
tester.wsClient().qualityGates().createCondition(CreateConditionRequest.builder()
.setQualityGateId(qualityGate.getId())
.setMetricKey("new_coverage")
.setOperator("LT")
.setWarning("90")
.setError("80")
.setPeriod(1)
.build());
tester.settings().setProjectSetting(project.getKey(), "sonar.leak.period", "previous_version");
String password = "password1";
WsUsers.CreateWsResponse.User user = tester.users().generateAdministrator(organization, u -> u.setPassword(password));
WsResponse response = tester.wsClient().wsConnector().call(new GetRequest("api/navigation/component").setParam("componentKey", project.getKey()));
Map currentQualityGate = (Map) ItUtils.jsonToMap(response.content()).get("qualityGate");
assertThat((long) (double) (Double) currentQualityGate.get("key")).isEqualTo(qualityGate.getId());
orchestrator.executeBuild(
SonarScanner.create(projectDir("shared/xoo-sample"))
.setProperty("sonar.organization", organization.getKey())
.setProjectKey(project.getKey())
.setProjectName(project.getName())
.setProperty("sonar.login", user.getLogin())
.setProperty("sonar.password", password)
.setDebugLogs(true));
WsResponse response2 = tester.wsClient().wsConnector().call(new GetRequest("api/navigation/component").setParam("componentKey", project.getKey()));
Map currentQualityGate2 = (Map) ItUtils.jsonToMap(response2.content()).get("qualityGate");
assertThat((long) (double) (Double) currentQualityGate2.get("key")).isEqualTo(qualityGate.getId());
CreateWsResponse qualityGate2 = tester.qGates().generate();
tester.qGates().associateProject(qualityGate2, project);
tester.wsClient().qualityGates().createCondition(CreateConditionRequest.builder()
.setQualityGateId(qualityGate2.getId())
.setMetricKey("new_coverage")
.setOperator("LT")
.setWarning("90")
.setError("80")
.setPeriod(1)
.build());
WsResponse response3 = tester.wsClient().wsConnector().call(new GetRequest("api/navigation/component").setParam("componentKey", project.getKey()));
Map currentQualityGate3 = (Map) ItUtils.jsonToMap(response3.content()).get("qualityGate");
assertThat((long) (double) (Double) currentQualityGate3.get("key")).isEqualTo(qualityGate2.getId());
}
}