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");
}
}
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"));
}
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);
}
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);
}
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);
}
Aggregations