Search in sources :

Example 36 with RuleParamDto

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.*");
}
Also used : RuleDto(org.sonar.db.rule.RuleDto) RuleKey(org.sonar.api.rule.RuleKey) RuleParamDto(org.sonar.db.rule.RuleParamDto) Test(org.junit.Test)

Example 37 with RuleParamDto

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;
}
Also used : RuleDto(org.sonar.db.rule.RuleDto) RuleParamDto(org.sonar.db.rule.RuleParamDto) Date(java.util.Date)

Aggregations

RuleParamDto (org.sonar.db.rule.RuleParamDto)37 RuleDto (org.sonar.db.rule.RuleDto)29 Test (org.junit.Test)17 ActiveRuleParamDto (org.sonar.db.qualityprofile.ActiveRuleParamDto)14 ActiveRuleDto (org.sonar.db.qualityprofile.ActiveRuleDto)12 RuleKey (org.sonar.api.rule.RuleKey)10 ArrayList (java.util.ArrayList)6 WsTester (org.sonar.server.ws.WsTester)6 Date (java.util.Date)5 QualityProfileDto (org.sonar.db.qualityprofile.QualityProfileDto)5 SearchOptions (org.sonar.server.es.SearchOptions)4 RuleQuery (org.sonar.server.rule.index.RuleQuery)4 ActiveRuleDao (org.sonar.db.qualityprofile.ActiveRuleDao)3 QualityProfileDao (org.sonar.db.qualityprofile.QualityProfileDao)3 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)2 RulesDefinition (org.sonar.api.server.rule.RulesDefinition)2 DbSession (org.sonar.db.DbSession)2 Collection (java.util.Collection)1 Map (java.util.Map)1 Before (org.junit.Before)1