]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9132 remove redundant "org-enabled" check for custom rule delete
authorDaniel Schwarz <daniel.schwarz@sonarsource.com>
Thu, 20 Apr 2017 11:34:16 +0000 (13:34 +0200)
committerDaniel Schwarz <bartfastiel@users.noreply.github.com>
Wed, 26 Apr 2017 14:03:12 +0000 (16:03 +0200)
server/sonar-server/src/main/java/org/sonar/server/rule/RuleDeleter.java
server/sonar-server/src/test/java/org/sonar/server/rule/RuleDeleterTest.java

index 2587185a788ea1de78aa85ffc9297f90f0b71be5..3faab5576cadd8c690aab77c9043ad5d83670e7f 100644 (file)
@@ -26,7 +26,6 @@ import org.sonar.api.utils.System2;
 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;
 
@@ -37,20 +36,16 @@ public class RuleDeleter {
   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");
index 1d88580c63e3cc2f7691e35fc84564c52810e4f8..42dcbc6ae4be918d48ac0c158c36c14565c4e547 100644 (file)
@@ -27,10 +27,7 @@ import org.sonar.api.utils.System2;
 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;
@@ -41,7 +38,7 @@ import static org.mockito.Mockito.mock;
 
 public class RuleDeleterTest {
 
-  static final long PAST = 10000L;
+  private static final long PAST = 10000L;
 
   @org.junit.Rule
   public UserSessionRule userSessionRule = UserSessionRule.standalone();
@@ -53,14 +50,11 @@ public class RuleDeleterTest {
   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),
@@ -96,15 +90,4 @@ public class RuleDeleterTest {
 
     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());
-  }
 }