Search in sources :

Example 56 with RuleDto

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

the class SearchActionMediumTest method search_all_active_rules.

@Test
public void search_all_active_rules() throws Exception {
    QualityProfileDto profile = QProfileTesting.newXooP1("org-123");
    tester.get(QualityProfileDao.class).insert(dbSession, profile);
    RuleDto rule = RuleTesting.newXooX1();
    ruleDao.insert(dbSession, rule);
    ActiveRuleDto activeRule = newActiveRule(profile, rule);
    tester.get(ActiveRuleDao.class).insert(dbSession, activeRule);
    dbSession.commit();
    ruleIndexer.index();
    activeRuleIndexer.index();
    WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
    request.setParam(WebService.Param.TEXT_QUERY, "x1");
    request.setParam(PARAM_ACTIVATION, "true");
    request.setParam(WebService.Param.FIELDS, "");
    WsTester.Result result = request.execute();
    result.assertJson(this.getClass(), "search_active_rules.json");
}
Also used : ActiveRuleDao(org.sonar.db.qualityprofile.ActiveRuleDao) QualityProfileDao(org.sonar.db.qualityprofile.QualityProfileDao) WsTester(org.sonar.server.ws.WsTester) ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) RuleDto(org.sonar.db.rule.RuleDto) ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto) Test(org.junit.Test)

Example 57 with RuleDto

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

the class SearchActionMediumTest method get_note_as_markdown_and_html.

@Test
public void get_note_as_markdown_and_html() throws Exception {
    QualityProfileDto profile = QProfileTesting.newXooP1("org-123");
    tester.get(QualityProfileDao.class).insert(dbSession, profile);
    RuleDto rule = RuleTesting.newXooX1().setNoteData("this is *bold*");
    ruleDao.insert(dbSession, rule);
    dbSession.commit();
    ruleIndexer.index();
    activeRuleIndexer.index();
    WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
    request.setParam(WebService.Param.FIELDS, "htmlNote, mdNote");
    WsTester.Result result = request.execute();
    result.assertJson(this.getClass(), "get_note_as_markdown_and_html.json");
}
Also used : QualityProfileDao(org.sonar.db.qualityprofile.QualityProfileDao) WsTester(org.sonar.server.ws.WsTester) ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) RuleDto(org.sonar.db.rule.RuleDto) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto) Test(org.junit.Test)

Example 58 with RuleDto

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

the class SearchActionMediumTest method search_all_active_rules_params.

@Test
public void search_all_active_rules_params() throws Exception {
    QualityProfileDto profile = QProfileTesting.newXooP1("org-123");
    tester.get(QualityProfileDao.class).insert(dbSession, profile);
    RuleDto rule = RuleTesting.newXooX1();
    ruleDao.insert(dbSession, rule);
    dbSession.commit();
    RuleParamDto param = RuleParamDto.createFor(rule).setDefaultValue("some value").setType("string").setDescription("My small description").setName("my_var");
    ruleDao.insertRuleParam(dbSession, rule, param);
    RuleParamDto param2 = RuleParamDto.createFor(rule).setDefaultValue("other value").setType("integer").setDescription("My small description").setName("the_var");
    ruleDao.insertRuleParam(dbSession, rule, param2);
    ActiveRuleDto activeRule = newActiveRule(profile, rule);
    tester.get(ActiveRuleDao.class).insert(dbSession, activeRule);
    ActiveRuleParamDto activeRuleParam = ActiveRuleParamDto.createFor(param).setValue("The VALUE");
    tester.get(ActiveRuleDao.class).insertParam(dbSession, activeRule, activeRuleParam);
    ActiveRuleParamDto activeRuleParam2 = ActiveRuleParamDto.createFor(param2).setValue("The Other Value");
    tester.get(ActiveRuleDao.class).insertParam(dbSession, activeRule, activeRuleParam2);
    dbSession.commit();
    ruleIndexer.index();
    activeRuleIndexer.index();
    WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
    request.setParam(WebService.Param.TEXT_QUERY, "x1");
    request.setParam(PARAM_ACTIVATION, "true");
    request.setParam(WebService.Param.FIELDS, "params");
    WsTester.Result result = request.execute();
    result.assertJson(this.getClass(), "search_active_rules_params.json");
}
Also used : ActiveRuleDao(org.sonar.db.qualityprofile.ActiveRuleDao) QualityProfileDao(org.sonar.db.qualityprofile.QualityProfileDao) WsTester(org.sonar.server.ws.WsTester) ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) RuleDto(org.sonar.db.rule.RuleDto) ActiveRuleParamDto(org.sonar.db.qualityprofile.ActiveRuleParamDto) ActiveRuleParamDto(org.sonar.db.qualityprofile.ActiveRuleParamDto) RuleParamDto(org.sonar.db.rule.RuleParamDto) ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto) Test(org.junit.Test)

Example 59 with RuleDto

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

the class CreateActionMediumTest method create_custom_rule.

@Test
public void create_custom_rule() throws Exception {
    // Template rule
    RuleDto templateRule = RuleTesting.newTemplateRule(RuleKey.of("java", "S001"));
    ruleDao.insert(session, templateRule);
    RuleParamDto param = RuleParamDto.createFor(templateRule).setName("regex").setType("STRING").setDescription("Reg ex").setDefaultValue(".*");
    ruleDao.insertRuleParam(session, templateRule, param);
    session.commit();
    WsTester.TestRequest request = wsTester.newPostRequest("api/rules", "create").setParam("custom_key", "MY_CUSTOM").setParam("template_key", templateRule.getKey().toString()).setParam("name", "My custom rule").setParam("markdown_description", "Description").setParam("severity", "MAJOR").setParam("status", "BETA").setParam("params", "regex=a.*");
    request.execute().assertJson(getClass(), "create_custom_rule.json");
}
Also used : WsTester(org.sonar.server.ws.WsTester) RuleDto(org.sonar.db.rule.RuleDto) RuleParamDto(org.sonar.db.rule.RuleParamDto) Test(org.junit.Test)

Example 60 with RuleDto

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

the class CreateActionMediumTest method create_custom_rule_with_prevent_reactivation_param_to_true.

@Test
public void create_custom_rule_with_prevent_reactivation_param_to_true() throws Exception {
    RuleDto templateRule = RuleTesting.newTemplateRule(RuleKey.of("java", "S001"));
    ruleDao.insert(session, templateRule);
    // insert a removed rule
    RuleDto customRule = RuleTesting.newCustomRule(templateRule).setRuleKey("MY_CUSTOM").setStatus(RuleStatus.REMOVED).setName("My custom rule").setDescription("Description").setDescriptionFormat(RuleDto.Format.MARKDOWN).setSeverity(Severity.MAJOR);
    tester.get(RuleDao.class).insert(session, customRule);
    session.commit();
    WsTester.TestRequest request = wsTester.newPostRequest("api/rules", "create").setParam("custom_key", "MY_CUSTOM").setParam("template_key", templateRule.getKey().toString()).setParam("name", "My custom rule").setParam("markdown_description", "Description").setParam("severity", "MAJOR").setParam("prevent_reactivation", "true");
    request.execute().assertJson(getClass(), "create_rule_with_prevent_reactivation_param_to_true.json").assertStatus(409);
}
Also used : RuleDao(org.sonar.db.rule.RuleDao) WsTester(org.sonar.server.ws.WsTester) 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