From c85249a0cabf07007a3b52253873c6ceaadf9c48 Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20Lesaint?= Date: Thu, 14 Sep 2017 11:01:58 +0200 Subject: [PATCH] SONAR-8730 replace severity by rule type in new issues notifications --- .../step/SendIssueNotificationsStep.java | 2 +- .../AbstractNewIssuesEmailTemplate.java | 25 ++-- .../MyNewIssuesEmailTemplate.java | 2 +- .../notification/NewIssuesNotification.java | 27 ++-- .../notification/NewIssuesStatistics.java | 26 ++-- .../step/SendIssueNotificationsStepTest.java | 34 ++--- .../MyNewIssuesEmailTemplateTest.java | 73 +++++++--- .../NewIssuesEmailTemplateTest.java | 82 +++++++---- .../NewIssuesNotificationTest.java | 23 ++- .../notification/NewIssuesStatisticsTest.java | 135 +++++++----------- .../email_with_all_details.txt | 20 --- .../email_with_issue_on_branch.txt | 8 -- ...email_with_no_assignee_tags_components.txt | 8 -- .../email_with_all_details.txt | 24 ---- .../email_with_issue_on_branch.txt | 8 -- .../email_with_partial_details.txt | 8 -- .../tests/issue/IssueNotificationsTest.java | 2 +- 17 files changed, 231 insertions(+), 276 deletions(-) delete mode 100644 server/sonar-server/src/test/resources/org/sonar/server/issue/notification/MyNewIssuesEmailTemplateTest/email_with_all_details.txt delete mode 100644 server/sonar-server/src/test/resources/org/sonar/server/issue/notification/MyNewIssuesEmailTemplateTest/email_with_issue_on_branch.txt delete mode 100644 server/sonar-server/src/test/resources/org/sonar/server/issue/notification/MyNewIssuesEmailTemplateTest/email_with_no_assignee_tags_components.txt delete mode 100644 server/sonar-server/src/test/resources/org/sonar/server/issue/notification/NewIssuesEmailTemplateTest/email_with_all_details.txt delete mode 100644 server/sonar-server/src/test/resources/org/sonar/server/issue/notification/NewIssuesEmailTemplateTest/email_with_issue_on_branch.txt delete mode 100644 server/sonar-server/src/test/resources/org/sonar/server/issue/notification/NewIssuesEmailTemplateTest/email_with_partial_details.txt diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/SendIssueNotificationsStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/SendIssueNotificationsStep.java index 6bf79d4b85d..ff8bc5ad97b 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/SendIssueNotificationsStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/SendIssueNotificationsStep.java @@ -91,7 +91,7 @@ public class SendIssueNotificationsStep implements ComputationStep { private void doExecute(Component project) { long analysisDate = analysisMetadataHolder.getAnalysisDate(); - Predicate isOnLeakPredicate = i -> i.isNew() && i.creationDate().getTime() >= truncateToSeconds(analysisDate); + Predicate isOnLeakPredicate = i -> i.isNew() && i.creationDate().getTime() >= truncateToSeconds(analysisDate); NewIssuesStatistics newIssuesStats = new NewIssuesStatistics(isOnLeakPredicate); try (CloseableIterator issues = issueCache.traverse()) { processIssues(newIssuesStats, issues, project); diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/notification/AbstractNewIssuesEmailTemplate.java b/server/sonar-server/src/main/java/org/sonar/server/issue/notification/AbstractNewIssuesEmailTemplate.java index 8b66c747288..e720fa8c9ee 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/notification/AbstractNewIssuesEmailTemplate.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/notification/AbstractNewIssuesEmailTemplate.java @@ -19,16 +19,16 @@ */ package org.sonar.server.issue.notification; -import com.google.common.collect.Lists; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; +import java.util.Arrays; import java.util.Date; import java.util.Iterator; import java.util.Locale; import org.sonar.api.config.EmailSettings; import org.sonar.api.i18n.I18n; import org.sonar.api.notifications.Notification; -import org.sonar.api.rule.Severity; +import org.sonar.api.rules.RuleType; import org.sonar.api.utils.DateUtils; import org.sonar.plugins.emailnotifications.api.EmailMessage; import org.sonar.plugins.emailnotifications.api.EmailTemplate; @@ -79,7 +79,7 @@ public abstract class AbstractNewIssuesEmailTemplate extends EmailTemplate { StringBuilder message = new StringBuilder(); message.append("Project: ").append(projectName).append(NEW_LINE).append(NEW_LINE); - appendSeverity(message, notification); + appendRuleType(message, notification); appendAssignees(message, notification); appendRules(message, notification); appendTags(message, notification); @@ -97,7 +97,7 @@ public abstract class AbstractNewIssuesEmailTemplate extends EmailTemplate { protected String subject(Notification notification, String projectName) { return String.format("%s: %s new issues (new debt: %s)", projectName, - notification.getFieldValue(Metric.SEVERITY + COUNT), + notification.getFieldValue(Metric.RULE_TYPE + COUNT), notification.getFieldValue(Metric.EFFORT + COUNT)); } @@ -145,23 +145,24 @@ public abstract class AbstractNewIssuesEmailTemplate extends EmailTemplate { genericAppendOfMetric(Metric.RULE, "Rules", message, notification); } - protected void appendSeverity(StringBuilder message, Notification notification) { + protected void appendRuleType(StringBuilder message, Notification notification) { message .append(String.format("%s new issues (new debt: %s)", - notification.getFieldValue(Metric.SEVERITY + COUNT), + notification.getFieldValue(Metric.RULE_TYPE + COUNT), notification.getFieldValue(Metric.EFFORT + COUNT))) .append(NEW_LINE).append(NEW_LINE) .append(TAB) - .append("Severity") + .append("Type") .append(NEW_LINE) .append(TAB) .append(TAB); - for (Iterator severityIterator = Lists.reverse(Severity.ALL).iterator(); severityIterator.hasNext();) { - String severity = severityIterator.next(); - String severityLabel = i18n.message(getLocale(), "severity." + severity, severity); - message.append(severityLabel).append(": ").append(notification.getFieldValue(Metric.SEVERITY + DOT + severity + COUNT)); - if (severityIterator.hasNext()) { + + for (Iterator ruleTypeIterator = Arrays.asList(RuleType.BUG, RuleType.VULNERABILITY, RuleType.CODE_SMELL).iterator(); ruleTypeIterator.hasNext();) { + RuleType ruleType = ruleTypeIterator.next(); + String ruleTypeLabel = i18n.message(getLocale(), "rule_type." + ruleType, ruleType.name()); + message.append(ruleTypeLabel).append(": ").append(notification.getFieldValue(Metric.RULE_TYPE + DOT + ruleType + COUNT)); + if (ruleTypeIterator.hasNext()) { message.append(TAB); } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/notification/MyNewIssuesEmailTemplate.java b/server/sonar-server/src/main/java/org/sonar/server/issue/notification/MyNewIssuesEmailTemplate.java index 5b1a35ecb31..c112a77d6a9 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/notification/MyNewIssuesEmailTemplate.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/notification/MyNewIssuesEmailTemplate.java @@ -49,7 +49,7 @@ public class MyNewIssuesEmailTemplate extends AbstractNewIssuesEmailTemplate { @Override protected String subject(Notification notification, String projectName) { return String.format("You have %s new issues on project %s", - notification.getFieldValue(Metric.SEVERITY + COUNT), + notification.getFieldValue(Metric.RULE_TYPE + COUNT), projectName); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/notification/NewIssuesNotification.java b/server/sonar-server/src/main/java/org/sonar/server/issue/notification/NewIssuesNotification.java index 7475b14c97f..b2e4d46f6e2 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/notification/NewIssuesNotification.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/notification/NewIssuesNotification.java @@ -19,7 +19,7 @@ */ package org.sonar.server.issue.notification; -import com.google.common.collect.ImmutableMap; +import java.util.Arrays; import java.util.Comparator; import java.util.Date; import java.util.List; @@ -30,7 +30,7 @@ import java.util.function.ToIntFunction; import javax.annotation.Nullable; import org.sonar.api.notifications.Notification; import org.sonar.api.rule.RuleKey; -import org.sonar.api.rule.Severity; +import org.sonar.api.rules.RuleType; import org.sonar.api.utils.DateUtils; import org.sonar.api.utils.Duration; import org.sonar.api.utils.Durations; @@ -49,7 +49,7 @@ import static org.sonar.server.issue.notification.NewIssuesEmailTemplate.FIELD_P import static org.sonar.server.issue.notification.NewIssuesEmailTemplate.FIELD_PROJECT_KEY; import static org.sonar.server.issue.notification.NewIssuesEmailTemplate.FIELD_PROJECT_NAME; import static org.sonar.server.issue.notification.NewIssuesEmailTemplate.FIELD_PROJECT_UUID; -import static org.sonar.server.issue.notification.NewIssuesStatistics.Metric.SEVERITY; +import static org.sonar.server.issue.notification.NewIssuesStatistics.Metric.RULE_TYPE; public class NewIssuesNotification extends Notification { @@ -90,10 +90,10 @@ public class NewIssuesNotification extends Notification { } public NewIssuesNotification setStatistics(String projectName, NewIssuesStatistics.Stats stats) { - setDefaultMessage(stats.getDistributedMetricStats(SEVERITY).getOnLeak() + " new issues on " + projectName + ".\n"); + setDefaultMessage(stats.getDistributedMetricStats(RULE_TYPE).getOnLeak() + " new issues on " + projectName + ".\n"); try (DbSession dbSession = dbClient.openSession(false)) { - setSeverityStatistics(stats); + setRuleTypeStatistics(stats); setAssigneesStatistics(stats); setTagsStatistics(stats); setComponentsStatistics(dbSession, stats); @@ -111,7 +111,7 @@ public class NewIssuesNotification extends Notification { .map(Map.Entry::getKey) .map(RuleKey::parse) .collect(MoreCollectors.toSet(fiveBiggest.size())); - ImmutableMap ruleByRuleKey = dbClient.ruleDao().selectDefinitionByKeys(dbSession, ruleKeys) + Map ruleByRuleKey = dbClient.ruleDao().selectDefinitionByKeys(dbSession, ruleKeys) .stream() .collect(MoreCollectors.uniqueIndex(s -> s.getKey().toString())); int i = 1; @@ -186,14 +186,13 @@ public class NewIssuesNotification extends Notification { return this; } - private void setSeverityStatistics(NewIssuesStatistics.Stats stats) { - DistributedMetricStatsInt distributedMetricStats = stats.getDistributedMetricStats(SEVERITY); - setFieldValue(SEVERITY + COUNT, String.valueOf(distributedMetricStats.getOnLeak())); - for (String severity : Severity.ALL) { - setFieldValue( - SEVERITY + DOT + severity + COUNT, - String.valueOf(distributedMetricStats.getForLabel(severity).map(MetricStatsInt::getOnLeak).orElse(0))); - } + private void setRuleTypeStatistics(NewIssuesStatistics.Stats stats) { + DistributedMetricStatsInt distributedMetricStats = stats.getDistributedMetricStats(RULE_TYPE); + setFieldValue(RULE_TYPE + COUNT, String.valueOf(distributedMetricStats.getOnLeak())); + Arrays.stream(RuleType.values()) + .forEach(ruleType -> setFieldValue( + RULE_TYPE + DOT + ruleType + COUNT, + String.valueOf(distributedMetricStats.getForLabel(ruleType.name()).map(MetricStatsInt::getOnLeak).orElse(0)))); } @Override diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/notification/NewIssuesStatistics.java b/server/sonar-server/src/main/java/org/sonar/server/issue/notification/NewIssuesStatistics.java index 3d39a6ccca9..a66f84e035b 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/notification/NewIssuesStatistics.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/notification/NewIssuesStatistics.java @@ -23,27 +23,27 @@ import java.util.EnumMap; import java.util.LinkedHashMap; import java.util.Map; import java.util.function.Predicate; -import org.sonar.api.issue.Issue; import org.sonar.api.rule.RuleKey; import org.sonar.api.utils.Duration; +import org.sonar.core.issue.DefaultIssue; import static org.sonar.server.issue.notification.NewIssuesStatistics.Metric.ASSIGNEE; import static org.sonar.server.issue.notification.NewIssuesStatistics.Metric.COMPONENT; import static org.sonar.server.issue.notification.NewIssuesStatistics.Metric.RULE; -import static org.sonar.server.issue.notification.NewIssuesStatistics.Metric.SEVERITY; +import static org.sonar.server.issue.notification.NewIssuesStatistics.Metric.RULE_TYPE; import static org.sonar.server.issue.notification.NewIssuesStatistics.Metric.TAG; public class NewIssuesStatistics { - private final Predicate onLeakPredicate; + private final Predicate onLeakPredicate; private final Map assigneesStatistics = new LinkedHashMap<>(); private final Stats globalStatistics; - public NewIssuesStatistics(Predicate onLeakPredicate) { + public NewIssuesStatistics(Predicate onLeakPredicate) { this.onLeakPredicate = onLeakPredicate; this.globalStatistics = new Stats(onLeakPredicate); } - public void add(Issue issue) { + public void add(DefaultIssue issue) { globalStatistics.add(issue); String login = issue.assignee(); if (login != null) { @@ -72,7 +72,7 @@ public class NewIssuesStatistics { } public enum Metric { - SEVERITY(true), TAG(true), COMPONENT(true), ASSIGNEE(true), EFFORT(false), RULE(true); + RULE_TYPE(true), TAG(true), COMPONENT(true), ASSIGNEE(true), EFFORT(false), RULE(true); private final boolean isComputedByDistribution; Metric(boolean isComputedByDistribution) { @@ -93,11 +93,11 @@ public class NewIssuesStatistics { } public static class Stats { - private final Predicate onLeakPredicate; + private final Predicate onLeakPredicate; private final Map distributions = new EnumMap<>(Metric.class); private MetricStatsLong effortStats = new MetricStatsLong(); - public Stats(Predicate onLeakPredicate) { + public Stats(Predicate onLeakPredicate) { this.onLeakPredicate = onLeakPredicate; for (Metric metric : Metric.values()) { if (metric.isComputedByDistribution()) { @@ -106,9 +106,9 @@ public class NewIssuesStatistics { } } - public void add(Issue issue) { + public void add(DefaultIssue issue) { boolean isOnLeak = onLeakPredicate.test(issue); - distributions.get(SEVERITY).increment(issue.severity(), isOnLeak); + distributions.get(RULE_TYPE).increment(issue.type().name(), isOnLeak); String componentUuid = issue.componentUuid(); if (componentUuid != null) { distributions.get(COMPONENT).increment(componentUuid, isOnLeak); @@ -139,15 +139,15 @@ public class NewIssuesStatistics { } public boolean hasIssues() { - return getDistributedMetricStats(SEVERITY).getTotal() > 0; + return getDistributedMetricStats(RULE_TYPE).getTotal() > 0; } public boolean hasIssuesOnLeak() { - return getDistributedMetricStats(SEVERITY).getOnLeak() > 0; + return getDistributedMetricStats(RULE_TYPE).getOnLeak() > 0; } public boolean hasIssuesOffLeak() { - return getDistributedMetricStats(SEVERITY).getOffLeak() > 0; + return getDistributedMetricStats(RULE_TYPE).getOffLeak() > 0; } @Override diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/SendIssueNotificationsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/SendIssueNotificationsStepTest.java index 5456d7625a9..016cc0e584e 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/SendIssueNotificationsStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/SendIssueNotificationsStepTest.java @@ -34,7 +34,7 @@ import org.junit.rules.TemporaryFolder; import org.mockito.ArgumentCaptor; import org.mockito.exceptions.verification.junit.ArgumentsAreDifferent; import org.sonar.api.notifications.Notification; -import org.sonar.api.rule.Severity; +import org.sonar.api.rules.RuleType; import org.sonar.api.utils.Duration; import org.sonar.api.utils.System2; import org.sonar.core.issue.DefaultIssue; @@ -101,6 +101,8 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { @Rule public TemporaryFolder temp = new TemporaryFolder(); + private final Random random = new Random(); + private final RuleType randomRuleType = RuleType.values()[random.nextInt(RuleType.values().length)]; private NotificationService notificationService = mock(NotificationService.class); private NewIssuesNotificationFactory newIssuesNotificationFactory = mock(NewIssuesNotificationFactory.class); private NewIssuesNotification newIssuesNotificationMock = createNewIssuesNotificationMock(); @@ -131,7 +133,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { @Test public void send_global_new_issues_notification() throws Exception { issueCache.newAppender().append( - new DefaultIssue().setSeverity(Severity.BLOCKER).setEffort(ISSUE_DURATION) + new DefaultIssue().setType(randomRuleType).setEffort(ISSUE_DURATION) .setCreationDate(new Date(ANALYSE_DATE))) .close(); when(notificationService.hasProjectSubscribersForTypes(PROJECT.getUuid(), SendIssueNotificationsStep.NOTIF_TYPES)).thenReturn(true); @@ -152,10 +154,10 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { Integer[] backDatedEfforts = IntStream.range(0, 1 + random.nextInt(10)).mapToObj(i -> 10 + random.nextInt(100)).toArray(Integer[]::new); Duration expectedEffort = Duration.create(Arrays.stream(efforts).mapToInt(i -> i).sum()); List issues = Stream.concat(Arrays.stream(efforts) - .map(effort -> new DefaultIssue().setSeverity(Severity.BLOCKER).setEffort(Duration.create(effort)) + .map(effort -> new DefaultIssue().setType(randomRuleType).setEffort(Duration.create(effort)) .setCreationDate(new Date(ANALYSE_DATE))), Arrays.stream(backDatedEfforts) - .map(effort -> new DefaultIssue().setSeverity(Severity.BLOCKER).setEffort(Duration.create(effort)) + .map(effort -> new DefaultIssue().setType(randomRuleType).setEffort(Duration.create(effort)) .setCreationDate(new Date(ANALYSE_DATE - FIVE_MINUTES_IN_MS)))) .collect(Collectors.toList()); Collections.shuffle(issues); @@ -172,7 +174,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { NewIssuesStatistics.Stats stats = statsCaptor.getValue(); assertThat(stats.hasIssues()).isTrue(); // just checking all issues have been added to the stats - DistributedMetricStatsInt severity = stats.getDistributedMetricStats(NewIssuesStatistics.Metric.SEVERITY); + DistributedMetricStatsInt severity = stats.getDistributedMetricStats(NewIssuesStatistics.Metric.RULE_TYPE); assertThat(severity.getOnLeak()).isEqualTo(efforts.length); assertThat(severity.getOffLeak()).isEqualTo(backDatedEfforts.length); assertThat(severity.getTotal()).isEqualTo(backDatedEfforts.length + efforts.length); @@ -181,7 +183,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { @Test public void do_not_send_global_new_issues_notification_if_issue_has_been_backdated() { issueCache.newAppender().append( - new DefaultIssue().setSeverity(Severity.BLOCKER).setEffort(ISSUE_DURATION) + new DefaultIssue().setType(randomRuleType).setEffort(ISSUE_DURATION) .setCreationDate(new Date(ANALYSE_DATE - FIVE_MINUTES_IN_MS))) .close(); when(notificationService.hasProjectSubscribersForTypes(PROJECT.getUuid(), SendIssueNotificationsStep.NOTIF_TYPES)).thenReturn(true); @@ -195,7 +197,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { public void send_global_new_issues_notification_on_branch() throws Exception { ComponentDto branch = setUpProjectWithBranch(); issueCache.newAppender().append( - new DefaultIssue().setSeverity(Severity.BLOCKER).setEffort(ISSUE_DURATION).setCreationDate(new Date(ANALYSE_DATE))).close(); + new DefaultIssue().setType(randomRuleType).setEffort(ISSUE_DURATION).setCreationDate(new Date(ANALYSE_DATE))).close(); when(notificationService.hasProjectSubscribersForTypes(branch.uuid(), SendIssueNotificationsStep.NOTIF_TYPES)).thenReturn(true); analysisMetadataHolder.setBranch(newBranch()); @@ -212,7 +214,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { public void do_not_send_global_new_issues_notification_on_branch_if_issue_has_been_backdated() throws Exception { ComponentDto branch = setUpProjectWithBranch(); issueCache.newAppender().append( - new DefaultIssue().setSeverity(Severity.BLOCKER).setEffort(ISSUE_DURATION).setCreationDate(new Date(ANALYSE_DATE - FIVE_MINUTES_IN_MS))).close(); + new DefaultIssue().setType(randomRuleType).setEffort(ISSUE_DURATION).setCreationDate(new Date(ANALYSE_DATE - FIVE_MINUTES_IN_MS))).close(); when(notificationService.hasProjectSubscribersForTypes(branch.uuid(), SendIssueNotificationsStep.NOTIF_TYPES)).thenReturn(true); analysisMetadataHolder.setBranch(newBranch()); @@ -224,7 +226,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { @Test public void send_new_issues_notification_to_user() throws Exception { issueCache.newAppender().append( - new DefaultIssue().setSeverity(Severity.BLOCKER).setEffort(ISSUE_DURATION).setAssignee(ISSUE_ASSIGNEE) + new DefaultIssue().setType(randomRuleType).setEffort(ISSUE_DURATION).setAssignee(ISSUE_ASSIGNEE) .setCreationDate(new Date(ANALYSE_DATE))) .close(); when(notificationService.hasProjectSubscribersForTypes(PROJECT.getUuid(), SendIssueNotificationsStep.NOTIF_TYPES)).thenReturn(true); @@ -249,11 +251,11 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { String assignee = randomAlphanumeric(5); String otherAssignee = randomAlphanumeric(5); List issues = Stream.concat(Arrays.stream(assigned) - .map(effort -> new DefaultIssue().setSeverity(Severity.BLOCKER).setEffort(Duration.create(effort)) + .map(effort -> new DefaultIssue().setType(randomRuleType).setEffort(Duration.create(effort)) .setAssignee(assignee) .setCreationDate(new Date(ANALYSE_DATE))), Arrays.stream(assignedToOther) - .map(effort -> new DefaultIssue().setSeverity(Severity.BLOCKER).setEffort(Duration.create(effort)) + .map(effort -> new DefaultIssue().setType(randomRuleType).setEffort(Duration.create(effort)) .setAssignee(otherAssignee) .setCreationDate(new Date(ANALYSE_DATE)))) .collect(Collectors.toList()); @@ -288,7 +290,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { NewIssuesStatistics.Stats stats = statsCaptor.getValue(); assertThat(stats.hasIssues()).isTrue(); // just checking all issues have been added to the stats - DistributedMetricStatsInt severity = stats.getDistributedMetricStats(NewIssuesStatistics.Metric.SEVERITY); + DistributedMetricStatsInt severity = stats.getDistributedMetricStats(NewIssuesStatistics.Metric.RULE_TYPE); assertThat(severity.getOnLeak()).isEqualTo(assigned.length); assertThat(severity.getOffLeak()).isEqualTo(0); assertThat(severity.getTotal()).isEqualTo(assigned.length); @@ -301,11 +303,11 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { Integer[] backDatedEfforts = IntStream.range(0, 1 + random.nextInt(10)).mapToObj(i -> 10 + random.nextInt(100)).toArray(Integer[]::new); Duration expectedEffort = Duration.create(Arrays.stream(efforts).mapToInt(i -> i).sum()); List issues = Stream.concat(Arrays.stream(efforts) - .map(effort -> new DefaultIssue().setSeverity(Severity.BLOCKER).setEffort(Duration.create(effort)) + .map(effort -> new DefaultIssue().setType(randomRuleType).setEffort(Duration.create(effort)) .setAssignee(ISSUE_ASSIGNEE) .setCreationDate(new Date(ANALYSE_DATE))), Arrays.stream(backDatedEfforts) - .map(effort -> new DefaultIssue().setSeverity(Severity.BLOCKER).setEffort(Duration.create(effort)) + .map(effort -> new DefaultIssue().setType(randomRuleType).setEffort(Duration.create(effort)) .setAssignee(ISSUE_ASSIGNEE) .setCreationDate(new Date(ANALYSE_DATE - FIVE_MINUTES_IN_MS)))) .collect(Collectors.toList()); @@ -325,7 +327,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { NewIssuesStatistics.Stats stats = statsCaptor.getValue(); assertThat(stats.hasIssues()).isTrue(); // just checking all issues have been added to the stats - DistributedMetricStatsInt severity = stats.getDistributedMetricStats(NewIssuesStatistics.Metric.SEVERITY); + DistributedMetricStatsInt severity = stats.getDistributedMetricStats(NewIssuesStatistics.Metric.RULE_TYPE); assertThat(severity.getOnLeak()).isEqualTo(efforts.length); assertThat(severity.getOffLeak()).isEqualTo(backDatedEfforts.length); assertThat(severity.getTotal()).isEqualTo(backDatedEfforts.length + efforts.length); @@ -334,7 +336,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { @Test public void do_not_send_new_issues_notification_to_user_if_issue_is_backdated() throws Exception { issueCache.newAppender().append( - new DefaultIssue().setSeverity(Severity.BLOCKER).setEffort(ISSUE_DURATION).setAssignee(ISSUE_ASSIGNEE) + new DefaultIssue().setType(randomRuleType).setEffort(ISSUE_DURATION).setAssignee(ISSUE_ASSIGNEE) .setCreationDate(new Date(ANALYSE_DATE - FIVE_MINUTES_IN_MS))) .close(); when(notificationService.hasProjectSubscribersForTypes(PROJECT.getUuid(), SendIssueNotificationsStep.NOTIF_TYPES)).thenReturn(true); diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/MyNewIssuesEmailTemplateTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/MyNewIssuesEmailTemplateTest.java index 5bd31513272..6d236c44a40 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/MyNewIssuesEmailTemplateTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/MyNewIssuesEmailTemplateTest.java @@ -26,7 +26,6 @@ import java.util.Locale; import org.apache.commons.io.IOUtils; import org.junit.Before; import org.junit.Test; -import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import org.sonar.api.config.EmailSettings; import org.sonar.api.notifications.Notification; @@ -44,7 +43,7 @@ import static org.mockito.Mockito.when; import static org.sonar.server.issue.notification.NewIssuesStatistics.Metric.COMPONENT; import static org.sonar.server.issue.notification.NewIssuesStatistics.Metric.EFFORT; import static org.sonar.server.issue.notification.NewIssuesStatistics.Metric.RULE; -import static org.sonar.server.issue.notification.NewIssuesStatistics.Metric.SEVERITY; +import static org.sonar.server.issue.notification.NewIssuesStatistics.Metric.RULE_TYPE; import static org.sonar.server.issue.notification.NewIssuesStatistics.Metric.TAG; public class MyNewIssuesEmailTemplateTest { @@ -62,17 +61,11 @@ public class MyNewIssuesEmailTemplateTest { date = new Date(); userIndex = mock(UserIndex.class); // returns the login passed in parameter - when(userIndex.getNullableByLogin(anyString())).thenAnswer(new Answer() { - @Override - public UserDoc answer(InvocationOnMock invocationOnMock) throws Throwable { - return new UserDoc().setName((String) invocationOnMock.getArguments()[0]); - } - }); - when(i18n.message(any(Locale.class), eq("severity.BLOCKER"), anyString())).thenReturn("Blocker"); - when(i18n.message(any(Locale.class), eq("severity.CRITICAL"), anyString())).thenReturn("Critical"); - when(i18n.message(any(Locale.class), eq("severity.MAJOR"), anyString())).thenReturn("Major"); - when(i18n.message(any(Locale.class), eq("severity.MINOR"), anyString())).thenReturn("Minor"); - when(i18n.message(any(Locale.class), eq("severity.INFO"), anyString())).thenReturn("Info"); + when(userIndex.getNullableByLogin(anyString())) + .thenAnswer((Answer) invocationOnMock -> new UserDoc().setName((String) invocationOnMock.getArguments()[0])); + when(i18n.message(any(Locale.class), eq("rule_type.BUG"), anyString())).thenReturn("Bug"); + when(i18n.message(any(Locale.class), eq("rule_type.CODE_SMELL"), anyString())).thenReturn("Code Smell"); + when(i18n.message(any(Locale.class), eq("rule_type.VULNERABILITY"), anyString())).thenReturn("Vulnerability"); underTest = new MyNewIssuesEmailTemplate(settings, i18n); } @@ -94,7 +87,27 @@ public class MyNewIssuesEmailTemplateTest { EmailMessage message = underTest.format(notification); // TODO datetime to be completed when test is isolated from JVM timezone - assertStartsWithFile(message.getMessage(), "MyNewIssuesEmailTemplateTest/email_with_all_details.txt"); + assertThat(message.getMessage()).startsWith( + "Project: Struts\n" + + "\n" + + "32 new issues (new debt: 1d3h)\n" + + "\n" + + " Type\n" + + " Bug: 1 Vulnerability: 3 Code Smell: 0\n" + + "\n" + + " Rules\n" + + " Rule the Universe (Clojure): 42\n" + + " Rule the World (Java): 5\n" + + "\n" + + " Tags\n" + + " oscar: 3\n" + + " cesar: 10\n" + + "\n" + + " Most impacted files\n" + + " /path/to/file: 3\n" + + " /path/to/directory: 7\n" + + "\n" + + "See it in SonarQube: http://nemo.sonarsource.org/project/issues?id=org.apache%3Astruts&assignees=lo.gin&createdAt=2010-05-18"); } @Test @@ -122,7 +135,15 @@ public class MyNewIssuesEmailTemplateTest { EmailMessage message = underTest.format(notification); // TODO datetime to be completed when test is isolated from JVM timezone - assertStartsWithFile(message.getMessage(), "MyNewIssuesEmailTemplateTest/email_with_no_assignee_tags_components.txt"); + assertThat(message.getMessage()) + .startsWith("Project: Struts\n" + + "\n" + + "32 new issues (new debt: 1d3h)\n" + + "\n" + + " Type\n" + + " Bug: 1 Vulnerability: 3 Code Smell: 0\n" + + "\n" + + "See it in SonarQube: http://nemo.sonarsource.org/project/issues?id=org.apache%3Astruts&assignees=lo.gin&createdAt=2010-05-18"); } @Test @@ -133,13 +154,21 @@ public class MyNewIssuesEmailTemplateTest { EmailMessage message = underTest.format(notification); // TODO datetime to be completed when test is isolated from JVM timezone - assertStartsWithFile(message.getMessage(), "MyNewIssuesEmailTemplateTest/email_with_issue_on_branch.txt"); + assertThat(message.getMessage()) + .startsWith("Project: Struts\n" + + "\n" + + "32 new issues (new debt: 1d3h)\n" + + "\n" + + " Type\n" + + " Bug: 1 Vulnerability: 3 Code Smell: 0\n" + + "\n" + + "See it in SonarQube: http://nemo.sonarsource.org/project/issues?id=org.apache%3Astruts&assignees=lo.gin&branch=feature1&createdAt=2010-05-18"); } @Test public void do_not_add_footer_when_properties_missing() { Notification notification = new Notification(MyNewIssuesNotification.MY_NEW_ISSUES_NOTIF_TYPE) - .setFieldValue(SEVERITY + ".count", "32") + .setFieldValue(RULE_TYPE + ".count", "32") .setFieldValue("projectName", "Struts"); EmailMessage message = underTest.format(notification); @@ -154,12 +183,10 @@ public class MyNewIssuesEmailTemplateTest { .setFieldValue("projectDate", "2010-05-18T14:50:45+0000") .setFieldValue("assignee", "lo.gin") .setFieldValue(EFFORT + ".count", "1d3h") - .setFieldValue(SEVERITY + ".count", "32") - .setFieldValue(SEVERITY + ".INFO.count", "1") - .setFieldValue(SEVERITY + ".MINOR.count", "3") - .setFieldValue(SEVERITY + ".MAJOR.count", "10") - .setFieldValue(SEVERITY + ".CRITICAL.count", "5") - .setFieldValue(SEVERITY + ".BLOCKER.count", "0"); + .setFieldValue(RULE_TYPE + ".count", "32") + .setFieldValue(RULE_TYPE + ".BUG.count", "1") + .setFieldValue(RULE_TYPE + ".VULNERABILITY.count", "3") + .setFieldValue(RULE_TYPE + ".CODE_SMELL.count", "0"); } private void addTags(Notification notification) { diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/NewIssuesEmailTemplateTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/NewIssuesEmailTemplateTest.java index 7c8fce8dcdd..dca87c0ead6 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/NewIssuesEmailTemplateTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/NewIssuesEmailTemplateTest.java @@ -20,10 +20,11 @@ package org.sonar.server.issue.notification; import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.Locale; import org.apache.commons.io.IOUtils; import org.junit.Before; import org.junit.Test; -import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import org.sonar.api.config.EmailSettings; import org.sonar.api.notifications.Notification; @@ -32,9 +33,6 @@ import org.sonar.plugins.emailnotifications.api.EmailMessage; import org.sonar.server.user.index.UserDoc; import org.sonar.server.user.index.UserIndex; -import java.nio.charset.StandardCharsets; -import java.util.Locale; - import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyString; @@ -45,7 +43,7 @@ import static org.sonar.server.issue.notification.NewIssuesStatistics.Metric.ASS import static org.sonar.server.issue.notification.NewIssuesStatistics.Metric.COMPONENT; import static org.sonar.server.issue.notification.NewIssuesStatistics.Metric.EFFORT; import static org.sonar.server.issue.notification.NewIssuesStatistics.Metric.RULE; -import static org.sonar.server.issue.notification.NewIssuesStatistics.Metric.SEVERITY; +import static org.sonar.server.issue.notification.NewIssuesStatistics.Metric.RULE_TYPE; import static org.sonar.server.issue.notification.NewIssuesStatistics.Metric.TAG; public class NewIssuesEmailTemplateTest { @@ -61,17 +59,11 @@ public class NewIssuesEmailTemplateTest { i18n = mock(DefaultI18n.class); userIndex = mock(UserIndex.class); // returns the login passed in parameter - when(userIndex.getNullableByLogin(anyString())).thenAnswer(new Answer() { - @Override - public UserDoc answer(InvocationOnMock invocationOnMock) throws Throwable { - return new UserDoc().setName((String) invocationOnMock.getArguments()[0]); - } - }); - when(i18n.message(any(Locale.class), eq("severity.BLOCKER"), anyString())).thenReturn("Blocker"); - when(i18n.message(any(Locale.class), eq("severity.CRITICAL"), anyString())).thenReturn("Critical"); - when(i18n.message(any(Locale.class), eq("severity.MAJOR"), anyString())).thenReturn("Major"); - when(i18n.message(any(Locale.class), eq("severity.MINOR"), anyString())).thenReturn("Minor"); - when(i18n.message(any(Locale.class), eq("severity.INFO"), anyString())).thenReturn("Info"); + when(userIndex.getNullableByLogin(anyString())) + .thenAnswer((Answer) invocationOnMock -> new UserDoc().setName((String) invocationOnMock.getArguments()[0])); + when(i18n.message(any(Locale.class), eq("rule_type.CODE_SMELL"), anyString())).thenReturn("Code Smell"); + when(i18n.message(any(Locale.class), eq("rule_type.VULNERABILITY"), anyString())).thenReturn("Vulnerability"); + when(i18n.message(any(Locale.class), eq("rule_type.BUG"), anyString())).thenReturn("Bug"); template = new NewIssuesEmailTemplate(settings, i18n); } @@ -112,7 +104,31 @@ public class NewIssuesEmailTemplateTest { EmailMessage message = template.format(notification); // TODO datetime to be completed when test is isolated from JVM timezone - assertStartsWithFile(message.getMessage(), "NewIssuesEmailTemplateTest/email_with_all_details.txt"); + assertThat(message.getMessage()) + .startsWith("Project: Struts\n" + + "\n" + + "32 new issues (new debt: 1d3h)\n" + + "\n" + + " Type\n" + + " Bug: 1 Vulnerability: 10 Code Smell: 3\n" + + "\n" + + " Assignees\n" + + " robin.williams: 5\n" + + " al.pacino: 7\n" + + "\n" + + " Rules\n" + + " Rule the Universe (Clojure): 42\n" + + " Rule the World (Java): 5\n" + + "\n" + + " Tags\n" + + " oscar: 3\n" + + " cesar: 10\n" + + "\n" + + " Most impacted files\n" + + " /path/to/file: 3\n" + + " /path/to/directory: 7\n" + + "\n" + + "See it in SonarQube: http://nemo.sonarsource.org/project/issues?id=org.apache%3Astruts&createdAt=2010-05-1"); } @Test @@ -122,7 +138,15 @@ public class NewIssuesEmailTemplateTest { EmailMessage message = template.format(notification); // TODO datetime to be completed when test is isolated from JVM timezone - assertStartsWithFile(message.getMessage(), "NewIssuesEmailTemplateTest/email_with_partial_details.txt"); + assertThat(message.getMessage()) + .startsWith("Project: Struts\n" + + "\n" + + "32 new issues (new debt: 1d3h)\n" + + "\n" + + " Type\n" + + " Bug: 1 Vulnerability: 10 Code Smell: 3\n" + + "\n" + + "See it in SonarQube: http://nemo.sonarsource.org/project/issues?id=org.apache%3Astruts&createdAt=2010-05-1"); } @Test @@ -133,13 +157,21 @@ public class NewIssuesEmailTemplateTest { EmailMessage message = template.format(notification); // TODO datetime to be completed when test is isolated from JVM timezone - assertStartsWithFile(message.getMessage(), "NewIssuesEmailTemplateTest/email_with_issue_on_branch.txt"); + assertThat(message.getMessage()) + .startsWith("Project: Struts\n" + + "\n" + + "32 new issues (new debt: 1d3h)\n" + + "\n" + + " Type\n" + + " Bug: 1 Vulnerability: 10 Code Smell: 3\n" + + "\n" + + "See it in SonarQube: http://nemo.sonarsource.org/project/issues?id=org.apache%3Astruts&branch=feature1&createdAt=2010-05-1"); } @Test public void do_not_add_footer_when_properties_missing() { Notification notification = new Notification(NewIssuesNotification.TYPE) - .setFieldValue(SEVERITY + ".count", "32") + .setFieldValue(RULE_TYPE + ".count", "32") .setFieldValue("projectName", "Struts"); EmailMessage message = template.format(notification); @@ -154,12 +186,10 @@ public class NewIssuesEmailTemplateTest { .setFieldValue("projectUuid", "ABCDE") .setFieldValue("projectDate", "2010-05-18T14:50:45+0000") .setFieldValue(EFFORT + ".count", "1d3h") - .setFieldValue(SEVERITY + ".count", "32") - .setFieldValue(SEVERITY + ".INFO.count", "1") - .setFieldValue(SEVERITY + ".MINOR.count", "3") - .setFieldValue(SEVERITY + ".MAJOR.count", "10") - .setFieldValue(SEVERITY + ".CRITICAL.count", "5") - .setFieldValue(SEVERITY + ".BLOCKER.count", "0"); + .setFieldValue(RULE_TYPE + ".count", "32") + .setFieldValue(RULE_TYPE + ".BUG.count", "1") + .setFieldValue(RULE_TYPE + ".CODE_SMELL.count", "3") + .setFieldValue(RULE_TYPE + ".VULNERABILITY.count", "10"); } private void addAssignees(Notification notification) { diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/NewIssuesNotificationTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/NewIssuesNotificationTest.java index 430c3b056ba..9ca07bbfae3 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/NewIssuesNotificationTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/NewIssuesNotificationTest.java @@ -31,7 +31,7 @@ import java.util.stream.IntStream; import org.junit.Before; import org.junit.Test; import org.sonar.api.rule.RuleKey; -import org.sonar.api.rule.Severity; +import org.sonar.api.rules.RuleType; import org.sonar.api.utils.DateUtils; import org.sonar.api.utils.Duration; import org.sonar.api.utils.Durations; @@ -57,11 +57,13 @@ import static org.sonar.server.issue.notification.NewIssuesStatistics.Metric.ASS import static org.sonar.server.issue.notification.NewIssuesStatistics.Metric.COMPONENT; import static org.sonar.server.issue.notification.NewIssuesStatistics.Metric.EFFORT; import static org.sonar.server.issue.notification.NewIssuesStatistics.Metric.RULE; -import static org.sonar.server.issue.notification.NewIssuesStatistics.Metric.SEVERITY; +import static org.sonar.server.issue.notification.NewIssuesStatistics.Metric.RULE_TYPE; import static org.sonar.server.issue.notification.NewIssuesStatistics.Metric.TAG; public class NewIssuesNotificationTest { + private final Random random = new Random(); + private final RuleType randomRuleType = RuleType.values()[random.nextInt(RuleType.values().length)]; private NewIssuesStatistics.Stats stats = new NewIssuesStatistics.Stats(i -> true); private UserIndex userIndex = mock(UserIndex.class); private DbClient dbClient = mock(DbClient.class); @@ -124,8 +126,8 @@ public class NewIssuesNotificationTest { underTest.setStatistics("project-long-name", stats); - assertThat(underTest.getFieldValue(SEVERITY + ".INFO.count")).isEqualTo("5"); - assertThat(underTest.getFieldValue(SEVERITY + ".BLOCKER.count")).isEqualTo("3"); + assertThat(underTest.getFieldValue(RULE_TYPE + ".BUG.count")).isEqualTo("5"); + assertThat(underTest.getFieldValue(RULE_TYPE + ".CODE_SMELL.count")).isEqualTo("3"); assertThat(underTest.getFieldValue(ASSIGNEE + ".1.label")).isEqualTo("maynard"); assertThat(underTest.getFieldValue(ASSIGNEE + ".1.count")).isEqualTo("5"); assertThat(underTest.getFieldValue(ASSIGNEE + ".2.label")).isEqualTo("keenan"); @@ -147,12 +149,11 @@ public class NewIssuesNotificationTest { @Test public void add_only_5_assignees_with_biggest_issue_counts() { - Random random = new Random(); String[] assignees = IntStream.range(0, 6 + random.nextInt(10)).mapToObj(s -> "assignee" + s).toArray(String[]::new); NewIssuesStatistics.Stats stats = new NewIssuesStatistics.Stats(i -> true); int i = assignees.length; for (String assignee : assignees) { - IntStream.range(0, i).mapToObj(j -> new DefaultIssue().setAssignee(assignee)).forEach(stats::add); + IntStream.range(0, i).mapToObj(j -> new DefaultIssue().setType(randomRuleType).setAssignee(assignee)).forEach(stats::add); i--; } @@ -169,12 +170,11 @@ public class NewIssuesNotificationTest { @Test public void add_only_5_components_with_biggest_issue_counts() { - Random random = new Random(); String[] componentUuids = IntStream.range(0, 6 + random.nextInt(10)).mapToObj(s -> "component_uuid_" + s).toArray(String[]::new); NewIssuesStatistics.Stats stats = new NewIssuesStatistics.Stats(i -> true); int i = componentUuids.length; for (String component : componentUuids) { - IntStream.range(0, i).mapToObj(j -> new DefaultIssue().setComponentUuid(component)).forEach(stats::add); + IntStream.range(0, i).mapToObj(j -> new DefaultIssue().setType(randomRuleType).setComponentUuid(component)).forEach(stats::add); i--; } when(componentDao.selectByUuids(dbSession, Arrays.stream(componentUuids).limit(5).collect(Collectors.toSet()))) @@ -194,13 +194,12 @@ public class NewIssuesNotificationTest { @Test public void add_only_5_rules_with_biggest_issue_counts() { - Random random = new Random(); String repository = randomAlphanumeric(4); String[] ruleKeys = IntStream.range(0, 6 + random.nextInt(10)).mapToObj(s -> "rule_" + s).toArray(String[]::new); NewIssuesStatistics.Stats stats = new NewIssuesStatistics.Stats(i -> true); int i = ruleKeys.length; for (String ruleKey : ruleKeys) { - IntStream.range(0, i).mapToObj(j -> new DefaultIssue().setRuleKey(RuleKey.of(repository, ruleKey))).forEach(stats::add); + IntStream.range(0, i).mapToObj(j -> new DefaultIssue().setType(randomRuleType).setRuleKey(RuleKey.of(repository, ruleKey))).forEach(stats::add); i--; } when(ruleDao.selectDefinitionByKeys(dbSession, Arrays.stream(ruleKeys).limit(5).map(s -> RuleKey.of(repository, s)).collect(MoreCollectors.toSet(5)))) @@ -241,7 +240,7 @@ public class NewIssuesNotificationTest { return new DefaultIssue() .setAssignee("maynard") .setComponentUuid("file-uuid") - .setSeverity(Severity.INFO) + .setType(RuleType.BUG) .setTags(Lists.newArrayList("bug", "owasp")) .setRuleKey(RuleKey.of("SonarQube", "rule-the-world")) .setEffort(Duration.create(5L)); @@ -251,7 +250,7 @@ public class NewIssuesNotificationTest { return new DefaultIssue() .setAssignee("keenan") .setComponentUuid("directory-uuid") - .setSeverity(Severity.BLOCKER) + .setType(RuleType.CODE_SMELL) .setTags(Lists.newArrayList("owasp")) .setRuleKey(RuleKey.of("SonarQube", "rule-the-universe")) .setEffort(Duration.create(10L)); diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/NewIssuesStatisticsTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/NewIssuesStatisticsTest.java index 0637551a81a..2d0c015b99e 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/NewIssuesStatisticsTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/NewIssuesStatisticsTest.java @@ -21,6 +21,7 @@ package org.sonar.server.issue.notification; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; +import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Optional; @@ -29,10 +30,12 @@ import java.util.stream.Collectors; import java.util.stream.IntStream; import java.util.stream.Stream; import javax.annotation.CheckForNull; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import org.sonar.api.issue.Issue; import org.sonar.api.rule.RuleKey; -import org.sonar.api.rule.Severity; +import org.sonar.api.rules.RuleType; import org.sonar.api.utils.Duration; import org.sonar.core.issue.DefaultIssue; import org.sonar.server.issue.notification.NewIssuesStatistics.Metric; @@ -42,8 +45,22 @@ import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; import static org.assertj.core.api.Assertions.assertThat; public class NewIssuesStatisticsTest { + @Rule + public ExpectedException expectedException = ExpectedException.none(); - NewIssuesStatistics underTest = new NewIssuesStatistics(Issue::isNew); + private final Random random = new Random(); + private RuleType randomRuleType = RuleType.values()[random.nextInt(RuleType.values().length)]; + private NewIssuesStatistics underTest = new NewIssuesStatistics(Issue::isNew); + + @Test + public void add_fails_with_NPE_if_RuleType_is_null() { + String assignee = randomAlphanumeric(10); + DefaultIssue issue = new DefaultIssue().setType(null).setAssignee(assignee).setNew(new Random().nextBoolean()); + + expectedException.expect(NullPointerException.class); + + underTest.add(issue); + } @Test public void add_issues_with_correct_global_statistics() { @@ -51,7 +68,7 @@ public class NewIssuesStatisticsTest { .setAssignee("maynard") .setComponentUuid("file-uuid") .setNew(true) - .setSeverity(Severity.INFO) + .setType(RuleType.BUG) .setRuleKey(RuleKey.of("SonarQube", "rule-the-world")) .setTags(Lists.newArrayList("bug", "owasp")) .setEffort(Duration.create(5L)); @@ -66,8 +83,8 @@ public class NewIssuesStatisticsTest { assertThat(countDistributionTotal(Metric.ASSIGNEE, "wrong.login")).isNull(); assertThat(countDistributionTotal(Metric.COMPONENT, "file-uuid")).isEqualTo(3); assertThat(countDistributionTotal(Metric.COMPONENT, "wrong-uuid")).isNull(); - assertThat(countDistributionTotal(Metric.SEVERITY, Severity.INFO)).isEqualTo(3); - assertThat(countDistributionTotal(Metric.SEVERITY, Severity.CRITICAL)).isNull(); + assertThat(countDistributionTotal(Metric.RULE_TYPE, RuleType.BUG.name())).isEqualTo(3); + assertThat(countDistributionTotal(Metric.RULE_TYPE, RuleType.CODE_SMELL.name())).isNull(); assertThat(countDistributionTotal(Metric.TAG, "owasp")).isEqualTo(3); assertThat(countDistributionTotal(Metric.TAG, "wrong-tag")).isNull(); assertThat(countDistributionTotal(Metric.RULE, "SonarQube:rule-the-world")).isEqualTo(3); @@ -79,55 +96,29 @@ public class NewIssuesStatisticsTest { } @Test - public void add_counts_issue_per_severity_on_leak_globally_and_per_assignee() { + public void add_counts_issue_per_RuleType_on_leak_globally_and_per_assignee() { String assignee = randomAlphanumeric(10); - Severity.ALL.stream() - .map(severity -> new DefaultIssue().setSeverity(severity).setAssignee(assignee).setNew(true)) + Arrays.stream(RuleType.values()) + .map(ruleType -> new DefaultIssue().setType(ruleType).setAssignee(assignee).setNew(true)) .forEach(underTest::add); - DistributedMetricStatsInt globalDistribution = underTest.globalStatistics().getDistributedMetricStats(Metric.SEVERITY); - DistributedMetricStatsInt assigneeDistribution = underTest.getAssigneesStatistics().get(assignee).getDistributedMetricStats(Metric.SEVERITY); + DistributedMetricStatsInt globalDistribution = underTest.globalStatistics().getDistributedMetricStats(Metric.RULE_TYPE); + DistributedMetricStatsInt assigneeDistribution = underTest.getAssigneesStatistics().get(assignee).getDistributedMetricStats(Metric.RULE_TYPE); Stream.of(globalDistribution, assigneeDistribution) - .forEach(distribution -> { - assertStats(distribution, Severity.INFO, 1, 0, 1); - assertStats(distribution, Severity.MAJOR, 1, 0, 1); - assertStats(distribution, Severity.CRITICAL, 1, 0, 1); - assertStats(distribution, Severity.MINOR, 1, 0, 1); - assertStats(distribution, Severity.BLOCKER, 1, 0, 1); - }); + .forEach(distribution -> Arrays.stream(RuleType.values()).forEach(ruleType -> assertStats(distribution, ruleType.name(), 1, 0, 1))); } @Test - public void add_counts_issue_per_severity_off_leak_globally_and_per_assignee() { + public void add_counts_issue_per_RuleType_off_leak_globally_and_per_assignee() { String assignee = randomAlphanumeric(10); - Severity.ALL.stream() - .map(severity -> new DefaultIssue().setSeverity(severity).setAssignee(assignee).setNew(false)) + Arrays.stream(RuleType.values()) + .map(ruleType -> new DefaultIssue().setType(ruleType).setAssignee(assignee).setNew(false)) .forEach(underTest::add); - DistributedMetricStatsInt globalDistribution = underTest.globalStatistics().getDistributedMetricStats(Metric.SEVERITY); - DistributedMetricStatsInt assigneeDistribution = underTest.getAssigneesStatistics().get(assignee).getDistributedMetricStats(Metric.SEVERITY); + DistributedMetricStatsInt globalDistribution = underTest.globalStatistics().getDistributedMetricStats(Metric.RULE_TYPE); + DistributedMetricStatsInt assigneeDistribution = underTest.getAssigneesStatistics().get(assignee).getDistributedMetricStats(Metric.RULE_TYPE); Stream.of(globalDistribution, assigneeDistribution) - .forEach(distribution -> { - assertStats(distribution, Severity.INFO, 0, 1, 1); - assertStats(distribution, Severity.MAJOR, 0, 1, 1); - assertStats(distribution, Severity.CRITICAL, 0, 1, 1); - assertStats(distribution, Severity.MINOR, 0, 1, 1); - assertStats(distribution, Severity.BLOCKER, 0, 1, 1); - }); - } - - @Test - public void add_counts_severity_if_null_globally_and_per_assignee_as_it_should_not_be_null() { - String assignee = randomAlphanumeric(10); - underTest.add(new DefaultIssue().setSeverity(null).setAssignee(assignee).setNew(new Random().nextBoolean())); - - DistributedMetricStatsInt globalDistribution = underTest.globalStatistics().getDistributedMetricStats(Metric.SEVERITY); - DistributedMetricStatsInt assigneeDistribution = underTest.getAssigneesStatistics().get(assignee).getDistributedMetricStats(Metric.SEVERITY); - Stream.of(globalDistribution, assigneeDistribution) - .forEach(distribution -> { - assertThat(distribution.getTotal()).isEqualTo(1); - assertThat(distribution.getForLabel(null).isPresent()).isTrue(); - }); + .forEach(distribution -> Arrays.stream(RuleType.values()).forEach(ruleType -> assertStats(distribution, ruleType.name(), 0, 1, 1))); } @Test @@ -135,7 +126,7 @@ public class NewIssuesStatisticsTest { List componentUuids = IntStream.range(0, 1 + new Random().nextInt(10)).mapToObj(i -> randomAlphabetic(3)).collect(Collectors.toList()); String assignee = randomAlphanumeric(10); componentUuids.stream() - .map(componentUuid -> new DefaultIssue().setComponentUuid(componentUuid).setAssignee(assignee).setNew(true)) + .map(componentUuid -> new DefaultIssue().setType(randomRuleType).setComponentUuid(componentUuid).setAssignee(assignee).setNew(true)) .forEach(underTest::add); DistributedMetricStatsInt globalDistribution = underTest.globalStatistics().getDistributedMetricStats(Metric.COMPONENT); @@ -149,7 +140,7 @@ public class NewIssuesStatisticsTest { List componentUuids = IntStream.range(0, 1 + new Random().nextInt(10)).mapToObj(i -> randomAlphabetic(3)).collect(Collectors.toList()); String assignee = randomAlphanumeric(10); componentUuids.stream() - .map(componentUuid -> new DefaultIssue().setComponentUuid(componentUuid).setAssignee(assignee).setNew(false)) + .map(componentUuid -> new DefaultIssue().setType(randomRuleType).setComponentUuid(componentUuid).setAssignee(assignee).setNew(false)) .forEach(underTest::add); DistributedMetricStatsInt globalDistribution = underTest.globalStatistics().getDistributedMetricStats(Metric.COMPONENT); @@ -162,7 +153,7 @@ public class NewIssuesStatisticsTest { @Test public void add_does_not_count_component_if_null_neither_globally_nor_per_assignee() { String assignee = randomAlphanumeric(10); - underTest.add(new DefaultIssue().setComponentUuid(null).setAssignee(assignee).setNew(new Random().nextBoolean())); + underTest.add(new DefaultIssue().setType(randomRuleType).setComponentUuid(null).setAssignee(assignee).setNew(new Random().nextBoolean())); DistributedMetricStatsInt globalDistribution = underTest.globalStatistics().getDistributedMetricStats(Metric.COMPONENT); DistributedMetricStatsInt assigneeDistribution = underTest.getAssigneesStatistics().get(assignee).getDistributedMetricStats(Metric.COMPONENT); @@ -179,7 +170,7 @@ public class NewIssuesStatisticsTest { List ruleKeys = IntStream.range(0, 1 + new Random().nextInt(10)).mapToObj(i -> randomAlphabetic(3)).collect(Collectors.toList()); String assignee = randomAlphanumeric(10); ruleKeys.stream() - .map(ruleKey -> new DefaultIssue().setRuleKey(RuleKey.of(repository, ruleKey)).setAssignee(assignee).setNew(true)) + .map(ruleKey -> new DefaultIssue().setType(randomRuleType).setRuleKey(RuleKey.of(repository, ruleKey)).setAssignee(assignee).setNew(true)) .forEach(underTest::add); DistributedMetricStatsInt globalDistribution = underTest.globalStatistics().getDistributedMetricStats(Metric.RULE); @@ -195,7 +186,7 @@ public class NewIssuesStatisticsTest { List ruleKeys = IntStream.range(0, 1 + new Random().nextInt(10)).mapToObj(i -> randomAlphabetic(3)).collect(Collectors.toList()); String assignee = randomAlphanumeric(10); ruleKeys.stream() - .map(ruleKey -> new DefaultIssue().setRuleKey(RuleKey.of(repository, ruleKey)).setAssignee(assignee).setNew(false)) + .map(ruleKey -> new DefaultIssue().setType(randomRuleType).setRuleKey(RuleKey.of(repository, ruleKey)).setAssignee(assignee).setNew(false)) .forEach(underTest::add); DistributedMetricStatsInt globalDistribution = underTest.globalStatistics().getDistributedMetricStats(Metric.RULE); @@ -207,7 +198,7 @@ public class NewIssuesStatisticsTest { @Test public void add_does_not_count_ruleKey_if_null_neither_globally_nor_per_assignee() { String assignee = randomAlphanumeric(10); - underTest.add(new DefaultIssue().setRuleKey(null).setAssignee(assignee).setNew(new Random().nextBoolean())); + underTest.add(new DefaultIssue().setType(randomRuleType).setRuleKey(null).setAssignee(assignee).setNew(new Random().nextBoolean())); DistributedMetricStatsInt globalDistribution = underTest.globalStatistics().getDistributedMetricStats(Metric.RULE); DistributedMetricStatsInt assigneeDistribution = underTest.getAssigneesStatistics().get(assignee).getDistributedMetricStats(Metric.RULE); @@ -222,7 +213,7 @@ public class NewIssuesStatisticsTest { public void add_counts_issue_per_assignee_on_leak_globally_and_per_assignee() { List assignees = IntStream.range(0, 1 + new Random().nextInt(10)).mapToObj(i -> randomAlphabetic(3)).collect(Collectors.toList()); assignees.stream() - .map(assignee -> new DefaultIssue().setAssignee(assignee).setNew(true)) + .map(assignee -> new DefaultIssue().setType(randomRuleType).setAssignee(assignee).setNew(true)) .forEach(underTest::add); DistributedMetricStatsInt globalDistribution = underTest.globalStatistics().getDistributedMetricStats(Metric.ASSIGNEE); @@ -252,7 +243,7 @@ public class NewIssuesStatisticsTest { public void add_counts_issue_per_assignee_off_leak_globally_and_per_assignee() { List assignees = IntStream.range(0, 1 + new Random().nextInt(10)).mapToObj(i -> randomAlphabetic(3)).collect(Collectors.toList()); assignees.stream() - .map(assignee -> new DefaultIssue().setAssignee(assignee).setNew(false)) + .map(assignee -> new DefaultIssue().setType(randomRuleType).setAssignee(assignee).setNew(false)) .forEach(underTest::add); DistributedMetricStatsInt globalDistribution = underTest.globalStatistics().getDistributedMetricStats(Metric.ASSIGNEE); @@ -280,7 +271,7 @@ public class NewIssuesStatisticsTest { @Test public void add_does_not_assignee_if_empty_neither_globally_nor_per_assignee() { - underTest.add(new DefaultIssue().setAssignee(null).setNew(new Random().nextBoolean())); + underTest.add(new DefaultIssue().setType(randomRuleType).setAssignee(null).setNew(new Random().nextBoolean())); DistributedMetricStatsInt globalDistribution = underTest.globalStatistics().getDistributedMetricStats(Metric.ASSIGNEE); assertThat(globalDistribution.getTotal()).isEqualTo(0); @@ -292,7 +283,7 @@ public class NewIssuesStatisticsTest { public void add_counts_issue_per_tags_on_leak_globally_and_per_assignee() { List tags = IntStream.range(0, 1 + new Random().nextInt(10)).mapToObj(i -> randomAlphabetic(3)).collect(Collectors.toList()); String assignee = randomAlphanumeric(10); - underTest.add(new DefaultIssue().setTags(tags).setAssignee(assignee).setNew(true)); + underTest.add(new DefaultIssue().setType(randomRuleType).setTags(tags).setAssignee(assignee).setNew(true)); DistributedMetricStatsInt globalDistribution = underTest.globalStatistics().getDistributedMetricStats(Metric.TAG); DistributedMetricStatsInt assigneeDistribution = underTest.getAssigneesStatistics().get(assignee).getDistributedMetricStats(Metric.TAG); @@ -304,7 +295,7 @@ public class NewIssuesStatisticsTest { public void add_counts_issue_per_tags_off_leak_globally_and_per_assignee() { List tags = IntStream.range(0, 1 + new Random().nextInt(10)).mapToObj(i -> randomAlphabetic(3)).collect(Collectors.toList()); String assignee = randomAlphanumeric(10); - underTest.add(new DefaultIssue().setTags(tags).setAssignee(assignee).setNew(false)); + underTest.add(new DefaultIssue().setType(randomRuleType).setTags(tags).setAssignee(assignee).setNew(false)); DistributedMetricStatsInt globalDistribution = underTest.globalStatistics().getDistributedMetricStats(Metric.TAG); DistributedMetricStatsInt assigneeDistribution = underTest.getAssigneesStatistics().get(assignee).getDistributedMetricStats(Metric.TAG); @@ -315,7 +306,7 @@ public class NewIssuesStatisticsTest { @Test public void add_does_not_count_tags_if_empty_neither_globally_nor_per_assignee() { String assignee = randomAlphanumeric(10); - underTest.add(new DefaultIssue().setTags(Collections.emptyList()).setAssignee(assignee).setNew(new Random().nextBoolean())); + underTest.add(new DefaultIssue().setType(randomRuleType).setTags(Collections.emptyList()).setAssignee(assignee).setNew(new Random().nextBoolean())); DistributedMetricStatsInt globalDistribution = underTest.globalStatistics().getDistributedMetricStats(Metric.TAG); DistributedMetricStatsInt assigneeDistribution = underTest.getAssigneesStatistics().get(assignee).getDistributedMetricStats(Metric.TAG); @@ -333,7 +324,7 @@ public class NewIssuesStatisticsTest { int expected = efforts.stream().mapToInt(s -> s).sum(); String assignee = randomAlphanumeric(10); efforts.stream() - .map(effort -> new DefaultIssue().setEffort(Duration.create(effort)).setAssignee(assignee).setNew(true)) + .map(effort -> new DefaultIssue().setType(randomRuleType).setEffort(Duration.create(effort)).setAssignee(assignee).setNew(true)) .forEach(underTest::add); MetricStatsLong globalDistribution = underTest.globalStatistics().effort(); @@ -353,7 +344,7 @@ public class NewIssuesStatisticsTest { int expected = efforts.stream().mapToInt(s -> s).sum(); String assignee = randomAlphanumeric(10); efforts.stream() - .map(effort -> new DefaultIssue().setEffort(Duration.create(effort)).setAssignee(assignee).setNew(false)) + .map(effort -> new DefaultIssue().setType(randomRuleType).setEffort(Duration.create(effort)).setAssignee(assignee).setNew(false)) .forEach(underTest::add); MetricStatsLong globalDistribution = underTest.globalStatistics().effort(); @@ -369,7 +360,7 @@ public class NewIssuesStatisticsTest { @Test public void add_does_not_sum_effort_if_null_neither_globally_nor_per_assignee() { String assignee = randomAlphanumeric(10); - underTest.add(new DefaultIssue().setEffort(null).setAssignee(assignee).setNew(new Random().nextBoolean())); + underTest.add(new DefaultIssue().setType(randomRuleType).setEffort(null).setAssignee(assignee).setNew(new Random().nextBoolean())); MetricStatsLong globalDistribution = underTest.globalStatistics().effort(); MetricStatsLong assigneeDistribution = underTest.getAssigneesStatistics().get(assignee).effort(); @@ -377,24 +368,6 @@ public class NewIssuesStatisticsTest { .forEach(distribution -> assertThat(distribution.getTotal()).isEqualTo(0)); } - @Test - public void add_counts_issue_per_severity_per_assignee() { - String assignee = randomAlphanumeric(20); - Severity.ALL.stream().map(severity -> new DefaultIssue() - .setSeverity(severity) - .setAssignee(assignee)).forEach(underTest::add); - - assertThat(underTest.globalStatistics() - .getDistributedMetricStats(Metric.SEVERITY) - .getForLabel(Severity.INFO) - .map(MetricStatsInt::getTotal) - .orElse(null)).isEqualTo(1); - assertThat(countDistributionTotal(Metric.SEVERITY, Severity.MINOR)).isEqualTo(1); - assertThat(countDistributionTotal(Metric.SEVERITY, Severity.CRITICAL)).isEqualTo(1); - assertThat(countDistributionTotal(Metric.SEVERITY, Severity.BLOCKER)).isEqualTo(1); - assertThat(countDistributionTotal(Metric.SEVERITY, Severity.MAJOR)).isEqualTo(1); - } - @Test public void do_not_have_issues_when_no_issue_added() { assertThat(underTest.globalStatistics().hasIssues()).isFalse(); @@ -408,7 +381,7 @@ public class NewIssuesStatisticsTest { int effort = 10 + new Random().nextInt(5); RuleKey ruleKey = RuleKey.of(randomAlphanumeric(5), randomAlphanumeric(6)); underTest.add(new DefaultIssue() - .setSeverity(Severity.BLOCKER) + .setType(randomRuleType) .setComponentUuid(componentUuid) .setTags(ImmutableSet.of(tag)) .setAssignee(assignee) @@ -419,8 +392,8 @@ public class NewIssuesStatisticsTest { .isEqualTo("NewIssuesStatistics{" + "assigneesStatistics={" + assignee + "=" + "Stats{distributions={" + - "SEVERITY=DistributedMetricStatsInt{globalStats=MetricStatsInt{onLeak=1, offLeak=0}, " + - "statsPerLabel={" + Severity.BLOCKER + "=MetricStatsInt{onLeak=1, offLeak=0}}}, " + + "RULE_TYPE=DistributedMetricStatsInt{globalStats=MetricStatsInt{onLeak=1, offLeak=0}, " + + "statsPerLabel={" + randomRuleType.name() + "=MetricStatsInt{onLeak=1, offLeak=0}}}, " + "TAG=DistributedMetricStatsInt{globalStats=MetricStatsInt{onLeak=1, offLeak=0}, " + "statsPerLabel={" + tag + "=MetricStatsInt{onLeak=1, offLeak=0}}}, " + "COMPONENT=DistributedMetricStatsInt{globalStats=MetricStatsInt{onLeak=1, offLeak=0}, " + @@ -431,8 +404,8 @@ public class NewIssuesStatisticsTest { "statsPerLabel={" + ruleKey.toString() + "=MetricStatsInt{onLeak=1, offLeak=0}}}}, " + "effortStats=MetricStatsLong{onLeak=" + effort + ", offLeak=0}}}, " + "globalStatistics=Stats{distributions={" + - "SEVERITY=DistributedMetricStatsInt{globalStats=MetricStatsInt{onLeak=1, offLeak=0}, " + - "statsPerLabel={" + Severity.BLOCKER + "=MetricStatsInt{onLeak=1, offLeak=0}}}, " + + "RULE_TYPE=DistributedMetricStatsInt{globalStats=MetricStatsInt{onLeak=1, offLeak=0}, " + + "statsPerLabel={" + randomRuleType.name() + "=MetricStatsInt{onLeak=1, offLeak=0}}}, " + "TAG=DistributedMetricStatsInt{globalStats=MetricStatsInt{onLeak=1, offLeak=0}, " + "statsPerLabel={" + tag + "=MetricStatsInt{onLeak=1, offLeak=0}}}, " + "COMPONENT=DistributedMetricStatsInt{globalStats=MetricStatsInt{onLeak=1, offLeak=0}, " + diff --git a/server/sonar-server/src/test/resources/org/sonar/server/issue/notification/MyNewIssuesEmailTemplateTest/email_with_all_details.txt b/server/sonar-server/src/test/resources/org/sonar/server/issue/notification/MyNewIssuesEmailTemplateTest/email_with_all_details.txt deleted file mode 100644 index 9091a95f55d..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/issue/notification/MyNewIssuesEmailTemplateTest/email_with_all_details.txt +++ /dev/null @@ -1,20 +0,0 @@ -Project: Struts - -32 new issues (new debt: 1d3h) - - Severity - Blocker: 0 Critical: 5 Major: 10 Minor: 3 Info: 1 - - Rules - Rule the Universe (Clojure): 42 - Rule the World (Java): 5 - - Tags - oscar: 3 - cesar: 10 - - Most impacted files - /path/to/file: 3 - /path/to/directory: 7 - -See it in SonarQube: http://nemo.sonarsource.org/project/issues?id=org.apache%3Astruts&assignees=lo.gin&createdAt=2010-05-18 diff --git a/server/sonar-server/src/test/resources/org/sonar/server/issue/notification/MyNewIssuesEmailTemplateTest/email_with_issue_on_branch.txt b/server/sonar-server/src/test/resources/org/sonar/server/issue/notification/MyNewIssuesEmailTemplateTest/email_with_issue_on_branch.txt deleted file mode 100644 index 38979565eaa..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/issue/notification/MyNewIssuesEmailTemplateTest/email_with_issue_on_branch.txt +++ /dev/null @@ -1,8 +0,0 @@ -Project: Struts - -32 new issues (new debt: 1d3h) - - Severity - Blocker: 0 Critical: 5 Major: 10 Minor: 3 Info: 1 - -See it in SonarQube: http://nemo.sonarsource.org/project/issues?id=org.apache%3Astruts&assignees=lo.gin&branch=feature1&createdAt=2010-05-18 diff --git a/server/sonar-server/src/test/resources/org/sonar/server/issue/notification/MyNewIssuesEmailTemplateTest/email_with_no_assignee_tags_components.txt b/server/sonar-server/src/test/resources/org/sonar/server/issue/notification/MyNewIssuesEmailTemplateTest/email_with_no_assignee_tags_components.txt deleted file mode 100644 index b5d1129d312..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/issue/notification/MyNewIssuesEmailTemplateTest/email_with_no_assignee_tags_components.txt +++ /dev/null @@ -1,8 +0,0 @@ -Project: Struts - -32 new issues (new debt: 1d3h) - - Severity - Blocker: 0 Critical: 5 Major: 10 Minor: 3 Info: 1 - -See it in SonarQube: http://nemo.sonarsource.org/project/issues?id=org.apache%3Astruts&assignees=lo.gin&createdAt=2010-05-18 diff --git a/server/sonar-server/src/test/resources/org/sonar/server/issue/notification/NewIssuesEmailTemplateTest/email_with_all_details.txt b/server/sonar-server/src/test/resources/org/sonar/server/issue/notification/NewIssuesEmailTemplateTest/email_with_all_details.txt deleted file mode 100644 index 7c4bb6c0118..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/issue/notification/NewIssuesEmailTemplateTest/email_with_all_details.txt +++ /dev/null @@ -1,24 +0,0 @@ -Project: Struts - -32 new issues (new debt: 1d3h) - - Severity - Blocker: 0 Critical: 5 Major: 10 Minor: 3 Info: 1 - - Assignees - robin.williams: 5 - al.pacino: 7 - - Rules - Rule the Universe (Clojure): 42 - Rule the World (Java): 5 - - Tags - oscar: 3 - cesar: 10 - - Most impacted files - /path/to/file: 3 - /path/to/directory: 7 - -See it in SonarQube: http://nemo.sonarsource.org/project/issues?id=org.apache%3Astruts&createdAt=2010-05-1 \ No newline at end of file diff --git a/server/sonar-server/src/test/resources/org/sonar/server/issue/notification/NewIssuesEmailTemplateTest/email_with_issue_on_branch.txt b/server/sonar-server/src/test/resources/org/sonar/server/issue/notification/NewIssuesEmailTemplateTest/email_with_issue_on_branch.txt deleted file mode 100644 index bc0afd30a33..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/issue/notification/NewIssuesEmailTemplateTest/email_with_issue_on_branch.txt +++ /dev/null @@ -1,8 +0,0 @@ -Project: Struts - -32 new issues (new debt: 1d3h) - - Severity - Blocker: 0 Critical: 5 Major: 10 Minor: 3 Info: 1 - -See it in SonarQube: http://nemo.sonarsource.org/project/issues?id=org.apache%3Astruts&branch=feature1&createdAt=2010-05-1 diff --git a/server/sonar-server/src/test/resources/org/sonar/server/issue/notification/NewIssuesEmailTemplateTest/email_with_partial_details.txt b/server/sonar-server/src/test/resources/org/sonar/server/issue/notification/NewIssuesEmailTemplateTest/email_with_partial_details.txt deleted file mode 100644 index 6c6e92ee3ce..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/issue/notification/NewIssuesEmailTemplateTest/email_with_partial_details.txt +++ /dev/null @@ -1,8 +0,0 @@ -Project: Struts - -32 new issues (new debt: 1d3h) - - Severity - Blocker: 0 Critical: 5 Major: 10 Minor: 3 Info: 1 - -See it in SonarQube: http://nemo.sonarsource.org/project/issues?id=org.apache%3Astruts&createdAt=2010-05-1 \ No newline at end of file diff --git a/tests/src/test/java/org/sonarqube/tests/issue/IssueNotificationsTest.java b/tests/src/test/java/org/sonarqube/tests/issue/IssueNotificationsTest.java index c110478180b..a8c63074e1d 100644 --- a/tests/src/test/java/org/sonarqube/tests/issue/IssueNotificationsTest.java +++ b/tests/src/test/java/org/sonarqube/tests/issue/IssueNotificationsTest.java @@ -153,7 +153,7 @@ public class IssueNotificationsTest extends AbstractIssueTest { assertThat(message.getHeader("To", null)).isEqualTo(""); assertThat((String) message.getContent()).contains("Sample"); assertThat((String) message.getContent()).contains("17 new issues (new debt: 17min)"); - assertThat((String) message.getContent()).contains("Severity"); + assertThat((String) message.getContent()).contains("Type"); assertThat((String) message.getContent()).contains("One Issue Per Line (xoo): 17"); assertThat((String) message.getContent()).contains( "See it in SonarQube: http://localhost:9000/project/issues?id=sample&createdAt=2015-12-15T00%3A00%3A00%2B"); -- 2.39.5