Search in sources :

Example 41 with ActiveRuleDto

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;
}
Also used : ActiveRuleParamDto(org.sonar.db.qualityprofile.ActiveRuleParamDto) RulesProfileDto(org.sonar.db.qualityprofile.RulesProfileDto) ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) QProfileChangeDto(org.sonar.db.qualityprofile.QProfileChangeDto)

Example 42 with ActiveRuleDto

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;
}
Also used : ActiveRuleParamDto(org.sonar.db.qualityprofile.ActiveRuleParamDto) ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto)

Example 43 with ActiveRuleDto

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);
}
Also used : QProfileDto(org.sonar.db.qualityprofile.QProfileDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) ActiveRuleParamDto(org.sonar.db.qualityprofile.ActiveRuleParamDto) RuleParamDto(org.sonar.db.rule.RuleParamDto) ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) Test(org.junit.Test)

Example 44 with ActiveRuleDto

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();
}
Also used : ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto)

Example 45 with ActiveRuleDto

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()));
}
Also used : ActiveRuleChange(org.sonar.server.qualityprofile.ActiveRuleChange) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) BuiltInQualityProfilesDefinition(org.sonar.api.server.profile.BuiltInQualityProfilesDefinition) NewBuiltInQualityProfile(org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.NewBuiltInQualityProfile) OrgActiveRuleDto(org.sonar.db.qualityprofile.OrgActiveRuleDto) ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) Test(org.junit.Test)

Aggregations

ActiveRuleDto (org.sonar.db.qualityprofile.ActiveRuleDto)112 Test (org.junit.Test)51 ActiveRuleParamDto (org.sonar.db.qualityprofile.ActiveRuleParamDto)49 RuleDefinitionDto (org.sonar.db.rule.RuleDefinitionDto)26 OrgActiveRuleDto (org.sonar.db.qualityprofile.OrgActiveRuleDto)21 QualityProfileDto (org.sonar.db.qualityprofile.QualityProfileDto)21 RuleDto (org.sonar.db.rule.RuleDto)21 ActiveRuleDao (org.sonar.db.qualityprofile.ActiveRuleDao)19 RuleParamDto (org.sonar.db.rule.RuleParamDto)19 QProfileDto (org.sonar.db.qualityprofile.QProfileDto)18 ActiveRuleKey (org.sonar.db.qualityprofile.ActiveRuleKey)15 ActiveRuleChange (org.sonar.server.qualityprofile.ActiveRuleChange)14 RuleKey (org.sonar.api.rule.RuleKey)12 RuleQuery (org.sonar.server.rule.index.RuleQuery)11 QualityProfileDao (org.sonar.db.qualityprofile.QualityProfileDao)10 ArrayList (java.util.ArrayList)9 BuiltInQualityProfilesDefinition (org.sonar.api.server.profile.BuiltInQualityProfilesDefinition)9 NewBuiltInQualityProfile (org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.NewBuiltInQualityProfile)9 Map (java.util.Map)7 WsTester (org.sonar.server.ws.WsTester)6