use of org.sonar.db.qualityprofile.QProfileDto in project sonarqube by SonarSource.
the class QProfileResetImplTest method reset.
@Test
public void reset() {
QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage(LANGUAGE));
RuleDefinitionDto existingRule = db.rules().insert(r -> r.setLanguage(LANGUAGE));
qProfileRules.activateAndCommit(db.getSession(), profile, singleton(RuleActivation.create(existingRule.getUuid())));
RuleDefinitionDto newRule = db.rules().insert(r -> r.setLanguage(LANGUAGE));
BulkChangeResult result = underTest.reset(db.getSession(), profile, singletonList(RuleActivation.create(newRule.getUuid())));
assertThat(db.getDbClient().activeRuleDao().selectByProfile(db.getSession(), profile)).extracting(OrgActiveRuleDto::getRuleKey).containsExactlyInAnyOrder(newRule.getKey());
// Only activated rules are returned in the result
assertThat(result.getChanges()).extracting(ActiveRuleChange::getKey, ActiveRuleChange::getType).containsExactlyInAnyOrder(tuple(ActiveRuleKey.of(profile, newRule.getKey()), ACTIVATED));
verify(qualityProfileChangeEventService).distributeRuleChangeEvent(any(), any(), eq(profile.getLanguage()));
}
use of org.sonar.db.qualityprofile.QProfileDto in project sonarqube by SonarSource.
the class QProfileResetImplTest method fail_when_profile_is_not_persisted.
@Test
public void fail_when_profile_is_not_persisted() {
QProfileDto profile = QualityProfileTesting.newQualityProfileDto().setRulesProfileUuid(null).setLanguage(LANGUAGE);
RuleDefinitionDto defaultRule = db.rules().insert(r -> r.setLanguage(LANGUAGE));
assertThatThrownBy(() -> {
underTest.reset(db.getSession(), profile, singletonList(RuleActivation.create(defaultRule.getUuid())));
}).isInstanceOf(NullPointerException.class).hasMessage("Quality profile must be persisted");
verifyNoInteractions(qualityProfileChangeEventService);
}
use of org.sonar.db.qualityprofile.QProfileDto in project sonarqube by SonarSource.
the class QProfileResetImplTest method fail_when_profile_is_built_in.
@Test
public void fail_when_profile_is_built_in() {
QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage(LANGUAGE).setIsBuiltIn(true));
RuleDefinitionDto defaultRule = db.rules().insert(r -> r.setLanguage(LANGUAGE));
assertThatThrownBy(() -> {
underTest.reset(db.getSession(), profile, singletonList(RuleActivation.create(defaultRule.getUuid())));
}).isInstanceOf(IllegalArgumentException.class).hasMessage(String.format("Operation forbidden for built-in Quality Profile '%s'", profile.getKee()));
verifyNoInteractions(qualityProfileChangeEventService);
}
use of org.sonar.db.qualityprofile.QProfileDto in project sonarqube by SonarSource.
the class QProfileRulesImplTest method activate_one_rule.
@Test
public void activate_one_rule() {
QProfileDto qProfile = db.qualityProfiles().insert();
RuleDefinitionDto rule = db.rules().insert(r -> r.setLanguage(qProfile.getLanguage()));
RuleActivation ruleActivation = RuleActivation.create(rule.getUuid(), Severity.CRITICAL, Collections.emptyMap());
qProfileRules.activateAndCommit(db.getSession(), qProfile, singleton(ruleActivation));
assertThat(db.getDbClient().activeRuleDao().selectByProfile(db.getSession(), qProfile)).extracting(ActiveRuleDto::getRuleKey, ActiveRuleDto::getSeverityString).containsExactlyInAnyOrder(tuple(rule.getKey(), Severity.CRITICAL));
verify(qualityProfileChangeEventService).distributeRuleChangeEvent(any(), any(), eq(qProfile.getLanguage()));
}
use of org.sonar.db.qualityprofile.QProfileDto in project sonarqube by SonarSource.
the class RegisterQualityProfilesNotificationTest method notification_does_not_include_inherited_profiled_when_rule_is_changed.
@Test
public void notification_does_not_include_inherited_profiled_when_rule_is_changed() {
String language = newLanguageKey();
RuleDefinitionDto rule = db.rules().insert(r -> r.setLanguage(language).setSeverity(Severity.MINOR));
QProfileDto builtInProfile = insertProfile(orgQProfile -> orgQProfile.setIsBuiltIn(true).setLanguage(language));
db.qualityProfiles().activateRule(builtInProfile, rule, ar -> ar.setSeverity(Severity.MINOR));
QProfileDto childProfile = insertProfile(orgQProfile -> orgQProfile.setIsBuiltIn(false).setLanguage(language).setParentKee(builtInProfile.getKee()));
db.qualityProfiles().activateRule(childProfile, rule, ar -> ar.setInheritance(ActiveRuleDto.INHERITED).setSeverity(Severity.MINOR));
addPluginProfile(builtInProfile, rule);
builtInQProfileRepositoryRule.initialize();
db.commit();
underTest.start();
ArgumentCaptor<Multimap> captor = ArgumentCaptor.forClass(Multimap.class);
verify(builtInQualityProfilesNotification).onChange(captor.capture(), anyLong(), anyLong());
Multimap<QProfileName, ActiveRuleChange> updatedProfiles = captor.getValue();
assertThat(updatedProfiles.keySet()).extracting(QProfileName::getName, QProfileName::getLanguage).containsExactlyInAnyOrder(tuple(builtInProfile.getName(), builtInProfile.getLanguage()));
assertThat(updatedProfiles.values()).extracting(value -> value.getActiveRule().getRuleUuid(), ActiveRuleChange::getType).containsExactlyInAnyOrder(tuple(rule.getUuid(), UPDATED));
}
Aggregations