Search in sources :

Example 1 with ProjectStatusWsResponse

use of org.sonarqube.ws.WsQualityGates.ProjectStatusWsResponse 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 ProjectStatusWsResponse

use of org.sonarqube.ws.WsQualityGates.ProjectStatusWsResponse in project sonarqube by SonarSource.

the class ProjectStatusActionTest method return_undefined_status_if_snapshot_is_not_found.

@Test
public void return_undefined_status_if_snapshot_is_not_found() {
    ComponentDto project = db.components().insertProject(db.organizations().insert());
    userSession.addProjectUuidPermissions(UserRole.USER, project.uuid());
    ProjectStatusWsResponse result = callByProjectUuid(project.uuid());
    assertThat(result.getProjectStatus().getStatus()).isEqualTo(Status.NONE);
    assertThat(result.getProjectStatus().getConditionsCount()).isEqualTo(0);
}
Also used : ProjectStatusWsResponse(org.sonarqube.ws.WsQualityGates.ProjectStatusWsResponse) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 3 with ProjectStatusWsResponse

use of org.sonarqube.ws.WsQualityGates.ProjectStatusWsResponse in project sonarqube by SonarSource.

the class ProjectStatusActionTest method return_undefined_status_if_measure_is_not_found.

@Test
public void return_undefined_status_if_measure_is_not_found() {
    ComponentDto project = db.components().insertProject(db.organizations().insert());
    SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(project));
    dbSession.commit();
    userSession.addProjectUuidPermissions(UserRole.USER, project.uuid());
    ProjectStatusWsResponse result = call(snapshot.getUuid());
    assertThat(result.getProjectStatus().getStatus()).isEqualTo(Status.NONE);
    assertThat(result.getProjectStatus().getConditionsCount()).isEqualTo(0);
}
Also used : ProjectStatusWsResponse(org.sonarqube.ws.WsQualityGates.ProjectStatusWsResponse) SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Aggregations

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