public void delete(long idToDelete) {
checkPermission(UserSession.get());
QualityGateDto qGate = getNonNullQgate(idToDelete);
- if (isDefault(qGate)) {
- throw new BadRequestException("Impossible to delete default quality gate.");
- }
SqlSession session = myBatis.openSession();
try {
+ if (isDefault(qGate)) {
+ propertiesDao.deleteGlobalProperty(SONAR_QUALITYGATE_PROPERTY, session);
+ }
propertiesDao.deleteProjectProperties(SONAR_QUALITYGATE_PROPERTY, Long.toString(idToDelete), session);
dao.delete(qGate, session);
session.commit();
verify(dao).delete(toDelete, session);
}
- @Test(expected = BadRequestException.class)
- public void should_not_delete_qgate_if_default() throws Exception {
+ @Test
+ public void should_delete_qgate_even_if_default() throws Exception {
long idToDelete = 42L;
String name = "To Delete";
QualityGateDto toDelete = new QualityGateDto().setId(idToDelete).setName(name);
when(dao.selectById(idToDelete)).thenReturn(toDelete);
- when(propertiesDao.selectGlobalProperty("sonar.qualitygate")).thenReturn(new PropertyDto().setValue(Long.toString(idToDelete)));
+ when(propertiesDao.selectGlobalProperty("sonar.qualitygate")).thenReturn(new PropertyDto().setValue("42"));
+ SqlSession session = mock(SqlSession.class);
+ when(myBatis.openSession()).thenReturn(session);
qGates.delete(idToDelete);
+ verify(dao).selectById(idToDelete);
+ verify(propertiesDao).deleteGlobalProperty("sonar.qualitygate", session);
+ verify(propertiesDao).deleteProjectProperties("sonar.qualitygate", "42", session);
+ verify(dao).delete(toDelete, session);
}
@Test