use of org.sonar.db.qualityprofile.OrgActiveRuleDto in project sonarqube by SonarSource.
the class ChangeParentActionTest method change_parent_with_names.
@Test
public void change_parent_with_names() {
QProfileDto parent1 = createProfile();
QProfileDto parent2 = createProfile();
QProfileDto child = createProfile();
RuleDefinitionDto rule1 = createRule();
RuleDefinitionDto rule2 = createRule();
createActiveRule(rule1, parent1);
createActiveRule(rule2, parent2);
ruleIndexer.commitAndIndex(dbSession, rule1.getUuid());
activeRuleIndexer.indexAll();
assertThat(dbClient.activeRuleDao().selectByProfileUuid(dbSession, child.getKee())).isEmpty();
// 1. Set parent 1
ws.newRequest().setMethod("POST").setParam(PARAM_LANGUAGE, child.getLanguage()).setParam(PARAM_QUALITY_PROFILE, child.getName()).setParam(PARAM_PARENT_QUALITY_PROFILE, parent1.getName()).execute();
// 1. check rule 1 enabled
List<OrgActiveRuleDto> activeRules1 = dbClient.activeRuleDao().selectByProfile(dbSession, child);
assertThat(activeRules1).hasSize(1);
assertThat(activeRules1.get(0).getKey().getRuleKey().rule()).isEqualTo(rule1.getRuleKey());
assertThat(ruleIndex.search(new RuleQuery().setActivation(true).setQProfile(child), new SearchOptions()).getUuids()).hasSize(1);
// 2. Set parent 2
ws.newRequest().setMethod("POST").setParam(PARAM_LANGUAGE, child.getLanguage()).setParam(PARAM_QUALITY_PROFILE, child.getName()).setParam(QualityProfileWsParameters.PARAM_PARENT_QUALITY_PROFILE, parent2.getName()).execute();
// 2. check rule 2 enabled
List<OrgActiveRuleDto> activeRules2 = dbClient.activeRuleDao().selectByProfile(dbSession, child);
assertThat(activeRules2).hasSize(1);
assertThat(activeRules2.get(0).getKey().getRuleKey().rule()).isEqualTo(rule2.getRuleKey());
// 3. Remove parent
ws.newRequest().setMethod("POST").setParam(PARAM_LANGUAGE, child.getLanguage()).setParam(PARAM_QUALITY_PROFILE, child.getName()).setParam(QualityProfileWsParameters.PARAM_PARENT_QUALITY_PROFILE, "").execute();
// 3. check no rule enabled
List<OrgActiveRuleDto> activeRules = dbClient.activeRuleDao().selectByProfile(dbSession, child);
assertThat(activeRules).isEmpty();
assertThat(ruleIndex.search(new RuleQuery().setActivation(true).setQProfile(child), new SearchOptions()).getUuids()).isEmpty();
}
use of org.sonar.db.qualityprofile.OrgActiveRuleDto in project sonarqube by SonarSource.
the class ChangeParentActionTest method replace_existing_parent.
@Test
public void replace_existing_parent() {
QProfileDto parent1 = createProfile();
QProfileDto parent2 = createProfile();
QProfileDto child = createProfile();
RuleDefinitionDto rule1 = createRule();
RuleDefinitionDto rule2 = createRule();
createActiveRule(rule1, parent1);
createActiveRule(rule2, parent2);
ruleIndexer.commitAndIndex(dbSession, asList(rule1.getUuid(), rule2.getUuid()));
activeRuleIndexer.indexAll();
// Set parent 1
qProfileTree.setParentAndCommit(dbSession, child, parent1);
// Set parent 2 through WS
ws.newRequest().setMethod("POST").setParam(PARAM_LANGUAGE, child.getLanguage()).setParam(PARAM_QUALITY_PROFILE, child.getName()).setParam(PARAM_PARENT_QUALITY_PROFILE, parent2.getName()).execute();
// Check rule 2 enabled
List<OrgActiveRuleDto> activeRules2 = dbClient.activeRuleDao().selectByProfile(dbSession, child);
assertThat(activeRules2).hasSize(1);
assertThat(activeRules2.get(0).getKey().getRuleKey().rule()).isEqualTo(rule2.getRuleKey());
assertThat(ruleIndex.search(new RuleQuery().setActivation(true).setQProfile(child), new SearchOptions()).getUuids()).hasSize(1);
}
use of org.sonar.db.qualityprofile.OrgActiveRuleDto in project sonarqube by SonarSource.
the class QProfileExporters method wrap.
private RulesProfile wrap(DbSession dbSession, QProfileDto profile) {
RulesProfile target = new RulesProfile(profile.getName(), profile.getLanguage());
List<OrgActiveRuleDto> activeRuleDtos = dbClient.activeRuleDao().selectByProfile(dbSession, profile);
List<ActiveRuleParamDto> activeRuleParamDtos = dbClient.activeRuleDao().selectParamsByActiveRuleUuids(dbSession, Lists.transform(activeRuleDtos, ActiveRuleDto::getUuid));
ListMultimap<String, ActiveRuleParamDto> activeRuleParamsByActiveRuleUuid = FluentIterable.from(activeRuleParamDtos).index(ActiveRuleParamDto::getActiveRuleUuid);
for (ActiveRuleDto activeRule : activeRuleDtos) {
// TODO all rules should be loaded by using one query with all active rule keys as parameter
Rule rule = ruleFinder.findByKey(activeRule.getRuleKey());
org.sonar.api.rules.ActiveRule wrappedActiveRule = target.activateRule(rule, RulePriority.valueOf(activeRule.getSeverityString()));
List<ActiveRuleParamDto> paramDtos = activeRuleParamsByActiveRuleUuid.get(activeRule.getUuid());
for (ActiveRuleParamDto activeRuleParamDto : paramDtos) {
wrappedActiveRule.setParameter(activeRuleParamDto.getKey(), activeRuleParamDto.getValue());
}
}
return target;
}
Aggregations