use of org.sonar.server.rule.index.RuleQuery in project sonarqube by SonarSource.
the class QProfileExportersTest method import_xml.
@Test
public void import_xml() {
QualityProfileDto profileDto = QProfileTesting.newQProfileDto("org-123", QProfileName.createFor("xoo", "import_xml"), "import_xml");
db.qualityProfileDao().insert(dbSession, profileDto);
dbSession.commit();
assertThat(db.activeRuleDao().selectByProfileKey(dbSession, profileDto.getKey())).isEmpty();
QProfileResult result = exporters.importXml(profileDto, "XooProfileImporter", toInputStream("<xml/>", UTF_8), dbSession);
dbSession.commit();
activeRuleIndexer.index(result.getChanges());
// Check in db
List<ActiveRuleDto> activeRules = db.activeRuleDao().selectByProfileKey(dbSession, profileDto.getKey());
assertThat(activeRules).hasSize(1);
ActiveRuleDto activeRule = activeRules.get(0);
assertThat(activeRule.getKey().ruleKey()).isEqualTo(RuleKey.of("xoo", "R1"));
assertThat(activeRule.getSeverityString()).isEqualTo(Severity.CRITICAL);
// Check in es
assertThat(tester.get(RuleIndex.class).searchAll(new RuleQuery().setQProfileKey(profileDto.getKey()).setActivation(true))).containsOnly(RuleKey.of("xoo", "R1"));
}
use of org.sonar.server.rule.index.RuleQuery in project sonarqube by SonarSource.
the class RuleActivatorMediumTest method verifyHasActiveRuleInIndex.
private void verifyHasActiveRuleInIndex(ActiveRuleKey activeRuleKey, String expectedSeverity, @Nullable String expectedInheritance) {
// verify es
List<RuleKey> ruleKeys = newArrayList(tester.get(RuleIndex.class).searchAll(new RuleQuery().setKey(activeRuleKey.ruleKey().toString()).setQProfileKey(activeRuleKey.qProfile()).setActivation(true).setInheritance(singleton(expectedInheritance == null ? ActiveRule.Inheritance.NONE.name() : ActiveRule.Inheritance.valueOf(expectedInheritance).name())).setActiveSeverities(singleton(expectedSeverity))));
assertThat(ruleKeys).as("Rule is not activated in index").hasSize(1);
}
use of org.sonar.server.rule.index.RuleQuery in project sonarqube by SonarSource.
the class RuleActivatorMediumTest method bulk_activation_ignores_errors.
@Test
public void bulk_activation_ignores_errors() {
// 1. bulk activate all the rules, even non xoo-rules and xoo templates
BulkChangeResult result = ruleActivator.bulkActivate(new RuleQuery(), XOO_P1_KEY, "MINOR");
// 2. assert that all activations have been commit to DB and ES
// -> xoo rules x1, x2 and custom1
dbSession.clearCache();
assertThat(db.activeRuleDao().selectByProfileKey(dbSession, XOO_P1_KEY)).hasSize(3);
assertThat(db.activeRuleDao().selectByProfileKey(dbSession, XOO_P1_KEY)).hasSize(3);
assertThat(result.countSucceeded()).isEqualTo(3);
assertThat(result.countFailed()).isGreaterThan(0);
}
use of org.sonar.server.rule.index.RuleQuery in project sonarqube by SonarSource.
the class RuleActivatorMediumTest method bulk_deactivate.
@Test
public void bulk_deactivate() {
activate(new RuleActivation(XOO_X1), XOO_P1_KEY);
activate(new RuleActivation(XOO_X2), XOO_P1_KEY);
assertThat(countActiveRules(XOO_P1_KEY)).isEqualTo(2);
BulkChangeResult result = ruleActivator.bulkDeactivate(new RuleQuery().setActivation(true).setQProfileKey(XOO_P1_KEY), XOO_P1_KEY);
dbSession.clearCache();
assertThat(countActiveRules(XOO_P1_KEY)).isEqualTo(0);
assertThat(result.countFailed()).isEqualTo(0);
assertThat(result.countSucceeded()).isEqualTo(2);
assertThat(result.getChanges()).hasSize(2);
}
use of org.sonar.server.rule.index.RuleQuery in project sonarqube by SonarSource.
the class RuleQueryFactoryTest method create_empty_query.
@Test
public void create_empty_query() throws Exception {
RuleQuery result = execute();
assertThat(result.getKey()).isNull();
assertThat(result.getActivation()).isNull();
assertThat(result.getActiveSeverities()).isNull();
assertThat(result.isAscendingSort()).isTrue();
assertThat(result.getAvailableSinceLong()).isNull();
assertThat(result.getInheritance()).isNull();
assertThat(result.isTemplate()).isNull();
assertThat(result.getLanguages()).isNull();
assertThat(result.getQueryText()).isNull();
assertThat(result.getQProfileKey()).isNull();
assertThat(result.getRepositories()).isNull();
assertThat(result.getRuleKey()).isNull();
assertThat(result.getSeverities()).isNull();
assertThat(result.getStatuses()).isEmpty();
assertThat(result.getTags()).isNull();
assertThat(result.templateKey()).isNull();
assertThat(result.getTypes()).isEmpty();
assertThat(result.getSortField()).isNull();
}
Aggregations