Search in sources :

Example 1 with ItUtils.getMeasure

use of util.ItUtils.getMeasure 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());
    }
}
Also used : BuildResult(com.sonar.orchestrator.build.BuildResult) Measure(org.sonarqube.ws.WsMeasures.Measure) ItUtils.getMeasure(util.ItUtils.getMeasure) QualityGate(org.sonar.wsclient.qualitygate.QualityGate) SonarScanner(com.sonar.orchestrator.build.SonarScanner) Test(org.junit.Test)

Aggregations

BuildResult (com.sonar.orchestrator.build.BuildResult)1 SonarScanner (com.sonar.orchestrator.build.SonarScanner)1 Test (org.junit.Test)1 QualityGate (org.sonar.wsclient.qualitygate.QualityGate)1 Measure (org.sonarqube.ws.WsMeasures.Measure)1 ItUtils.getMeasure (util.ItUtils.getMeasure)1