Search in sources :

Example 21 with ActiveRuleKey

use of org.sonar.db.qualityprofile.ActiveRuleKey in project sonarqube by SonarSource.

the class RuleActivatorMediumTest method verifyHasActiveRuleInIndex.

private void verifyHasActiveRuleInIndex(ActiveRuleKey activeRuleKey, String expectedSeverity, @Nullable String expectedInheritance) {
    // verify es
    List<RuleKey> ruleKeys = newArrayList(tester.get(RuleIndex.class).searchAll(new RuleQuery().setKey(activeRuleKey.ruleKey().toString()).setQProfileKey(activeRuleKey.qProfile()).setActivation(true).setInheritance(singleton(expectedInheritance == null ? ActiveRule.Inheritance.NONE.name() : ActiveRule.Inheritance.valueOf(expectedInheritance).name())).setActiveSeverities(singleton(expectedSeverity))));
    assertThat(ruleKeys).as("Rule is not activated in index").hasSize(1);
}
Also used : RuleKey(org.sonar.api.rule.RuleKey) ActiveRuleKey(org.sonar.db.qualityprofile.ActiveRuleKey) RuleQuery(org.sonar.server.rule.index.RuleQuery)

Example 22 with ActiveRuleKey

use of org.sonar.db.qualityprofile.ActiveRuleKey in project sonarqube by SonarSource.

the class ActiveRuleIndexerTest method index_from_changes_remove_deactivated_rules.

@Test
public void index_from_changes_remove_deactivated_rules() throws Exception {
    ActiveRuleKey activeRuleKey1 = ActiveRuleKey.of(QUALITY_PROFILE_KEY1, RULE_KEY_1);
    ActiveRuleKey activeRuleKey2 = ActiveRuleKey.of(QUALITY_PROFILE_KEY1, RULE_KEY_2);
    ActiveRuleKey activeRuleKey3 = ActiveRuleKey.of(QUALITY_PROFILE_KEY2, RULE_KEY_2);
    ActiveRuleKey activeRuleKey4 = ActiveRuleKey.of(QUALITY_PROFILE_KEY2, RULE_KEY_3);
    indexActiveRules(newDoc(activeRuleKey1), newDoc(activeRuleKey2), newDoc(activeRuleKey3), newDoc(activeRuleKey4));
    assertThat(esTester.getIds(INDEX_TYPE_ACTIVE_RULE)).hasSize(4);
    indexer.index(Arrays.asList(ActiveRuleChange.createFor(ACTIVATED, activeRuleKey1), ActiveRuleChange.createFor(DEACTIVATED, activeRuleKey2), ActiveRuleChange.createFor(DEACTIVATED, activeRuleKey3)));
    assertThat(esTester.getIds(INDEX_TYPE_ACTIVE_RULE)).containsOnly(activeRuleKey1.toString(), activeRuleKey4.toString());
}
Also used : ActiveRuleKey(org.sonar.db.qualityprofile.ActiveRuleKey) Test(org.junit.Test)

Example 23 with ActiveRuleKey

use of org.sonar.db.qualityprofile.ActiveRuleKey in project sonarqube by SonarSource.

the class ActiveRuleResultSetIteratorTest method iterator_over_active_rules.

@Test
public void iterator_over_active_rules() {
    dbTester.prepareDbUnit(getClass(), "shared.xml");
    ActiveRuleResultSetIterator it = ActiveRuleResultSetIterator.create(dbTester.getDbClient(), dbTester.getSession(), 0L);
    Map<ActiveRuleKey, ActiveRuleDoc> activeRulesByKey = activeRulesByKey(it);
    it.close();
    assertThat(activeRulesByKey).hasSize(3);
    ActiveRuleKey key = ActiveRuleKey.of("sonar-way", RuleKey.of("xoo", "S002"));
    ActiveRuleDoc activeRule = activeRulesByKey.get(key);
    assertThat(activeRule.key()).isEqualTo(key);
    assertThat(activeRule.severity()).isEqualTo(CRITICAL);
    assertThat(activeRule.inheritance()).isEqualTo(ActiveRule.Inheritance.NONE);
    assertThat(activeRule.createdAt()).isEqualTo(2000000000000L);
    assertThat(activeRule.updatedAt()).isEqualTo(2100000000000L);
    key = ActiveRuleKey.of("parent", RuleKey.of("xoo", "S001"));
    activeRule = activeRulesByKey.get(key);
    assertThat(activeRule.key()).isEqualTo(key);
    assertThat(activeRule.severity()).isEqualTo(INFO);
    assertThat(activeRule.inheritance()).isEqualTo(ActiveRule.Inheritance.NONE);
    assertThat(activeRule.createdAt()).isEqualTo(1700000000000L);
    assertThat(activeRule.updatedAt()).isEqualTo(1800000000000L);
    key = ActiveRuleKey.of("child", RuleKey.of("xoo", "S001"));
    activeRule = activeRulesByKey.get(key);
    assertThat(activeRule.key()).isEqualTo(key);
    assertThat(activeRule.severity()).isEqualTo(BLOCKER);
    assertThat(activeRule.inheritance()).isEqualTo(INHERITED);
    assertThat(activeRule.createdAt()).isEqualTo(1500000000000L);
    assertThat(activeRule.updatedAt()).isEqualTo(1600000000000L);
}
Also used : ActiveRuleKey(org.sonar.db.qualityprofile.ActiveRuleKey) Test(org.junit.Test)

