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));
}
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();
}
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();
}
}
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);
}
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);
}
Aggregations