]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7330 ClearRulesOverloadedDebt is now using only RuleDao
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 22 Feb 2016 15:14:12 +0000 (16:14 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 29 Feb 2016 12:26:54 +0000 (13:26 +0100)
server/sonar-server/src/main/java/org/sonar/server/startup/ClearRulesOverloadedDebt.java
server/sonar-server/src/test/java/org/sonar/server/startup/ClearRulesOverloadedDebtTest.java

index 96742f5263d8c9843c9b2a26576f9c183c003360..05e849a637b0e0bc1bc55df1621daab0ab77a39d 100644 (file)
@@ -22,10 +22,10 @@ package org.sonar.server.startup;
 import org.picocontainer.Startable;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
+import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.loadedtemplate.LoadedTemplateDto;
 import org.sonar.db.rule.RuleDto;
-import org.sonar.server.db.DbClient;
 
 import static org.sonar.db.loadedtemplate.LoadedTemplateDto.ONE_SHOT_TASK_TYPE;
 
@@ -70,13 +70,13 @@ public class ClearRulesOverloadedDebt implements Startable {
 
   private void clearDebt(DbSession session) {
     int countClearedRules = 0;
-    for (RuleDto rule : dbClient.deprecatedRuleDao().selectAll(session)) {
+    for (RuleDto rule : dbClient.ruleDao().selectAll(session)) {
       if (isDebtOverridden(rule)) {
         rule.setSubCharacteristicId(null);
         rule.setRemediationFunction(null);
         rule.setRemediationCoefficient(null);
         rule.setRemediationOffset(null);
-        dbClient.deprecatedRuleDao().update(session, rule);
+        dbClient.ruleDao().update(session, rule);
         countClearedRules++;
       }
     }
index 94f4428ff3022b09a10abe686d5e08aaf9a2c19b..21e113b27f4785c252694bef3254e3001ee00044 100644 (file)
@@ -21,22 +21,19 @@ package org.sonar.server.startup;
 
 import java.util.Date;
 import javax.annotation.Nullable;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.ClassRule;
+import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.rule.RuleKey;
+import org.sonar.api.utils.System2;
 import org.sonar.api.utils.log.LogTester;
 import org.sonar.api.utils.log.LoggerLevel;
+import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
+import org.sonar.db.DbTester;
 import org.sonar.db.property.PropertyDto;
+import org.sonar.db.rule.RuleDao;
 import org.sonar.db.rule.RuleDto;
 import org.sonar.db.rule.RuleTesting;
-import org.sonar.server.db.DbClient;
-import org.sonar.server.rule.Rule;
-import org.sonar.server.rule.db.RuleDao;
-import org.sonar.server.rule.index.RuleIndex;
-import org.sonar.server.tester.ServerTester;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.sonar.db.loadedtemplate.LoadedTemplateDto.ONE_SHOT_TASK_TYPE;
@@ -49,29 +46,18 @@ public class ClearRulesOverloadedDebtTest {
   private static final RuleKey RULE_KEY_2 = RuleTesting.XOO_X2;
   private static final RuleKey RULE_KEY_3 = RuleTesting.XOO_X3;
 
-  @ClassRule
-  public static ServerTester tester = new ServerTester();
+  @Rule
+  public DbTester tester = DbTester.create(System2.INSTANCE);
 
-  @org.junit.Rule
+  @Rule
   public LogTester logTester = new LogTester();
 
-  RuleDao ruleDao = tester.get(RuleDao.class);
-  RuleIndex ruleIndex = tester.get(RuleIndex.class);
-  DbClient dbClient = tester.get(DbClient.class);
-  DbSession dbSession = tester.get(DbClient.class).openSession(false);
+  DbClient dbClient = tester.getDbClient();
+  DbSession dbSession = tester.getSession();
+  RuleDao ruleDao = new RuleDao();
 
   ClearRulesOverloadedDebt underTest = new ClearRulesOverloadedDebt(dbClient);
 
-  @Before
-  public void before() {
-    tester.clearDbAndIndexes();
-  }
-
-  @After
-  public void after() {
-    dbSession.close();
-  }
-
   @Test
   public void remove_overridden_debt() throws Exception {
     // Characteristic and remediation function is overridden
@@ -97,7 +83,7 @@ public class ClearRulesOverloadedDebtTest {
 
     underTest.start();
 
-    RuleDto reloaded = ruleDao.getByKey(dbSession, RULE_KEY_1);
+    RuleDto reloaded = ruleDao.selectOrFailByKey(dbSession, RULE_KEY_1);
     assertThat(reloaded.getUpdatedAt()).isEqualTo(updateAt);
     verifyRuleHasNotOverriddenDebt(RULE_KEY_1);
 
@@ -113,12 +99,9 @@ public class ClearRulesOverloadedDebtTest {
 
     underTest.start();
 
-    RuleDto reloaded = ruleDao.getByKey(dbSession, RULE_KEY_1);
+    RuleDto reloaded = ruleDao.selectOrFailByKey(dbSession, RULE_KEY_1);
     assertThat(reloaded.getUpdatedAt()).isEqualTo(updateAt);
 
-    Rule ruleEs = ruleIndex.getByKey(RULE_KEY_1);
-    assertThat(ruleEs.debtOverloaded()).isTrue();
-
     verifyTaskRegistered();
     verifyEmptyLog();
   }
@@ -140,14 +123,11 @@ public class ClearRulesOverloadedDebtTest {
     // Refresh session
     dbSession.commit(true);
 
-    RuleDto ruleDto = ruleDao.getByKey(dbSession, ruleKey);
+    RuleDto ruleDto = ruleDao.selectOrFailByKey(dbSession, ruleKey);
     assertThat(ruleDto.getSubCharacteristicId()).isNull();
     assertThat(ruleDto.getRemediationFunction()).isNull();
     assertThat(ruleDto.getRemediationCoefficient()).isNull();
     assertThat(ruleDto.getRemediationOffset()).isNull();
-
-    Rule rule = ruleIndex.getByKey(ruleKey);
-    assertThat(rule.debtOverloaded()).isFalse();
   }
 
   private RuleDto insertRuleDto(RuleKey ruleKey, @Nullable Integer subCharId, @Nullable String function, @Nullable String coeff, @Nullable String offset) {