use of org.sonar.api.server.rule.RulesDefinition.NewRepository in project sonarlint-core by SonarSource.
the class SonarLintRuleDefinitionTests method convertMarkdownDescriptionToHtml.
@Test
void convertMarkdownDescriptionToHtml() {
RulesDefinition.Context context = new RulesDefinition.Context();
NewRepository newRepository = context.createRepository("my-repo", "java");
NewRule createRule = newRepository.createRule("my-rule-with-markdown-description").setName("My Rule");
createRule.setMarkdownDescription(" = Title\n * one\n* two");
newRepository.done();
Rule rule = context.repositories().get(0).rule("my-rule-with-markdown-description");
SonarLintRuleDefinition underTest = new SonarLintRuleDefinition(rule);
assertThat(underTest.getHtmlDescription()).isEqualTo("<h1>Title</h1><ul><li>one</li>\n" + "<li>two</li></ul>");
}
use of org.sonar.api.server.rule.RulesDefinition.NewRepository 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();
}
use of org.sonar.api.server.rule.RulesDefinition.NewRepository in project sonarqube by SonarSource.
the class RegisterRulesTest method update_if_only_renamed_and_deprecated_key_declared.
@Test
@UseDataProvider("allRenamingCases")
public void update_if_only_renamed_and_deprecated_key_declared(String ruleKey1, String repo1, String ruleKey2, String repo2) {
String name = "Name1";
String description = "Description";
system.setNow(DATE1.getTime());
execute(context -> {
NewRepository repo = context.createRepository(repo1, "java");
repo.createRule(ruleKey1).setName(name).setHtmlDescription(description);
repo.done();
});
RuleDto rule1 = dbClient.ruleDao().selectOrFailByKey(db.getSession(), RuleKey.of(repo1, ruleKey1));
assertThat(ruleIndex.search(new RuleQuery().setQueryText(name), new SearchOptions()).getUuids()).containsOnly(rule1.getUuid());
system.setNow(DATE2.getTime());
execute(context -> {
NewRepository repo = context.createRepository(repo2, "java");
repo.createRule(ruleKey2).setName(name).setHtmlDescription(description).addDeprecatedRuleKey(repo1, ruleKey1);
repo.done();
});
// rule2 is actually rule1
RuleDto rule2 = dbClient.ruleDao().selectOrFailByKey(db.getSession(), RuleKey.of(repo2, ruleKey2));
assertThat(rule2.getUuid()).isEqualTo(rule1.getUuid());
assertThat(rule2.getName()).isEqualTo(rule1.getName());
assertThat(rule2.getDescription()).isEqualTo(rule1.getDescription());
assertThat(ruleIndex.search(new RuleQuery().setQueryText(name), new SearchOptions()).getUuids()).containsOnly(rule2.getUuid());
}
use of org.sonar.api.server.rule.RulesDefinition.NewRepository in project sonarqube by SonarSource.
the class RegisterRulesTest method update_only_rule_name.
@Test
public void update_only_rule_name() {
system.setNow(DATE1.getTime());
execute(context -> {
NewRepository repo = context.createRepository("fake", "java");
repo.createRule("rule").setName("Name1").setHtmlDescription("Description");
repo.done();
});
system.setNow(DATE2.getTime());
execute(context -> {
NewRepository repo = context.createRepository("fake", "java");
repo.createRule("rule").setName("Name2").setHtmlDescription("Description");
repo.done();
});
// rule1 has been updated
RuleDto rule1 = dbClient.ruleDao().selectOrFailByKey(db.getSession(), RuleKey.of("fake", "rule"));
assertThat(rule1.getName()).isEqualTo("Name2");
assertThat(rule1.getDescription()).isEqualTo("Description");
assertThat(ruleIndex.search(new RuleQuery().setQueryText("Name2"), new SearchOptions()).getTotal()).isOne();
assertThat(ruleIndex.search(new RuleQuery().setQueryText("Name1"), new SearchOptions()).getTotal()).isZero();
}
use of org.sonar.api.server.rule.RulesDefinition.NewRepository in project sonarqube by SonarSource.
the class RegisterRulesTest method declaring_two_rules_with_same_deprecated_RuleKey_should_throw_ISE.
@Test
public void declaring_two_rules_with_same_deprecated_RuleKey_should_throw_ISE() {
assertThatThrownBy(() -> {
execute(context -> {
NewRepository repo = context.createRepository("fake", "java");
createRule(repo, "newKey1").addDeprecatedRuleKey("fake", "old");
createRule(repo, "newKey2").addDeprecatedRuleKey("fake", "old");
repo.done();
});
}).isInstanceOf(IllegalStateException.class).hasMessage("The following deprecated rule keys are declared at least twice [fake:old]");
}
Aggregations