use of org.sonar.server.rule.index.RuleQuery 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.server.rule.index.RuleQuery in project sonarqube by SonarSource.
the class QProfileFactoryMediumTest method delete.
@Test
public void delete() {
initRules();
db.qualityProfileDao().insert(dbSession, QProfileTesting.newXooP1("org-123"));
tester.get(RuleActivator.class).activate(dbSession, new RuleActivation(RuleTesting.XOO_X1), XOO_P1_KEY);
dbSession.commit();
dbSession.clearCache();
List<ActiveRuleChange> changes = factory.delete(dbSession, XOO_P1_KEY, false);
dbSession.commit();
activeRuleIndexer.index(changes);
dbSession.clearCache();
assertThat(db.qualityProfileDao().selectAll(dbSession)).isEmpty();
assertThat(db.activeRuleDao().selectAll(dbSession)).isEmpty();
assertThat(db.activeRuleDao().selectAllParams(dbSession)).isEmpty();
assertThat(db.activeRuleDao().selectByProfileKey(dbSession, XOO_P1_KEY)).isEmpty();
assertThat(tester.get(RuleIndex.class).searchAll(new RuleQuery().setQProfileKey(XOO_P1_KEY).setActivation(true))).isEmpty();
}
use of org.sonar.server.rule.index.RuleQuery in project sonarqube by SonarSource.
the class CreateActionTest method create_profile_from_backup_xml.
@Test
public void create_profile_from_backup_xml() {
logInAsQProfileAdministrator();
insertRule(RULE);
executeRequest("New Profile", XOO_LANGUAGE, ImmutableMap.of("xoo_lint", "<xml/>"));
QualityProfileDto dto = dbClient.qualityProfileDao().selectByNameAndLanguage("New Profile", XOO_LANGUAGE, dbSession);
assertThat(dto.getKey()).isNotNull();
assertThat(dbClient.activeRuleDao().selectByProfileKey(dbSession, dto.getKey())).hasSize(1);
assertThat(ruleIndex.searchAll(new RuleQuery().setQProfileKey(dto.getKey()).setActivation(true))).hasSize(1);
}
use of org.sonar.server.rule.index.RuleQuery 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.server.rule.index.RuleQuery 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