import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.rule.RuleDefinitionDto;
-import org.sonar.server.organization.OrganizationFlags;
import org.sonar.server.qualityprofile.RuleActivator;
import org.sonar.server.rule.index.RuleIndexer;
private final RuleIndexer ruleIndexer;
private final DbClient dbClient;
private final RuleActivator ruleActivator;
- private final OrganizationFlags organizationFlags;
- public RuleDeleter(System2 system2, RuleIndexer ruleIndexer, DbClient dbClient, RuleActivator ruleActivator, OrganizationFlags organizationFlags) {
+ public RuleDeleter(System2 system2, RuleIndexer ruleIndexer, DbClient dbClient, RuleActivator ruleActivator) {
this.system2 = system2;
this.ruleIndexer = ruleIndexer;
this.dbClient = dbClient;
this.ruleActivator = ruleActivator;
- this.organizationFlags = organizationFlags;
}
public void delete(RuleKey ruleKey) {
try (DbSession dbSession = dbClient.openSession(false)) {
- organizationFlags.checkDisabled(dbSession);
-
RuleDefinitionDto rule = dbClient.ruleDao().selectOrFailDefinitionByKey(dbSession, ruleKey);
if (!rule.isCustomRule()) {
throw new IllegalStateException("Only custom rules can be deleted");
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
-import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.rule.RuleDefinitionDto;
-import org.sonar.server.organization.OrganizationFlags;
-import org.sonar.server.organization.TestOrganizationFlags;
import org.sonar.server.qualityprofile.RuleActivator;
import org.sonar.server.rule.index.RuleIndexer;
import org.sonar.server.tester.UserSessionRule;
public class RuleDeleterTest {
- static final long PAST = 10000L;
+ private static final long PAST = 10000L;
@org.junit.Rule
public UserSessionRule userSessionRule = UserSessionRule.standalone();
private DbClient dbClient = dbTester.getDbClient();
private DbSession dbSession = dbTester.getSession();
private RuleIndexer ruleIndexer = mock(RuleIndexer.class);
- private OrganizationFlags organizationFlags = TestOrganizationFlags.standalone();
private RuleActivator ruleActivator = mock(RuleActivator.class);
- private RuleDeleter deleter = new RuleDeleter(System2.INSTANCE, ruleIndexer, dbClient, ruleActivator, organizationFlags);
+ private RuleDeleter deleter = new RuleDeleter(System2.INSTANCE, ruleIndexer, dbClient, ruleActivator);
@Test
public void delete_custom_rule() {
- OrganizationDto organization = dbTester.organizations().insert();
-
RuleDefinitionDto templateRule = dbTester.rules().insert(
r -> r.setIsTemplate(true),
r -> r.setCreatedAt(PAST),
deleter.delete(rule.getKey());
}
-
- @Test
- public void fail_if_organizations_enabled() {
- RuleDefinitionDto rule = dbTester.rules().insert();
- organizationFlags.enable(dbSession);
-
- thrown.expect(IllegalStateException.class);
- thrown.expectMessage("Organization support is enabled");
-
- deleter.delete(rule.getKey());
- }
}