package org.sonar.server.rule.ws;
+import com.google.common.base.Strings;
import org.sonar.api.i18n.I18n;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.server.ws.Request;
}
private void addNote(Rule rule, JsonWriter json) {
- if (rule.ruleNote() != null && rule.ruleNote().data() != null) {
+ if (rule.ruleNote() != null && !Strings.isNullOrEmpty(rule.ruleNote().data())) {
json.prop("noteRaw", rule.ruleNote().data())
.prop("noteHtml", Markdown.convertToHtml(rule.ruleNote().data()));
}
request.execute().assertJson(getClass(), "show_rule_with_dates.json");
}
+ @Test
+ public void show_rule_with_note() throws Exception {
+ Rule rule = createStandardRule();
+ RuleNote note = mock(RuleNote.class);
+ when(note.data()).thenReturn("*Extended rule description*");
+ when(rule.ruleNote()).thenReturn(note);
+
+ when(rules.findByKey(RuleKey.of("squid", "AvoidCycle"))).thenReturn(rule);
+
+ MockUserSession.set();
+ WsTester.TestRequest request = tester.newRequest("show").setParam("key", rule.ruleKey().toString());
+ request.execute().assertJson(getClass(), "show_rule_with_note.json");
+ }
+
+ @Test
+ public void show_rule_with_tags() throws Exception {
+ Rule rule = createStandardRule();
+ when(rule.adminTags()).thenReturn(ImmutableList.of("complexity"));
+ when(rule.systemTags()).thenReturn(ImmutableList.of("security"));
+
+ when(rules.findByKey(RuleKey.of("squid", "AvoidCycle"))).thenReturn(rule);
+
+ MockUserSession.set();
+ WsTester.TestRequest request = tester.newRequest("show").setParam("key", rule.ruleKey().toString());
+ request.execute().assertJson(getClass(), "show_rule_with_tags.json");
+ }
+
private Rule create(String repoKey, String key, String name, String description) {
Rule mockRule = mock(Rule.class);
when(mockRule.repositoryKey()).thenReturn(repoKey);
when(mockRule.ruleKey()).thenReturn(RuleKey.of(repoKey, key));
when(mockRule.name()).thenReturn(name);
when(mockRule.description()).thenReturn(description);
- when(mockRule.adminTags()).thenReturn(ImmutableList.of("complexity"));
- when(mockRule.systemTags()).thenReturn(ImmutableList.of("security"));
- RuleNote note = mock(RuleNote.class);
- when(note.data()).thenReturn("*Extended rule description*");
- when(mockRule.ruleNote()).thenReturn(note);
return mockRule;
}
"key": "squid:AvoidCycle",
"name": "Avoid cycle",
"description": "Avoid cycle between packages",
- "noteRaw": "*Extended rule description*",
- "noteHtml": "<em>Extended rule description</em>",
- "tags": ["complexity"],
- "sysTags": ["security"]
+ "tags": [],
+ "sysTags": []
}
}
"key": "squid:AvoidCycle",
"name": "Avoid cycle",
"description": "Avoid cycle between packages",
- "noteRaw": "*Extended rule description*",
- "noteHtml": "<em>Extended rule description</em>",
"createdAt": "2014-01-22T19:10:03+0100",
"fCreatedAt": "Jan 22, 2014 10:03 AM",
"updatedAt": "2014-01-23T19:10:03+0100",
"fUpdatedAt": "Jan 23, 2014 10:03 AM",
- "tags": ["complexity"],
- "sysTags": ["security"]
+ "tags": [],
+ "sysTags": []
}
}
"description": "Avoid cycle between packages",
"noteRaw": "*Extended rule description*",
"noteHtml": "<em>Extended rule description</em>",
- "tags": ["Complexity"],
- "sysTags": ["Security"]
+ "tags": [],
+ "sysTags": []
}
}
"key": "squid:AvoidCycle",
"name": "Avoid cycle",
"description": "Avoid cycle between packages",
- "noteRaw": "*Extended rule description*",
- "noteHtml": "<em>Extended rule description</em>",
- "tags": ["Complexity"],
- "sysTags": ["Security"]
+ "tags": ["complexity"],
+ "sysTags": ["security"]
}
}