use of org.sonar.db.qualityprofile.ActiveRuleDto in project sonarqube by SonarSource.
the class CompareActionMediumTest method createActiveRuleWithParam.
private ActiveRuleDto createActiveRuleWithParam(RuleDto rule, QualityProfileDto profile, String value) {
ActiveRuleDto activeRule = createActiveRule(rule, profile);
RuleParamDto paramDto = db.ruleDao().selectRuleParamsByRuleKey(session, rule.getKey()).get(0);
ActiveRuleParamDto activeRuleParam = ActiveRuleParamDto.createFor(paramDto).setValue(value);
db.activeRuleDao().insertParam(session, activeRule, activeRuleParam);
return activeRule;
}
use of org.sonar.db.qualityprofile.ActiveRuleDto in project sonarqube by SonarSource.
the class CompareActionMediumTest method createActiveRuleWithSeverity.
private ActiveRuleDto createActiveRuleWithSeverity(RuleDto rule, QualityProfileDto profile, String severity) {
ActiveRuleDto activeRule = ActiveRuleDto.createFor(profile, rule).setSeverity(severity);
db.activeRuleDao().insert(session, activeRule);
return activeRule;
}
use of org.sonar.db.qualityprofile.ActiveRuleDto in project sonarqube by SonarSource.
the class RuleActivatorMediumTest method verifyZeroActiveRules.
private void verifyZeroActiveRules(String key) {
// verify db
dbSession.clearCache();
List<ActiveRuleDto> activeRuleDtos = db.activeRuleDao().selectByProfileKey(dbSession, key);
assertThat(activeRuleDtos).isEmpty();
// verify es
assertThat(tester.get(RuleIndex.class).searchAll(new RuleQuery().setQProfileKey(key).setActivation(true))).isEmpty();
}
use of org.sonar.db.qualityprofile.ActiveRuleDto in project sonarqube by SonarSource.
the class QProfileBackuperMediumTest method restore_parent_profile.
@Test
public void restore_parent_profile() throws Exception {
// define two parent/child profiles
db.qualityProfileDao().insert(dbSession, newXooP1("org-123"), newXooP2("org-123").setParentKee(XOO_P1_KEY));
dbSession.commit();
// rule x1 is activated on parent profile (so inherited by child profile)
RuleActivation activation = new RuleActivation(XOO_X1);
activation.setSeverity(Severity.INFO);
activation.setParameter("max", "10");
tester.get(RuleActivator.class).activate(dbSession, activation, XOO_P1_KEY);
dbSession.commit();
dbSession.clearCache();
activeRuleIndexer.index();
// restore backup of parent profile -> update x1 and propagates to child
tester.get(QProfileBackuper.class).restore(new StringReader(Resources.toString(getClass().getResource("QProfileBackuperMediumTest/restore-parent.xml"), StandardCharsets.UTF_8)), null);
// parent profile is updated
List<ActiveRuleDto> activeRules = db.activeRuleDao().selectByProfileKey(dbSession, XOO_P1_KEY);
assertThat(activeRules).hasSize(1);
ActiveRuleDto activeRuleDoc = activeRules.get(0);
assertThat(activeRuleDoc.getSeverityString()).isEqualTo("BLOCKER");
assertThat(activeRuleDoc.getInheritance()).isNull();
ActiveRuleDto activeRuleDto = db.activeRuleDao().selectOrFailByKey(dbSession, activeRuleDoc.getKey());
List<ActiveRuleParamDto> params = tester.get(ActiveRuleDao.class).selectParamsByActiveRuleId(dbSession, activeRuleDto.getId());
assertThat(params).hasSize(1);
assertThat(params.get(0).getKey()).isEqualTo("max");
assertThat(params.get(0).getValue()).isEqualTo("7");
// child profile is inherited
activeRules = db.activeRuleDao().selectByProfileKey(dbSession, XOO_P2_KEY);
assertThat(activeRules).hasSize(1);
activeRuleDoc = activeRules.get(0);
assertThat(activeRuleDoc.getSeverityString()).isEqualTo("BLOCKER");
assertThat(activeRuleDoc.getInheritance()).isEqualTo(INHERITED);
activeRuleDto = db.activeRuleDao().selectOrFailByKey(dbSession, activeRuleDoc.getKey());
params = tester.get(ActiveRuleDao.class).selectParamsByActiveRuleId(dbSession, activeRuleDto.getId());
assertThat(params).hasSize(1);
assertThat(params.get(0).getKey()).isEqualTo("max");
assertThat(params.get(0).getValue()).isEqualTo("7");
}
use of org.sonar.db.qualityprofile.ActiveRuleDto in project sonarqube by SonarSource.
the class QProfileBackuperMediumTest method restore_and_update_profile.
@Test
public void restore_and_update_profile() throws Exception {
// create profile P1 with rules x1 and x2 activated
db.qualityProfileDao().insert(dbSession, newXooP1("org-123"));
RuleActivation activation = new RuleActivation(XOO_X1);
activation.setSeverity(Severity.INFO);
activation.setParameter("max", "10");
tester.get(RuleActivator.class).activate(dbSession, activation, XOO_P1_NAME);
activation = new RuleActivation(XOO_X2);
activation.setSeverity(Severity.INFO);
tester.get(RuleActivator.class).activate(dbSession, activation, XOO_P1_NAME);
dbSession.commit();
dbSession.clearCache();
activeRuleIndexer.index();
// restore backup, which activates only x1
// -> update x1 and deactivate x2
tester.get(QProfileBackuper.class).restore(new StringReader(Resources.toString(getClass().getResource("QProfileBackuperMediumTest/restore.xml"), StandardCharsets.UTF_8)), null);
// Check in db
List<ActiveRuleDto> activeRules = db.activeRuleDao().selectByProfileKey(dbSession, XOO_P1_KEY);
assertThat(activeRules).hasSize(1);
ActiveRuleDto activeRuleDoc = activeRules.get(0);
assertThat(activeRuleDoc.getSeverityString()).isEqualTo("BLOCKER");
assertThat(activeRuleDoc.getInheritance()).isNull();
ActiveRuleDto activeRuleDto = db.activeRuleDao().selectOrFailByKey(dbSession, activeRuleDoc.getKey());
List<ActiveRuleParamDto> params = tester.get(ActiveRuleDao.class).selectParamsByActiveRuleId(dbSession, activeRuleDto.getId());
assertThat(params).hasSize(1);
assertThat(params.get(0).getKey()).isEqualTo("max");
assertThat(params.get(0).getValue()).isEqualTo("7");
// Check in es
assertThat(tester.get(RuleIndex.class).searchAll(new RuleQuery().setQProfileKey(XOO_P1_KEY).setActivation(true))).containsOnly(XOO_X1);
}
Aggregations