Search in sources :

Example 6 with RuleActivation

use of org.sonar.server.qualityprofile.RuleActivation in project sonarqube by SonarSource.

the class RegisterRulesMediumTest method do_not_deactivate_removed_rules_if_repository_accidentally_uninstalled.

@Test
public void do_not_deactivate_removed_rules_if_repository_accidentally_uninstalled() {
    Rules rules = new Rules() {

        @Override
        public void init(RulesDefinition.NewRepository repository) {
            repository.createRule("x1").setName("x1 name").setHtmlDescription("x1 desc");
        }
    };
    register(rules);
    // create a profile and activate rule
    logInAsQProfileAdministrator();
    db.qualityProfileDao().insert(dbSession, QProfileTesting.newXooP1("org-123"));
    dbSession.commit();
    dbSession.clearCache();
    RuleActivation activation = new RuleActivation(RuleTesting.XOO_X1);
    TESTER.get(QProfileService.class).activate(QProfileTesting.XOO_P1_KEY, activation);
    // Restart without xoo
    register(null);
    dbSession.commit();
    dbSession.clearCache();
    assertThat(ruleIndex.search(new RuleQuery().setKey(RuleTesting.XOO_X1.toString()), new SearchOptions()).getTotal()).isEqualTo(0);
    assertThat(db.activeRuleDao().selectByProfileKey(dbSession, QProfileTesting.XOO_P1_KEY)).isEmpty();
    // Re-install
    register(rules);
    assertThat(ruleIndex.search(new RuleQuery().setKey(RuleTesting.XOO_X1.toString()), new SearchOptions()).getTotal()).isEqualTo(1);
    assertThat(db.activeRuleDao().selectByProfileKey(dbSession, QProfileTesting.XOO_P1_KEY)).hasSize(1);
}
Also used : QProfileService(org.sonar.server.qualityprofile.QProfileService) RuleActivation(org.sonar.server.qualityprofile.RuleActivation) RuleQuery(org.sonar.server.rule.index.RuleQuery) SearchOptions(org.sonar.server.es.SearchOptions) Test(org.junit.Test)

Aggregations

RuleActivation (org.sonar.server.qualityprofile.RuleActivation)6 Test (org.junit.Test)5 QProfileService (org.sonar.server.qualityprofile.QProfileService)3 RuleQuery (org.sonar.server.rule.index.RuleQuery)3 RulesDefinition (org.sonar.api.server.rule.RulesDefinition)2 ActiveRuleDto (org.sonar.db.qualityprofile.ActiveRuleDto)2 ActiveRuleParamDto (org.sonar.db.qualityprofile.ActiveRuleParamDto)2 QualityProfileDto (org.sonar.db.qualityprofile.QualityProfileDto)2 RuleDto (org.sonar.db.rule.RuleDto)2 SearchOptions (org.sonar.server.es.SearchOptions)2 RuleKey (org.sonar.api.rule.RuleKey)1 ActiveRuleKey (org.sonar.db.qualityprofile.ActiveRuleKey)1 RuleParamDto (org.sonar.db.rule.RuleParamDto)1 RuleActivator (org.sonar.server.qualityprofile.RuleActivator)1