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;
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++;
}
}
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;
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
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);
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();
}
// 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) {