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();
}
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();
}
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");
}
}
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();
}
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();
}
Aggregations