dbSession.commit();
// 0. get all rules
Result<Rule> result = index.search(new RuleQuery(),
new QueryContext());
assertThat(result.getHits()).hasSize(4);
// 1. get all active rules
result = index.search(new RuleQuery().setActivation(true),
new QueryContext());
assertThat(result.getHits()).hasSize(3);
// 2. get all inactive rules.
result = index.search(new RuleQuery().setActivation(false),
new QueryContext());
assertThat(result.getHits()).hasSize(1);
assertThat(result.getHits().get(0).name()).isEqualTo(rule4.getName());
// 3. get Inherited Rules on profile1
result = index.search(new RuleQuery().setActivation(true)
.setQProfileKey(qualityProfileDto1.getKey())
.setInheritance(ImmutableSet.of(ActiveRule.Inheritance.INHERITED.name())),
new QueryContext()
);
assertThat(result.getHits()).hasSize(0);
// 4. get Inherited Rules on profile2
result = index.search(new RuleQuery().setActivation(true)
.setQProfileKey(qualityProfileDto2.getKey())
.setInheritance(ImmutableSet.of(ActiveRule.Inheritance.INHERITED.name())),
new QueryContext()
);
assertThat(result.getHits()).hasSize(2);
// 5. get Overridden Rules on profile1
result = index.search(new RuleQuery().setActivation(true)
.setQProfileKey(qualityProfileDto1.getKey())
.setInheritance(ImmutableSet.of(ActiveRule.Inheritance.OVERRIDES.name())),
new QueryContext()
);
assertThat(result.getHits()).hasSize(0);
// 6. get Overridden Rules on profile2
result = index.search(new RuleQuery().setActivation(true)
.setQProfileKey(qualityProfileDto2.getKey())
.setInheritance(ImmutableSet.of(ActiveRule.Inheritance.OVERRIDES.name())),
new QueryContext()
);
assertThat(result.getHits()).hasSize(1);
// 7. get Inherited AND Overridden Rules on profile1
result = index.search(new RuleQuery().setActivation(true)
.setQProfileKey(qualityProfileDto1.getKey())
.setInheritance(ImmutableSet.of(
ActiveRule.Inheritance.INHERITED.name(), ActiveRule.Inheritance.OVERRIDES.name())),
new QueryContext()
);
assertThat(result.getHits()).hasSize(0);
// 8. get Inherited AND Overridden Rules on profile2
result = index.search(new RuleQuery().setActivation(true)
.setQProfileKey(qualityProfileDto2.getKey())
.setInheritance(ImmutableSet.of(
ActiveRule.Inheritance.INHERITED.name(), ActiveRule.Inheritance.OVERRIDES.name())),
new QueryContext()
);
assertThat(result.getHits()).hasSize(3);
}