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