use of org.sonar.db.qualityprofile.ActiveRuleDto in project sonarqube by SonarSource.
the class QProfileBackuperMediumTest method restore_and_create_profile.
@Test
public void restore_and_create_profile() throws Exception {
// Backup file declares profile P1 on xoo
tester.get(QProfileBackuper.class).restore(new StringReader(Resources.toString(getClass().getResource("QProfileBackuperMediumTest/restore.xml"), StandardCharsets.UTF_8)), null);
// Check in db
QualityProfileDto profile = db.qualityProfileDao().selectByNameAndLanguage("P1", "xoo", dbSession);
assertThat(profile).isNotNull();
List<ActiveRuleDto> activeRules = db.activeRuleDao().selectByProfileKey(dbSession, profile.getKey());
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(profile.getKey()).setActivation(true))).containsOnly(XOO_X1);
}
use of org.sonar.db.qualityprofile.ActiveRuleDto in project sonarqube by SonarSource.
the class QProfileBackuperMediumTest method restore_and_override_profile_name.
@Test
public void restore_and_override_profile_name() throws Exception {
tester.get(QProfileBackuper.class).restore(new StringReader(Resources.toString(getClass().getResource("QProfileBackuperMediumTest/restore.xml"), StandardCharsets.UTF_8)), XOO_P3_NAME);
List<ActiveRuleDto> activeRules = db.activeRuleDao().selectByProfileKey(dbSession, XOO_P1_KEY);
assertThat(activeRules).hasSize(0);
QualityProfileDto target = db.qualityProfileDao().selectByNameAndLanguage("P3", "xoo", dbSession);
assertThat(target).isNotNull();
assertThat(db.activeRuleDao().selectByProfileKey(dbSession, target.getKey())).hasSize(1);
}
use of org.sonar.db.qualityprofile.ActiveRuleDto in project sonarqube by SonarSource.
the class InheritanceActionMediumTest method createActiveRule.
private ActiveRuleDto createActiveRule(RuleDto rule, QualityProfileDto profile) {
long now = new Date().getTime();
ActiveRuleDto activeRule = ActiveRuleDto.createFor(profile, rule).setSeverity(rule.getSeverityString()).setUpdatedAt(now).setCreatedAt(now);
db.activeRuleDao().insert(session, activeRule);
return activeRule;
}
use of org.sonar.db.qualityprofile.ActiveRuleDto in project sonarqube by SonarSource.
the class ChangeParentActionMediumTest method change_parent_with_no_parent_before.
@Test
public void change_parent_with_no_parent_before() throws Exception {
QualityProfileDto parent1 = createProfile("xoo", "Parent 1");
QualityProfileDto child = createProfile("xoo", "Child");
RuleDto rule1 = createRule("xoo", "rule1");
createActiveRule(rule1, parent1);
session.commit();
ruleIndexer.index();
activeRuleIndexer.index();
assertThat(db.activeRuleDao().selectByProfileKey(session, child.getKey())).isEmpty();
// Set parent
wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, "change_parent").setParam(QProfileRef.PARAM_PROFILE_KEY, child.getKey()).setParam("parentKey", parent1.getKey()).execute();
session.clearCache();
// Check rule 1 enabled
List<ActiveRuleDto> activeRules1 = db.activeRuleDao().selectByProfileKey(session, child.getKey());
assertThat(activeRules1).hasSize(1);
assertThat(activeRules1.get(0).getKey().ruleKey().rule()).isEqualTo("rule1");
assertThat(ruleIndex.search(new RuleQuery().setActivation(true).setQProfileKey(child.getKey()), new SearchOptions()).getIds()).hasSize(1);
}
use of org.sonar.db.qualityprofile.ActiveRuleDto in project sonarqube by SonarSource.
the class ChangeParentActionMediumTest method remove_parent_with_empty_key.
@Test
public void remove_parent_with_empty_key() throws Exception {
QualityProfileDto parent = createProfile("xoo", "Parent 1");
QualityProfileDto child = createProfile("xoo", "Child");
RuleDto rule1 = createRule("xoo", "rule1");
createActiveRule(rule1, parent);
session.commit();
ruleIndexer.index();
activeRuleIndexer.index();
assertThat(db.activeRuleDao().selectByProfileKey(session, child.getKey())).isEmpty();
// Set parent
tester.get(RuleActivator.class).setParent(session, child.getKey(), parent.getKey());
session.clearCache();
// Remove parent
wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, "change_parent").setParam(QProfileRef.PARAM_PROFILE_KEY, child.getKey()).setParam("parentKey", "").execute();
session.clearCache();
// Check no rule enabled
List<ActiveRuleDto> activeRules = db.activeRuleDao().selectByProfileKey(session, child.getKey());
assertThat(activeRules).isEmpty();
assertThat(ruleIndex.search(new RuleQuery().setActivation(true).setQProfileKey(child.getKey()), new SearchOptions()).getIds()).isEmpty();
}
Aggregations