Search in sources :

Example 91 with RuleDto

use of org.sonar.db.rule.RuleDto in project sonarqube by SonarSource.

the class RuleCreatorMediumTest method create_custom_rule_with_no_parameter_value.

@Test
public void create_custom_rule_with_no_parameter_value() {
    // insert template rule
    RuleDto templateRule = createTemplateRuleWithIntArrayParam();
    NewCustomRule newRule = NewCustomRule.createForCustomRule("CUSTOM_RULE", templateRule.getKey()).setName("My custom").setHtmlDescription("Some description").setSeverity(Severity.MAJOR).setStatus(RuleStatus.READY);
    RuleKey customRuleKey = creator.create(newRule);
    dbSession.clearCache();
    List<RuleParamDto> params = db.ruleDao().selectRuleParamsByRuleKey(dbSession, customRuleKey);
    assertThat(params).hasSize(1);
    RuleParamDto param = params.get(0);
    assertThat(param.getName()).isEqualTo("myIntegers");
    assertThat(param.getDescription()).isEqualTo("My Integers");
    assertThat(param.getType()).isEqualTo("INTEGER,multiple=true,values=1;2;3");
    assertThat(param.getDefaultValue()).isNull();
}
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 92 with RuleDto

use of org.sonar.db.rule.RuleDto in project sonarqube by SonarSource.

the class RuleCreatorMediumTest method create_custom_rule_with_invalid_parameters.

@Test
public void create_custom_rule_with_invalid_parameters() {
    // insert template rule
    RuleDto templateRule = createTemplateRuleWithTwoIntParams();
    // Create custom rule
    NewCustomRule newRule = NewCustomRule.createForCustomRule("CUSTOM_RULE", templateRule.getKey()).setName("My custom").setMarkdownDescription("Some description").setSeverity(Severity.MAJOR).setStatus(RuleStatus.READY).setParameters(ImmutableMap.of("first", "polop", "second", "palap"));
    try {
        creator.create(newRule);
        Fail.failBecauseExceptionWasNotThrown(BadRequestException.class);
    } catch (BadRequestException badRequest) {
        assertThat(badRequest.errors().toString()).contains("palap").contains("polop");
    }
    dbSession.clearCache();
}
Also used : RuleDto(org.sonar.db.rule.RuleDto) BadRequestException(org.sonar.server.exceptions.BadRequestException) Test(org.junit.Test)

Example 93 with RuleDto

use of org.sonar.db.rule.RuleDto in project sonarqube by SonarSource.

the class RuleCreatorMediumTest method fail_to_create_custom_rule_when_missing_severity.

@Test
public void fail_to_create_custom_rule_when_missing_severity() {
    // insert template rule
    RuleDto templateRule = createTemplateRule();
    NewCustomRule newRule = NewCustomRule.createForCustomRule("CUSTOM_RULE", templateRule.getKey()).setName("My custom").setHtmlDescription("Some description").setStatus(RuleStatus.READY).setParameters(ImmutableMap.of("regex", "a.*"));
    try {
        creator.create(newRule);
        fail();
    } catch (Exception e) {
        assertThat(e).isInstanceOf(BadRequestException.class).hasMessage("The severity is missing");
    }
}
Also used : RuleDto(org.sonar.db.rule.RuleDto) BadRequestException(org.sonar.server.exceptions.BadRequestException) Test(org.junit.Test)

Example 94 with RuleDto

use of org.sonar.db.rule.RuleDto in project sonarqube by SonarSource.

the class RuleCreatorMediumTest method create_custom_rule_with_invalid_parameter.

@Test
public void create_custom_rule_with_invalid_parameter() {
    // insert template rule
    RuleDto templateRule = createTemplateRuleWithIntArrayParam();
    // Create custom rule
    NewCustomRule newRule = NewCustomRule.createForCustomRule("CUSTOM_RULE", templateRule.getKey()).setName("My custom").setMarkdownDescription("Some description").setSeverity(Severity.MAJOR).setStatus(RuleStatus.READY).setParameters(ImmutableMap.of("myIntegers", "1,polop,2"));
    try {
        creator.create(newRule);
        Fail.failBecauseExceptionWasNotThrown(BadRequestException.class);
    } catch (BadRequestException iae) {
        assertThat(iae).hasMessage("Value 'polop' must be an integer.");
    }
    dbSession.clearCache();
}
Also used : RuleDto(org.sonar.db.rule.RuleDto) BadRequestException(org.sonar.server.exceptions.BadRequestException) Test(org.junit.Test)

Example 95 with RuleDto

use of org.sonar.db.rule.RuleDto in project sonarqube by SonarSource.

the class ClearRulesOverloadedDebtTest method not_update_rule_debt_when_sqale_is_installed.

@Test
public void not_update_rule_debt_when_sqale_is_installed() throws Exception {
    insertSqaleProperty();
    RuleDto rule = insertRuleDto(RULE_KEY_1, "LINEAR", null, "1d");
    long updateAt = rule.getUpdatedAt();
    underTest.start();
    RuleDto reloaded = ruleDao.selectOrFailByKey(dbSession, RULE_KEY_1);
    assertThat(reloaded.getUpdatedAt()).isEqualTo(updateAt);
    verifyTaskRegistered();
    verifyEmptyLog();
}
Also used : RuleDto(org.sonar.db.rule.RuleDto) Test(org.junit.Test)

Aggregations

RuleDto (org.sonar.db.rule.RuleDto)197 Test (org.junit.Test)140 ActiveRuleDto (org.sonar.db.qualityprofile.ActiveRuleDto)80 ComponentDto (org.sonar.db.component.ComponentDto)47 WsTester (org.sonar.server.ws.WsTester)38 QualityProfileDto (org.sonar.db.qualityprofile.QualityProfileDto)29 RuleParamDto (org.sonar.db.rule.RuleParamDto)29 IssueDto (org.sonar.db.issue.IssueDto)28 RuleKey (org.sonar.api.rule.RuleKey)24 SearchOptions (org.sonar.server.es.SearchOptions)16 RuleQuery (org.sonar.server.rule.index.RuleQuery)16 BadRequestException (org.sonar.server.exceptions.BadRequestException)15 RuleTesting.newRuleDto (org.sonar.db.rule.RuleTesting.newRuleDto)14 ActiveRuleParamDto (org.sonar.db.qualityprofile.ActiveRuleParamDto)12 IssueIndexer (org.sonar.server.issue.index.IssueIndexer)10 Date (java.util.Date)9 RulesDefinition (org.sonar.api.server.rule.RulesDefinition)8 QualityProfileDao (org.sonar.db.qualityprofile.QualityProfileDao)8 ActiveRuleDao (org.sonar.db.qualityprofile.ActiveRuleDao)7 ArrayList (java.util.ArrayList)6