use of org.sonar.db.qualitygate.QualityGateDto in project sonarqube by SonarSource.
the class QualityGatesTest method should_get_qgate_by_id.
@Test
public void should_get_qgate_by_id() {
long id = QUALITY_GATE_ID;
final String name = "Golden";
QualityGateDto existing = new QualityGateDto().setId(id).setName(name);
when(dao.selectById(dbSession, id)).thenReturn(existing);
assertThat(underTest.get(id)).isEqualTo(existing);
verify(dao).selectById(dbSession, id);
}
use of org.sonar.db.qualitygate.QualityGateDto in project sonarqube by SonarSource.
the class QualityGatesTest method should_allow_rename_with_same_name.
@Test
public void should_allow_rename_with_same_name() {
long id = QUALITY_GATE_ID;
String name = "SG-1";
QualityGateDto existing = new QualityGateDto().setId(id).setName(name);
when(dao.selectById(dbSession, id)).thenReturn(existing);
QualityGateDto sg1 = underTest.rename(id, name);
assertThat(sg1.getName()).isEqualTo(name);
verify(dao).selectById(dbSession, id);
verify(dao).selectByName(dbSession, name);
verify(dao).update(sg1, dbSession);
}
use of org.sonar.db.qualitygate.QualityGateDto 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.QualityGateDto in project sonarqube by SonarSource.
the class QualityGatesTest method should_delete_qgate_even_if_default.
@Test
public void should_delete_qgate_even_if_default() {
long idToDelete = QUALITY_GATE_ID;
String name = "To Delete";
QualityGateDto toDelete = new QualityGateDto().setId(idToDelete).setName(name);
when(dao.selectById(dbSession, idToDelete)).thenReturn(toDelete);
when(propertiesDao.selectGlobalProperty("sonar.qualitygate")).thenReturn(new PropertyDto().setValue("42"));
when(dbClient.openSession(false)).thenReturn(dbSession);
underTest.delete(idToDelete);
verify(dao).selectById(dbSession, idToDelete);
verify(propertiesDao).deleteGlobalProperty("sonar.qualitygate", dbSession);
verify(propertiesDao).deleteProjectProperties("sonar.qualitygate", "42", dbSession);
verify(dao).delete(toDelete, dbSession);
}
use of org.sonar.db.qualitygate.QualityGateDto in project sonarqube by SonarSource.
the class QualityGatesTest method should_rename_qgate.
@Test
public void should_rename_qgate() {
long id = QUALITY_GATE_ID;
String name = "SG-1";
QualityGateDto existing = new QualityGateDto().setId(id).setName("Golden");
when(dao.selectById(dbSession, id)).thenReturn(existing);
QualityGateDto sg1 = underTest.rename(id, name);
assertThat(sg1.getName()).isEqualTo(name);
verify(dao).selectById(dbSession, id);
verify(dao).selectByName(dbSession, name);
verify(dao).update(sg1, dbSession);
}
Aggregations