Search in sources :

Example 96 with RuleDto

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

the class ClearRulesOverloadedDebtTest method verifyRuleHasNotOverriddenDebt.

private void verifyRuleHasNotOverriddenDebt(RuleKey ruleKey) {
    // Refresh session
    dbSession.commit(true);
    RuleDto ruleDto = ruleDao.selectOrFailByKey(dbSession, ruleKey);
    assertThat(ruleDto.getRemediationFunction()).isNull();
    assertThat(ruleDto.getRemediationGapMultiplier()).isNull();
    assertThat(ruleDto.getRemediationBaseEffort()).isNull();
}
Also used : RuleDto(org.sonar.db.rule.RuleDto)

Example 97 with RuleDto

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

the class ShowActionMediumTest method show_rule.

@Test
public void show_rule() throws Exception {
    RuleDto ruleDto = RuleTesting.newDto(RuleKey.of("java", "S001")).setName("Rule S001").setDescription("Rule S001 <b>description</b>").setDescriptionFormat(Format.HTML).setSeverity(MINOR).setStatus(RuleStatus.BETA).setConfigKey("InternalKeyS001").setLanguage("xoo").setTags(newHashSet("tag1", "tag2")).setSystemTags(newHashSet("systag1", "systag2")).setType(RuleType.BUG);
    ruleDao.insert(session, ruleDto);
    RuleParamDto param = RuleParamDto.createFor(ruleDto).setName("regex").setType("STRING").setDescription("Reg *exp*").setDefaultValue(".*");
    ruleDao.insertRuleParam(session, ruleDto, param);
    session.commit();
    session.clearCache();
    WsTester.TestRequest request = wsTester.newGetRequest("api/rules", "show").setParam("key", ruleDto.getKey().toString());
    request.execute().assertJson(getClass(), "show_rule.json");
}
Also used : WsTester(org.sonar.server.ws.WsTester) ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) RuleDto(org.sonar.db.rule.RuleDto) ActiveRuleParamDto(org.sonar.db.qualityprofile.ActiveRuleParamDto) RuleParamDto(org.sonar.db.rule.RuleParamDto) Test(org.junit.Test)

Example 98 with RuleDto

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

the class ShowActionMediumTest method show_rule_with_default_and_overridden_debt_infos.

@Test
public void show_rule_with_default_and_overridden_debt_infos() throws Exception {
    RuleDto ruleDto = RuleTesting.newDto(RuleKey.of("java", "S001")).setName("Rule S001").setDescription("Rule S001 <b>description</b>").setSeverity(MINOR).setStatus(RuleStatus.BETA).setConfigKey("InternalKeyS001").setLanguage("xoo").setDefaultRemediationFunction("LINEAR").setDefaultRemediationGapMultiplier("5min").setDefaultRemediationBaseEffort(null).setRemediationFunction("LINEAR_OFFSET").setRemediationGapMultiplier("5d").setRemediationBaseEffort("10h");
    ruleDao.insert(session, ruleDto);
    session.commit();
    session.clearCache();
    WsTester.TestRequest request = wsTester.newGetRequest("api/rules", "show").setParam("key", ruleDto.getKey().toString());
    request.execute().assertJson(getClass(), "show_rule_with_default_and_overridden_debt_infos.json");
}
Also used : WsTester(org.sonar.server.ws.WsTester) ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) RuleDto(org.sonar.db.rule.RuleDto) Test(org.junit.Test)

Example 99 with RuleDto

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

the class ShowActionMediumTest method encode_html_description_of_custom_rule.

@Test
public void encode_html_description_of_custom_rule() throws Exception {
    // Template rule
    RuleDto templateRule = RuleTesting.newTemplateRule(RuleKey.of("java", "S001"));
    ruleDao.insert(session, templateRule);
    session.commit();
    // Custom rule
    NewCustomRule customRule = NewCustomRule.createForCustomRule("MY_CUSTOM", templateRule.getKey()).setName("My custom").setSeverity(MINOR).setStatus(RuleStatus.READY).setMarkdownDescription("<div>line1\nline2</div>");
    RuleKey customRuleKey = tester.get(RuleCreator.class).create(customRule);
    session.clearCache();
    WsTester.TestRequest request = wsTester.newGetRequest("api/rules", "show").setParam("key", customRuleKey.toString());
    request.execute().assertJson(getClass(), "encode_html_description_of_custom_rule.json");
}
Also used : WsTester(org.sonar.server.ws.WsTester) ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) RuleDto(org.sonar.db.rule.RuleDto) RuleKey(org.sonar.api.rule.RuleKey) NewCustomRule(org.sonar.server.rule.NewCustomRule) RuleCreator(org.sonar.server.rule.RuleCreator) Test(org.junit.Test)

Example 100 with RuleDto

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

the class IssueDbTester method insertIssue.

public IssueDto insertIssue() {
    RuleDto rule = db.rules().insertRule(newRuleDto());
    ComponentDto project = db.components().insertProject();
    ComponentDto file = db.components().insertComponent(newFileDto(project));
    return insertIssue(newDto(rule, file, project));
}
Also used : RuleDto(org.sonar.db.rule.RuleDto) RuleTesting.newRuleDto(org.sonar.db.rule.RuleTesting.newRuleDto) ComponentDto(org.sonar.db.component.ComponentDto)

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