use of org.sonar.db.qualityprofile.ActiveRuleDto 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.ActiveRuleDto in project sonarqube by SonarSource.
the class QProfileBackuperImplTest method activate.
private ActiveRuleDto activate(QProfileDto profile, RuleDefinitionDto rule, RuleParamDto param) {
ActiveRuleDto activeRule = db.qualityProfiles().activateRule(profile, rule);
ActiveRuleParamDto dto = ActiveRuleParamDto.createFor(param).setValue("20").setActiveRuleUuid(activeRule.getUuid());
db.getDbClient().activeRuleDao().insertParam(db.getSession(), activeRule, dto);
return activeRule;
}
use of org.sonar.db.qualityprofile.ActiveRuleDto in project sonarqube by SonarSource.
the class QProfileBackuperImplTest method copy_profile.
@Test
public void copy_profile() {
RuleDefinitionDto rule = createRule();
RuleParamDto param = db.rules().insertRuleParam(rule);
QProfileDto from = createProfile(rule.getLanguage());
ActiveRuleDto activeRule = activate(from, rule, param);
QProfileDto to = createProfile(rule.getLanguage());
underTest.copy(db.getSession(), from, to);
assertThat(reset.calledActivations).extracting(RuleActivation::getRuleUuid).containsOnly(activeRule.getRuleUuid());
assertThat(reset.calledActivations.get(0).getParameter(param.getName())).isEqualTo("20");
assertThat(reset.calledProfile).isEqualTo(to);
}
use of org.sonar.db.qualityprofile.ActiveRuleDto in project sonarqube by SonarSource.
the class RegisterQualityProfilesNotificationTest method activateRuleInDb.
private void activateRuleInDb(RulesProfileDto profile, RuleDefinitionDto rule, RulePriority severity) {
ActiveRuleDto dto = new ActiveRuleDto().setProfileUuid(profile.getUuid()).setSeverity(severity.name()).setRuleUuid(rule.getUuid()).setCreatedAt(nextLong()).setUpdatedAt(nextLong());
db.getDbClient().activeRuleDao().insert(db.getSession(), dto);
db.commit();
}
use of org.sonar.db.qualityprofile.ActiveRuleDto in project sonarqube by SonarSource.
the class BuiltInQProfileUpdateImplTest method activate_rule_on_built_in_profile_resets_severity_to_default_if_not_overridden.
// SONAR-10473
@Test
public void activate_rule_on_built_in_profile_resets_severity_to_default_if_not_overridden() {
RuleDefinitionDto rule = db.rules().insert(r -> r.setSeverity(Severity.MAJOR).setLanguage("xoo"));
BuiltInQualityProfilesDefinition.Context context = new BuiltInQualityProfilesDefinition.Context();
NewBuiltInQualityProfile newQp = context.createBuiltInQualityProfile("Sonar way", "xoo");
newQp.activateRule(rule.getRepositoryKey(), rule.getRuleKey());
newQp.done();
BuiltInQProfile builtIn = builtInProfileRepository.create(context.profile("xoo", "Sonar way"), rule);
underTest.update(db.getSession(), builtIn, persistedProfile);
List<ActiveRuleDto> activeRules = db.getDbClient().activeRuleDao().selectByRuleProfile(db.getSession(), persistedProfile);
assertThatRuleIsNewlyActivated(activeRules, rule, MAJOR);
// emulate an upgrade of analyzer that changes the default severity of the rule
rule.setSeverity(Severity.MINOR);
db.rules().update(rule);
List<ActiveRuleChange> changes = underTest.update(db.getSession(), builtIn, persistedProfile);
activeRules = db.getDbClient().activeRuleDao().selectByRuleProfile(db.getSession(), persistedProfile);
assertThatRuleIsNewlyActivated(activeRules, rule, MINOR);
verify(qualityProfileChangeEventService).distributeRuleChangeEvent(any(), eq(changes), eq(persistedProfile.getLanguage()));
}
Aggregations