use of org.sonar.wsclient.qualitygate.QualityGate in project sonarqube by SonarSource.
the class QualityGateTest method test_status_ok.
@Test
public void test_status_ok() throws IOException {
QualityGate simple = qgClient().create("SimpleWithHighThreshold");
qgClient().setDefault(simple.id());
qgClient().createCondition(NewCondition.create(simple.id()).metricKey("ncloc").operator("GT").warningThreshold("40"));
try {
SonarScanner build = SonarScanner.create(projectDir("qualitygate/xoo-sample"));
BuildResult buildResult = orchestrator.executeBuild(build);
verifyQGStatusInPostTask(buildResult, TASK_STATUS_SUCCESS, QG_STATUS_OK);
assertThat(getGateStatusMeasure().getValue()).isEqualTo("OK");
} finally {
qgClient().unsetDefault();
qgClient().destroy(simple.id());
}
}
use of org.sonar.wsclient.qualitygate.QualityGate in project sonarqube by SonarSource.
the class ProjectQualityGatePageTest method should_set_default.
@Test
public void should_set_default() {
QualityGate customQualityGate = createCustomQualityGate("should_set_default");
qualityGateClient().setDefault(customQualityGate.id());
ProjectQualityGatePage page = openPage();
page.setQualityGate(customQualityGate.name());
SelenideElement selectedQualityGate = page.getSelectedQualityGate();
selectedQualityGate.should(Condition.hasText("Default"));
selectedQualityGate.should(Condition.hasText(customQualityGate.name()));
}
use of org.sonar.wsclient.qualitygate.QualityGate in project sonarqube by SonarSource.
the class QualityGateTest method conditions_on_multiple_metric_types.
@Test
public void conditions_on_multiple_metric_types() throws IOException {
QualityGate allTypes = qgClient().create("AllMetricTypes");
qgClient().createCondition(NewCondition.create(allTypes.id()).metricKey("ncloc").operator("GT").warningThreshold("10"));
qgClient().createCondition(NewCondition.create(allTypes.id()).metricKey("duplicated_lines_density").operator("GT").warningThreshold("20"));
qgClient().setDefault(allTypes.id());
try {
SonarScanner build = SonarScanner.create(projectDir("qualitygate/xoo-sample")).setProperty("sonar.cpd.xoo.minimumLines", "2").setProperty("sonar.cpd.xoo.minimumTokens", "5");
BuildResult buildResult = orchestrator.executeBuild(build);
verifyQGStatusInPostTask(buildResult, TASK_STATUS_SUCCESS, QG_STATUS_WARN);
Measure alertStatus = getGateStatusMeasure();
assertThat(alertStatus.getValue()).isEqualTo("WARN");
String qualityGateDetailJson = ItUtils.getMeasure(orchestrator, PROJECT_KEY, "quality_gate_details").getValue();
assertThat(QualityGateDetails.parse(qualityGateDetailJson).getConditions()).extracting(QualityGateDetails.Conditions::getMetric, QualityGateDetails.Conditions::getOp, QualityGateDetails.Conditions::getWarning).contains(tuple("ncloc", "GT", "10"), tuple("duplicated_lines_density", "GT", "20"));
} finally {
qgClient().unsetDefault();
qgClient().destroy(allTypes.id());
}
}
use of org.sonar.wsclient.qualitygate.QualityGate in project sonarqube by SonarSource.
the class QualityGateTest method test_status_warning.
@Test
public void test_status_warning() throws IOException {
QualityGate simple = qgClient().create("SimpleWithLowThreshold");
qgClient().setDefault(simple.id());
qgClient().createCondition(NewCondition.create(simple.id()).metricKey("ncloc").operator("GT").warningThreshold("10"));
try {
SonarScanner build = SonarScanner.create(projectDir("qualitygate/xoo-sample"));
BuildResult buildResult = orchestrator.executeBuild(build);
verifyQGStatusInPostTask(buildResult, TASK_STATUS_SUCCESS, QG_STATUS_WARN);
assertThat(getGateStatusMeasure().getValue()).isEqualTo("WARN");
} finally {
qgClient().unsetDefault();
qgClient().destroy(simple.id());
}
}
use of org.sonar.wsclient.qualitygate.QualityGate in project sonarqube by SonarSource.
the class QualityGateTest method status_ok_if_empty_gate.
@Test
public void status_ok_if_empty_gate() throws IOException {
QualityGate empty = qgClient().create("Empty");
qgClient().setDefault(empty.id());
try {
SonarScanner build = SonarScanner.create(projectDir("qualitygate/xoo-sample"));
BuildResult buildResult = orchestrator.executeBuild(build);
verifyQGStatusInPostTask(buildResult, TASK_STATUS_SUCCESS, QG_STATUS_OK);
assertThat(getGateStatusMeasure().getValue()).isEqualTo("OK");
} finally {
qgClient().unsetDefault();
qgClient().destroy(empty.id());
}
}
Aggregations