Search in sources :

Example 16 with QualityGateConditionDto

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);
}
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) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 17 with QualityGateConditionDto

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);
}
Also used : QualityGateConditionDto(org.sonar.db.qualitygate.QualityGateConditionDto) Test(org.junit.Test)

Example 18 with QualityGateConditionDto

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);
}
Also used : QualityGateConditionDto(org.sonar.db.qualitygate.QualityGateConditionDto) Metric(org.sonar.api.measures.Metric) Test(org.junit.Test)

Example 19 with QualityGateConditionDto

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);
}
Also used : QualityGateConditionDto(org.sonar.db.qualitygate.QualityGateConditionDto) Test(org.junit.Test)

Example 20 with QualityGateConditionDto

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);
}
Also used : QualityGateConditionDto(org.sonar.db.qualitygate.QualityGateConditionDto) Metric(org.sonar.api.measures.Metric) Test(org.junit.Test)

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