use of org.sonar.db.qualityprofile.QProfileDto in project sonarqube by SonarSource.
the class QProfileRuleImplTest method deactivate_rule_that_has_REMOVED_status.
@Test
public void deactivate_rule_that_has_REMOVED_status() {
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()));
rule.setStatus(RuleStatus.REMOVED);
db.getDbClient().ruleDao().update(db.getSession(), rule);
changes = deactivate(profile, rule);
verifyNoActiveRules();
assertThatChangeIsDeactivation(changes, rule);
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_on_parent_is_not_propagated_to_overridden_profiles.
@Test
public void reset_on_parent_is_not_propagated_to_overridden_profiles() {
RuleDefinitionDto rule = createRule();
RuleParamDto param = db.rules().insertRuleParam(rule);
QProfileDto parentProfile = createProfile(rule);
QProfileDto childProfile = createChildProfile(parentProfile);
QProfileDto grandChildProfile = createChildProfile(childProfile);
RuleActivation initialActivation = RuleActivation.create(rule.getUuid(), MAJOR, of(param.getName(), "foo"));
List<ActiveRuleChange> changes = activate(parentProfile, initialActivation);
verify(qualityProfileChangeEventService).distributeRuleChangeEvent(any(), eq(changes), eq(parentProfile.getLanguage()));
RuleActivation overrideActivation = RuleActivation.create(rule.getUuid(), CRITICAL, of(param.getName(), "bar"));
changes = activate(grandChildProfile, overrideActivation);
verify(qualityProfileChangeEventService).distributeRuleChangeEvent(any(), eq(changes), eq(grandChildProfile.getLanguage()));
// reset parent --> touch child but not grandChild
RuleActivation updateActivation = RuleActivation.createReset(rule.getUuid());
changes = activate(parentProfile, updateActivation);
assertThatRuleIsUpdated(parentProfile, rule, rule.getSeverityString(), null, of(param.getName(), param.getDefaultValue()));
assertThatRuleIsUpdated(childProfile, rule, rule.getSeverityString(), INHERITED, of(param.getName(), param.getDefaultValue()));
assertThatRuleIsUpdated(grandChildProfile, rule, CRITICAL, ActiveRuleInheritance.OVERRIDES, of(param.getName(), "bar"));
assertThat(changes).hasSize(2);
verify(qualityProfileChangeEventService).distributeRuleChangeEvent(any(), eq(changes), eq(parentProfile.getLanguage()));
}
use of org.sonar.db.qualityprofile.QProfileDto in project sonarqube by SonarSource.
the class QProfileRuleImplTest method update_activation_removes_parameter_without_default_value.
@Test
public void update_activation_removes_parameter_without_default_value() {
RuleDefinitionDto rule = createRule();
RuleParamDto paramWithoutDefault = db.rules().insertRuleParam(rule, p -> p.setName("min").setDefaultValue(null));
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(paramWithoutDefault.getName(), "20"));
List<ActiveRuleChange> changes = activate(profile, activation);
verify(qualityProfileChangeEventService).distributeRuleChangeEvent(any(), eq(changes), eq(profile.getLanguage()));
// remove parameter
RuleActivation updateActivation = RuleActivation.create(rule.getUuid(), null, of(paramWithoutDefault.getName(), ""));
changes = activate(profile, updateActivation);
assertThatRuleIsUpdated(profile, rule, rule.getSeverityString(), null, of(paramWithDefault.getName(), paramWithDefault.getDefaultValue()));
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 delete_rule_from_all_profiles.
@Test
public void delete_rule_from_all_profiles() {
RuleDefinitionDto rule = createRule();
QProfileDto parentProfile = createProfile(rule);
QProfileDto childProfile = createChildProfile(parentProfile);
QProfileDto grandChildProfile = createChildProfile(childProfile);
RuleActivation activation = RuleActivation.create(rule.getUuid(), CRITICAL, null);
activate(parentProfile, activation);
RuleActivation overrideActivation = RuleActivation.create(rule.getUuid(), BLOCKER, null);
activate(grandChildProfile, overrideActivation);
// Reset on parent do not change child nor grandchild
List<ActiveRuleChange> changes = underTest.deleteRule(db.getSession(), rule);
assertThatRuleIsNotPresent(parentProfile, rule);
assertThatRuleIsNotPresent(childProfile, rule);
assertThatRuleIsNotPresent(grandChildProfile, rule);
assertThat(changes).extracting(ActiveRuleChange::getType).containsOnly(ActiveRuleChange.Type.DEACTIVATED).hasSize(3);
}
use of org.sonar.db.qualityprofile.QProfileDto in project sonarqube by SonarSource.
the class QProfileRuleImplTest method assertThatProfileIsUpdatedByUser.
private void assertThatProfileIsUpdatedByUser(QProfileDto profile) {
QProfileDto loaded = db.getDbClient().qualityProfileDao().selectByUuid(db.getSession(), profile.getKee());
assertThat(loaded.getUserUpdatedAt()).isNotNull();
assertThat(loaded.getRulesUpdatedAt()).isNotEmpty();
}
Aggregations