use of org.sonar.db.qualityprofile.ActiveRuleKey in project sonarqube by SonarSource.
the class RuleIndexTest method search_by_profile_and_inheritance.
@Test
public void search_by_profile_and_inheritance() {
indexRules(newDoc(RULE_KEY_1), newDoc(RULE_KEY_2), newDoc(RULE_KEY_3), newDoc(RULE_KEY_4));
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_KEY1, RULE_KEY_3);
indexActiveRules(ActiveRuleDocTesting.newDoc(activeRuleKey1), ActiveRuleDocTesting.newDoc(activeRuleKey2), ActiveRuleDocTesting.newDoc(activeRuleKey3), // Profile 2 is a child a profile 1
ActiveRuleDocTesting.newDoc(ActiveRuleKey.of(QUALITY_PROFILE_KEY2, RULE_KEY_1)).setInheritance(INHERITED.name()), ActiveRuleDocTesting.newDoc(ActiveRuleKey.of(QUALITY_PROFILE_KEY2, RULE_KEY_2)).setInheritance(OVERRIDES.name()), ActiveRuleDocTesting.newDoc(ActiveRuleKey.of(QUALITY_PROFILE_KEY2, RULE_KEY_3)).setInheritance(INHERITED.name()));
// 0. get all rules
assertThat(index.search(new RuleQuery(), new SearchOptions()).getIds()).hasSize(4);
// 1. get all active rules
assertThat(index.search(new RuleQuery().setActivation(true), new SearchOptions()).getIds()).hasSize(3);
// 2. get all inactive rules.
assertThat(index.search(new RuleQuery().setActivation(false), new SearchOptions()).getIds()).containsOnly(RULE_KEY_4);
// 3. get Inherited Rules on profile1
assertThat(index.search(new RuleQuery().setActivation(true).setQProfileKey(QUALITY_PROFILE_KEY1).setInheritance(ImmutableSet.of(INHERITED.name())), new SearchOptions()).getIds()).isEmpty();
// 4. get Inherited Rules on profile2
assertThat(index.search(new RuleQuery().setActivation(true).setQProfileKey(QUALITY_PROFILE_KEY2).setInheritance(ImmutableSet.of(INHERITED.name())), new SearchOptions()).getIds()).hasSize(2);
// 5. get Overridden Rules on profile1
assertThat(index.search(new RuleQuery().setActivation(true).setQProfileKey(QUALITY_PROFILE_KEY1).setInheritance(ImmutableSet.of(OVERRIDES.name())), new SearchOptions()).getIds()).isEmpty();
// 6. get Overridden Rules on profile2
assertThat(index.search(new RuleQuery().setActivation(true).setQProfileKey(QUALITY_PROFILE_KEY2).setInheritance(ImmutableSet.of(OVERRIDES.name())), new SearchOptions()).getIds()).hasSize(1);
// 7. get Inherited AND Overridden Rules on profile1
assertThat(index.search(new RuleQuery().setActivation(true).setQProfileKey(QUALITY_PROFILE_KEY1).setInheritance(ImmutableSet.of(INHERITED.name(), OVERRIDES.name())), new SearchOptions()).getIds()).isEmpty();
// 8. get Inherited AND Overridden Rules on profile2
assertThat(index.search(new RuleQuery().setActivation(true).setQProfileKey(QUALITY_PROFILE_KEY2).setInheritance(ImmutableSet.of(INHERITED.name(), OVERRIDES.name())), new SearchOptions()).getIds()).hasSize(3);
}
Aggregations