Search in sources :

Example 21 with QualityGateConditionDto

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

the class QualityGatesTest method should_copy_qgate.

@Test
public void should_copy_qgate() {
    String name = "Atlantis";
    long sourceId = QUALITY_GATE_ID;
    final long destId = 43L;
    long metric1Id = 1L;
    long metric2Id = 2L;
    QualityGateConditionDto cond1 = new QualityGateConditionDto().setMetricId(metric1Id);
    QualityGateConditionDto cond2 = new QualityGateConditionDto().setMetricId(metric2Id);
    Collection<QualityGateConditionDto> conditions = ImmutableList.of(cond1, cond2);
    when(dao.selectById(dbSession, sourceId)).thenReturn(new QualityGateDto().setId(sourceId).setName("SG-1"));
    Mockito.doAnswer(invocation -> {
        ((QualityGateDto) invocation.getArguments()[1]).setId(destId);
        return null;
    }).when(dao).insert(eq(dbSession), any(QualityGateDto.class));
    when(conditionDao.selectForQualityGate(eq(dbSession), anyLong())).thenReturn(conditions);
    QualityGateDto atlantis = underTest.copy(sourceId, name);
    assertThat(atlantis.getName()).isEqualTo(name);
    verify(dao).selectByName(dbSession, name);
    verify(dao).insert(dbSession, atlantis);
    verify(conditionDao).selectForQualityGate(eq(dbSession), anyLong());
    verify(conditionDao, times(conditions.size())).insert(any(QualityGateConditionDto.class), eq(dbSession));
}
Also used : QualityGateConditionDto(org.sonar.db.qualitygate.QualityGateConditionDto) QualityGateDto(org.sonar.db.qualitygate.QualityGateDto) Test(org.junit.Test)

Example 22 with QualityGateConditionDto

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

the class UpdateConditionActionTest method setUp.

@Before
public void setUp() throws Exception {
    MetricDto metricDto = dbClient.metricDao().insert(dbSession, coverageMetricDto);
    qualityGateDto = qualityGateDbTester.insertQualityGate();
    conditionDto = new QualityGateConditionDto().setQualityGateId(qualityGateDto.getId()).setMetricId(metricDto.getId()).setOperator("GT").setWarningThreshold(null).setErrorThreshold("80").setPeriod(1);
    dbClient.gateConditionDao().insert(conditionDto, dbSession);
    dbSession.commit();
}
Also used : MetricTesting.newMetricDto(org.sonar.db.metric.MetricTesting.newMetricDto) MetricDto(org.sonar.db.metric.MetricDto) QualityGateConditionDto(org.sonar.db.qualitygate.QualityGateConditionDto) Before(org.junit.Before)

Example 23 with QualityGateConditionDto

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

the class UpdateConditionActionTest 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();
    }
}
Also used : ArrayList(java.util.ArrayList) QualityGateConditionDto(org.sonar.db.qualitygate.QualityGateConditionDto)

Example 24 with QualityGateConditionDto

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

the class QualityGateConditionsUpdaterTest method update_condition_on_rating_metric.

@Test
public void update_condition_on_rating_metric() {
    QualityGateConditionDto condition = insertCondition(ratingMetricDto.getId(), "LT", null, "3", null);
    QualityGateConditionDto result = underTest.updateCondition(dbSession, condition.getId(), ratingMetricDto.getKey(), "GT", "4", null, null);
    verifyCondition(result, ratingMetricDto.getId(), "GT", "4", null, null);
}
Also used : QualityGateConditionDto(org.sonar.db.qualitygate.QualityGateConditionDto) Test(org.junit.Test)

Example 25 with QualityGateConditionDto

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

the class QualityGateConditionsUpdaterTest method update_condition_over_leak_period.

@Test
public void update_condition_over_leak_period() {
    QualityGateConditionDto condition = insertCondition(coverageMetricDto.getId(), "GT", "80", null, 1);
    QualityGateConditionDto result = underTest.updateCondition(dbSession, condition.getId(), "coverage", "LT", null, "80", null);
    verifyCondition(result, coverageMetricDto.getId(), "LT", null, "80", null);
}
Also used : QualityGateConditionDto(org.sonar.db.qualitygate.QualityGateConditionDto) 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