use of org.sonar.db.rule.RuleDto in project sonarqube by SonarSource.
the class RegisterRulesMediumTest method do_not_update_custom_rule_params_from_template.
@Test
public void do_not_update_custom_rule_params_from_template() {
register(new Rules() {
@Override
public void init(RulesDefinition.NewRepository repository) {
repository.createRule("T1").setName("template1 name").setHtmlDescription("template1 desc").setSeverity(Severity.MAJOR).setTemplate(true).createParam("format").setDefaultValue("csv").setType(RuleParamType.STRING).setDescription("format parameter");
}
});
RuleDto templateRule = ruleDao.selectOrFailByKey(dbSession, RuleKey.of("xoo", "T1"));
// Create custom rule
RuleKey customRuleKey = TESTER.get(RuleCreator.class).create(NewCustomRule.createForCustomRule("CUSTOM_RULE", templateRule.getKey()).setName("My custom").setHtmlDescription("Some description").setSeverity(Severity.MAJOR).setStatus(RuleStatus.READY).setParameters(ImmutableMap.of("format", "txt")));
register(new Rules() {
@Override
public void init(RulesDefinition.NewRepository repository) {
repository.createRule("T1").setName("template1 name").setHtmlDescription("template1 desc").setSeverity(Severity.MAJOR).setTemplate(true).createParam("format2").setDefaultValue("csv").setType(RuleParamType.STRING).setDescription("format parameter");
}
});
// Verify custom rule param has not been changed!
List<RuleParamDto> customRuleParams = ruleDao.selectRuleParamsByRuleKey(dbSession, customRuleKey);
assertThat(customRuleParams.get(0).getName()).isEqualTo("format");
}
use of org.sonar.db.rule.RuleDto in project sonarqube by SonarSource.
the class RegisterRulesMediumTest method disable_custom_rules_if_template_disabled.
@Test
public void disable_custom_rules_if_template_disabled() {
Rules rules = new Rules() {
@Override
public void init(RulesDefinition.NewRepository repository) {
repository.createRule("T1").setName("template1 name").setHtmlDescription("template1 desc").setSeverity(Severity.MAJOR).setTemplate(true).createParam("format").setDefaultValue("csv").setType(RuleParamType.STRING).setDescription("format parameter");
}
};
register(rules);
RuleDto templateRule = ruleDao.selectOrFailByKey(dbSession, RuleKey.of("xoo", "T1"));
// Create custom rule
RuleKey customRuleKey = TESTER.get(RuleCreator.class).create(NewCustomRule.createForCustomRule("CUSTOM_RULE", templateRule.getKey()).setName("My custom").setHtmlDescription("Some description").setSeverity(Severity.MAJOR).setStatus(RuleStatus.READY).setParameters(ImmutableMap.of("format", "txt")));
assertThat(ruleDao.selectOrFailByKey(dbSession, customRuleKey).getStatus()).isEqualTo(RuleStatus.READY);
// Restart without template
register(null);
// Verify custom rule is removed
assertThat(ruleDao.selectOrFailByKey(dbSession, templateRule.getKey()).getStatus()).isEqualTo(RuleStatus.REMOVED);
assertThat(ruleDao.selectOrFailByKey(dbSession, customRuleKey).getStatus()).isEqualTo(RuleStatus.REMOVED);
// Re-install template
register(rules);
assertThat(ruleDao.selectOrFailByKey(dbSession, templateRule.getKey()).getStatus()).isEqualTo(RuleStatus.READY);
assertThat(ruleDao.selectOrFailByKey(dbSession, customRuleKey).getStatus()).isEqualTo(RuleStatus.READY);
}
use of org.sonar.db.rule.RuleDto in project sonarqube by SonarSource.
the class RegisterRulesMediumTest method remove_user_tags_that_are_newly_declared_as_system.
@Test
public void remove_user_tags_that_are_newly_declared_as_system() {
register(new Rules() {
@Override
public void init(RulesDefinition.NewRepository repository) {
repository.createRule("x1").setName("x1 name").setHtmlDescription("x1 desc").setTags("tag1");
}
});
RuleDto rule = ruleDao.selectOrFailByKey(dbSession, RuleTesting.XOO_X1);
assertThat(rule.getSystemTags()).containsOnly("tag1");
assertThat(rule.getTags()).isEmpty();
// User adds tag
TESTER.get(RuleUpdater.class).update(dbSession, RuleUpdate.createForPluginRule(RuleTesting.XOO_X1).setTags(newHashSet("tag2")), userSessionRule);
dbSession.clearCache();
rule = ruleDao.selectOrFailByKey(dbSession, RuleTesting.XOO_X1);
assertThat(rule.getSystemTags()).containsOnly("tag1");
assertThat(rule.getTags()).containsOnly("tag2");
// Definition updated -> user tag "tag2" becomes a system tag
register(new Rules() {
@Override
public void init(RulesDefinition.NewRepository repository) {
repository.createRule("x1").setName("x1 name").setHtmlDescription("x1 desc").setTags("tag1", "tag2");
}
});
rule = ruleDao.selectOrFailByKey(dbSession, RuleTesting.XOO_X1);
assertThat(rule.getSystemTags()).containsOnly("tag1", "tag2");
assertThat(rule.getTags()).isEmpty();
}
use of org.sonar.db.rule.RuleDto in project sonarqube by SonarSource.
the class RegisterRulesTest method add_new_tag.
@Test
public void add_new_tag() {
execute(new RulesDefinition() {
@Override
public void define(RulesDefinition.Context context) {
RulesDefinition.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(dbTester.getSession(), RULE_KEY1);
assertThat(rule.getSystemTags()).containsOnly("tag1");
execute(new RulesDefinition() {
@Override
public void define(RulesDefinition.Context context) {
RulesDefinition.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(dbTester.getSession(), RULE_KEY1);
assertThat(rule.getSystemTags()).containsOnly("tag1", "tag2");
}
use of org.sonar.db.rule.RuleDto in project sonarqube by SonarSource.
the class RegisterRulesTest method remove_system_tags_when_plugin_does_not_provide_any.
@Test
public void remove_system_tags_when_plugin_does_not_provide_any() {
// Rule already exists in DB, with some system tags
dbClient.ruleDao().insert(dbTester.getSession(), new RuleDto().setRuleKey("rule1").setRepositoryKey("findbugs").setName("Rule One").setDescription("Rule one description").setDescriptionFormat(RuleDto.Format.HTML).setSystemTags(newHashSet("tag1", "tag2")));
dbTester.getSession().commit();
// Synchronize rule without tag
execute(new FindbugsRepository());
List<RuleDto> rules = dbClient.ruleDao().selectAll(dbTester.getSession());
assertThat(rules).hasSize(1);
RuleDto result = rules.get(0);
assertThat(result.getKey()).isEqualTo(RuleKey.of("findbugs", "rule1"));
assertThat(result.getSystemTags()).isEmpty();
}
Aggregations