Search in sources :

Example 6 with Measure

use of org.sonarqube.ws.WsMeasures.Measure 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)

Example 7 with Measure

use of org.sonarqube.ws.WsMeasures.Measure in project sonar-web by SonarSource.

the class WebTestSuite method getMeasure.

@CheckForNull
static Measure getMeasure(Orchestrator orchestrator, String componentKey, String metricKey) {
    WsMeasures.ComponentWsResponse response = newWsClient(orchestrator).measures().component(new ComponentWsRequest().setComponentKey(componentKey).setMetricKeys(Collections.singletonList(metricKey)));
    List<Measure> measures = response.getComponent().getMeasuresList();
    return measures.size() == 1 ? measures.get(0) : null;
}
Also used : WsMeasures(org.sonarqube.ws.WsMeasures) Measure(org.sonarqube.ws.WsMeasures.Measure) ComponentWsRequest(org.sonarqube.ws.client.measure.ComponentWsRequest) CheckForNull(javax.annotation.CheckForNull)

Aggregations

Measure (org.sonarqube.ws.WsMeasures.Measure)7 Test (org.junit.Test)6 WsMeasures (org.sonarqube.ws.WsMeasures)3 SonarScanner (com.sonar.orchestrator.build.SonarScanner)2 ComponentDto (org.sonar.db.component.ComponentDto)2 SnapshotDto (org.sonar.db.component.SnapshotDto)2 MetricDto (org.sonar.db.metric.MetricDto)2 MetricTesting.newMetricDto (org.sonar.db.metric.MetricTesting.newMetricDto)2 SearchWsResponse (org.sonarqube.ws.WsMeasures.SearchWsResponse)2 BuildResult (com.sonar.orchestrator.build.BuildResult)1 FileLocation (com.sonar.orchestrator.locator.FileLocation)1 Integer.parseInt (java.lang.Integer.parseInt)1 Map (java.util.Map)1 CheckForNull (javax.annotation.CheckForNull)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 AfterClass (org.junit.AfterClass)1 Before (org.junit.Before)1 IssueQuery (org.sonar.wsclient.issue.IssueQuery)1 QualityGate (org.sonar.wsclient.qualitygate.QualityGate)1 SearchHistoryResponse (org.sonarqube.ws.WsMeasures.SearchHistoryResponse)1