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);
}
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();
}
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);
}
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()));
}
Aggregations