Search in sources :

Example 1 with ProjectStatusWsRequest

use of org.sonarqube.ws.client.qualitygate.ProjectStatusWsRequest in project sonarqube by SonarSource.

the class QualityGateTest method ad_hoc_build_break_strategy.

@Test
public void ad_hoc_build_break_strategy() throws IOException {
    QualityGate simple = qgClient().create("SimpleWithLowThresholdForBuildBreakStrategy");
    qgClient().setDefault(simple.id());
    qgClient().createCondition(NewCondition.create(simple.id()).metricKey("ncloc").operator("GT").errorThreshold("7"));
    try {
        File projectDir = projectDir("qualitygate/xoo-sample");
        SonarScanner build = SonarScanner.create(projectDir);
        BuildResult buildResult = orchestrator.executeBuild(build);
        verifyQGStatusInPostTask(buildResult, TASK_STATUS_SUCCESS, QG_STATUS_ERROR);
        String taskId = getTaskIdInLocalReport(projectDir);
        String analysisId = getAnalysisId(taskId);
        ProjectStatusWsResponse projectStatusWsResponse = wsClient.qualityGates().projectStatus(new ProjectStatusWsRequest().setAnalysisId(analysisId));
        ProjectStatusWsResponse.ProjectStatus projectStatus = projectStatusWsResponse.getProjectStatus();
        assertThat(projectStatus.getStatus()).isEqualTo(ProjectStatusWsResponse.Status.ERROR);
        assertThat(projectStatus.getConditionsCount()).isEqualTo(1);
        ProjectStatusWsResponse.Condition condition = projectStatus.getConditionsList().get(0);
        assertThat(condition.getMetricKey()).isEqualTo("ncloc");
        assertThat(condition.getErrorThreshold()).isEqualTo("7");
    } finally {
        qgClient().unsetDefault();
        qgClient().destroy(simple.id());
    }
}
Also used : BuildResult(com.sonar.orchestrator.build.BuildResult) ProjectStatusWsResponse(org.sonarqube.ws.WsQualityGates.ProjectStatusWsResponse) ProjectStatusWsRequest(org.sonarqube.ws.client.qualitygate.ProjectStatusWsRequest) File(java.io.File) QualityGate(org.sonar.wsclient.qualitygate.QualityGate) SonarScanner(com.sonar.orchestrator.build.SonarScanner) Test(org.junit.Test)

Example 2 with ProjectStatusWsRequest

use of org.sonarqube.ws.client.qualitygate.ProjectStatusWsRequest in project sonarqube by SonarSource.

the class ProjectStatusAction method toProjectStatusWsRequest.

private static ProjectStatusWsRequest toProjectStatusWsRequest(Request request) {
    ProjectStatusWsRequest projectStatusWsRequest = new ProjectStatusWsRequest().setAnalysisId(request.param(PARAM_ANALYSIS_ID)).setProjectId(request.param(PARAM_PROJECT_ID)).setProjectKey(request.param(PARAM_PROJECT_KEY));
    checkRequest(!isNullOrEmpty(projectStatusWsRequest.getAnalysisId()) ^ !isNullOrEmpty(projectStatusWsRequest.getProjectId()) ^ !isNullOrEmpty(projectStatusWsRequest.getProjectKey()), MSG_ONE_PARAMETER_ONLY);
    return projectStatusWsRequest;
}
Also used : ProjectStatusWsRequest(org.sonarqube.ws.client.qualitygate.ProjectStatusWsRequest)

Aggregations

ProjectStatusWsRequest (org.sonarqube.ws.client.qualitygate.ProjectStatusWsRequest)2 BuildResult (com.sonar.orchestrator.build.BuildResult)1 SonarScanner (com.sonar.orchestrator.build.SonarScanner)1 File (java.io.File)1 Test (org.junit.Test)1 QualityGate (org.sonar.wsclient.qualitygate.QualityGate)1 ProjectStatusWsResponse (org.sonarqube.ws.WsQualityGates.ProjectStatusWsResponse)1