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