use of org.sonar.api.rule.RuleStatus.REMOVED in project sonarqube by SonarSource.
the class RegisterRulesTest method mass_insert_then_remove_rule.
@Test
public void mass_insert_then_remove_rule() {
int numberOfRules = 5000;
// register many rules
execute(context -> {
NewRepository repo = context.createRepository("fake", "java");
IntStream.range(0, numberOfRules).mapToObj(i -> "rule-" + i).forEach(ruleKey -> repo.createRule(ruleKey).setName(randomAlphanumeric(20)).setHtmlDescription(randomAlphanumeric(20)));
repo.done();
});
// verify db
assertThat(dbClient.ruleDao().selectAllDefinitions(db.getSession())).hasSize(numberOfRules).extracting(RuleDefinitionDto::getStatus).containsOnly(READY);
// verify index
assertThat(es.countDocuments(RuleIndexDefinition.TYPE_RULE)).isEqualTo(numberOfRules);
assertThat(ruleIndex.search(new RuleQuery(), new SearchOptions()).getUuids()).isNotEmpty();
// register no rule
execute(context -> context.createRepository("fake", "java").done());
// verify db
assertThat(dbClient.ruleDao().selectAllDefinitions(db.getSession())).hasSize(numberOfRules).extracting(RuleDefinitionDto::getStatus).containsOnly(REMOVED);
// verify index (documents are still in the index, but all are removed)
assertThat(es.countDocuments(RuleIndexDefinition.TYPE_RULE)).isEqualTo(numberOfRules);
assertThat(ruleIndex.search(new RuleQuery(), new SearchOptions()).getUuids()).isEmpty();
}
Aggregations