Search in sources :

Example 21 with NewBuiltInQualityProfile

use of org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.NewBuiltInQualityProfile in project sonarqube by SonarSource.

the class BuiltInQProfileInsertImplTest method insert_active_rules_and_changelog.

@Test
public void insert_active_rules_and_changelog() {
    RuleDefinitionDto rule1 = db.rules().insert(r -> r.setLanguage("xoo"));
    RuleDefinitionDto rule2 = db.rules().insert(r -> r.setLanguage("xoo"));
    BuiltInQualityProfilesDefinition.Context context = new BuiltInQualityProfilesDefinition.Context();
    NewBuiltInQualityProfile newQp = context.createBuiltInQualityProfile("the name", "xoo");
    newQp.activateRule(rule1.getRepositoryKey(), rule1.getRuleKey()).overrideSeverity(Severity.CRITICAL);
    newQp.activateRule(rule2.getRepositoryKey(), rule2.getRuleKey()).overrideSeverity(Severity.MAJOR);
    newQp.done();
    BuiltInQProfile builtIn = builtInQProfileRepository.create(context.profile("xoo", "the name"), rule1, rule2);
    call(builtIn);
    verifyTableSize("rules_profiles", 1);
    verifyTableSize("org_qprofiles", 1);
    verifyTableSize("active_rules", 2);
    verifyTableSize("active_rule_parameters", 0);
    verifyTableSize("qprofile_changes", 2);
    verifyTableSize("default_qprofiles", 0);
    QProfileDto profile = verifyProfileInDb(builtIn);
    verifyActiveRuleInDb(profile, rule1, Severity.CRITICAL);
    verifyActiveRuleInDb(profile, rule2, Severity.MAJOR);
}
Also used : QProfileDto(org.sonar.db.qualityprofile.QProfileDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) BuiltInQualityProfilesDefinition(org.sonar.api.server.profile.BuiltInQualityProfilesDefinition) NewBuiltInQualityProfile(org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.NewBuiltInQualityProfile) Test(org.junit.Test)

Example 22 with NewBuiltInQualityProfile

use of org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.NewBuiltInQualityProfile in project sonarqube by SonarSource.

the class BuiltInQProfileInsertImplTest method dont_flag_profile_as_default_if_not_declared_as_default_by_api.

@Test
public void dont_flag_profile_as_default_if_not_declared_as_default_by_api() {
    BuiltInQualityProfilesDefinition.Context context = new BuiltInQualityProfilesDefinition.Context();
    NewBuiltInQualityProfile newQp = context.createBuiltInQualityProfile("the name", "xoo").setDefault(false);
    newQp.done();
    BuiltInQProfile builtIn = builtInQProfileRepository.create(context.profile("xoo", "the name"));
    call(builtIn);
    QProfileDto defaultProfile = db.getDbClient().qualityProfileDao().selectDefaultProfile(dbSession, "xoo");
    assertThat(defaultProfile).isNull();
}
Also used : QProfileDto(org.sonar.db.qualityprofile.QProfileDto) BuiltInQualityProfilesDefinition(org.sonar.api.server.profile.BuiltInQualityProfilesDefinition) NewBuiltInQualityProfile(org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.NewBuiltInQualityProfile) Test(org.junit.Test)

Example 23 with NewBuiltInQualityProfile

use of org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.NewBuiltInQualityProfile in project sonarqube by SonarSource.

the class BuiltInQProfileUpdateImplTest method already_activated_rule_is_not_touched_if_no_differences.

