]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5091 Allow deletion of default quality gate
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Tue, 18 Mar 2014 12:50:15 +0000 (13:50 +0100)
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Tue, 18 Mar 2014 12:50:15 +0000 (13:50 +0100)
sonar-server/src/main/java/org/sonar/server/qualitygate/QualityGates.java
sonar-server/src/test/java/org/sonar/server/qualitygate/QualityGatesTest.java

index 10ab51f61a5a9b7f643dff72a6c2873a457887d2..5f51aa76eb8f834e08caff46e59b870ff0f20195 100644 (file)
@@ -139,11 +139,11 @@ public class QualityGates {
   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();
index 55ef7f025a524eecd9bf0fc770fd869e224cce50..31fb5d557161fb8e0f6dc50e79c48ffcb2ffc5cc 100644 (file)
@@ -257,14 +257,20 @@ public class QualityGatesTest {
     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