use of org.sonar.db.qualityprofile.ActiveRuleKey in project sonarqube by SonarSource.
the class RuleActivatorContextFactory method initActiveRules.
private void initActiveRules(String profileKey, RuleKey ruleKey, RuleActivatorContext context, DbSession session, boolean parent) {
ActiveRuleKey key = ActiveRuleKey.of(profileKey, ruleKey);
Optional<ActiveRuleDto> activeRule = db.activeRuleDao().selectByKey(session, key);
Collection<ActiveRuleParamDto> activeRuleParams = null;
if (activeRule.isPresent()) {
activeRuleParams = db.activeRuleDao().selectParamsByActiveRuleId(session, activeRule.get().getId());
}
if (parent) {
context.setParentActiveRule(activeRule.orNull());
context.setParentActiveRuleParams(activeRuleParams);
} else {
context.setActiveRule(activeRule.orNull());
context.setActiveRuleParams(activeRuleParams);
}
}
use of org.sonar.db.qualityprofile.ActiveRuleKey in project sonarqube by SonarSource.
the class RuleActivatorMediumTest method do_not_change_severity_and_params_if_unset_and_already_activated.
@Test
public void do_not_change_severity_and_params_if_unset_and_already_activated() {
// initial activation
ActiveRuleKey activeRuleKey = ActiveRuleKey.of(XOO_P1_KEY, XOO_X1);
RuleActivation activation = new RuleActivation(XOO_X1);
activation.setSeverity(BLOCKER);
activation.setParameter("max", "7");
activate(activation, XOO_P1_KEY);
// update without any severity or params => keep
RuleActivation update = new RuleActivation(XOO_X1);
activate(update, XOO_P1_KEY);
assertThat(countActiveRules(XOO_P1_KEY)).isEqualTo(1);
verifyHasActiveRuleInDb(activeRuleKey, BLOCKER, null, ImmutableMap.of("max", "7"));
}
use of org.sonar.db.qualityprofile.ActiveRuleKey in project sonarqube by SonarSource.
the class RuleActivatorMediumTest method revert_activation_to_default_severity_and_parameters.
@Test
public void revert_activation_to_default_severity_and_parameters() {
// initial activation
ActiveRuleKey activeRuleKey = ActiveRuleKey.of(XOO_P1_KEY, XOO_X1);
RuleActivation activation = new RuleActivation(XOO_X1);
activation.setSeverity(BLOCKER);
activation.setParameter("max", "7");
activation.setParameter("min", "3");
activate(activation, XOO_P1_KEY);
// update without any severity or params = reset
RuleActivation update = new RuleActivation(XOO_X1).setReset(true);
activate(update, XOO_P1_KEY);
assertThat(countActiveRules(XOO_P1_KEY)).isEqualTo(1);
verifyHasActiveRuleInDb(activeRuleKey, MINOR, null, // only default values
ImmutableMap.of("max", "10"));
}
use of org.sonar.db.qualityprofile.ActiveRuleKey in project sonarqube by SonarSource.
the class RuleActivatorMediumTest method ignore_deactivation_if_rule_not_activated.
@Test
public void ignore_deactivation_if_rule_not_activated() {
// deactivation
ActiveRuleKey key = ActiveRuleKey.of(XOO_P1_KEY, XOO_X1);
ruleActivator.deactivate(key);
verifyZeroActiveRules(XOO_P1_KEY);
}
use of org.sonar.db.qualityprofile.ActiveRuleKey in project sonarqube by SonarSource.
the class RuleActivatorMediumTest method update_activation_but_new_parameter.
@Test
public void update_activation_but_new_parameter() {
// initial activation
ActiveRuleKey activeRuleKey = ActiveRuleKey.of(XOO_P1_KEY, XOO_X1);
RuleActivation activation = new RuleActivation(XOO_X1);
activation.setSeverity(BLOCKER);
activate(activation, XOO_P1_KEY);
assertThat(db.activeRuleDao().selectParamByKeyAndName(activeRuleKey, "max", dbSession)).isNotNull();
db.activeRuleDao().deleteParamByKeyAndName(dbSession, activeRuleKey, "max");
dbSession.commit();
assertThat(db.activeRuleDao().selectParamByKeyAndName(activeRuleKey, "max", dbSession)).isNull();
dbSession.clearCache();
// update
RuleActivation update = new RuleActivation(XOO_X1);
update.setSeverity(CRITICAL);
update.setParameter("max", "42");
// contrary to activerule, the param 'max' is supposed to be inserted but not updated
activate(update, XOO_P1_KEY);
assertThat(countActiveRules(XOO_P1_KEY)).isEqualTo(1);
verifyHasActiveRuleInDb(activeRuleKey, CRITICAL, null, ImmutableMap.of("max", "42"));
}
Aggregations