use of org.sonar.server.rule.NewCustomRule 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");
}
use of org.sonar.server.rule.NewCustomRule in project sonarqube by SonarSource.
the class CreateAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
String customKey = request.mandatoryParam(PARAM_CUSTOM_KEY);
try (DbSession dbSession = dbClient.openSession(false)) {
try {
NewCustomRule newRule = NewCustomRule.createForCustomRule(customKey, RuleKey.parse(request.mandatoryParam(PARAM_TEMPLATE_KEY))).setName(request.mandatoryParam(PARAM_NAME)).setMarkdownDescription(request.mandatoryParam(PARAM_DESCRIPTION)).setSeverity(request.mandatoryParam(PARAM_SEVERITY)).setStatus(RuleStatus.valueOf(request.mandatoryParam(PARAM_STATUS))).setPreventReactivation(request.mandatoryParamAsBoolean(PARAM_PREVENT_REACTIVATION));
String params = request.param(PARAMS);
if (!isNullOrEmpty(params)) {
newRule.setParameters(KeyValueFormat.parse(params));
}
writeResponse(dbSession, request, response, ruleCreator.create(newRule));
} catch (ReactivationException e) {
write409(dbSession, request, response, e.ruleKey());
}
}
}
use of org.sonar.server.rule.NewCustomRule in project sonarqube by SonarSource.
the class UpdateActionMediumTest method update_custom_rule.
@Test
public void update_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();
// Custom rule
NewCustomRule newRule = NewCustomRule.createForCustomRule("MY_CUSTOM", templateRule.getKey()).setName("Old custom").setHtmlDescription("Old description").setSeverity(Severity.MINOR).setStatus(RuleStatus.BETA).setParameters(ImmutableMap.of("regex", "a"));
RuleKey customRuleKey = tester.get(RuleCreator.class).create(newRule);
session.clearCache();
WsTester.TestRequest request = wsTester.newPostRequest("api/rules", "update").setParam("key", customRuleKey.toString()).setParam("name", "My custom rule").setParam("markdown_description", "Description").setParam("severity", "MAJOR").setParam("status", "BETA").setParam("params", "regex=a.*");
request.execute().assertJson(getClass(), "update_custom_rule.json");
}
Aggregations