use of org.sonar.server.qualityprofile.builtin.QProfileName in project sonarqube by SonarSource.
the class RegisterQualityProfilesNotificationTest method notification_does_not_include_inherited_profiles_when_rule_is_added.
@Test
public void notification_does_not_include_inherited_profiles_when_rule_is_added() {
String language = newLanguageKey();
RuleDefinitionDto newRule = db.rules().insert(r -> r.setLanguage(language));
QProfileDto builtInQProfileDto = insertProfile(orgQProfile -> orgQProfile.setIsBuiltIn(true).setLanguage(language));
QProfileDto childQProfileDto = insertProfile(orgQProfile -> orgQProfile.setIsBuiltIn(false).setLanguage(language).setParentKee(builtInQProfileDto.getKee()));
addPluginProfile(builtInQProfileDto, newRule);
builtInQProfileRepositoryRule.initialize();
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(builtInQProfileDto.getName(), builtInQProfileDto.getLanguage()));
assertThat(updatedProfiles.values()).extracting(value -> value.getActiveRule().getRuleUuid(), ActiveRuleChange::getType).containsExactlyInAnyOrder(tuple(newRule.getUuid(), ACTIVATED));
}
use of org.sonar.server.qualityprofile.builtin.QProfileName in project sonarqube by SonarSource.
the class RegisterQualityProfilesNotificationTest method send_notification_when_a_rule_is_deactivated.
@Test
public void send_notification_when_a_rule_is_deactivated() {
String language = newLanguageKey();
RuleDefinitionDto existingRule = db.rules().insert(r -> r.setLanguage(language));
RulesProfileDto dbProfile = insertBuiltInProfile(language);
activateRuleInDb(dbProfile, existingRule, MAJOR);
addPluginProfile(dbProfile);
builtInQProfileRepositoryRule.initialize();
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(dbProfile.getName(), dbProfile.getLanguage()));
assertThat(updatedProfiles.values()).extracting(value -> value.getActiveRule().getRuleUuid(), ActiveRuleChange::getType).containsExactlyInAnyOrder(tuple(existingRule.getUuid(), DEACTIVATED));
}
use of org.sonar.server.qualityprofile.builtin.QProfileName in project sonarqube by SonarSource.
the class RegisterQualityProfilesNotificationTest method notification_does_not_include_inherited_profiles_when_rule_is_deactivated.
@Test
public void notification_does_not_include_inherited_profiles_when_rule_is_deactivated() {
String language = newLanguageKey();
RuleDefinitionDto rule = db.rules().insert(r -> r.setLanguage(language).setSeverity(Severity.MINOR));
QProfileDto builtInQProfileDto = insertProfile(orgQProfile -> orgQProfile.setIsBuiltIn(true).setLanguage(language));
db.qualityProfiles().activateRule(builtInQProfileDto, rule);
QProfileDto childQProfileDto = insertProfile(orgQProfile -> orgQProfile.setIsBuiltIn(false).setLanguage(language).setParentKee(builtInQProfileDto.getKee()));
qProfileRules.activateAndCommit(db.getSession(), childQProfileDto, singleton(RuleActivation.create(rule.getUuid())));
db.commit();
addPluginProfile(builtInQProfileDto);
builtInQProfileRepositoryRule.initialize();
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(builtInQProfileDto.getName(), builtInQProfileDto.getLanguage()));
assertThat(updatedProfiles.values()).extracting(value -> value.getActiveRule().getRuleUuid(), ActiveRuleChange::getType).containsExactlyInAnyOrder(tuple(rule.getUuid(), DEACTIVATED));
}
use of org.sonar.server.qualityprofile.builtin.QProfileName in project sonarqube by SonarSource.
the class QProfileBackuperImpl method restore.
private QProfileRestoreSummary restore(DbSession dbSession, ImportedQProfile qProfile, Function<QProfileName, QProfileDto> profileLoader) {
QProfileName targetName = new QProfileName(qProfile.getProfileLang(), qProfile.getProfileName());
QProfileDto targetProfile = profileLoader.apply(targetName);
List<ImportedRule> importedRules = qProfile.getRules();
Map<RuleKey, RuleDefinitionDto> ruleDefinitionsByKey = getImportedRulesDefinitions(dbSession, importedRules);
checkIfRulesFromExternalEngines(ruleDefinitionsByKey.values());
Map<RuleKey, RuleDefinitionDto> customRulesDefinitions = createCustomRulesIfNotExist(dbSession, importedRules, ruleDefinitionsByKey);
ruleDefinitionsByKey.putAll(customRulesDefinitions);
List<RuleActivation> ruleActivations = toRuleActivations(importedRules, ruleDefinitionsByKey);
BulkChangeResult changes = profileReset.reset(dbSession, targetProfile, ruleActivations);
return new QProfileRestoreSummary(targetProfile, changes);
}
use of org.sonar.server.qualityprofile.builtin.QProfileName in project sonarqube by SonarSource.
the class QProfileFactoryImplTest method checkAndCreateCustom_throws_BadRequestException_if_already_exists.
@Test
public void checkAndCreateCustom_throws_BadRequestException_if_already_exists() {
QProfileName name = new QProfileName("xoo", "P1");
underTest.checkAndCreateCustom(dbSession, name);
dbSession.commit();
expectBadRequestException(() -> underTest.checkAndCreateCustom(dbSession, name), "Quality profile already exists: xoo/P1");
}
Aggregations