public class ModuleIssuesTest {
static final RuleKey SQUID_RULE_KEY = RuleKey.of("squid", "AvoidCycle");
+ static final Rule SQUID_RULE = Rule.create("squid", "AvoidCycle").setName("Avoid Cycle");
@Mock
IssueCache cache;
verifyZeroInteractions(cache);
}
+ @Test
+ public void fail_if_rule_has_no_name_and_issue_has_no_message() throws Exception {
+ when(ruleFinder.findByKey(SQUID_RULE_KEY)).thenReturn(Rule.create("squid", "AvoidCycle"));
+ DefaultIssue issue = new DefaultIssue().setRuleKey(SQUID_RULE_KEY).setMessage("");
+
+ try {
+ moduleIssues.initAndAddIssue(issue);
+ fail();
+ } catch (Exception e) {
+ assertThat(e).isInstanceOf(MessageException.class);
+ }
+
+ verifyZeroInteractions(cache);
+ }
+
@Test
public void ignore_null_active_rule() throws Exception {
when(qProfile.getActiveRule(anyString(), anyString())).thenReturn(null);
- when(ruleFinder.findByKey(SQUID_RULE_KEY)).thenReturn(Rule.create("squid", "AvoidCycle"));
+ when(ruleFinder.findByKey(SQUID_RULE_KEY)).thenReturn(SQUID_RULE);
DefaultIssue issue = new DefaultIssue().setRuleKey(SQUID_RULE_KEY);
boolean added = moduleIssues.initAndAddIssue(issue);
ActiveRule activeRule = mock(ActiveRule.class);
when(activeRule.getRule()).thenReturn(null);
when(qProfile.getActiveRule(anyString(), anyString())).thenReturn(activeRule);
- when(ruleFinder.findByKey(SQUID_RULE_KEY)).thenReturn(Rule.create("squid", "AvoidCycle"));
+ when(ruleFinder.findByKey(SQUID_RULE_KEY)).thenReturn(SQUID_RULE);
DefaultIssue issue = new DefaultIssue().setRuleKey(SQUID_RULE_KEY);
boolean added = moduleIssues.initAndAddIssue(issue);
@Test
public void add_issue_to_cache() throws Exception {
- Rule rule = Rule.create("squid", "AvoidCycle");
+ Rule rule = SQUID_RULE;
ActiveRule activeRule = mock(ActiveRule.class);
when(activeRule.getRule()).thenReturn(rule);
when(activeRule.getSeverity()).thenReturn(RulePriority.INFO);
when(qProfile.getActiveRule("squid", "AvoidCycle")).thenReturn(activeRule);
- when(ruleFinder.findByKey(SQUID_RULE_KEY)).thenReturn(Rule.create("squid", "AvoidCycle"));
+ when(ruleFinder.findByKey(SQUID_RULE_KEY)).thenReturn(rule);
Date analysisDate = new Date();
when(project.getAnalysisDate()).thenReturn(analysisDate);
@Test
public void use_severity_from_active_rule_if_no_severity() throws Exception {
- Rule rule = Rule.create("squid", "AvoidCycle");
+ Rule rule = SQUID_RULE;
ActiveRule activeRule = mock(ActiveRule.class);
when(activeRule.getRule()).thenReturn(rule);
when(activeRule.getSeverity()).thenReturn(RulePriority.INFO);
when(qProfile.getActiveRule("squid", "AvoidCycle")).thenReturn(activeRule);
- when(ruleFinder.findByKey(SQUID_RULE_KEY)).thenReturn(Rule.create("squid", "AvoidCycle"));
+ when(ruleFinder.findByKey(SQUID_RULE_KEY)).thenReturn(rule);
Date analysisDate = new Date();
when(project.getAnalysisDate()).thenReturn(analysisDate);
@Test
public void use_rule_name_if_no_message() throws Exception {
- Rule rule = Rule.create("squid", "AvoidCycle");
+ Rule rule = SQUID_RULE;
ActiveRule activeRule = mock(ActiveRule.class);
when(activeRule.getRule()).thenReturn(rule);
when(activeRule.getSeverity()).thenReturn(RulePriority.INFO);
when(qProfile.getActiveRule("squid", "AvoidCycle")).thenReturn(activeRule);
- when(ruleFinder.findByKey(SQUID_RULE_KEY)).thenReturn(Rule.create("squid", "AvoidCycle").setName("Avoid Cycle"));
+ when(ruleFinder.findByKey(SQUID_RULE_KEY)).thenReturn(rule);
Date analysisDate = new Date();
when(project.getAnalysisDate()).thenReturn(analysisDate);
@Test
public void add_deprecated_violation() throws Exception {
- Rule rule = Rule.create("squid", "AvoidCycle");
+ Rule rule = SQUID_RULE;
Resource resource = new JavaFile("org.struts.Action").setEffectiveKey("struts:org.struts.Action");
Violation violation = new Violation(rule, resource);
violation.setLineId(42);
when(activeRule.getRule()).thenReturn(rule);
when(activeRule.getSeverity()).thenReturn(RulePriority.INFO);
when(qProfile.getActiveRule("squid", "AvoidCycle")).thenReturn(activeRule);
- when(ruleFinder.findByKey(SQUID_RULE_KEY)).thenReturn(Rule.create("squid", "AvoidCycle"));
+ when(ruleFinder.findByKey(SQUID_RULE_KEY)).thenReturn(rule);
when(filters.accept(any(DefaultIssue.class), eq(violation))).thenReturn(true);
boolean added = moduleIssues.initAndAddViolation(violation);
@Test
public void filter_issue() throws Exception {
- Rule rule = Rule.create("squid", "AvoidCycle");
+ Rule rule = SQUID_RULE;
ActiveRule activeRule = mock(ActiveRule.class);
when(activeRule.getRule()).thenReturn(rule);
when(activeRule.getSeverity()).thenReturn(RulePriority.INFO);
when(qProfile.getActiveRule("squid", "AvoidCycle")).thenReturn(activeRule);
- when(ruleFinder.findByKey(SQUID_RULE_KEY)).thenReturn(Rule.create("squid", "AvoidCycle"));
+ when(ruleFinder.findByKey(SQUID_RULE_KEY)).thenReturn(rule);
DefaultIssue issue = new DefaultIssue()
.setKey("ABCDE")
@Test
public void set_remediation_cost() throws Exception {
- Rule rule = Rule.create("squid", "AvoidCycle");
+ Rule rule = SQUID_RULE;
ActiveRule activeRule = mock(ActiveRule.class);
when(activeRule.getRule()).thenReturn(rule);
when(activeRule.getSeverity()).thenReturn(RulePriority.INFO);
when(qProfile.getActiveRule("squid", "AvoidCycle")).thenReturn(activeRule);
- when(ruleFinder.findByKey(SQUID_RULE_KEY)).thenReturn(Rule.create("squid", "AvoidCycle"));
+ when(ruleFinder.findByKey(SQUID_RULE_KEY)).thenReturn(rule);
Date analysisDate = new Date();
when(project.getAnalysisDate()).thenReturn(analysisDate);
Component component = result.component(issue);
Component project = result.project(issue);
String actionPlanKey = issue.actionPlanKey();
+ ActionPlan actionPlan = result.actionPlan(issue);
WorkDayDuration technicalDebt = issue.technicalDebt();
Date updateDate = issue.updateDate();
Date closeDate = issue.closeDate();
.prop("severity", issue.severity())
.prop("author", issue.authorLogin())
.prop("actionPlan", actionPlanKey)
+ .prop("actionPlanName", actionPlan != null ? actionPlan.name() : null)
.prop("debt", technicalDebt != null ? debtFormatter.format(UserSession.get().locale(), technicalDebt) : null)
- .prop("actionPlanName", actionPlanKey != null ? result.actionPlan(issue).name() : null)
.prop("creationDate", DateUtils.formatDateTime(issue.creationDate()))
.prop("fCreationDate", formatDate(issue.creationDate()))
.prop("updateDate", updateDate != null ? DateUtils.formatDateTime(updateDate) : null)
private void addCharacteristics(IssueQueryResult result, DefaultIssue issue, JsonWriter json) {
Characteristic requirement = technicalDebtManager.findRequirementByRule(result.rule(issue));
// Requirement can be null if it has been disabled
- if (requirement != null) {
+ if (requirement != null && requirement.rootId() != null && requirement.parentId() != null) {
Characteristic characteristic = technicalDebtManager.findCharacteristicById(requirement.rootId());
json.prop("characteristic", characteristic != null ? characteristic.name() : null);
Characteristic subCharacteristic = technicalDebtManager.findCharacteristicById(requirement.parentId());
String login = UserSession.get().login();
for (IssueComment comment : issue.comments()) {
String userLogin = comment.userLogin();
+ User user = userLogin != null ? queryResult.user(userLogin) : null;
json
.beginObject()
.prop("key", comment.key())
- .prop("userName", userLogin != null ? queryResult.user(userLogin).name() : null)
+ .prop("userName", user != null ? user.name() : null)
.prop("raw", comment.markdownText())
.prop("html", Markdown.convertToHtml(comment.markdownText()))
.prop("createdAt", DateUtils.formatDateTime(comment.createdAt()))
.prop("fCreatedAge", formatAgeDate(comment.createdAt()))
- .prop("updatable", login != null && login.equals(comment.userLogin()))
+ .prop("updatable", login != null && login.equals(userLogin))
.endObject();
}
json.endArray();