use of org.sonar.db.qualityprofile.RulesProfileDto in project sonarqube by SonarSource.
the class QProfileFactoryImplTest method createBuiltInProfile.
private RulesProfileDto createBuiltInProfile() {
RulesProfileDto rulesProfileDto = new RulesProfileDto().setIsBuiltIn(true).setUuid(Uuids.createFast()).setLanguage("xoo").setName("Sonar way");
db.getDbClient().qualityProfileDao().insert(dbSession, rulesProfileDto);
ActiveRuleDto activeRuleDto = new ActiveRuleDto().setProfileUuid(rulesProfileDto.getUuid()).setRuleUuid(rule.getUuid()).setSeverity(Severity.BLOCKER);
db.getDbClient().activeRuleDao().insert(dbSession, activeRuleDto);
ActiveRuleParamDto activeRuleParam = new ActiveRuleParamDto().setRulesParameterUuid(ruleParam.getUuid()).setKey("foo").setValue("bar");
db.getDbClient().activeRuleDao().insertParam(dbSession, activeRuleDto, activeRuleParam);
db.getDbClient().qProfileChangeDao().insert(dbSession, new QProfileChangeDto().setChangeType(ActiveRuleChange.Type.ACTIVATED.name()).setRulesProfileUuid(rulesProfileDto.getUuid()));
db.commit();
return rulesProfileDto;
}
use of org.sonar.db.qualityprofile.RulesProfileDto in project sonarqube by SonarSource.
the class RegisterQualityProfilesNotificationTest method send_a_single_notification_when_multiple_rules_are_activated.
@Test
public void send_a_single_notification_when_multiple_rules_are_activated() {
String language = newLanguageKey();
RuleDefinitionDto existingRule1 = db.rules().insert(r -> r.setLanguage(language));
RuleDefinitionDto newRule1 = db.rules().insert(r -> r.setLanguage(language));
RulesProfileDto dbProfile1 = insertBuiltInProfile(language);
activateRuleInDb(dbProfile1, existingRule1, MAJOR);
addPluginProfile(dbProfile1, existingRule1, newRule1);
RuleDefinitionDto existingRule2 = db.rules().insert(r -> r.setLanguage(language));
RuleDefinitionDto newRule2 = db.rules().insert(r -> r.setLanguage(language));
RulesProfileDto dbProfile2 = insertBuiltInProfile(language);
activateRuleInDb(dbProfile2, existingRule2, MAJOR);
addPluginProfile(dbProfile2, existingRule2, newRule2);
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(dbProfile1.getName(), dbProfile1.getLanguage()), tuple(dbProfile2.getName(), dbProfile2.getLanguage()));
assertThat(updatedProfiles.values()).extracting(value -> value.getActiveRule().getRuleUuid(), ActiveRuleChange::getType).containsExactlyInAnyOrder(tuple(newRule1.getUuid(), ACTIVATED), tuple(newRule2.getUuid(), ACTIVATED));
}
use of org.sonar.db.qualityprofile.RulesProfileDto in project sonarqube by SonarSource.
the class RegisterQualityProfilesNotificationTest method do_not_send_notification_when_profile_is_not_updated.
@Test
public void do_not_send_notification_when_profile_is_not_updated() {
String language = newLanguageKey();
RuleDefinitionDto dbRule = db.rules().insert(r -> r.setLanguage(language));
RulesProfileDto dbProfile = insertBuiltInProfile(language);
activateRuleInDb(dbProfile, dbRule, MAJOR);
addPluginProfile(dbProfile, dbRule);
builtInQProfileRepositoryRule.initialize();
underTest.start();
verifyNoInteractions(builtInQualityProfilesNotification);
}
use of org.sonar.db.qualityprofile.RulesProfileDto 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.db.qualityprofile.RulesProfileDto in project sonarqube by SonarSource.
the class BuiltInQProfileUpdateImplTest method assertThatProfileIsNotMarkedAsUpdated.
private void assertThatProfileIsNotMarkedAsUpdated(RulesProfileDto dto) {
RulesProfileDto reloaded = db.getDbClient().qualityProfileDao().selectBuiltInRuleProfiles(db.getSession()).stream().filter(p -> p.getUuid().equals(dto.getUuid())).findFirst().get();
assertThat(reloaded.getRulesUpdatedAt()).isNull();
}
Aggregations