use of org.sonar.db.qualityprofile.QProfileDto in project sonarqube by SonarSource.
the class QProfileTreeImplTest method set_then_unset_parent.
@Test
public void set_then_unset_parent() {
RuleDefinitionDto rule1 = createJavaRule();
RuleDefinitionDto rule2 = createJavaRule();
QProfileDto profile1 = createProfile(rule1);
List<ActiveRuleChange> changes = activate(profile1, RuleActivation.create(rule1.getUuid()));
assertThat(changes).hasSize(1);
QProfileDto profile2 = createProfile(rule2);
changes = activate(profile2, RuleActivation.create(rule2.getUuid()));
assertThat(changes).hasSize(1);
changes = underTest.setParentAndCommit(db.getSession(), profile2, profile1);
assertThat(changes).hasSize(1);
assertThatRuleIsActivated(profile2, rule1, changes, rule1.getSeverityString(), INHERITED, emptyMap());
assertThatRuleIsActivated(profile2, rule2, null, rule2.getSeverityString(), null, emptyMap());
verify(qualityProfileChangeEventService, times(2)).distributeRuleChangeEvent(any(), any(), eq(profile2.getLanguage()));
changes = underTest.removeParentAndCommit(db.getSession(), profile2);
assertThat(changes).hasSize(1);
assertThatRuleIsActivated(profile2, rule2, null, rule2.getSeverityString(), null, emptyMap());
assertThatRuleIsNotPresent(profile2, rule1);
verify(qualityProfileChangeEventService, times(2)).distributeRuleChangeEvent(any(), any(), eq(profile2.getLanguage()));
}
use of org.sonar.db.qualityprofile.QProfileDto in project sonarqube by SonarSource.
the class QProfileTreeImplTest method activation_errors_are_ignored_when_setting_a_parent.
@Test
public void activation_errors_are_ignored_when_setting_a_parent() {
RuleDefinitionDto rule1 = createJavaRule();
RuleDefinitionDto rule2 = createJavaRule();
QProfileDto parentProfile = createProfile(rule1);
activate(parentProfile, RuleActivation.create(rule1.getUuid()));
activate(parentProfile, RuleActivation.create(rule2.getUuid()));
rule1.setStatus(RuleStatus.REMOVED);
db.rules().update(rule1);
QProfileDto childProfile = createProfile(rule1);
List<ActiveRuleChange> changes = underTest.setParentAndCommit(db.getSession(), childProfile, parentProfile);
verify(qualityProfileChangeEventService, times(2)).distributeRuleChangeEvent(any(), any(), eq(childProfile.getLanguage()));
assertThatRuleIsNotPresent(childProfile, rule1);
assertThatRuleIsActivated(childProfile, rule2, changes, rule2.getSeverityString(), INHERITED, emptyMap());
}
use of org.sonar.db.qualityprofile.QProfileDto in project sonarqube by SonarSource.
the class QProfileTreeImplTest method set_itself_as_parent_fails.
@Test
public void set_itself_as_parent_fails() {
RuleDefinitionDto rule = createRule();
QProfileDto profile = createProfile(rule);
assertThatThrownBy(() -> underTest.setParentAndCommit(db.getSession(), profile, profile)).isInstanceOf(BadRequestException.class).hasMessageContaining(" can not be selected as parent of ");
}
use of org.sonar.db.qualityprofile.QProfileDto in project sonarqube by SonarSource.
the class QProfileTreeImplTest method set_then_unset_parent_keep_overridden_rules.
@Test
public void set_then_unset_parent_keep_overridden_rules() {
RuleDefinitionDto rule1 = createJavaRule();
RuleDefinitionDto rule2 = createJavaRule();
QProfileDto profile1 = createProfile(rule1);
List<ActiveRuleChange> changes = activate(profile1, RuleActivation.create(rule1.getUuid()));
assertThat(changes).hasSize(1);
QProfileDto profile2 = createProfile(rule2);
changes = activate(profile2, RuleActivation.create(rule2.getUuid()));
assertThat(changes).hasSize(1);
changes = underTest.setParentAndCommit(db.getSession(), profile2, profile1);
assertThat(changes).hasSize(1);
assertThatRuleIsActivated(profile2, rule1, changes, rule1.getSeverityString(), INHERITED, emptyMap());
assertThatRuleIsActivated(profile2, rule2, null, rule2.getSeverityString(), null, emptyMap());
verify(qualityProfileChangeEventService, times(2)).distributeRuleChangeEvent(any(), any(), eq(profile2.getLanguage()));
RuleActivation activation = RuleActivation.create(rule1.getUuid(), BLOCKER, null);
changes = activate(profile2, activation);
assertThat(changes).hasSize(1);
assertThatRuleIsUpdated(profile2, rule1, BLOCKER, ActiveRuleInheritance.OVERRIDES, emptyMap());
assertThatRuleIsActivated(profile2, rule2, null, rule2.getSeverityString(), null, emptyMap());
changes = underTest.removeParentAndCommit(db.getSession(), profile2);
assertThat(changes).hasSize(1);
// Not testing changes here since severity is not set in changelog
assertThatRuleIsActivated(profile2, rule1, null, BLOCKER, null, emptyMap());
assertThatRuleIsActivated(profile2, rule2, null, rule2.getSeverityString(), null, emptyMap());
verify(qualityProfileChangeEventService, times(3)).distributeRuleChangeEvent(anyList(), any(), eq(profile2.getLanguage()));
}
use of org.sonar.db.qualityprofile.QProfileDto in project sonarqube by SonarSource.
the class QProfileTreeImplTest method set_child_as_parent_fails.
@Test
public void set_child_as_parent_fails() {
RuleDefinitionDto rule = createRule();
QProfileDto parentProfile = createProfile(rule);
QProfileDto childProfile = createChildProfile(parentProfile);
assertThatThrownBy(() -> underTest.setParentAndCommit(db.getSession(), parentProfile, childProfile)).isInstanceOf(BadRequestException.class).hasMessageContaining(" can not be selected as parent of ");
}
Aggregations