Example 24 with ActiveRuleKey

use of org.sonar.db.qualityprofile.ActiveRuleKey in project sonarqube by SonarSource.

the class ActiveRuleResultSetIteratorTest method active_rule_with_inherited_inheritance.

@Test
public void active_rule_with_inherited_inheritance() {
    dbTester.prepareDbUnit(getClass(), "active_rule_with_inherited_inheritance.xml");
    ActiveRuleResultSetIterator it = ActiveRuleResultSetIterator.create(dbTester.getDbClient(), dbTester.getSession(), 0L);
    Map<ActiveRuleKey, ActiveRuleDoc> activeRulesByKey = activeRulesByKey(it);
    it.close();
    assertThat(activeRulesByKey).hasSize(2);
    ActiveRuleKey key = ActiveRuleKey.of("child", RuleKey.of("xoo", "S001"));
    ActiveRuleDoc activeRule = activeRulesByKey.get(key);
    assertThat(activeRule.inheritance()).isEqualTo(INHERITED);
}
Also used : ActiveRuleKey(org.sonar.db.qualityprofile.ActiveRuleKey) Test(org.junit.Test)

Example 25 with ActiveRuleKey

use of org.sonar.db.qualityprofile.ActiveRuleKey in project sonarqube by SonarSource.

the class RuleActivatorMediumTest method deactivation_fails_if_rule_not_found.

@Test
public void deactivation_fails_if_rule_not_found() {
    ActiveRuleKey key = ActiveRuleKey.of(XOO_P1_KEY, RuleKey.of("xoo", "x3"));
    try {
        ruleActivator.deactivate(key);
        fail();
    } catch (BadRequestException e) {
        assertThat(e).hasMessage("Rule not found: xoo:x3");
        verifyZeroActiveRules(XOO_P1_KEY);
    }
}
Also used : BadRequestException(org.sonar.server.exceptions.BadRequestException) ActiveRuleKey(org.sonar.db.qualityprofile.ActiveRuleKey) Test(org.junit.Test)

Aggregations

ActiveRuleKey (org.sonar.db.qualityprofile.ActiveRuleKey)26 Test (org.junit.Test)18 ActiveRuleDto (org.sonar.db.qualityprofile.ActiveRuleDto)9 ActiveRuleParamDto (org.sonar.db.qualityprofile.ActiveRuleParamDto)7 RuleKey (org.sonar.api.rule.RuleKey)6 QualityProfileDto (org.sonar.db.qualityprofile.QualityProfileDto)5 ActiveRuleDao (org.sonar.db.qualityprofile.ActiveRuleDao)3 QualityProfileDao (org.sonar.db.qualityprofile.QualityProfileDao)3 BadRequestException (org.sonar.server.exceptions.BadRequestException)3 HashMap (java.util.HashMap)2 RulesProfile (org.sonar.api.profiles.RulesProfile)2 RulesDefinition (org.sonar.api.server.rule.RulesDefinition)2 RuleDto (org.sonar.db.rule.RuleDto)2 SearchOptions (org.sonar.server.es.SearchOptions)2 RuleQuery (org.sonar.server.rule.index.RuleQuery)2 Multimap (com.google.common.collect.Multimap)1 RuleParam (org.sonar.api.rules.RuleParam)1 DbSession (org.sonar.db.DbSession)1 Platform (org.sonar.server.platform.Platform)1 ServerTester (org.sonar.server.tester.ServerTester)1