diff options
author | Zipeng WU <zipeng.wu@sonarsource.com> | 2024-04-30 16:14:07 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2024-05-03 20:02:50 +0000 |
commit | 835fe2efc3643adbb8cf9632b83c8927ce96e7e9 (patch) | |
tree | 86a9eba599c4f43d41dbbf69f82959ff8ed5899f /server/sonar-webserver-webapi | |
parent | 4cadd793241b54e5246f32e03fbdc7f838cd2d59 (diff) | |
download | sonarqube-835fe2efc3643adbb8cf9632b83c8927ce96e7e9.tar.gz sonarqube-835fe2efc3643adbb8cf9632b83c8927ce96e7e9.zip |
SONAR-22170 Removing a quality gate should remove QG conditions
Diffstat (limited to 'server/sonar-webserver-webapi')
2 files changed, 28 insertions, 0 deletions
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(); } |