import org.sonar.api.i18n.I18n;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rules.RuleFinder;
+import org.sonar.api.rules.RulePriority;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.RequestHandler;
import org.sonar.api.server.ws.Response;
if (ruleKey.repository().equals(Rule.MANUAL_REPOSITORY_KEY)) {
org.sonar.api.rules.Rule rule = ruleFinder.findByKey(ruleKey);
if (rule != null) {
+ RulePriority severity = rule.getSeverity();
return new Rule.Builder()
.setKey(rule.getKey())
.setRepositoryKey(rule.getRepositoryKey())
.setName(rule.getName())
.setDescription(rule.getDescription())
- .setSeverity(rule.getSeverity().name())
+ .setSeverity(severity != null ? severity.name() : null)
.setStatus(rule.getStatus())
.setCreatedAt(rule.getCreatedAt())
.setUpdatedAt(rule.getUpdatedAt()).build();
}
@Test
- public void show_manuel_rule() throws Exception {
+ public void show_manual_rule() throws Exception {
String ruleKey = "manual:api";
- when(ruleFinder.findByKey(RuleKey.of("manual", "api"))).thenReturn(org.sonar.api.rules.Rule.create("manual", "api", "API").setDescription("API rule description"));
+ when(ruleFinder.findByKey(RuleKey.of("manual", "api"))).thenReturn(
+ org.sonar.api.rules.Rule.create("manual", "api", "API").setDescription("API rule description"));
MockUserSession.set();
WsTester.TestRequest request = tester.newRequest("show").setParam("key", ruleKey);
}
@Test
- public void return_not_found_on_unkwown_manual_rule() throws Exception {
+ public void show_manual_rule_without_severity() throws Exception {
+ String ruleKey = "manual:api";
+ org.sonar.api.rules.Rule rule = mock(org.sonar.api.rules.Rule.class);
+ when(rule.getKey()).thenReturn("api");
+ when(rule.getRepositoryKey()).thenReturn("manual");
+ when(rule.getName()).thenReturn("API");
+ when(rule.getDescription()).thenReturn("API rule description");
+ when(rule.getSeverity()).thenReturn(null);
+ when(ruleFinder.findByKey(RuleKey.of("manual", "api"))).thenReturn(rule);
+
+ MockUserSession.set();
+ WsTester.TestRequest request = tester.newRequest("show").setParam("key", ruleKey);
+ request.execute();
+ request.execute().assertJson(getClass(), "show_manuel_rule.json");
+ }
+
+ @Test
+ public void return_not_found_on_unknown_manual_rule() throws Exception {
String ruleKey = "manual:api";
when(rules.findByKey(RuleKey.of("squid", "AvoidCycle"))).thenReturn(null);