aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/sonar-db-dao/src/it/java/org/sonar/db/qualitygate/QualityGateConditionDaoIT.java13
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateConditionDao.java4
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateConditionMapper.java2
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateConditionMapper.xml4
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualitygate/ws/DestroyActionIT.java27
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/DestroyAction.java1
6 files changed, 51 insertions, 0 deletions
diff --git a/server/sonar-db-dao/src/it/java/org/sonar/db/qualitygate/QualityGateConditionDaoIT.java b/server/sonar-db-dao/src/it/java/org/sonar/db/qualitygate/QualityGateConditionDaoIT.java
index 9d484660ef0..f085811598f 100644
--- a/server/sonar-db-dao/src/it/java/org/sonar/db/qualitygate/QualityGateConditionDaoIT.java
+++ b/server/sonar-db-dao/src/it/java/org/sonar/db/qualitygate/QualityGateConditionDaoIT.java
@@ -117,6 +117,19 @@ class QualityGateConditionDaoIT {
}
@Test
+ void testDeleteForQualityGate() {
+ QualityGateConditionDto condition1 = insertQGCondition("qualityGateUuid");
+ QualityGateConditionDto condition2 = insertQGCondition("qualityGateUuid");
+
+ underTest.deleteForQualityGate("qualityGateUuid", dbSession);
+ dbSession.commit();
+
+ assertThat(underTest.selectForQualityGate(dbSession, "qualityGateUuid")).isEmpty();
+ assertThat(underTest.selectByUuid(condition1.getUuid(), dbSession)).isNull();
+ assertThat(underTest.selectByUuid(condition2.getUuid(), dbSession)).isNull();
+ }
+
+ @Test
void testUpdate() {
QualityGateConditionDto condition1 = insertQGCondition("2");
QualityGateConditionDto condition2 = insertQGCondition("3");
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateConditionDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateConditionDao.java
index 4fa4145eef6..33399d630d2 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateConditionDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateConditionDao.java
@@ -46,6 +46,10 @@ public class QualityGateConditionDao implements Dao {
mapper(session).delete(qGate.getUuid());
}
+ public void deleteForQualityGate(String qGateUuid, DbSession session) {
+ mapper(session).deleteForQualityGate(qGateUuid);
+ }
+
public void update(QualityGateConditionDto qGate, DbSession session) {
mapper(session).update(qGate.setUpdatedAt(new Date()));
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateConditionMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateConditionMapper.java
index 7990c77c05b..5fba86f0cf6 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateConditionMapper.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateConditionMapper.java
@@ -35,5 +35,7 @@ public interface QualityGateConditionMapper {
void delete(String uuid);
+ void deleteForQualityGate(String qGateUuid);
+
void deleteConditionsWithInvalidMetrics();
}
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateConditionMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateConditionMapper.xml
index 0efc2c5d5b5..1159f6ec40e 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateConditionMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateConditionMapper.xml
@@ -37,6 +37,10 @@
delete from quality_gate_conditions where uuid=#{uuid}
</update>
+ <update id="deleteForQualityGate" parameterType="String">
+ delete from quality_gate_conditions where qgate_uuid=#{qGateUuid}
+ </update>
+
<update id="update" parameterType="QualityGateCondition">
update quality_gate_conditions set
metric_uuid=#{metricUuid},
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualitygate/ws/DestroyActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualitygate/ws/DestroyActionIT.java
index ef3e862a1a9..b7d547ffc42 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualitygate/ws/DestroyActionIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualitygate/ws/DestroyActionIT.java
@@ -27,6 +27,7 @@ import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.Pagination;
import org.sonar.db.project.ProjectDto;
+import org.sonar.db.qualitygate.QualityGateConditionDto;
import org.sonar.db.qualitygate.QualityGateDto;
import org.sonar.db.user.GroupDto;
import org.sonar.db.user.UserDto;
@@ -39,6 +40,7 @@ import org.sonar.server.ws.WsActionTester;
import static java.lang.String.format;
import static java.lang.String.valueOf;
+import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.tuple;
@@ -77,6 +79,23 @@ public class DestroyActionIT {
}
@Test
+ public void delete_quality_gate_should_delete_its_conditions() {
+ userSession.addPermission(ADMINISTER_QUALITY_GATES);
+ db.qualityGates().createDefaultQualityGate();
+ QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
+
+ insertARandomCondition(qualityGate);
+
+ ws.newRequest()
+ .setParam(PARAM_NAME, qualityGate.getName())
+ .execute();
+
+ assertThat(db.getDbClient().qualityGateDao().selectByUuid(dbSession, qualityGate.getUuid())).isNull();
+ assertThat(db.getDbClient().gateConditionDao().selectForQualityGate(dbSession, qualityGate.getUuid())).isEmpty();
+ }
+
+
+ @Test
public void delete_quality_gate_if_non_default_when_a_default_exist() {
db.qualityGates().createDefaultQualityGate();
QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
@@ -228,4 +247,12 @@ public class DestroyActionIT {
tuple("name", true));
}
+ private void insertARandomCondition(QualityGateDto qualityGate) {
+ QualityGateConditionDto condition = new QualityGateConditionDto()
+ .setUuid(randomAlphanumeric(40))
+ .setMetricUuid(randomAlphanumeric(40))
+ .setQualityGateUuid(qualityGate.getUuid());
+ db.getDbClient().gateConditionDao().insert(condition, db.getSession());
+ db.commit();
+ }
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/DestroyAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/DestroyAction.java
index 96236d5717d..fdd2f31ad7c 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/DestroyAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/DestroyAction.java
@@ -82,6 +82,7 @@ public class DestroyAction implements QualityGatesWsAction {
dbClient.qualityGateGroupPermissionsDao().deleteByQualityGate(dbSession, qualityGate);
dbClient.qualityGateUserPermissionDao().deleteByQualityGate(dbSession, qualityGate);
dbClient.qualityGateDao().delete(qualityGate, dbSession);
+ dbClient.gateConditionDao().deleteForQualityGate(qualityGate.getUuid(), dbSession);
dbSession.commit();
response.noContent();
}