use of org.sonar.db.qualityprofile.QProfileDto in project sonarqube by SonarSource.
the class QProfileRuleImplTest method reset_parameter_to_default_value.
@Test
public void reset_parameter_to_default_value() {
RuleDefinitionDto rule = createRule();
RuleParamDto paramWithDefault = db.rules().insertRuleParam(rule, p -> p.setName("max").setDefaultValue("10"));
QProfileDto profile = createProfile(rule);
// initial activation -> param "max" has a default value
RuleActivation activation = RuleActivation.create(rule.getUuid(), null, of(paramWithDefault.getName(), "20"));
List<ActiveRuleChange> changes = activate(profile, activation);
verify(qualityProfileChangeEventService).distributeRuleChangeEvent(any(), eq(changes), eq(profile.getLanguage()));
// reset to default_value
RuleActivation updateActivation = RuleActivation.create(rule.getUuid(), null, of(paramWithDefault.getName(), ""));
changes = activate(profile, updateActivation);
assertThatRuleIsUpdated(profile, rule, rule.getSeverityString(), null, of(paramWithDefault.getName(), "10"));
assertThat(changes).hasSize(1);
verify(qualityProfileChangeEventService).distributeRuleChangeEvent(any(), eq(changes), eq(profile.getLanguage()));
}
use of org.sonar.db.qualityprofile.QProfileDto in project sonarqube by SonarSource.
the class QProfileRuleImplTest method reset_child_profile_do_not_change_parent.
@Test
public void reset_child_profile_do_not_change_parent() {
RuleDefinitionDto rule = createRule();
QProfileDto parentProfile = createProfile(rule);
QProfileDto childProfile = createChildProfile(parentProfile);
RuleActivation activation = RuleActivation.create(rule.getUuid(), CRITICAL, null);
List<ActiveRuleChange> changes = activate(parentProfile, activation);
assertThatRuleIsActivated(parentProfile, rule, changes, CRITICAL, null, emptyMap());
assertThatRuleIsActivated(childProfile, rule, changes, CRITICAL, INHERITED, emptyMap());
assertThat(changes).hasSize(2);
RuleActivation childActivation = RuleActivation.create(rule.getUuid(), BLOCKER, null);
changes = activate(childProfile, childActivation);
assertThatRuleIsUpdated(childProfile, rule, BLOCKER, ActiveRuleInheritance.OVERRIDES, emptyMap());
assertThat(changes).hasSize(1);
RuleActivation resetActivation = RuleActivation.createReset(rule.getUuid());
changes = activate(childProfile, resetActivation);
assertThatRuleIsUpdated(childProfile, rule, CRITICAL, INHERITED, emptyMap());
assertThatRuleIsUpdated(parentProfile, rule, CRITICAL, null, emptyMap());
assertThat(changes).hasSize(1);
}
use of org.sonar.db.qualityprofile.QProfileDto in project sonarqube by SonarSource.
the class QProfileRuleImplTest method cannot_deactivate_rule_inherited.
@Test
public void cannot_deactivate_rule_inherited() {
RuleDefinitionDto rule = createRule();
QProfileDto parentProfile = createProfile(rule);
QProfileDto childProfile = createChildProfile(parentProfile);
RuleActivation activation = RuleActivation.create(rule.getUuid());
List<ActiveRuleChange> changes = activate(parentProfile, activation);
assertThatRuleIsActivated(parentProfile, rule, changes, rule.getSeverityString(), null, emptyMap());
assertThatRuleIsActivated(childProfile, rule, changes, rule.getSeverityString(), INHERITED, emptyMap());
assertThatThrownBy(() -> deactivate(childProfile, rule)).isInstanceOf(BadRequestException.class).hasMessageContaining("Cannot deactivate inherited rule");
verify(qualityProfileChangeEventService).distributeRuleChangeEvent(any(), any(), eq(parentProfile.getLanguage()));
}
use of org.sonar.db.qualityprofile.QProfileDto in project sonarqube by SonarSource.
the class QProfileRuleImplTest method fail_to_activate_if_template.
@Test
public void fail_to_activate_if_template() {
RuleDefinitionDto rule = db.rules().insert(r -> r.setIsTemplate(true));
QProfileDto profile = createProfile(rule);
RuleActivation activation = RuleActivation.create(rule.getUuid());
expectFailure("Rule template can't be activated on a Quality profile: " + rule.getKey(), () -> activate(profile, activation));
verifyNoInteractions(qualityProfileChangeEventService);
}
use of org.sonar.db.qualityprofile.QProfileDto in project sonarqube by SonarSource.
the class QProfileRuleImplTest method system_deactivates_a_rule.
@Test
public void system_deactivates_a_rule() {
RuleDefinitionDto rule = createRule();
QProfileDto profile = createProfile(rule);
RuleActivation activation = RuleActivation.create(rule.getUuid());
List<ActiveRuleChange> changes = activate(profile, activation);
verify(qualityProfileChangeEventService).distributeRuleChangeEvent(any(), eq(changes), eq(profile.getLanguage()));
changes = deactivate(profile, rule);
verifyNoActiveRules();
assertThatProfileIsUpdatedBySystem(profile);
assertThatChangeIsDeactivation(changes, rule);
verify(qualityProfileChangeEventService).distributeRuleChangeEvent(any(), eq(changes), eq(profile.getLanguage()));
}
Aggregations