Search in sources :

Example 11 with QualityGateConditionDto

use of org.sonar.db.qualitygate.QualityGateConditionDto in project sonarqube by SonarSource.

the class QualityGateConditionsUpdaterTest method fail_to_update_condition_when_condition_on_same_metric_already_exist.

@Test
public void fail_to_update_condition_when_condition_on_same_metric_already_exist() throws Exception {
    QualityGateConditionDto conditionNotOnLeakPeriod = insertCondition(coverageMetricDto.getId(), "GT", "80", null, null);
    QualityGateConditionDto conditionOnLeakPeriod = insertCondition(coverageMetricDto.getId(), "GT", "80", null, 1);
    expectedException.expect(BadRequestException.class);
    expectedException.expectMessage("Condition on metric 'Coverage' over leak period already exists.");
    // Update condition not on leak period to be on leak period => will fail as this condition already exist
    underTest.updateCondition(dbSession, conditionNotOnLeakPeriod.getId(), coverageMetricDto.getKey(), "GT", "80", null, 1);
}
Also used : QualityGateConditionDto(org.sonar.db.qualitygate.QualityGateConditionDto) Test(org.junit.Test)

Example 12 with QualityGateConditionDto

use of org.sonar.db.qualitygate.QualityGateConditionDto in project sonarqube by SonarSource.

the class QualityGateConditionsUpdaterTest method create_warning_condition_without_period.

@Test
public void create_warning_condition_without_period() {
    QualityGateConditionDto result = underTest.createCondition(dbSession, qualityGateDto.getId(), "coverage", "LT", "90", null, null);
    verifyCondition(result, coverageMetricDto.getId(), "LT", "90", null, null);
}
Also used : QualityGateConditionDto(org.sonar.db.qualitygate.QualityGateConditionDto) Test(org.junit.Test)

Example 13 with QualityGateConditionDto

use of org.sonar.db.qualitygate.QualityGateConditionDto in project sonarqube by SonarSource.

the class QualityGateConditionsUpdaterTest method create_error_condition_with_period.

@Test
public void create_error_condition_with_period() {
    MetricDto metricDto = dbClient.metricDao().insert(dbSession, newMetricDto().setKey("new_coverage").setValueType(INT.name()).setHidden(false));
    dbSession.commit();
    QualityGateConditionDto result = underTest.createCondition(dbSession, qualityGateDto.getId(), "new_coverage", "LT", null, "80", 1);
    verifyCondition(result, metricDto.getId(), "LT", null, "80", 1);
}
Also used : MetricTesting.newMetricDto(org.sonar.db.metric.MetricTesting.newMetricDto) MetricDto(org.sonar.db.metric.MetricDto) QualityGateConditionDto(org.sonar.db.qualitygate.QualityGateConditionDto) Test(org.junit.Test)

Example 14 with QualityGateConditionDto

use of org.sonar.db.qualitygate.QualityGateConditionDto in project sonarqube by SonarSource.

the class QualityGateConditionsUpdaterTest method create_condition_on_rating_metric.

@Test
public void create_condition_on_rating_metric() {
    QualityGateConditionDto result = underTest.createCondition(dbSession, qualityGateDto.getId(), ratingMetricDto.getKey(), "GT", null, "3", null);
    verifyCondition(result, ratingMetricDto.getId(), "GT", null, "3", null);
}
Also used : QualityGateConditionDto(org.sonar.db.qualitygate.QualityGateConditionDto) Test(org.junit.Test)

Example 15 with QualityGateConditionDto

use of org.sonar.db.qualitygate.QualityGateConditionDto in project sonarqube by SonarSource.

the class ShowAction method handle.

@Override
public void handle(Request request, Response response) {
    Long qGateId = request.paramAsLong(QualityGatesWsParameters.PARAM_ID);
    String qGateName = request.param(QualityGatesWsParameters.PARAM_NAME);
    checkOneOfIdOrNamePresent(qGateId, qGateName);
    QualityGateDto qGate = qGateId == null ? qualityGates.get(qGateName) : qualityGates.get(qGateId);
    qGateId = qGate.getId();
    JsonWriter writer = response.newJsonWriter().beginObject().prop(QualityGatesWsParameters.PARAM_ID, qGate.getId()).prop(QualityGatesWsParameters.PARAM_NAME, qGate.getName());
    Collection<QualityGateConditionDto> conditions = qualityGates.listConditions(qGateId);
    if (!conditions.isEmpty()) {
        writer.name("conditions").beginArray();
        for (QualityGateConditionDto condition : conditions) {
            QualityGatesWs.writeQualityGateCondition(condition, writer);
        }
        writer.endArray();
    }
    writer.endObject().close();
}
Also used : QualityGateConditionDto(org.sonar.db.qualitygate.QualityGateConditionDto) JsonWriter(org.sonar.api.utils.text.JsonWriter) QualityGateDto(org.sonar.db.qualitygate.QualityGateDto)

Aggregations

QualityGateConditionDto (org.sonar.db.qualitygate.QualityGateConditionDto)28 Test (org.junit.Test)16 MetricDto (org.sonar.db.metric.MetricDto)6 QualityGateDto (org.sonar.db.qualitygate.QualityGateDto)5 MetricTesting.newMetricDto (org.sonar.db.metric.MetricTesting.newMetricDto)4 Metric (org.sonar.api.measures.Metric)3 ArrayList (java.util.ArrayList)2 DbSession (org.sonar.db.DbSession)2 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)1 Before (org.junit.Before)1 JsonWriter (org.sonar.api.utils.text.JsonWriter)1 CreateConditionWsResponse (org.sonarqube.ws.WsQualityGates.CreateConditionWsResponse)1 UpdateConditionWsResponse (org.sonarqube.ws.WsQualityGates.UpdateConditionWsResponse)1