use of org.sonar.db.qualitygate.QualityGateConditionDto in project sonarqube by SonarSource.
the class CreateConditionAction method doHandle.
private CreateConditionWsResponse doHandle(CreateConditionRequest request, DbSession dbSession) {
QualityGateConditionDto condition = qualityGateConditionsUpdater.createCondition(dbSession, request.getQualityGateId(), request.getMetricKey(), request.getOperator(), request.getWarning(), request.getError(), request.getPeriod());
CreateConditionWsResponse.Builder response = CreateConditionWsResponse.newBuilder().setId(condition.getId()).setMetric(condition.getMetricKey()).setOp(condition.getOperator());
setNullable(condition.getWarningThreshold(), response::setWarning);
setNullable(condition.getErrorThreshold(), response::setError);
setNullable(condition.getPeriod(), response::setPeriod);
return response.build();
}
use of org.sonar.db.qualitygate.QualityGateConditionDto in project sonarqube by SonarSource.
the class QualityGatesWsTest method show_by_id_nominal.
@Test
public void show_by_id_nominal() throws Exception {
long gateId = 12345L;
when(qGates.get(gateId)).thenReturn(new QualityGateDto().setId(gateId).setName("Golden"));
when(qGates.listConditions(gateId)).thenReturn(ImmutableList.of(new QualityGateConditionDto().setId(1L).setMetricKey("ncloc").setOperator("GT").setErrorThreshold("10000"), new QualityGateConditionDto().setId(2L).setMetricKey("new_coverage").setOperator("LT").setWarningThreshold("90").setPeriod(3)));
tester.newGetRequest("api/qualitygates", "show").setParam("id", Long.toString(gateId)).execute().assertJson("{\"id\":12345,\"name\":\"Golden\",\"conditions\":[" + "{\"id\":1,\"metric\":\"ncloc\",\"op\":\"GT\",\"error\":\"10000\"}," + "{\"id\":2,\"metric\":\"new_coverage\",\"op\":\"LT\",\"warning\":\"90\",\"period\":3}" + "]}");
}
use of org.sonar.db.qualitygate.QualityGateConditionDto in project sonarqube by SonarSource.
the class QualityGatesWsTest method show_by_name_nominal.
@Test
public void show_by_name_nominal() throws Exception {
long qGateId = 12345L;
String gateName = "Golden";
when(qGates.get(gateName)).thenReturn(new QualityGateDto().setId(qGateId).setName(gateName));
when(qGates.listConditions(qGateId)).thenReturn(ImmutableList.of(new QualityGateConditionDto().setId(1L).setMetricKey("ncloc").setOperator("GT").setErrorThreshold("10000"), new QualityGateConditionDto().setId(2L).setMetricKey("new_coverage").setOperator("LT").setWarningThreshold("90").setPeriod(3)));
tester.newGetRequest("api/qualitygates", "show").setParam("name", gateName).execute().assertJson("{\"id\":12345,\"name\":\"Golden\",\"conditions\":[" + "{\"id\":1,\"metric\":\"ncloc\",\"op\":\"GT\",\"error\":\"10000\"}," + "{\"id\":2,\"metric\":\"new_coverage\",\"op\":\"LT\",\"warning\":\"90\",\"period\":3}" + "]}");
}
use of org.sonar.db.qualitygate.QualityGateConditionDto in project sonarqube by SonarSource.
the class CreateConditionActionTest method assertCondition.
private void assertCondition(CreateConditionWsResponse response, String operator, @Nullable String warning, @Nullable String error, @Nullable Integer period) {
List<QualityGateConditionDto> conditionDtoList = new ArrayList<>(dbClient.gateConditionDao().selectForQualityGate(dbSession, qualityGateDto.getId()));
assertThat(conditionDtoList).hasSize(1);
QualityGateConditionDto qualityGateConditionDto = conditionDtoList.get(0);
assertThat(qualityGateConditionDto.getQualityGateId()).isEqualTo(qualityGateDto.getId());
assertThat(qualityGateConditionDto.getMetricId()).isEqualTo(coverageMetricDto.getId().longValue());
assertThat(qualityGateConditionDto.getOperator()).isEqualTo(operator);
assertThat(qualityGateConditionDto.getWarningThreshold()).isEqualTo(warning);
assertThat(qualityGateConditionDto.getErrorThreshold()).isEqualTo(error);
assertThat(qualityGateConditionDto.getPeriod()).isEqualTo(period);
assertThat(response.getId()).isEqualTo(qualityGateConditionDto.getId());
assertThat(response.getMetric()).isEqualTo(coverageMetricDto.getKey());
assertThat(response.getOp()).isEqualTo(operator);
if (warning != null) {
assertThat(response.getWarning()).isEqualTo(warning);
} else {
assertThat(response.hasWarning()).isFalse();
}
if (error != null) {
assertThat(response.getError()).isEqualTo(error);
} else {
assertThat(response.hasError()).isFalse();
}
if (period != null) {
assertThat(response.getPeriod()).isEqualTo(period);
} else {
assertThat(response.hasPeriod()).isFalse();
}
}
use of org.sonar.db.qualitygate.QualityGateConditionDto in project sonarqube by SonarSource.
the class QualityGateConditionsUpdaterTest method insertCondition.
private QualityGateConditionDto insertCondition(long metricId, String operator, @Nullable String warning, @Nullable String error, @Nullable Integer period) {
QualityGateConditionDto qualityGateConditionDto = new QualityGateConditionDto().setQualityGateId(qualityGateDto.getId()).setMetricId(metricId).setOperator(operator).setWarningThreshold(warning).setErrorThreshold(error).setPeriod(period);
dbClient.gateConditionDao().insert(qualityGateConditionDto, dbSession);
dbSession.commit();
return qualityGateConditionDto;
}
Aggregations