Search in sources :

Example 11 with ActiveRuleKey

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

the class RuleActivatorMediumTest method deactivation_fails_if_profile_not_found.

@Test
public void deactivation_fails_if_profile_not_found() {
    ActiveRuleKey key = ActiveRuleKey.of("unknown", XOO_X1);
    try {
        ruleActivator.deactivate(key);
        fail();
    } catch (BadRequestException e) {
        assertThat(e).hasMessage("Quality profile not found: unknown");
    }
}
Also used : BadRequestException(org.sonar.server.exceptions.BadRequestException) ActiveRuleKey(org.sonar.db.qualityprofile.ActiveRuleKey) Test(org.junit.Test)

Example 12 with ActiveRuleKey

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

the class RuleActivatorMediumTest method ignore_parameters_when_activating_custom_rule.

@Test
public void ignore_parameters_when_activating_custom_rule() {
    // initial activation
    ActiveRuleKey activeRuleKey = ActiveRuleKey.of(XOO_P1_KEY, CUSTOM_RULE_KEY);
    RuleActivation activation = new RuleActivation(CUSTOM_RULE_KEY);
    activate(activation, XOO_P1_KEY);
    // update
    RuleActivation update = new RuleActivation(CUSTOM_RULE_KEY).setParameter("format", "xls");
    activate(update, XOO_P1_KEY);
    assertThat(countActiveRules(XOO_P1_KEY)).isEqualTo(1);
    verifyHasActiveRuleInDb(activeRuleKey, MINOR, null, ImmutableMap.of("format", "txt"));
}
Also used : ActiveRuleKey(org.sonar.db.qualityprofile.ActiveRuleKey) Test(org.junit.Test)

Example 13 with ActiveRuleKey

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

the class ActiveRuleIndexTest method stats_for_all.

@Test
public void stats_for_all() {
    indexRules(newDoc(RULE_KEY_1), newDoc(RULE_KEY_2));
    ActiveRuleKey activeRuleKey1 = ActiveRuleKey.of(QUALITY_PROFILE_KEY1, RULE_KEY_1);
    ActiveRuleKey activeRuleKey2 = ActiveRuleKey.of(QUALITY_PROFILE_KEY1, RULE_KEY_2);
    indexActiveRules(ActiveRuleDocTesting.newDoc(activeRuleKey1).setSeverity(BLOCKER), ActiveRuleDocTesting.newDoc(activeRuleKey2).setSeverity(MINOR), // Profile 2 is a child a profile 1
    ActiveRuleDocTesting.newDoc(ActiveRuleKey.of(QUALITY_PROFILE_KEY2, RULE_KEY_1)).setSeverity(MAJOR).setInheritance(INHERITED.name()), ActiveRuleDocTesting.newDoc(ActiveRuleKey.of(QUALITY_PROFILE_KEY2, RULE_KEY_2)).setSeverity(BLOCKER).setInheritance(OVERRIDES.name()));
    // 0. Test base case
    assertThat(tester.countDocuments(INDEX_TYPE_ACTIVE_RULE)).isEqualTo(4);
    // 1. Assert by term aggregation;
    Map<String, Multimap<String, FacetValue>> stats = index.getStatsByProfileKeys(ImmutableList.of(QUALITY_PROFILE_KEY1, QUALITY_PROFILE_KEY2));
    assertThat(stats).hasSize(2);
}
Also used : Multimap(com.google.common.collect.Multimap) ActiveRuleKey(org.sonar.db.qualityprofile.ActiveRuleKey) Test(org.junit.Test)

Example 14 with ActiveRuleKey

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

the class ActiveRuleResultSetIteratorTest method active_rule_with_overrides_inheritance.

@Test
public void active_rule_with_overrides_inheritance() {
    dbTester.prepareDbUnit(getClass(), "active_rule_with_overrides_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(ActiveRule.Inheritance.OVERRIDES);
}
Also used : ActiveRuleKey(org.sonar.db.qualityprofile.ActiveRuleKey) Test(org.junit.Test)

Example 15 with ActiveRuleKey

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

the class ActiveRuleResultSetIteratorTest method iterator_over_one_active_rule.

@Test
public void iterator_over_one_active_rule() {
    dbTester.prepareDbUnit(getClass(), "one_active_rule.xml");
    ActiveRuleResultSetIterator it = ActiveRuleResultSetIterator.create(dbTester.getDbClient(), dbTester.getSession(), 0L);
    Map<ActiveRuleKey, ActiveRuleDoc> activeRulesByKey = activeRulesByKey(it);
    it.close();
    assertThat(activeRulesByKey).hasSize(1);
    ActiveRuleKey key = ActiveRuleKey.of("sonar-way", RuleKey.of("xoo", "S001"));
    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(1500000000000L);
    assertThat(activeRule.updatedAt()).isEqualTo(1600000000000L);
}
Also used : 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