use of org.sonar.db.qualityprofile.QProfileDto in project sonarqube by SonarSource.
the class QProfileRuleImplTest method activate_rule_with_default_severity_and_parameters.
@Test
public void activate_rule_with_default_severity_and_parameters() {
RuleDefinitionDto rule = createRule();
RuleParamDto ruleParam = db.rules().insertRuleParam(rule, p -> p.setName("min").setDefaultValue("10"));
QProfileDto profile = createProfile(rule);
RuleActivation activation = RuleActivation.create(rule.getUuid());
List<ActiveRuleChange> changes = activate(profile, activation);
assertThatRuleIsActivated(profile, rule, changes, rule.getSeverityString(), null, of("min", "10"));
assertThatProfileIsUpdatedBySystem(profile);
verify(qualityProfileChangeEventService).distributeRuleChangeEvent(any(), any(), eq(profile.getLanguage()));
}
use of org.sonar.db.qualityprofile.QProfileDto in project sonarqube by SonarSource.
the class QProfileRuleImplTest method update_an_already_activated_rule.
@Test
public void update_an_already_activated_rule() {
RuleDefinitionDto rule = createRule();
RuleParamDto param = db.rules().insertRuleParam(rule, p -> p.setName("max").setDefaultValue("10"));
QProfileDto profile = createProfile(rule);
// initial activation
RuleActivation activation = RuleActivation.create(rule.getUuid(), MAJOR, null);
List<ActiveRuleChange> changes = activate(profile, activation);
verify(qualityProfileChangeEventService).distributeRuleChangeEvent(any(), eq(changes), eq(profile.getLanguage()));
// update
RuleActivation updateActivation = RuleActivation.create(rule.getUuid(), CRITICAL, of(param.getName(), "20"));
changes = activate(profile, updateActivation);
assertThatRuleIsUpdated(profile, rule, CRITICAL, null, of(param.getName(), "20"));
assertThatProfileIsUpdatedBySystem(profile);
verify(qualityProfileChangeEventService).distributeRuleChangeEvent(any(), eq(changes), eq(profile.getLanguage()));
}
use of org.sonar.db.qualityprofile.QProfileDto in project sonarqube by SonarSource.
the class QProfileRuleImplTest method bulk_deactivation.
@Test
public void bulk_deactivation() {
int bulkSize = SearchOptions.MAX_PAGE_SIZE + 10 + new Random().nextInt(100);
String language = randomAlphanumeric(10);
String repositoryKey = randomAlphanumeric(10);
QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage(language));
List<RuleDto> rules = new ArrayList<>();
IntStream.rangeClosed(1, bulkSize).forEach(i -> rules.add(db.rules().insertRule(r -> r.setLanguage(language).setRepositoryKey(repositoryKey))));
verifyNoActiveRules();
ruleIndexer.indexAll();
RuleQuery ruleQuery = new RuleQuery().setRepositories(singletonList(repositoryKey));
BulkChangeResult bulkChangeResult = underTest.bulkActivateAndCommit(db.getSession(), profile, ruleQuery, MINOR);
assertThat(bulkChangeResult.countFailed()).isZero();
assertThat(bulkChangeResult.countSucceeded()).isEqualTo(bulkSize);
assertThat(bulkChangeResult.getChanges()).hasSize(bulkSize);
assertThat(db.getDbClient().activeRuleDao().selectByProfile(db.getSession(), profile)).hasSize(bulkSize);
// Now deactivate all rules
bulkChangeResult = underTest.bulkDeactivateAndCommit(db.getSession(), profile, ruleQuery);
assertThat(bulkChangeResult.countFailed()).isZero();
assertThat(bulkChangeResult.countSucceeded()).isEqualTo(bulkSize);
assertThat(bulkChangeResult.getChanges()).hasSize(bulkSize);
assertThat(db.getDbClient().activeRuleDao().selectByProfile(db.getSession(), profile)).isEmpty();
rules.stream().forEach(r -> assertThatRuleIsNotPresent(profile, r.getDefinition()));
}
use of org.sonar.db.qualityprofile.QProfileDto in project sonarqube by SonarSource.
the class QProfileRuleImplTest method override_activation_of_inherited_profile.
@Test
public void override_activation_of_inherited_profile() {
RuleDefinitionDto rule = createRule();
RuleParamDto param = db.rules().insertRuleParam(rule);
QProfileDto parentProfile = createProfile(rule);
QProfileDto childProfile = createChildProfile(parentProfile);
QProfileDto grandChildProfile = createChildProfile(childProfile);
RuleActivation initialActivation = RuleActivation.create(rule.getUuid(), MAJOR, of(param.getName(), "foo"));
List<ActiveRuleChange> changes = activate(childProfile, initialActivation);
verify(qualityProfileChangeEventService).distributeRuleChangeEvent(any(), eq(changes), eq(childProfile.getLanguage()));
RuleActivation overrideActivation = RuleActivation.create(rule.getUuid(), CRITICAL, of(param.getName(), "bar"));
changes = activate(grandChildProfile, overrideActivation);
assertThatProfileHasNoActiveRules(parentProfile);
assertThatRuleIsUpdated(childProfile, rule, MAJOR, null, of(param.getName(), "foo"));
assertThatRuleIsUpdated(grandChildProfile, rule, CRITICAL, ActiveRuleInheritance.OVERRIDES, of(param.getName(), "bar"));
assertThat(changes).hasSize(1);
verify(qualityProfileChangeEventService).distributeRuleChangeEvent(any(), eq(changes), eq(childProfile.getLanguage()));
}
use of org.sonar.db.qualityprofile.QProfileDto in project sonarqube by SonarSource.
the class QProfileRuleImplTest method assertThatProfileIsUpdatedBySystem.
private void assertThatProfileIsUpdatedBySystem(QProfileDto profile) {
QProfileDto loaded = db.getDbClient().qualityProfileDao().selectByUuid(db.getSession(), profile.getKee());
assertThat(loaded.getUserUpdatedAt()).isNull();
assertThat(loaded.getRulesUpdatedAt()).isNotEmpty();
}
Aggregations