use of org.sonar.api.server.rule.RulesDefinition.NewRepository in project sonarqube by SonarSource.
the class RegisterRulesTest method update_if_repository_changed_and_deprecated_key_declared.
@Test
public void update_if_repository_changed_and_deprecated_key_declared() {
String ruleKey = "rule";
String repository1 = "fake1";
String repository2 = "fake2";
system.setNow(DATE1.getTime());
execute(context -> {
NewRepository repo = context.createRepository(repository1, "java");
repo.createRule(ruleKey).setName("Name1").setHtmlDescription("Description");
repo.done();
});
RuleDto rule1 = dbClient.ruleDao().selectOrFailByKey(db.getSession(), RuleKey.of(repository1, ruleKey));
SearchIdResult<String> searchRule1 = ruleIndex.search(new RuleQuery().setQueryText("Name1"), new SearchOptions());
assertThat(searchRule1.getUuids()).containsOnly(rule1.getUuid());
assertThat(searchRule1.getTotal()).isOne();
system.setNow(DATE2.getTime());
execute(context -> {
NewRepository repo = context.createRepository(repository2, "java");
repo.createRule(ruleKey).setName("Name2").setHtmlDescription("Description").addDeprecatedRuleKey(repository1, ruleKey);
repo.done();
});
// rule2 is actually rule1
RuleDto rule2 = dbClient.ruleDao().selectOrFailByKey(db.getSession(), RuleKey.of(repository2, ruleKey));
assertThat(rule2.getUuid()).isEqualTo(rule1.getUuid());
assertThat(rule2.getName()).isEqualTo("Name2");
assertThat(rule2.getDescription()).isEqualTo(rule1.getDescription());
SearchIdResult<String> searchRule2 = ruleIndex.search(new RuleQuery().setQueryText("Name2"), new SearchOptions());
assertThat(searchRule2.getUuids()).containsOnly(rule2.getUuid());
assertThat(searchRule2.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_a_rule_with_an_existing_RuleKey_still_used_should_throw_IAE.
@Test
public void declaring_a_rule_with_an_existing_RuleKey_still_used_should_throw_IAE() {
assertThatThrownBy(() -> {
execute(context -> {
NewRepository repo = context.createRepository("fake", "java");
createRule(repo, "newKey1");
createRule(repo, "newKey1");
repo.done();
});
}).isInstanceOf(IllegalArgumentException.class).hasMessage("The rule 'newKey1' of repository 'fake' is declared several times");
}
use of org.sonar.api.server.rule.RulesDefinition.NewRepository in project sonarqube by SonarSource.
the class RegisterRulesTest method add_new_security_standards.
@Test
public void add_new_security_standards() {
execute(context -> {
NewRepository repo = context.createRepository("fake", "java");
repo.createRule("rule1").setName("Rule One").setHtmlDescription("Description of Rule One").addOwaspTop10(Y2021, OwaspTop10.A1).addCwe(123);
repo.done();
});
RuleDto rule = dbClient.ruleDao().selectOrFailByKey(db.getSession(), RULE_KEY1);
assertThat(rule.getSecurityStandards()).containsOnly("cwe:123", "owaspTop10-2021:a1");
execute(context -> {
NewRepository repo = context.createRepository("fake", "java");
repo.createRule("rule1").setName("Rule One").setHtmlDescription("Description of Rule One").addOwaspTop10(Y2021, OwaspTop10.A1, OwaspTop10.A3).addCwe(1, 123, 863);
repo.done();
});
rule = dbClient.ruleDao().selectOrFailByKey(db.getSession(), RULE_KEY1);
assertThat(rule.getSecurityStandards()).containsOnly("cwe:1", "cwe:123", "cwe:863", "owaspTop10-2021:a1", "owaspTop10-2021:a3");
}
use of org.sonar.api.server.rule.RulesDefinition.NewRepository in project sonarqube by SonarSource.
the class RegisterRulesTest method add_new_tag.
@Test
public void add_new_tag() {
execute(context -> {
NewRepository repo = context.createRepository("fake", "java");
repo.createRule("rule1").setName("Rule One").setHtmlDescription("Description of Rule One").setTags("tag1");
repo.done();
});
RuleDto rule = dbClient.ruleDao().selectOrFailByKey(db.getSession(), RULE_KEY1);
assertThat(rule.getSystemTags()).containsOnly("tag1");
execute(context -> {
NewRepository repo = context.createRepository("fake", "java");
repo.createRule("rule1").setName("Rule One").setHtmlDescription("Description of Rule One").setTags("tag1", "tag2");
repo.done();
});
rule = dbClient.ruleDao().selectOrFailByKey(db.getSession(), RULE_KEY1);
assertThat(rule.getSystemTags()).containsOnly("tag1", "tag2");
}
use of org.sonar.api.server.rule.RulesDefinition.NewRepository in project sonarqube by SonarSource.
the class RegisterRulesTest method rules_that_deprecate_previous_rule_must_be_recorded.
@Test
public void rules_that_deprecate_previous_rule_must_be_recorded() {
execute(context -> {
NewRepository repo = context.createRepository("fake", "java");
createRule(repo, "rule1");
repo.done();
});
execute(context -> {
NewRepository repo = context.createRepository("fake", "java");
createRule(repo, "newKey").addDeprecatedRuleKey("fake", "rule1").addDeprecatedRuleKey("fake", "rule2");
repo.done();
});
List<RuleDefinitionDto> rules = dbClient.ruleDao().selectAllDefinitions(db.getSession());
Set<DeprecatedRuleKeyDto> deprecatedRuleKeys = dbClient.ruleDao().selectAllDeprecatedRuleKeys(db.getSession());
assertThat(rules).hasSize(1);
assertThat(deprecatedRuleKeys).hasSize(2);
}
Aggregations