use of org.sonar.db.rule.RuleParamDto in project sonarqube by SonarSource.
the class RuleCreatorMediumTest method reactivate_custom_rule_if_already_exists_in_removed_status.
@Test
public void reactivate_custom_rule_if_already_exists_in_removed_status() {
String key = "CUSTOM_RULE";
// insert template rule
RuleDto templateRule = createTemplateRule();
// insert a removed rule
RuleDto rule = RuleTesting.newCustomRule(templateRule).setRuleKey(key).setStatus(RuleStatus.REMOVED).setName("Old name").setDescription("Old description").setDescriptionFormat(Format.MARKDOWN).setSeverity(Severity.INFO);
dao.insert(dbSession, rule);
dao.insertRuleParam(dbSession, rule, dao.selectRuleParamsByRuleKey(dbSession, templateRule.getKey()).get(0).setDefaultValue("a.*"));
dbSession.commit();
dbSession.clearCache();
// Create custom rule with same key, but with different values
NewCustomRule newRule = NewCustomRule.createForCustomRule(key, templateRule.getKey()).setName("New name").setMarkdownDescription("New description").setSeverity(Severity.MAJOR).setStatus(RuleStatus.READY).setParameters(ImmutableMap.of("regex", "c.*"));
RuleKey customRuleKey = creator.create(newRule);
dbSession.clearCache();
RuleDto result = db.ruleDao().selectOrFailByKey(dbSession, customRuleKey);
assertThat(result.getKey()).isEqualTo(RuleKey.of("java", key));
assertThat(result.getStatus()).isEqualTo(RuleStatus.READY);
// These values should be the same than before
assertThat(result.getName()).isEqualTo("Old name");
assertThat(result.getDescription()).isEqualTo("Old description");
assertThat(result.getSeverityString()).isEqualTo(Severity.INFO);
List<RuleParamDto> params = db.ruleDao().selectRuleParamsByRuleKey(dbSession, customRuleKey);
assertThat(params).hasSize(1);
assertThat(params.get(0).getDefaultValue()).isEqualTo("a.*");
}
use of org.sonar.db.rule.RuleParamDto in project sonarqube by SonarSource.
the class RuleCreatorMediumTest method createTemplateRuleWithIntArrayParam.
private RuleDto createTemplateRuleWithIntArrayParam() {
RuleDto templateRule = RuleTesting.newDto(RuleKey.of("java", "S002")).setIsTemplate(true).setLanguage("java").setConfigKey("S002").setDefaultRemediationFunction(DebtRemediationFunction.Type.LINEAR_OFFSET.name()).setDefaultRemediationGapMultiplier("1h").setDefaultRemediationBaseEffort("5min").setGapDescription("desc").setCreatedAt(new Date().getTime()).setUpdatedAt(new Date().getTime());
dao.insert(dbSession, templateRule);
RuleParamDto ruleParamDto = RuleParamDto.createFor(templateRule).setName("myIntegers").setType("INTEGER,multiple=true,values=1;2;3").setDescription("My Integers").setDefaultValue("1");
dao.insertRuleParam(dbSession, templateRule, ruleParamDto);
dbSession.commit();
ruleIndexer.index();
return templateRule;
}
Aggregations