use of org.sonar.api.server.rule.RulesDefinition.NewRepository in project sonarqube by SonarSource.
the class RegisterRulesTest method update_template_rule_key_should_also_update_custom_rules.
@Test
public void update_template_rule_key_should_also_update_custom_rules() {
system.setNow(DATE1.getTime());
execute(context -> {
NewRepository repo = context.createRepository("squid", "java");
repo.createRule("rule").setName("Name1").setHtmlDescription("Description").setTemplate(true);
repo.done();
});
RuleDto rule1 = dbClient.ruleDao().selectOrFailByKey(db.getSession(), RuleKey.of("squid", "rule"));
// insert custom rule
db.rules().insert(new RuleDefinitionDto().setRuleKey(RuleKey.of("squid", "custom")).setLanguage("java").setScope(Scope.ALL).setTemplateUuid(rule1.getUuid()).setName("custom1"));
db.commit();
// re-key rule
execute(context -> {
NewRepository repo = context.createRepository("java", "java");
repo.createRule("rule").setName("Name1").setHtmlDescription("Description").addDeprecatedRuleKey("squid", "rule").setTemplate(true);
repo.done();
});
// template rule and custom rule have been updated
rule1 = dbClient.ruleDao().selectOrFailByKey(db.getSession(), RuleKey.of("java", "rule"));
RuleDto custom = dbClient.ruleDao().selectOrFailByKey(db.getSession(), RuleKey.of("java", "custom"));
}
use of org.sonar.api.server.rule.RulesDefinition.NewRepository in project sonarqube by SonarSource.
the class RegisterRulesTest method rule_previously_created_as_adhoc_becomes_none_adhoc.
@Test
public void rule_previously_created_as_adhoc_becomes_none_adhoc() {
RuleDefinitionDto rule = db.rules().insert(r -> r.setRepositoryKey("external_fake").setIsExternal(true).setIsAdHoc(true));
system.setNow(DATE2.getTime());
execute(context -> {
NewRepository repo = context.createExternalRepository("fake", rule.getLanguage());
repo.createRule(rule.getRuleKey()).setName(rule.getName()).setHtmlDescription(rule.getDescription());
repo.done();
});
RuleDto reloaded = dbClient.ruleDao().selectByKey(db.getSession(), rule.getKey()).get();
assertThat(reloaded.isAdHoc()).isFalse();
}
use of org.sonar.api.server.rule.RulesDefinition.NewRepository in project sonarqube by SonarSource.
the class RegisterRulesTest method rules_that_remove_deprecated_key_must_remove_records.
@Test
public void rules_that_remove_deprecated_key_must_remove_records() {
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();
});
assertThat(dbClient.ruleDao().selectAllDefinitions(db.getSession())).hasSize(1);
Set<DeprecatedRuleKeyDto> deprecatedRuleKeys = dbClient.ruleDao().selectAllDeprecatedRuleKeys(db.getSession());
assertThat(deprecatedRuleKeys).hasSize(2);
execute(context -> {
NewRepository repo = context.createRepository("fake", "java");
createRule(repo, "newKey");
repo.done();
});
assertThat(dbClient.ruleDao().selectAllDefinitions(db.getSession())).hasSize(1);
deprecatedRuleKeys = dbClient.ruleDao().selectAllDeprecatedRuleKeys(db.getSession());
assertThat(deprecatedRuleKeys).isEmpty();
}
use of org.sonar.api.server.rule.RulesDefinition.NewRepository in project sonarqube by SonarSource.
the class RegisterRulesTest method createRule.
@SafeVarargs
private void createRule(Context context, String language, String repositoryKey, String ruleKey, Consumer<NewRule>... consumers) {
NewRepository repo = context.createRepository(repositoryKey, language);
NewRule newRule = repo.createRule(ruleKey).setName(ruleKey).setHtmlDescription("Description of One").setSeverity(BLOCKER).setType(RuleType.CODE_SMELL).setStatus(RuleStatus.BETA);
Arrays.stream(consumers).forEach(c -> c.accept(newRule));
repo.done();
}
Aggregations