use of org.sonar.db.rule.RuleDto in project sonarqube by SonarSource.
the class RuleUpdaterMediumTest method fail_to_update_custom_rule_when_empty_name.
@Test
public void fail_to_update_custom_rule_when_empty_name() {
// Create template rule
RuleDto templateRule = RuleTesting.newTemplateRule(RuleKey.of("java", "S001"));
ruleDao.insert(dbSession, templateRule);
// Create custom rule
RuleDto customRule = RuleTesting.newCustomRule(templateRule);
ruleDao.insert(dbSession, customRule);
dbSession.commit();
// Update custom rule
RuleUpdate update = RuleUpdate.createForCustomRule(customRule.getKey()).setName("").setMarkdownDescription("New desc");
try {
underTest.update(update, userSessionRule);
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(IllegalArgumentException.class).hasMessage("The name is missing");
}
}
use of org.sonar.db.rule.RuleDto in project sonarqube by SonarSource.
the class RuleUpdaterMediumTest method set_markdown_note.
@Test
public void set_markdown_note() {
userSessionRule.logIn("me");
ruleDao.insert(dbSession, RuleTesting.newDto(RULE_KEY).setNoteData(null).setNoteUserLogin(null).setTags(ImmutableSet.of("tag1")).setRemediationFunction(DebtRemediationFunction.Type.CONSTANT_ISSUE.name()).setRemediationGapMultiplier("1d").setRemediationBaseEffort("5min"));
dbSession.commit();
RuleUpdate update = RuleUpdate.createForPluginRule(RULE_KEY);
update.setMarkdownNote("my *note*");
underTest.update(update, userSessionRule);
dbSession.clearCache();
RuleDto rule = ruleDao.selectOrFailByKey(dbSession, RULE_KEY);
assertThat(rule.getNoteData()).isEqualTo("my *note*");
assertThat(rule.getNoteUserLogin()).isEqualTo("me");
assertThat(rule.getNoteCreatedAt()).isNotNull();
assertThat(rule.getNoteUpdatedAt()).isNotNull();
// no other changes
assertThat(rule.getTags()).containsOnly("tag1");
assertThat(rule.getRemediationFunction()).isEqualTo(DebtRemediationFunction.Type.CONSTANT_ISSUE.name());
assertThat(rule.getRemediationGapMultiplier()).isEqualTo("1d");
assertThat(rule.getRemediationBaseEffort()).isEqualTo("5min");
}
use of org.sonar.db.rule.RuleDto in project sonarqube by SonarSource.
the class RuleUpdaterMediumTest method no_changes.
@Test
public void no_changes() {
ruleDao.insert(dbSession, RuleTesting.newDto(RULE_KEY).setNoteData("my *note*").setNoteUserLogin("me").setTags(ImmutableSet.of("tag1")).setRemediationFunction(DebtRemediationFunction.Type.CONSTANT_ISSUE.name()).setRemediationGapMultiplier("1d").setRemediationBaseEffort("5min"));
dbSession.commit();
RuleUpdate update = RuleUpdate.createForPluginRule(RULE_KEY);
assertThat(update.isEmpty()).isTrue();
underTest.update(update, userSessionRule);
dbSession.clearCache();
RuleDto rule = ruleDao.selectOrFailByKey(dbSession, RULE_KEY);
assertThat(rule.getNoteData()).isEqualTo("my *note*");
assertThat(rule.getNoteUserLogin()).isEqualTo("me");
assertThat(rule.getTags()).containsOnly("tag1");
assertThat(rule.getRemediationFunction()).isEqualTo(DebtRemediationFunction.Type.CONSTANT_ISSUE.name());
assertThat(rule.getRemediationGapMultiplier()).isEqualTo("1d");
assertThat(rule.getRemediationBaseEffort()).isEqualTo("5min");
}
use of org.sonar.db.rule.RuleDto in project sonarqube by SonarSource.
the class RuleUpdaterMediumTest method set_tags.
@Test
public void set_tags() {
// insert db
ruleDao.insert(dbSession, RuleTesting.newDto(RULE_KEY).setTags(Sets.newHashSet("security")).setSystemTags(Sets.newHashSet("java8", "javadoc")));
dbSession.commit();
// java8 is a system tag -> ignore
RuleUpdate update = RuleUpdate.createForPluginRule(RULE_KEY).setTags(Sets.newHashSet("bug", "java8"));
underTest.update(update, userSessionRule);
dbSession.clearCache();
RuleDto rule = ruleDao.selectOrFailByKey(dbSession, RULE_KEY);
assertThat(rule.getTags()).containsOnly("bug");
assertThat(rule.getSystemTags()).containsOnly("java8", "javadoc");
// verify that tags are indexed in index
Set<String> tags = tester.get(RuleService.class).listTags();
assertThat(tags).containsOnly("bug", "java8", "javadoc");
}
use of org.sonar.db.rule.RuleDto in project sonarqube by SonarSource.
the class RuleUpdaterMediumTest method update_custom_rule_with_empty_parameter.
@Test
public void update_custom_rule_with_empty_parameter() {
// Create template rule
RuleDto templateRule = RuleTesting.newTemplateRule(RuleKey.of("java", "S001"));
ruleDao.insert(dbSession, templateRule);
RuleParamDto templateRuleParam = RuleParamDto.createFor(templateRule).setName("regex").setType("STRING").setDescription("Reg ex");
ruleDao.insertRuleParam(dbSession, templateRule, templateRuleParam);
// Create custom rule
RuleDto customRule = RuleTesting.newCustomRule(templateRule).setName("Old name").setDescription("Old description").setSeverity(Severity.MINOR).setStatus(RuleStatus.BETA);
ruleDao.insert(dbSession, customRule);
ruleDao.insertRuleParam(dbSession, customRule, templateRuleParam);
dbSession.commit();
// Update custom rule without setting a value for the parameter
RuleUpdate update = RuleUpdate.createForCustomRule(customRule.getKey()).setName("New name").setMarkdownDescription("New description").setSeverity("MAJOR").setStatus(RuleStatus.READY);
underTest.update(update, userSessionRule);
dbSession.clearCache();
// Verify custom rule is updated
List<RuleParamDto> params = ruleDao.selectRuleParamsByRuleKey(dbSession, customRule.getKey());
assertThat(params.get(0).getDefaultValue()).isNull();
}
Aggregations