@Test
public void already_activated_rule_is_not_touched_if_no_differences() {
    RuleDefinitionDto rule = db.rules().insert(r -> r.setLanguage("xoo"));
    BuiltInQualityProfilesDefinition.Context context = new BuiltInQualityProfilesDefinition.Context();
    NewBuiltInQualityProfile newQp = context.createBuiltInQualityProfile("Sonar way", "xoo");
    newQp.activateRule(rule.getRepositoryKey(), rule.getRuleKey()).overrideSeverity(Severity.CRITICAL);
    newQp.done();
    BuiltInQProfile builtIn = builtInProfileRepository.create(context.profile("xoo", "Sonar way"), rule);
    activateRuleInDb(persistedProfile, rule, CRITICAL);
    underTest.update(db.getSession(), builtIn, persistedProfile);
    List<ActiveRuleDto> activeRules = db.getDbClient().activeRuleDao().selectByRuleProfile(db.getSession(), persistedProfile);
    assertThat(activeRules).hasSize(1);
    assertThatRuleIsUntouched(activeRules, rule, CRITICAL);
    assertThatProfileIsNotMarkedAsUpdated(persistedProfile);
    verifyNoInteractions(qualityProfileChangeEventService);
}
Also used : 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)

Example 24 with NewBuiltInQualityProfile

use of org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.NewBuiltInQualityProfile in project sonarqube by SonarSource.

the class BuiltInQProfileUpdateImplTest method activate_new_rules.

@Test
public void activate_new_rules() {
    RuleDefinitionDto rule1 = db.rules().insert(r -> r.setLanguage("xoo"));
    RuleDefinitionDto rule2 = db.rules().insert(r -> r.setLanguage("xoo"));
    BuiltInQualityProfilesDefinition.Context context = new BuiltInQualityProfilesDefinition.Context();
    NewBuiltInQualityProfile newQp = context.createBuiltInQualityProfile("Sonar way", "xoo");
    newQp.activateRule(rule1.getRepositoryKey(), rule1.getRuleKey()).overrideSeverity(Severity.CRITICAL);
    newQp.activateRule(rule2.getRepositoryKey(), rule2.getRuleKey()).overrideSeverity(Severity.MAJOR);
    newQp.done();
    BuiltInQProfile builtIn = builtInProfileRepository.create(context.profile("xoo", "Sonar way"), rule1, rule2);
    List<ActiveRuleChange> changes = underTest.update(db.getSession(), builtIn, persistedProfile);
    List<ActiveRuleDto> activeRules = db.getDbClient().activeRuleDao().selectByRuleProfile(db.getSession(), persistedProfile);
    assertThat(activeRules).hasSize(2);
    assertThatRuleIsNewlyActivated(activeRules, rule1, CRITICAL);
    assertThatRuleIsNewlyActivated(activeRules, rule2, MAJOR);
    assertThatProfileIsMarkedAsUpdated(persistedProfile);
    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

NewBuiltInQualityProfile (org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.NewBuiltInQualityProfile)24 Test (org.junit.Test)22 BuiltInQualityProfilesDefinition (org.sonar.api.server.profile.BuiltInQualityProfilesDefinition)19 RuleDefinitionDto (org.sonar.db.rule.RuleDefinitionDto)14 ActiveRuleChange (org.sonar.server.qualityprofile.ActiveRuleChange)11 ActiveRuleDto (org.sonar.db.qualityprofile.ActiveRuleDto)10 OrgActiveRuleDto (org.sonar.db.qualityprofile.OrgActiveRuleDto)10 QProfileDto (org.sonar.db.qualityprofile.QProfileDto)10 ActiveRuleParamDto (org.sonar.db.qualityprofile.ActiveRuleParamDto)4 RuleParamDto (org.sonar.db.rule.RuleParamDto)4 Map (java.util.Map)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Tuple.tuple (org.assertj.core.groups.Tuple.tuple)2 RuleKey (org.sonar.api.rule.RuleKey)2 BuiltInActiveRule (org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.BuiltInActiveRule)2 Arrays.asList (java.util.Arrays.asList)1 Collection (java.util.Collection)1 Collections.emptyMap (java.util.Collections.emptyMap)1 Collections.singletonList (java.util.Collections.singletonList)1 List (java.util.List)1