use of org.sonar.db.rule.RuleDto in project sonarqube by SonarSource.
the class RuleTagHelperTest method applyTags_do_not_duplicate_system_tags.
@Test
public void applyTags_do_not_duplicate_system_tags() {
RuleDto rule = new RuleDto().setTags(Sets.newHashSet("performance")).setSystemTags(Sets.newHashSet("security"));
boolean changed = RuleTagHelper.applyTags(rule, Sets.newHashSet("java8", "security"));
assertThat(changed).isTrue();
assertThat(rule.getTags()).containsOnly("java8");
assertThat(rule.getSystemTags()).containsOnly("security");
}
use of org.sonar.db.rule.RuleDto in project sonarqube by SonarSource.
the class RuleUpdaterMediumTest method override_debt_only_offset.
@Test
public void override_debt_only_offset() {
ruleDao.insert(dbSession, RuleTesting.newDto(RULE_KEY).setDefaultRemediationFunction(DebtRemediationFunction.Type.LINEAR.name()).setDefaultRemediationGapMultiplier("1d").setDefaultRemediationBaseEffort(null).setRemediationFunction(null).setRemediationGapMultiplier(null).setRemediationBaseEffort(null));
dbSession.commit();
RuleUpdate update = RuleUpdate.createForPluginRule(RULE_KEY).setDebtRemediationFunction(new DefaultDebtRemediationFunction(DebtRemediationFunction.Type.LINEAR, "2d", null));
underTest.update(update, userSessionRule);
dbSession.clearCache();
// verify debt is overridden
RuleDto rule = ruleDao.selectOrFailByKey(dbSession, RULE_KEY);
assertThat(rule.getRemediationFunction()).isEqualTo(DebtRemediationFunction.Type.LINEAR.name());
assertThat(rule.getRemediationGapMultiplier()).isEqualTo("2d");
assertThat(rule.getRemediationBaseEffort()).isNull();
assertThat(rule.getDefaultRemediationFunction()).isEqualTo(DebtRemediationFunction.Type.LINEAR.name());
assertThat(rule.getDefaultRemediationGapMultiplier()).isEqualTo("1d");
assertThat(rule.getDefaultRemediationBaseEffort()).isNull();
}
use of org.sonar.db.rule.RuleDto in project sonarqube by SonarSource.
the class RuleUpdaterMediumTest method fail_to_update_plugin_rule_if_name_is_set.
@Test
public void fail_to_update_plugin_rule_if_name_is_set() {
// Create rule rule
RuleDto ruleDto = RuleTesting.newDto(RuleKey.of("squid", "S01"));
ruleDao.insert(dbSession, ruleDto);
dbSession.commit();
try {
// Update rule
RuleUpdate.createForPluginRule(ruleDto.getKey()).setName("New name");
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not a custom rule");
}
}
use of org.sonar.db.rule.RuleDto in project sonarqube by SonarSource.
the class RuleUpdaterMediumTest method update_custom_rule.
@Test
public void update_custom_rule() {
// Create template rule
RuleDto templateRule = RuleTesting.newTemplateRule(RuleKey.of("java", "S001"));
ruleDao.insert(dbSession, templateRule);
RuleParamDto templateRuleParam1 = RuleParamDto.createFor(templateRule).setName("regex").setType("STRING").setDescription("Reg ex").setDefaultValue(".*");
RuleParamDto templateRuleParam2 = RuleParamDto.createFor(templateRule).setName("format").setType("STRING").setDescription("Format");
ruleDao.insertRuleParam(dbSession, templateRule, templateRuleParam1);
ruleDao.insertRuleParam(dbSession, templateRule, templateRuleParam2);
// 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, templateRuleParam1.setDefaultValue("a.*"));
ruleDao.insertRuleParam(dbSession, customRule, templateRuleParam2.setDefaultValue(null));
dbSession.commit();
// Update custom rule
RuleUpdate update = RuleUpdate.createForCustomRule(customRule.getKey()).setName("New name").setMarkdownDescription("New description").setSeverity("MAJOR").setStatus(RuleStatus.READY).setParameters(ImmutableMap.of("regex", "b.*"));
underTest.update(update, userSessionRule);
dbSession.clearCache();
// Verify custom rule is updated
RuleDto customRuleReloaded = ruleDao.selectOrFailByKey(dbSession, customRule.getKey());
assertThat(customRuleReloaded).isNotNull();
assertThat(customRuleReloaded.getName()).isEqualTo("New name");
assertThat(customRuleReloaded.getDescription()).isEqualTo("New description");
assertThat(customRuleReloaded.getSeverityString()).isEqualTo("MAJOR");
assertThat(customRuleReloaded.getStatus()).isEqualTo(RuleStatus.READY);
List<RuleParamDto> params = ruleDao.selectRuleParamsByRuleKey(dbSession, customRuleReloaded.getKey());
assertThat(params).hasSize(2);
assertThat(params.get(0).getDefaultValue()).isEqualTo("b.*");
assertThat(params.get(1).getDefaultValue()).isNull();
// Verify in index
assertThat(ruleIndex.search(new RuleQuery().setQueryText("New name"), new SearchOptions()).getIds()).containsOnly(customRule.getKey());
assertThat(ruleIndex.search(new RuleQuery().setQueryText("New description"), new SearchOptions()).getIds()).containsOnly(customRule.getKey());
assertThat(ruleIndex.search(new RuleQuery().setQueryText("Old name"), new SearchOptions()).getTotal()).isZero();
assertThat(ruleIndex.search(new RuleQuery().setQueryText("Old description"), new SearchOptions()).getTotal()).isZero();
}
use of org.sonar.db.rule.RuleDto in project sonarqube by SonarSource.
the class RuleUpdaterMediumTest method remove_markdown_note.
@Test
public void remove_markdown_note() {
ruleDao.insert(dbSession, RuleTesting.newDto(RULE_KEY).setNoteData("my *note*").setNoteUserLogin("me"));
dbSession.commit();
RuleUpdate update = RuleUpdate.createForPluginRule(RULE_KEY).setMarkdownNote(null);
underTest.update(update, userSessionRule);
dbSession.clearCache();
RuleDto rule = ruleDao.selectOrFailByKey(dbSession, RULE_KEY);
assertThat(rule.getNoteData()).isNull();
assertThat(rule.getNoteUserLogin()).isNull();
assertThat(rule.getNoteCreatedAt()).isNull();
assertThat(rule.getNoteUpdatedAt()).isNull();
}
Aggregations