use of org.sonar.db.qualitygate.QualityGateConditionDto in project sonarqube by SonarSource.
the class QualityGateConditionsUpdaterTest method fail_to_update_condition_on_invalid_metric.
@Test
@UseDataProvider("invalid_metrics")
public void fail_to_update_condition_on_invalid_metric(String metricKey, Metric.ValueType valueType, boolean hidden) {
MetricDto metricDto = dbClient.metricDao().insert(dbSession, newMetricDto().setKey(metricKey).setValueType(valueType.name()).setHidden(hidden));
QualityGateConditionDto condition = insertCondition(metricDto.getId(), "LT", null, "80", null);
dbSession.commit();
expectedException.expect(BadRequestException.class);
expectedException.expectMessage("Metric '" + metricKey + "' cannot be used to define a condition.");
underTest.updateCondition(dbSession, condition.getId(), metricDto.getKey(), "GT", "60", null, 1);
}
use of org.sonar.db.qualitygate.QualityGateConditionDto in project sonarqube by SonarSource.
the class QualityGateConditionsUpdaterTest method fail_to_update_condition_on_rating_metric_on_leak_period.
@Test
public void fail_to_update_condition_on_rating_metric_on_leak_period() {
QualityGateConditionDto condition = insertCondition(ratingMetricDto.getId(), "LT", null, "3", null);
expectedException.expect(BadRequestException.class);
expectedException.expectMessage("The metric 'Reliability Rating' cannot be used on the leak period");
underTest.updateCondition(dbSession, condition.getId(), ratingMetricDto.getKey(), "GT", "4", null, 1);
}
use of org.sonar.db.qualitygate.QualityGateConditionDto in project sonarqube by SonarSource.
the class QualityGatesTest method should_list_conditions.
@Test
public void should_list_conditions() {
long qGateId = QUALITY_GATE_ID;
long metric1Id = 1L;
String metric1Key = "polop";
long metric2Id = 2L;
String metric2Key = "palap";
QualityGateConditionDto cond1 = new QualityGateConditionDto().setMetricId(metric1Id);
QualityGateConditionDto cond2 = new QualityGateConditionDto().setMetricId(metric2Id);
Collection<QualityGateConditionDto> conditions = ImmutableList.of(cond1, cond2);
when(conditionDao.selectForQualityGate(dbSession, qGateId)).thenReturn(conditions);
Metric metric1 = mock(Metric.class);
when(metric1.getKey()).thenReturn(metric1Key);
when(metricFinder.findById((int) metric1Id)).thenReturn(metric1);
Metric metric2 = mock(Metric.class);
when(metric2.getKey()).thenReturn(metric2Key);
when(metricFinder.findById((int) metric2Id)).thenReturn(metric2);
assertThat(underTest.listConditions(qGateId)).isEqualTo(conditions);
Iterator<QualityGateConditionDto> iterator = conditions.iterator();
assertThat(iterator.next().getMetricKey()).isEqualTo(metric1Key);
assertThat(iterator.next().getMetricKey()).isEqualTo(metric2Key);
}
use of org.sonar.db.qualitygate.QualityGateConditionDto in project sonarqube by SonarSource.
the class QualityGatesTest method should_delete_condition.
@Test
public void should_delete_condition() {
long idToDelete = QUALITY_GATE_ID;
QualityGateConditionDto toDelete = new QualityGateConditionDto().setId(idToDelete);
when(conditionDao.selectById(idToDelete, dbSession)).thenReturn(toDelete);
underTest.deleteCondition(idToDelete);
verify(conditionDao).selectById(idToDelete, dbSession);
verify(conditionDao).delete(toDelete, dbSession);
}
use of org.sonar.db.qualitygate.QualityGateConditionDto in project sonarqube by SonarSource.
the class QualityGatesTest method should_do_a_sanity_check_when_listing_conditions.
@Test(expected = IllegalStateException.class)
public void should_do_a_sanity_check_when_listing_conditions() {
long qGateId = QUALITY_GATE_ID;
long metric1Id = 1L;
String metric1Key = "polop";
long metric2Id = 2L;
QualityGateConditionDto cond1 = new QualityGateConditionDto().setMetricId(metric1Id);
QualityGateConditionDto cond2 = new QualityGateConditionDto().setMetricId(metric2Id);
Collection<QualityGateConditionDto> conditions = ImmutableList.of(cond1, cond2);
when(conditionDao.selectForQualityGate(dbSession, qGateId)).thenReturn(conditions);
Metric metric1 = mock(Metric.class);
when(metric1.getKey()).thenReturn(metric1Key);
when(metricFinder.findById((int) metric1Id)).thenReturn(metric1);
underTest.listConditions(qGateId);
}
Aggregations