assertThat(underTest.selectByUuid(condition2.getUuid(), dbSession)).isNotNull();
}
+ @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");
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;
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;
assertThat(db.getDbClient().qualityGateDao().selectByUuid(dbSession, qualityGate.getUuid())).isNull();
}
+ @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();
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();
+ }
}