use of org.sonar.server.qualityprofile.ActiveRuleInheritance.INHERITED in project sonarqube by SonarSource.
the class RuleActivatorTest method request_new_severity_and_param_for_child_rule.
@Test
public void request_new_severity_and_param_for_child_rule() {
RuleDefinitionDto rule = db.rules().insert(r -> r.setLanguage("xoo").setSeverity(Severity.BLOCKER));
RuleParamDto ruleParam = db.rules().insertRuleParam(rule, p -> p.setName("min").setDefaultValue("10"));
QProfileDto parentProfile = db.qualityProfiles().insert(p -> p.setLanguage(rule.getLanguage()).setIsBuiltIn(true));
ActiveRuleDto parentActiveRuleDto = activateRuleInDb(RulesProfileDto.from(parentProfile), rule, RulePriority.valueOf(Severity.BLOCKER), null);
ActiveRuleParamDto parentActiveRuleParam = activateRuleParamInDb(parentActiveRuleDto, ruleParam, "10");
QProfileDto childProfile = createChildProfile(parentProfile);
ActiveRuleDto childActiveRuleDto = activateRuleInDb(RulesProfileDto.from(childProfile), rule, RulePriority.valueOf(Severity.BLOCKER), INHERITED);
ActiveRuleParamDto childActiveRuleParam = activateRuleParamInDb(childActiveRuleDto, ruleParam, "10");
DbSession session = db.getSession();
RuleActivation resetRequest = RuleActivation.create(rule.getUuid(), Severity.MINOR, ImmutableMap.of("min", "15"));
RuleActivationContext context = new RuleActivationContext.Builder().setProfiles(asList(parentProfile, childProfile)).setBaseProfile(RulesProfileDto.from(childProfile)).setDate(NOW).setDescendantProfilesSupplier((profiles, ruleUuids) -> new Result(emptyList(), emptyList(), emptyList())).setRules(singletonList(rule)).setRuleParams(singletonList(ruleParam)).setActiveRules(asList(parentActiveRuleDto, childActiveRuleDto)).setActiveRuleParams(asList(parentActiveRuleParam, childActiveRuleParam)).build();
List<ActiveRuleChange> result = underTest.activate(session, resetRequest, context);
assertThat(result).hasSize(1);
assertThat(result.get(0).getParameters()).containsEntry("min", "15");
assertThat(result.get(0).getSeverity()).isEqualTo(Severity.MINOR);
assertThat(result.get(0).getInheritance()).isEqualTo(OVERRIDES);
}
Aggregations