From dfd9b7bb5e955e6404041a5d21490ce80292fb21 Mon Sep 17 00:00:00 2001 From: lukasz-jarocki-sonarsource Date: Tue, 7 Nov 2023 12:25:21 +0100 Subject: [PATCH] SONAR-20932 Updated email issue notification to handle accepted issue status --- .../notification/NotificationFactory.java | 3 +- .../notification/NotificationFactoryTest.java | 1 - .../ChangesOnMyIssuesNotification.java | 2 +- ...ion.java => FPOrAcceptedNotification.java} | 30 ++-- ...a => FPOrAcceptedNotificationHandler.java} | 56 +++---- ...te.java => FpOrAcceptedEmailTemplate.java} | 44 +++--- .../IssuesChangesNotificationBuilder.java | 28 ++-- .../IssuesChangesNotificationModule.java | 6 +- .../IssuesChangesNotificationSerializer.java | 17 ++- ... FPOrAcceptedNotificationHandlerTest.java} | 144 ++++++++---------- ...java => FPOrAcceptedNotificationTest.java} | 38 ++--- ...ava => FpPrAcceptedEmailTemplateTest.java} | 82 +++++----- .../IssuesChangesNotificationBuilderTest.java | 28 +--- .../server/issue/ws/BulkChangeActionIT.java | 2 - .../sonar/server/issue/ws/IssueUpdaterIT.java | 4 - .../server/issue/ws/BulkChangeAction.java | 3 +- .../sonar/server/issue/ws/IssueUpdater.java | 8 +- .../notification/ws/DispatchersImplTest.java | 6 +- .../resources/org/sonar/l10n/core.properties | 2 +- 19 files changed, 234 insertions(+), 270 deletions(-) rename server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/{FPOrWontFixNotification.java => FPOrAcceptedNotification.java} (73%) rename server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/{FPOrWontFixNotificationHandler.java => FPOrAcceptedNotificationHandler.java} (74%) rename server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/{FpOrWontFixEmailTemplate.java => FpOrAcceptedEmailTemplate.java} (59%) rename server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/{FPOrWontFixNotificationHandlerTest.java => FPOrAcceptedNotificationHandlerTest.java} (80%) rename server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/{FPOrWontFixNotificationTest.java => FPOrAcceptedNotificationTest.java} (61%) rename server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/{FpOrWontFixEmailTemplateTest.java => FpPrAcceptedEmailTemplateTest.java} (84%) diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/notification/NotificationFactory.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/notification/NotificationFactory.java index 481f93f6fb8..def64e4e49f 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/notification/NotificationFactory.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/notification/NotificationFactory.java @@ -37,6 +37,7 @@ import org.sonar.ce.task.projectanalysis.component.TreeRootHolder; import org.sonar.ce.task.projectanalysis.component.TypeAwareVisitorAdapter; import org.sonar.ce.task.projectanalysis.issue.RuleRepository; import org.sonar.core.issue.DefaultIssue; +import org.sonar.core.issue.status.IssueStatus; import org.sonar.db.user.UserDto; import org.sonar.server.issue.notification.IssuesChangesNotification; import org.sonar.server.issue.notification.IssuesChangesNotificationBuilder; @@ -89,8 +90,8 @@ public class NotificationFactory { Set changedIssues = issues.stream() .map(issue -> new ChangedIssue.Builder(issue.key()) .setAssignee(getAssignee(issue.assignee(), assigneesByUuid)) - .setNewResolution(issue.resolution()) .setNewStatus(issue.status()) + .setNewIssueStatus(issue.status() != null ? IssueStatus.of(issue.status(), issue.resolution()) : null) .setRule(getRuleByRuleKey(issue.ruleKey())) .setProject(getProject()) .build()) diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/notification/NotificationFactoryTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/notification/NotificationFactoryTest.java index eca9c0d0269..318ab7685a2 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/notification/NotificationFactoryTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/notification/NotificationFactoryTest.java @@ -727,7 +727,6 @@ public class NotificationFactoryTest { issue -> { ChangedIssue changedIssue = changedIssuesByKey.get(issue.key()); assertThat(changedIssue.getNewStatus()).isEqualTo(issue.status()); - assertThat(changedIssue.getNewResolution()).isEmpty(); assertThat(changedIssue.getAssignee()).isEmpty(); assertThat(changedIssue.getRule().getKey()).isEqualTo(issue.ruleKey()); assertThat(changedIssue.getRule().getName()).isEqualTo(ruleRepository.getByKey(issue.ruleKey()).getName()); diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/ChangesOnMyIssuesNotification.java b/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/ChangesOnMyIssuesNotification.java index 24198f87128..7188da91a26 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/ChangesOnMyIssuesNotification.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/ChangesOnMyIssuesNotification.java @@ -33,7 +33,7 @@ import static org.sonar.core.util.stream.MoreCollectors.unorderedIndex; * This notification is never serialized to DB. *

* It is derived from {@link IssuesChangesNotification} by - * {@link FPOrWontFixNotificationHandler} and extends {@link Notification} only to comply with + * {@link FPOrAcceptedNotificationHandler} and extends {@link Notification} only to comply with * {@link org.sonar.server.issue.notification.EmailTemplate#format(Notification)} API. */ class ChangesOnMyIssuesNotification extends Notification { diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/FPOrWontFixNotification.java b/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/FPOrAcceptedNotification.java similarity index 73% rename from server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/FPOrWontFixNotification.java rename to server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/FPOrAcceptedNotification.java index 0bc3f9e3c8c..873525a2881 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/FPOrWontFixNotification.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/FPOrAcceptedNotification.java @@ -33,25 +33,25 @@ import static org.sonar.core.util.stream.MoreCollectors.unorderedIndex; * This notification is never serialized to DB. *

* It is derived from {@link IssuesChangesNotification} by - * {@link FPOrWontFixNotificationHandler} and extends {@link Notification} only to comply with + * {@link FPOrAcceptedNotificationHandler} and extends {@link Notification} only to comply with * {@link org.sonar.server.issue.notification.EmailTemplate#format(Notification)} API. */ -class FPOrWontFixNotification extends Notification { - private static final String KEY = "FPorWontFix"; +class FPOrAcceptedNotification extends Notification { + private static final String KEY = "FPorAccepted"; - public enum FpOrWontFix { - FP, WONT_FIX + public enum FpPrAccepted { + FP, ACCEPTED } private final Change change; private final SetMultimap changedIssues; - private final FpOrWontFix resolution; + private final FpPrAccepted issueStatusAfterUpdate; - public FPOrWontFixNotification(Change change, Collection changedIssues, FpOrWontFix resolution) { + public FPOrAcceptedNotification(Change change, Collection changedIssues, FpPrAccepted issueStatusAfterUpdate) { super(KEY); this.changedIssues = changedIssues.stream().collect(unorderedIndex(ChangedIssue::getProject, t -> t)); this.change = change; - this.resolution = resolution; + this.issueStatusAfterUpdate = issueStatusAfterUpdate; } public Change getChange() { @@ -62,8 +62,8 @@ class FPOrWontFixNotification extends Notification { return changedIssues; } - public FpOrWontFix getResolution() { - return resolution; + public FpPrAccepted getIssueStatusAfterUpdate() { + return issueStatusAfterUpdate; } @Override @@ -74,23 +74,23 @@ class FPOrWontFixNotification extends Notification { if (o == null || getClass() != o.getClass()) { return false; } - FPOrWontFixNotification that = (FPOrWontFixNotification) o; + FPOrAcceptedNotification that = (FPOrAcceptedNotification) o; return Objects.equals(changedIssues, that.changedIssues) && Objects.equals(change, that.change) && - resolution == that.resolution; + issueStatusAfterUpdate == that.issueStatusAfterUpdate; } @Override public int hashCode() { - return Objects.hash(changedIssues, change, resolution); + return Objects.hash(changedIssues, change, issueStatusAfterUpdate); } @Override public String toString() { - return "FPOrWontFixNotification{" + + return "FPOrAcceptedNotification{" + "changedIssues=" + changedIssues + ", change=" + change + - ", resolution=" + resolution + + ", issueStatusAfterUpdate=" + issueStatusAfterUpdate + '}'; } } diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/FPOrWontFixNotificationHandler.java b/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/FPOrAcceptedNotificationHandler.java similarity index 74% rename from server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/FPOrWontFixNotificationHandler.java rename to server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/FPOrAcceptedNotificationHandler.java index 554aa49ed83..da1e5ceb7c8 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/FPOrWontFixNotificationHandler.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/FPOrAcceptedNotificationHandler.java @@ -19,17 +19,17 @@ */ package org.sonar.server.issue.notification; -import com.google.common.collect.ImmutableSet; import com.google.common.collect.Multimap; import com.google.common.collect.SetMultimap; import java.util.Collection; +import java.util.EnumSet; import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; -import org.sonar.api.issue.Issue; +import org.sonar.core.issue.status.IssueStatus; import org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue; import org.sonar.server.notification.EmailNotificationHandler; import org.sonar.server.notification.NotificationDispatcherMetadata; @@ -41,26 +41,25 @@ import org.sonar.server.notification.email.EmailNotificationChannel.EmailDeliver import static com.google.common.collect.Sets.intersection; import static java.util.Collections.emptySet; import static java.util.Optional.of; -import static java.util.Optional.ofNullable; import static org.sonar.core.util.stream.MoreCollectors.unorderedFlattenIndex; import static org.sonar.core.util.stream.MoreCollectors.unorderedIndex; -import static org.sonar.server.issue.notification.FPOrWontFixNotification.FpOrWontFix.FP; -import static org.sonar.server.issue.notification.FPOrWontFixNotification.FpOrWontFix.WONT_FIX; +import static org.sonar.server.issue.notification.FPOrAcceptedNotification.FpPrAccepted.ACCEPTED; +import static org.sonar.server.issue.notification.FPOrAcceptedNotification.FpPrAccepted.FP; import static org.sonar.server.notification.NotificationManager.SubscriberPermissionsOnProject.ALL_MUST_HAVE_ROLE_USER; -public class FPOrWontFixNotificationHandler extends EmailNotificationHandler { +public class FPOrAcceptedNotificationHandler extends EmailNotificationHandler { public static final String KEY = "NewFalsePositiveIssue"; private static final NotificationDispatcherMetadata METADATA = NotificationDispatcherMetadata.create(KEY) .setProperty(NotificationDispatcherMetadata.GLOBAL_NOTIFICATION, String.valueOf(false)) .setProperty(NotificationDispatcherMetadata.PER_PROJECT_NOTIFICATION, String.valueOf(true)); - private static final Set FP_OR_WONTFIX_RESOLUTIONS = ImmutableSet.of(Issue.RESOLUTION_FALSE_POSITIVE, Issue.RESOLUTION_WONT_FIX); + private static final Set FP_OR_ACCEPTED_SIMPLE_STATUSES = EnumSet.of(IssueStatus.ACCEPTED, IssueStatus.FALSE_POSITIVE); private final NotificationManager notificationManager; private final IssuesChangesNotificationSerializer serializer; - public FPOrWontFixNotificationHandler(NotificationManager notificationManager, + public FPOrAcceptedNotificationHandler(NotificationManager notificationManager, EmailNotificationChannel emailNotificationChannel, IssuesChangesNotificationSerializer serializer) { super(emailNotificationChannel); this.notificationManager = notificationManager; @@ -83,18 +82,18 @@ public class FPOrWontFixNotificationHandler extends EmailNotificationHandler toEmailDeliveryRequests(Collection notifications) { - Set changeNotificationsWithFpOrWontFix = notifications.stream() + Set changeNotificationsWithFpOrAccepted = notifications.stream() .map(serializer::from) - // ignore notifications which contain no issue changed to a FP or Won't Fix resolution + // ignore notifications which contain no issue changed to a FP or Accepted status .filter(t -> t.getIssues().stream() - .filter(issue -> issue.getNewResolution().isPresent()) - .anyMatch(issue -> FP_OR_WONTFIX_RESOLUTIONS.contains(issue.getNewResolution().get()))) + .filter(issue -> issue.getNewIssueStatus().isPresent()) + .anyMatch(issue -> FP_OR_ACCEPTED_SIMPLE_STATUSES.contains(issue.getNewIssueStatus().get()))) .map(NotificationWithProjectKeys::new) .collect(Collectors.toSet()); - if (changeNotificationsWithFpOrWontFix.isEmpty()) { + if (changeNotificationsWithFpOrAccepted.isEmpty()) { return emptySet(); } - Set projectKeys = changeNotificationsWithFpOrWontFix.stream() + Set projectKeys = changeNotificationsWithFpOrAccepted.stream() .flatMap(t -> t.getProjectKeys().stream()) .collect(Collectors.toSet()); @@ -102,7 +101,7 @@ public class FPOrWontFixNotificationHandler extends EmailNotificationHandler recipients = notificationManager.findSubscribedEmailRecipients(KEY, projectKeys.iterator().next(), ALL_MUST_HAVE_ROLE_USER); - return changeNotificationsWithFpOrWontFix.stream() + return changeNotificationsWithFpOrAccepted.stream() .flatMap(notification -> toRequests(notification, projectKeys, recipients)) .collect(Collectors.toSet()); } @@ -120,7 +119,7 @@ public class FPOrWontFixNotificationHandler extends EmailNotificationHandler (Set) t.getValue(), Map.Entry::getKey)); - return changeNotificationsWithFpOrWontFix.stream() + return changeNotificationsWithFpOrAccepted.stream() .flatMap(notification -> { // builds sets of recipients for each sub group of the notification's projectKeys necessary SetMultimap, EmailRecipient> recipientsByProjectKeys = recipientsBySubscribedProjects.asMap().entrySet() @@ -137,35 +136,28 @@ public class FPOrWontFixNotificationHandler extends EmailNotificationHandler !notification.getChange().isAuthorLogin(recipient.login())) .flatMap(recipient -> { - SetMultimap issuesByNewResolution = notification.getIssues().stream() + SetMultimap issuesByNewIssueStatus = notification.getIssues().stream() // ignore issues not changed to a FP or Won't Fix resolution - .filter(issue -> issue.getNewResolution().filter(FP_OR_WONTFIX_RESOLUTIONS::contains).isPresent()) + .filter(issue -> issue.getNewIssueStatus().filter(FP_OR_ACCEPTED_SIMPLE_STATUSES::contains).isPresent()) // ignore issues belonging to projects the recipients have not subscribed to .filter(issue -> projectKeys.contains(issue.getProject().getKey())) - .collect(unorderedIndex(t -> t.getNewResolution().get(), issue -> issue)); + .collect(unorderedIndex(t -> t.getNewIssueStatus().get(), issue -> issue)); return Stream.of( - ofNullable(issuesByNewResolution.get(Issue.RESOLUTION_FALSE_POSITIVE)) + of(issuesByNewIssueStatus.get(IssueStatus.FALSE_POSITIVE)) .filter(t -> !t.isEmpty()) - .map(fpIssues -> new FPOrWontFixNotification(notification.getChange(), fpIssues, FP)) + .map(fpIssues -> new FPOrAcceptedNotification(notification.getChange(), fpIssues, FP)) .orElse(null), - ofNullable(issuesByNewResolution.get(Issue.RESOLUTION_WONT_FIX)) + of(issuesByNewIssueStatus.get(IssueStatus.ACCEPTED)) .filter(t -> !t.isEmpty()) - .map(wontFixIssues -> new FPOrWontFixNotification(notification.getChange(), wontFixIssues, WONT_FIX)) + .map(acceptedIssues -> new FPOrAcceptedNotification(notification.getChange(), acceptedIssues, ACCEPTED)) .orElse(null)) .filter(Objects::nonNull) - .map(fpOrWontFixNotification -> new EmailDeliveryRequest(recipient.email(), fpOrWontFixNotification)); + .map(fpOrAcceptedNotification -> new EmailDeliveryRequest(recipient.email(), fpOrAcceptedNotification)); }); } - private static final class EmailRecipientAndProject { - private final EmailRecipient recipient; - private final String projectKey; - - private EmailRecipientAndProject(EmailRecipient recipient, String projectKey) { - this.recipient = recipient; - this.projectKey = projectKey; - } + private record EmailRecipientAndProject(EmailRecipient recipient, String projectKey) { } } diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/FpOrWontFixEmailTemplate.java b/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/FpOrAcceptedEmailTemplate.java similarity index 59% rename from server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/FpOrWontFixEmailTemplate.java rename to server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/FpOrAcceptedEmailTemplate.java index 5afe9794b00..3a1225ce551 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/FpOrWontFixEmailTemplate.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/FpOrAcceptedEmailTemplate.java @@ -23,35 +23,35 @@ import javax.annotation.CheckForNull; import org.sonar.api.config.EmailSettings; import org.sonar.api.notifications.Notification; import org.sonar.core.i18n.I18n; -import org.sonar.server.issue.notification.FPOrWontFixNotification.FpOrWontFix; +import org.sonar.server.issue.notification.FPOrAcceptedNotification.FpPrAccepted; import org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.User; import org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.UserChange; -import static org.sonar.server.issue.notification.FPOrWontFixNotification.FpOrWontFix.FP; -import static org.sonar.server.issue.notification.FPOrWontFixNotification.FpOrWontFix.WONT_FIX; +import static org.sonar.server.issue.notification.FPOrAcceptedNotification.FpPrAccepted.ACCEPTED; +import static org.sonar.server.issue.notification.FPOrAcceptedNotification.FpPrAccepted.FP; /** * Creates email message for notification "issue-changes". */ -public class FpOrWontFixEmailTemplate extends IssueChangesEmailTemplate { +public class FpOrAcceptedEmailTemplate extends IssueChangesEmailTemplate { private static final String NOTIFICATION_NAME_I18N_KEY = "notification.dispatcher.NewFalsePositiveIssue"; - public FpOrWontFixEmailTemplate(I18n i18n, EmailSettings settings) { + public FpOrAcceptedEmailTemplate(I18n i18n, EmailSettings settings) { super(i18n, settings); } @Override @CheckForNull public EmailMessage format(Notification notif) { - if (!(notif instanceof FPOrWontFixNotification)) { + if (!(notif instanceof FPOrAcceptedNotification)) { return null; } - FPOrWontFixNotification notification = (FPOrWontFixNotification) notif; + FPOrAcceptedNotification notification = (FPOrAcceptedNotification) notif; EmailMessage emailMessage = new EmailMessage() - .setMessageId(getMessageId(notification.getResolution())) + .setMessageId(getMessageId(notification.getIssueStatusAfterUpdate())) .setSubject(buildSubject(notification)) .setHtmlMessage(buildMessage(notification)); if (notification.getChange() instanceof UserChange userChange) { @@ -61,25 +61,25 @@ public class FpOrWontFixEmailTemplate extends IssueChangesEmailTemplate { return emailMessage; } - private static String getMessageId(FpOrWontFix resolution) { - if (resolution == WONT_FIX) { - return "wontfix-issue-changes"; + private static String getMessageId(FpPrAccepted issueStatusAfterUpdate) { + if (issueStatusAfterUpdate == ACCEPTED) { + return "accepted-issue-changes"; } - if (resolution == FP) { + if (issueStatusAfterUpdate == FP) { return "fp-issue-changes"; } - throw new IllegalArgumentException("Unsupported resolution " + resolution); + throw new IllegalArgumentException("Unsupported issue status after update " + issueStatusAfterUpdate); } - private static String buildSubject(FPOrWontFixNotification notification) { - return "Issues marked as " + resolutionLabel(notification.getResolution()); + private static String buildSubject(FPOrAcceptedNotification notification) { + return "Issues marked as " + getIssueStatusLabel(notification.getIssueStatusAfterUpdate()); } - private String buildMessage(FPOrWontFixNotification notification) { + private String buildMessage(FPOrAcceptedNotification notification) { StringBuilder sb = new StringBuilder(); paragraph(sb, s -> s.append("Hi,")); paragraph(sb, s -> s.append("A manual change has resolved ").append(notification.getChangedIssues().size() > 1 ? "issues" : "an issue") - .append(" as ").append(resolutionLabel(notification.getResolution())).append(":")); + .append(" as ").append(getIssueStatusLabel(notification.getIssueStatusAfterUpdate())).append(":")); addIssuesByProjectThenRule(sb, notification.getChangedIssues()); @@ -88,14 +88,14 @@ public class FpOrWontFixEmailTemplate extends IssueChangesEmailTemplate { return sb.toString(); } - private static String resolutionLabel(FpOrWontFix resolution) { - if (resolution == WONT_FIX) { - return "Won't Fix"; + private static String getIssueStatusLabel(FpPrAccepted issueStatusAfterUpdate) { + if (issueStatusAfterUpdate == ACCEPTED) { + return "Accepted"; } - if (resolution == FP) { + if (issueStatusAfterUpdate == FP) { return "False Positive"; } - throw new IllegalArgumentException("Unsupported resolution " + resolution); + throw new IllegalArgumentException("Unsupported issue status after update " + issueStatusAfterUpdate); } } diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/IssuesChangesNotificationBuilder.java b/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/IssuesChangesNotificationBuilder.java index 18ca14de15a..7537a83a2ed 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/IssuesChangesNotificationBuilder.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/IssuesChangesNotificationBuilder.java @@ -28,6 +28,7 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; import org.sonar.api.rule.RuleKey; import org.sonar.api.rules.RuleType; +import org.sonar.core.issue.status.IssueStatus; import static com.google.common.base.Preconditions.checkArgument; import static java.util.Objects.requireNonNull; @@ -59,8 +60,7 @@ public class IssuesChangesNotificationBuilder { public static final class ChangedIssue { private final String key; private final String newStatus; - @CheckForNull - private final String newResolution; + private final IssueStatus newIssueStatus; @CheckForNull private final User assignee; private final Rule rule; @@ -69,7 +69,7 @@ public class IssuesChangesNotificationBuilder { public ChangedIssue(Builder builder) { this.key = requireNonNull(builder.key, KEY_CANT_BE_NULL_MESSAGE); this.newStatus = requireNonNull(builder.newStatus, "newStatus can't be null"); - this.newResolution = builder.newResolution; + this.newIssueStatus = builder.newIssueStatus; this.assignee = builder.assignee; this.rule = requireNonNull(builder.rule, "rule can't be null"); this.project = requireNonNull(builder.project, "project can't be null"); @@ -83,8 +83,8 @@ public class IssuesChangesNotificationBuilder { return newStatus; } - public Optional getNewResolution() { - return ofNullable(newResolution); + public Optional getNewIssueStatus() { + return ofNullable(newIssueStatus); } public Optional getAssignee() { @@ -101,9 +101,9 @@ public class IssuesChangesNotificationBuilder { public static class Builder { private final String key; - private String newStatus; @CheckForNull - private String newResolution; + private IssueStatus newIssueStatus; + private String newStatus; @CheckForNull private User assignee; private Rule rule; @@ -118,13 +118,13 @@ public class IssuesChangesNotificationBuilder { return this; } - public Builder setNewResolution(@Nullable String newResolution) { - this.newResolution = newResolution; + public Builder setAssignee(@Nullable User assignee) { + this.assignee = assignee; return this; } - public Builder setAssignee(@Nullable User assignee) { - this.assignee = assignee; + public Builder setNewIssueStatus(@Nullable IssueStatus newIssueStatus) { + this.newIssueStatus = newIssueStatus; return this; } @@ -154,7 +154,7 @@ public class IssuesChangesNotificationBuilder { ChangedIssue that = (ChangedIssue) o; return key.equals(that.key) && newStatus.equals(that.newStatus) && - Objects.equals(newResolution, that.newResolution) && + newIssueStatus == that.newIssueStatus && Objects.equals(assignee, that.assignee) && rule.equals(that.rule) && project.equals(that.project); @@ -162,7 +162,7 @@ public class IssuesChangesNotificationBuilder { @Override public int hashCode() { - return Objects.hash(key, newStatus, newResolution, assignee, rule, project); + return Objects.hash(key, newStatus, newIssueStatus, assignee, rule, project); } @Override @@ -170,7 +170,7 @@ public class IssuesChangesNotificationBuilder { return "ChangedIssue{" + "key='" + key + '\'' + ", newStatus='" + newStatus + '\'' + - ", newResolution='" + newResolution + '\'' + + ", newIssueStatus='" + newIssueStatus + '\'' + ", assignee=" + assignee + ", rule=" + rule + ", project=" + project + diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/IssuesChangesNotificationModule.java b/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/IssuesChangesNotificationModule.java index c4013fbe7bd..fcc5f9a3628 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/IssuesChangesNotificationModule.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/IssuesChangesNotificationModule.java @@ -28,10 +28,10 @@ public class IssuesChangesNotificationModule extends Module { ChangesOnMyIssueNotificationHandler.class, ChangesOnMyIssueNotificationHandler.newMetadata(), ChangesOnMyIssuesEmailTemplate.class, - FPOrWontFixNotificationHandler.class, - FPOrWontFixNotificationHandler.newMetadata(), + FPOrAcceptedNotificationHandler.class, + FPOrAcceptedNotificationHandler.newMetadata(), IssuesChangesNotificationSerializer.class, - FpOrWontFixEmailTemplate.class + FpOrAcceptedEmailTemplate.class ); } } diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/IssuesChangesNotificationSerializer.java b/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/IssuesChangesNotificationSerializer.java index 6f705071d26..fad0abbf8fb 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/IssuesChangesNotificationSerializer.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/IssuesChangesNotificationSerializer.java @@ -29,6 +29,7 @@ import javax.annotation.CheckForNull; import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; import org.sonar.api.rule.RuleKey; +import org.sonar.core.issue.status.IssueStatus; import org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue; import org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Project; import org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Rule; @@ -87,7 +88,7 @@ public class IssuesChangesNotificationSerializer { return issues.stream() .map(issue -> new ChangedIssue.Builder(issue.key) .setNewStatus(issue.newStatus) - .setNewResolution(issue.newResolution) + .setNewIssueStatus(issue.newIssueStatus == null ? null : IssueStatus.valueOf(issue.newIssueStatus)) .setAssignee(issue.assignee) .setRule(rules.get(issue.ruleKey)) .setProject(projects.get(issue.projectUuid)) @@ -121,9 +122,9 @@ public class IssuesChangesNotificationSerializer { assignee.getName() .ifPresent(name -> notification.setFieldValue(issuePropertyPrefix + ".assignee.name", name)); }); - issue.getNewResolution() - .ifPresent(newResolution -> notification.setFieldValue(issuePropertyPrefix + ".newResolution", newResolution)); notification.setFieldValue(issuePropertyPrefix + ".newStatus", issue.getNewStatus()); + issue.getNewIssueStatus() + .ifPresent(newIssueStatus -> notification.setFieldValue(issuePropertyPrefix + ".newIssueStatus", newIssueStatus.name())); notification.setFieldValue(issuePropertyPrefix + ".ruleKey", issue.getRule().getKey().toString()); notification.setFieldValue(issuePropertyPrefix + ".projectUuid", issue.getProject().getUuid()); } @@ -135,6 +136,7 @@ public class IssuesChangesNotificationSerializer { .setKey(getIssueFieldValue(notification, issuePropertyPrefix + ".key", index)) .setNewStatus(getIssueFieldValue(notification, issuePropertyPrefix + ".newStatus", index)) .setNewResolution(notification.getFieldValue(issuePropertyPrefix + ".newResolution")) + .setNewIssueStatus(notification.getFieldValue(issuePropertyPrefix + ".newIssueStatus")) .setAssignee(assignee) .setRuleKey(getIssueFieldValue(notification, issuePropertyPrefix + ".ruleKey", index)) .setProjectUuid(getIssueFieldValue(notification, issuePropertyPrefix + ".projectUuid", index)) @@ -250,6 +252,8 @@ public class IssuesChangesNotificationSerializer { @CheckForNull private final String newResolution; @CheckForNull + private final String newIssueStatus; + @CheckForNull private final User assignee; private final RuleKey ruleKey; private final String projectUuid; @@ -261,6 +265,7 @@ public class IssuesChangesNotificationSerializer { this.assignee = builder.assignee; this.ruleKey = RuleKey.parse(builder.ruleKey); this.projectUuid = builder.projectUuid; + this.newIssueStatus = builder.newIssueStatus; } static class Builder { @@ -272,6 +277,7 @@ public class IssuesChangesNotificationSerializer { private User assignee = null; private String ruleKey = null; private String projectUuid = null; + private String newIssueStatus = null; public Builder setKey(String key) { this.key = key; @@ -288,6 +294,11 @@ public class IssuesChangesNotificationSerializer { return this; } + public Builder setNewIssueStatus(@Nullable String newIssueStatus) { + this.newIssueStatus = newIssueStatus; + return this; + } + public Builder setAssignee(@Nullable User assignee) { this.assignee = assignee; return this; diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/FPOrWontFixNotificationHandlerTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/FPOrAcceptedNotificationHandlerTest.java similarity index 80% rename from server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/FPOrWontFixNotificationHandlerTest.java rename to server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/FPOrAcceptedNotificationHandlerTest.java index 7f8184450d8..b53f06b8a3e 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/FPOrWontFixNotificationHandlerTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/FPOrAcceptedNotificationHandlerTest.java @@ -34,7 +34,8 @@ import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Mockito; import org.sonar.api.issue.Issue; -import org.sonar.server.issue.notification.FPOrWontFixNotification.FpOrWontFix; +import org.sonar.core.issue.status.IssueStatus; +import org.sonar.server.issue.notification.FPOrAcceptedNotification.FpPrAccepted; import org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Change; import org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue; import org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Project; @@ -70,37 +71,37 @@ import static org.sonar.server.notification.NotificationDispatcherMetadata.PER_P import static org.sonar.server.notification.NotificationManager.SubscriberPermissionsOnProject.ALL_MUST_HAVE_ROLE_USER; @RunWith(DataProviderRunner.class) -public class FPOrWontFixNotificationHandlerTest { +public class FPOrAcceptedNotificationHandlerTest { private static final String DO_NOT_FIX_ISSUE_CHANGE_DISPATCHER_KEY = "NewFalsePositiveIssue"; private NotificationManager notificationManager = mock(NotificationManager.class); private EmailNotificationChannel emailNotificationChannel = mock(EmailNotificationChannel.class); private IssuesChangesNotificationSerializer serializerMock = mock(IssuesChangesNotificationSerializer.class); private IssuesChangesNotificationSerializer serializer = spy(new IssuesChangesNotificationSerializer()); private Class> requestSetType = (Class>) (Class) Set.class; - private FPOrWontFixNotificationHandler underTest = new FPOrWontFixNotificationHandler(notificationManager, emailNotificationChannel, serializer); + private FPOrAcceptedNotificationHandler underTest = new FPOrAcceptedNotificationHandler(notificationManager, emailNotificationChannel, serializer); @Test public void getMetadata_returns_same_instance_as_static_method() { - assertThat(underTest.getMetadata()).containsSame(FPOrWontFixNotificationHandler.newMetadata()); + assertThat(underTest.getMetadata()).containsSame(FPOrAcceptedNotificationHandler.newMetadata()); } @Test public void verify_fpOrWontFixIssues_notification_dispatcher_key() { - NotificationDispatcherMetadata metadata = FPOrWontFixNotificationHandler.newMetadata(); + NotificationDispatcherMetadata metadata = FPOrAcceptedNotificationHandler.newMetadata(); assertThat(metadata.getDispatcherKey()).isEqualTo(DO_NOT_FIX_ISSUE_CHANGE_DISPATCHER_KEY); } @Test public void fpOrWontFixIssues_notification_is_disabled_at_global_level() { - NotificationDispatcherMetadata metadata = FPOrWontFixNotificationHandler.newMetadata(); + NotificationDispatcherMetadata metadata = FPOrAcceptedNotificationHandler.newMetadata(); assertThat(metadata.getProperty(GLOBAL_NOTIFICATION)).isEqualTo("false"); } @Test public void fpOrWontFixIssues_notification_is_enable_at_project_level() { - NotificationDispatcherMetadata metadata = FPOrWontFixNotificationHandler.newMetadata(); + NotificationDispatcherMetadata metadata = FPOrAcceptedNotificationHandler.newMetadata(); assertThat(metadata.getProperty(PER_PROJECT_NOTIFICATION)).isEqualTo("true"); } @@ -133,7 +134,7 @@ public class FPOrWontFixNotificationHandlerTest { .collect(toSet()); when(emailNotificationChannel.isActivated()).thenReturn(true); when(serializerMock.from(any(IssuesChangesNotification.class))).thenReturn(mock(IssuesChangesNotificationBuilder.class)); - FPOrWontFixNotificationHandler underTest = new FPOrWontFixNotificationHandler(notificationManager, emailNotificationChannel, serializerMock); + FPOrAcceptedNotificationHandler underTest = new FPOrAcceptedNotificationHandler(notificationManager, emailNotificationChannel, serializerMock); underTest.deliver(notifications); @@ -151,7 +152,7 @@ public class FPOrWontFixNotificationHandlerTest { .thenReturn(mock(IssuesChangesNotificationBuilder.class)) .thenReturn(mock(IssuesChangesNotificationBuilder.class)) .thenThrow(expected); - FPOrWontFixNotificationHandler underTest = new FPOrWontFixNotificationHandler(notificationManager, emailNotificationChannel, serializerMock); + FPOrAcceptedNotificationHandler underTest = new FPOrAcceptedNotificationHandler(notificationManager, emailNotificationChannel, serializerMock); try { underTest.deliver(notifications); @@ -163,33 +164,12 @@ public class FPOrWontFixNotificationHandlerTest { } @Test - public void deliver_has_no_effect_if_no_issue_has_new_resolution() { + @UseDataProvider("notFPorAcceptedIssueStatus") + public void deliver_has_no_effect_if_no_issue_has_FP_or_wontfix_resolution(IssueStatus newIssueStatus) { when(emailNotificationChannel.isActivated()).thenReturn(true); Change changeMock = mock(Change.class); Set notifications = IntStream.range(0, 2 + new Random().nextInt(5)) - .mapToObj(j -> new IssuesChangesNotificationBuilder(randomIssues(t -> t.setNewResolution(null)).collect(toSet()), changeMock)) - .map(serializer::serialize) - .collect(toSet()); - reset(serializer); - - int deliver = underTest.deliver(notifications); - - assertThat(deliver).isZero(); - verify(serializer, times(notifications.size())).from(any(IssuesChangesNotification.class)); - verifyNoInteractions(changeMock); - verifyNoMoreInteractions(serializer); - verifyNoInteractions(notificationManager); - verify(emailNotificationChannel).isActivated(); - verifyNoMoreInteractions(emailNotificationChannel); - } - - @Test - @UseDataProvider("notFPorWontFixResolution") - public void deliver_has_no_effect_if_no_issue_has_FP_or_wontfix_resolution(String newResolution) { - when(emailNotificationChannel.isActivated()).thenReturn(true); - Change changeMock = mock(Change.class); - Set notifications = IntStream.range(0, 2 + new Random().nextInt(5)) - .mapToObj(j -> new IssuesChangesNotificationBuilder(randomIssues(t -> t.setNewResolution(newResolution)).collect(toSet()), changeMock)) + .mapToObj(j -> new IssuesChangesNotificationBuilder(randomIssues(t -> t.setNewIssueStatus(newIssueStatus)).collect(toSet()), changeMock)) .map(serializer::serialize) .collect(toSet()); reset(serializer); @@ -206,18 +186,18 @@ public class FPOrWontFixNotificationHandlerTest { } @DataProvider - public static Object[][] notFPorWontFixResolution() { + public static Object[][] notFPorAcceptedIssueStatus() { return new Object[][] { - {""}, - {randomAlphabetic(9)}, - {Issue.RESOLUTION_FIXED}, - {Issue.RESOLUTION_REMOVED} + {null}, + {IssueStatus.FIXED}, + {IssueStatus.OPEN} }; } @Test - @UseDataProvider("FPorWontFixResolution") - public void deliver_checks_by_projectKey_if_notifications_have_subscribed_assignee_to_FPorWontFix_notifications(String newResolution) { + @UseDataProvider("FPorWontFixResolutionWithCorrespondingIssueStatus") + public void deliver_checks_by_projectKey_if_notifications_have_subscribed_assignee_to_FPorWontFix_notifications(String newResolution, + IssueStatus newIssueStatus) { Project projectKey1 = newProject(randomAlphabetic(4)); Project projectKey2 = newProject(randomAlphabetic(5)); Project projectKey3 = newProject(randomAlphabetic(6)); @@ -226,19 +206,19 @@ public class FPOrWontFixNotificationHandlerTest { // some notifications with some issues on project1 Stream project1Notifications = IntStream.range(0, 1 + new Random().nextInt(2)) .mapToObj(j -> new IssuesChangesNotificationBuilder( - randomIssues(t -> t.setProject(projectKey1).setNewResolution(newResolution)).collect(toSet()), + randomIssues(t -> t.setProject(projectKey1).setNewIssueStatus(newIssueStatus)).collect(toSet()), changeMock)); // some notifications with some issues on project2 Stream project2Notifications = IntStream.range(0, 1 + new Random().nextInt(2)) .mapToObj(j -> new IssuesChangesNotificationBuilder( - randomIssues(t -> t.setProject(projectKey2).setNewResolution(newResolution)).collect(toSet()), + randomIssues(t -> t.setProject(projectKey2).setNewIssueStatus(newIssueStatus)).collect(toSet()), changeMock)); // some notifications with some issues on project3 and project 4 Stream project3And4Notifications = IntStream.range(0, 1 + new Random().nextInt(2)) .mapToObj(j -> new IssuesChangesNotificationBuilder( Stream.concat( - randomIssues(t -> t.setProject(projectKey3).setNewResolution(newResolution)), - randomIssues(t -> t.setProject(projectKey4).setNewResolution(newResolution))) + randomIssues(t -> t.setProject(projectKey3).setNewIssueStatus(newIssueStatus)), + randomIssues(t -> t.setProject(projectKey4).setNewIssueStatus(newIssueStatus))) .collect(toSet()), changeMock)); when(emailNotificationChannel.isActivated()).thenReturn(true); @@ -261,8 +241,8 @@ public class FPOrWontFixNotificationHandlerTest { } @Test - @UseDataProvider("FPorWontFixResolution") - public void deliver_does_not_send_email_request_for_notifications_a_subscriber_is_the_changeAuthor_of(String newResolution) { + @UseDataProvider("FPorWontFixResolutionWithCorrespondingIssueStatus") + public void deliver_does_not_send_email_request_for_notifications_a_subscriber_is_the_changeAuthor_of(String newResolution, IssueStatus newIssueStatus) { Project project = newProject(randomAlphabetic(5)); User subscriber1 = newUser("subscriber1"); User subscriber2 = newUser("subscriber2"); @@ -272,44 +252,45 @@ public class FPOrWontFixNotificationHandlerTest { // subscriber1 is the changeAuthor of some notifications with issues assigned to subscriber1 only Set subscriber1Notifications = IntStream.range(0, 1 + new Random().nextInt(2)) .mapToObj(j -> new IssuesChangesNotificationBuilder( - randomIssues(t -> t.setProject(project).setNewResolution(newResolution).setAssignee(subscriber2)).collect(toSet()), + randomIssues(t -> t.setProject(project).setNewIssueStatus(newIssueStatus).setAssignee(subscriber2)).collect(toSet()), newUserChange(subscriber1))) .collect(toSet()); // subscriber1 is the changeAuthor of some notifications with issues assigned to subscriber1 and subscriber2 Set subscriber1and2Notifications = IntStream.range(0, 1 + new Random().nextInt(2)) .mapToObj(j -> new IssuesChangesNotificationBuilder( Stream.concat( - randomIssues(t -> t.setProject(project).setNewResolution(newResolution).setAssignee(subscriber2)), - randomIssues(t -> t.setProject(project).setNewResolution(newResolution).setAssignee(subscriber1))) + randomIssues(t -> t.setProject(project).setNewIssueStatus(newIssueStatus).setAssignee(subscriber2)), + randomIssues(t -> t.setProject(project).setNewIssueStatus(newIssueStatus).setAssignee(subscriber1))) .collect(toSet()), newUserChange(subscriber1))) .collect(toSet()); // subscriber2 is the changeAuthor of some notifications with issues assigned to subscriber2 only Set subscriber2Notifications = IntStream.range(0, 1 + new Random().nextInt(2)) .mapToObj(j -> new IssuesChangesNotificationBuilder( - randomIssues(t -> t.setProject(project).setNewResolution(newResolution).setAssignee(subscriber2)).collect(toSet()), + randomIssues(t -> t.setProject(project).setNewIssueStatus(newIssueStatus).setAssignee(subscriber2)).collect(toSet()), newUserChange(subscriber2))) .collect(toSet()); // subscriber2 is the changeAuthor of some notifications with issues assigned to subscriber2 and subscriber 3 Set subscriber2And3Notifications = IntStream.range(0, 1 + new Random().nextInt(2)) .mapToObj(j -> new IssuesChangesNotificationBuilder( Stream.concat( - randomIssues(t -> t.setProject(project).setNewResolution(newResolution).setAssignee(subscriber2)), - randomIssues(t -> t.setProject(project).setNewResolution(newResolution).setAssignee(subscriber3))) + randomIssues(t -> t.setProject(project).setNewIssueStatus(newIssueStatus).setAssignee(subscriber2)), + randomIssues(t -> t.setProject(project).setNewIssueStatus(newIssueStatus).setAssignee(subscriber3))) .collect(toSet()), newUserChange(subscriber2))) .collect(toSet()); // subscriber3 is the changeAuthor of no notification // otherChangeAuthor has some notifications Set otherChangeAuthorNotifications = IntStream.range(0, 1 + new Random().nextInt(2)) - .mapToObj(j -> new IssuesChangesNotificationBuilder(randomIssues(t -> t.setProject(project).setNewResolution(newResolution)).collect(toSet()), + .mapToObj(j -> new IssuesChangesNotificationBuilder(randomIssues(t -> t.setProject(project) + .setNewIssueStatus(newIssueStatus)).collect(toSet()), newUserChange(otherChangeAuthor))) .collect(toSet()); when(emailNotificationChannel.isActivated()).thenReturn(true); Set subscriberLogins = ImmutableSet.of(subscriber1.getLogin(), subscriber2.getLogin(), subscriber3.getLogin()); when(notificationManager.findSubscribedEmailRecipients(DO_NOT_FIX_ISSUE_CHANGE_DISPATCHER_KEY, project.getKey(), ALL_MUST_HAVE_ROLE_USER)) - .thenReturn(subscriberLogins.stream().map(FPOrWontFixNotificationHandlerTest::emailRecipientOf).collect(toSet())); + .thenReturn(subscriberLogins.stream().map(FPOrAcceptedNotificationHandlerTest::emailRecipientOf).collect(toSet())); int deliveredCount = new Random().nextInt(200); when(emailNotificationChannel.deliverAll(anySet())) @@ -342,37 +323,37 @@ public class FPOrWontFixNotificationHandlerTest { .containsOnly( Stream.of( subscriber2Notifications.stream() - .map(notif -> newEmailDeliveryRequest(notif, subscriber1, toFpOrWontFix(newResolution))), + .map(notif -> newEmailDeliveryRequest(notif, subscriber1, toFpOrAccepted(newResolution))), subscriber2And3Notifications.stream() - .map(notif -> newEmailDeliveryRequest(notif, subscriber1, toFpOrWontFix(newResolution))), + .map(notif -> newEmailDeliveryRequest(notif, subscriber1, toFpOrAccepted(newResolution))), otherChangeAuthorNotifications.stream() - .map(notif -> newEmailDeliveryRequest(notif, subscriber1, toFpOrWontFix(newResolution)))) + .map(notif -> newEmailDeliveryRequest(notif, subscriber1, toFpOrAccepted(newResolution)))) .flatMap(t -> t) .toArray(EmailDeliveryRequest[]::new)); assertThat(requestsByRecipientEmail.get(emailOf(subscriber2.getLogin()))) .containsOnly( Stream.of( subscriber1Notifications.stream() - .map(notif -> newEmailDeliveryRequest(notif, subscriber2, toFpOrWontFix(newResolution))), + .map(notif -> newEmailDeliveryRequest(notif, subscriber2, toFpOrAccepted(newResolution))), subscriber1and2Notifications.stream() - .map(notif -> newEmailDeliveryRequest(notif, subscriber2, toFpOrWontFix(newResolution))), + .map(notif -> newEmailDeliveryRequest(notif, subscriber2, toFpOrAccepted(newResolution))), otherChangeAuthorNotifications.stream() - .map(notif -> newEmailDeliveryRequest(notif, subscriber2, toFpOrWontFix(newResolution)))) + .map(notif -> newEmailDeliveryRequest(notif, subscriber2, toFpOrAccepted(newResolution)))) .flatMap(t -> t) .toArray(EmailDeliveryRequest[]::new)); assertThat(requestsByRecipientEmail.get(emailOf(subscriber3.getLogin()))) .containsOnly( Stream.of( subscriber1Notifications.stream() - .map(notif -> newEmailDeliveryRequest(notif, subscriber3, toFpOrWontFix(newResolution))), + .map(notif -> newEmailDeliveryRequest(notif, subscriber3, toFpOrAccepted(newResolution))), subscriber1and2Notifications.stream() - .map(notif -> newEmailDeliveryRequest(notif, subscriber3, toFpOrWontFix(newResolution))), + .map(notif -> newEmailDeliveryRequest(notif, subscriber3, toFpOrAccepted(newResolution))), subscriber2Notifications.stream() - .map(notif -> newEmailDeliveryRequest(notif, subscriber3, toFpOrWontFix(newResolution))), + .map(notif -> newEmailDeliveryRequest(notif, subscriber3, toFpOrAccepted(newResolution))), subscriber2And3Notifications.stream() - .map(notif -> newEmailDeliveryRequest(notif, subscriber3, toFpOrWontFix(newResolution))), + .map(notif -> newEmailDeliveryRequest(notif, subscriber3, toFpOrAccepted(newResolution))), otherChangeAuthorNotifications.stream() - .map(notif -> newEmailDeliveryRequest(notif, subscriber3, toFpOrWontFix(newResolution)))) + .map(notif -> newEmailDeliveryRequest(notif, subscriber3, toFpOrAccepted(newResolution)))) .flatMap(t -> t) .toArray(EmailDeliveryRequest[]::new)); assertThat(requestsByRecipientEmail.get(emailOf(otherChangeAuthor.getLogin()))) @@ -387,10 +368,12 @@ public class FPOrWontFixNotificationHandlerTest { User changeAuthor = newUser("changeAuthor"); Set fpIssues = projects.stream() - .flatMap(project -> randomIssues(t -> t.setProject(project).setNewResolution(RESOLUTION_FALSE_POSITIVE).setAssignee(subscriber1))) + .flatMap(project -> randomIssues(t -> t.setProject(project) + .setNewIssueStatus(IssueStatus.FALSE_POSITIVE).setAssignee(subscriber1))) .collect(toSet()); Set wontFixIssues = projects.stream() - .flatMap(project -> randomIssues(t -> t.setProject(project).setNewResolution(RESOLUTION_WONT_FIX).setAssignee(subscriber1))) + .flatMap(project -> randomIssues(t -> t.setProject(project) + .setNewIssueStatus(IssueStatus.ACCEPTED).setAssignee(subscriber1))) .collect(toSet()); UserChange userChange = newUserChange(changeAuthor); IssuesChangesNotificationBuilder fpAndWontFixNotifications = new IssuesChangesNotificationBuilder( @@ -409,7 +392,7 @@ public class FPOrWontFixNotificationHandlerTest { int deliver = underTest.deliver(notifications); - assertThat(deliver).isEqualTo(deliveredCount); + assertThat(deliver).isEqualTo(deliveredCount); projects .forEach(project -> verify(notificationManager).findSubscribedEmailRecipients(DO_NOT_FIX_ISSUE_CHANGE_DISPATCHER_KEY, project.getKey(), ALL_MUST_HAVE_ROLE_USER)); verifyNoMoreInteractions(notificationManager); @@ -421,10 +404,10 @@ public class FPOrWontFixNotificationHandlerTest { .collect(index(EmailDeliveryRequest::recipientEmail)); assertThat(requestsByRecipientEmail.get(emailOf(subscriber1.getLogin()))) .containsOnly( - new EmailDeliveryRequest(emailOf(subscriber1.getLogin()), new FPOrWontFixNotification( - userChange, wontFixIssues, FpOrWontFix.WONT_FIX)), - new EmailDeliveryRequest(emailOf(subscriber1.getLogin()), new FPOrWontFixNotification( - userChange, fpIssues, FpOrWontFix.FP))); + new EmailDeliveryRequest(emailOf(subscriber1.getLogin()), new FPOrAcceptedNotification( + userChange, wontFixIssues, FpPrAccepted.ACCEPTED)), + new EmailDeliveryRequest(emailOf(subscriber1.getLogin()), new FPOrAcceptedNotification( + userChange, fpIssues, FpPrAccepted.FP))); } @DataProvider @@ -435,18 +418,18 @@ public class FPOrWontFixNotificationHandlerTest { }; } - private static EmailDeliveryRequest newEmailDeliveryRequest(IssuesChangesNotificationBuilder notif, User user, FpOrWontFix resolution) { + private static EmailDeliveryRequest newEmailDeliveryRequest(IssuesChangesNotificationBuilder notif, User user, FpPrAccepted resolution) { return new EmailDeliveryRequest( emailOf(user.getLogin()), - new FPOrWontFixNotification(notif.getChange(), notif.getIssues(), resolution)); + new FPOrAcceptedNotification(notif.getChange(), notif.getIssues(), resolution)); } - private static FpOrWontFix toFpOrWontFix(String newResolution) { + private static FpPrAccepted toFpOrAccepted(String newResolution) { if (newResolution.equals(Issue.RESOLUTION_WONT_FIX)) { - return FpOrWontFix.WONT_FIX; + return FpPrAccepted.ACCEPTED; } if (newResolution.equals(RESOLUTION_FALSE_POSITIVE)) { - return FpOrWontFix.FP; + return FpPrAccepted.FP; } throw new IllegalArgumentException("unsupported resolution " + newResolution); } @@ -462,10 +445,10 @@ public class FPOrWontFixNotificationHandlerTest { } @DataProvider - public static Object[][] FPorWontFixResolution() { + public static Object[][] FPorWontFixResolutionWithCorrespondingIssueStatus() { return new Object[][] { - {RESOLUTION_FALSE_POSITIVE}, - {Issue.RESOLUTION_WONT_FIX} + {RESOLUTION_FALSE_POSITIVE, IssueStatus.FALSE_POSITIVE}, + {Issue.RESOLUTION_WONT_FIX, IssueStatus.ACCEPTED} }; } @@ -475,7 +458,6 @@ public class FPOrWontFixNotificationHandlerTest { ChangedIssue.Builder builder = new ChangedIssue.Builder("key_" + i) .setAssignee(new User(randomAlphabetic(3), randomAlphabetic(4), randomAlphabetic(5))) .setNewStatus(randomAlphabetic(12)) - .setNewResolution(randomAlphabetic(13)) .setRule(newRandomNotAHotspotRule(randomAlphabetic(8))) .setProject(new Project.Builder(randomAlphabetic(9)) .setKey(randomAlphabetic(10)) diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/FPOrWontFixNotificationTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/FPOrAcceptedNotificationTest.java similarity index 61% rename from server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/FPOrWontFixNotificationTest.java rename to server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/FPOrAcceptedNotificationTest.java index 405809025d7..ea87d9eb269 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/FPOrWontFixNotificationTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/FPOrAcceptedNotificationTest.java @@ -33,11 +33,11 @@ import org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Rule import org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.User; import static org.assertj.core.api.Assertions.assertThat; -import static org.sonar.server.issue.notification.FPOrWontFixNotification.FpOrWontFix.FP; -import static org.sonar.server.issue.notification.FPOrWontFixNotification.FpOrWontFix.WONT_FIX; +import static org.sonar.server.issue.notification.FPOrAcceptedNotification.FpPrAccepted.FP; +import static org.sonar.server.issue.notification.FPOrAcceptedNotification.FpPrAccepted.ACCEPTED; import static org.sonar.server.issue.notification.IssuesChangesNotificationBuilderTesting.newRandomNotAHotspotRule; -public class FPOrWontFixNotificationTest { +public class FPOrAcceptedNotificationTest { @Test public void equals_is_based_on_issues_change_and_resolution() { Rule rule = newRandomNotAHotspotRule("rule_name"); @@ -51,18 +51,18 @@ public class FPOrWontFixNotificationTest { .collect(Collectors.toSet()); AnalysisChange change = new AnalysisChange(12); User user = new User("uuid", "login", null); - FPOrWontFixNotification underTest = new FPOrWontFixNotification(change, changedIssues, WONT_FIX); + FPOrAcceptedNotification underTest = new FPOrAcceptedNotification(change, changedIssues, ACCEPTED); assertThat(underTest) - .isEqualTo(new FPOrWontFixNotification(change, changedIssues, WONT_FIX)) - .isEqualTo(new FPOrWontFixNotification(change, ImmutableSet.copyOf(changedIssues), WONT_FIX)) + .isEqualTo(new FPOrAcceptedNotification(change, changedIssues, ACCEPTED)) + .isEqualTo(new FPOrAcceptedNotification(change, ImmutableSet.copyOf(changedIssues), ACCEPTED)) .isNotEqualTo(new Object()) .isNotNull() - .isNotEqualTo(new FPOrWontFixNotification(change, Collections.emptySet(), WONT_FIX)) - .isNotEqualTo(new FPOrWontFixNotification(change, ImmutableSet.of(changedIssues.iterator().next()), WONT_FIX)) - .isNotEqualTo(new FPOrWontFixNotification(new AnalysisChange(14), changedIssues, WONT_FIX)) - .isNotEqualTo(new FPOrWontFixNotification(new IssuesChangesNotificationBuilder.UserChange(12, user), changedIssues, WONT_FIX)) - .isNotEqualTo(new FPOrWontFixNotification(change, changedIssues, FP)); + .isNotEqualTo(new FPOrAcceptedNotification(change, Collections.emptySet(), ACCEPTED)) + .isNotEqualTo(new FPOrAcceptedNotification(change, ImmutableSet.of(changedIssues.iterator().next()), ACCEPTED)) + .isNotEqualTo(new FPOrAcceptedNotification(new AnalysisChange(14), changedIssues, ACCEPTED)) + .isNotEqualTo(new FPOrAcceptedNotification(new IssuesChangesNotificationBuilder.UserChange(12, user), changedIssues, ACCEPTED)) + .isNotEqualTo(new FPOrAcceptedNotification(change, changedIssues, FP)); } @Test @@ -78,16 +78,16 @@ public class FPOrWontFixNotificationTest { .collect(Collectors.toSet()); AnalysisChange change = new AnalysisChange(12); User user = new User("uuid", "login", null); - FPOrWontFixNotification underTest = new FPOrWontFixNotification(change, changedIssues, WONT_FIX); + FPOrAcceptedNotification underTest = new FPOrAcceptedNotification(change, changedIssues, ACCEPTED); assertThat(underTest.hashCode()) - .isEqualTo(new FPOrWontFixNotification(change, changedIssues, WONT_FIX).hashCode()) - .isEqualTo(new FPOrWontFixNotification(change, ImmutableSet.copyOf(changedIssues), WONT_FIX).hashCode()) + .isEqualTo(new FPOrAcceptedNotification(change, changedIssues, ACCEPTED).hashCode()) + .isEqualTo(new FPOrAcceptedNotification(change, ImmutableSet.copyOf(changedIssues), ACCEPTED).hashCode()) .isNotEqualTo(new Object().hashCode()) - .isNotEqualTo(new FPOrWontFixNotification(change, Collections.emptySet(), WONT_FIX).hashCode()) - .isNotEqualTo(new FPOrWontFixNotification(change, ImmutableSet.of(changedIssues.iterator().next()), WONT_FIX).hashCode()) - .isNotEqualTo(new FPOrWontFixNotification(new AnalysisChange(14), changedIssues, WONT_FIX).hashCode()) - .isNotEqualTo(new FPOrWontFixNotification(new IssuesChangesNotificationBuilder.UserChange(12, user), changedIssues, WONT_FIX).hashCode()) - .isNotEqualTo(new FPOrWontFixNotification(change, changedIssues, FP)).hashCode(); + .isNotEqualTo(new FPOrAcceptedNotification(change, Collections.emptySet(), ACCEPTED).hashCode()) + .isNotEqualTo(new FPOrAcceptedNotification(change, ImmutableSet.of(changedIssues.iterator().next()), ACCEPTED).hashCode()) + .isNotEqualTo(new FPOrAcceptedNotification(new AnalysisChange(14), changedIssues, ACCEPTED).hashCode()) + .isNotEqualTo(new FPOrAcceptedNotification(new IssuesChangesNotificationBuilder.UserChange(12, user), changedIssues, ACCEPTED).hashCode()) + .isNotEqualTo(new FPOrAcceptedNotification(change, changedIssues, FP)).hashCode(); } } diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/FpOrWontFixEmailTemplateTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/FpPrAcceptedEmailTemplateTest.java similarity index 84% rename from server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/FpOrWontFixEmailTemplateTest.java rename to server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/FpPrAcceptedEmailTemplateTest.java index f68200ce74a..b50aec22f87 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/FpOrWontFixEmailTemplateTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/FpPrAcceptedEmailTemplateTest.java @@ -36,7 +36,7 @@ import org.sonar.api.notifications.Notification; import org.sonar.api.rule.RuleKey; import org.sonar.api.rules.RuleType; import org.sonar.core.i18n.I18n; -import org.sonar.server.issue.notification.FPOrWontFixNotification.FpOrWontFix; +import org.sonar.server.issue.notification.FPOrAcceptedNotification.FpPrAccepted; import org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.AnalysisChange; import org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Change; import org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue; @@ -53,17 +53,17 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static org.sonar.api.rules.RuleType.SECURITY_HOTSPOT; -import static org.sonar.server.issue.notification.FPOrWontFixNotification.FpOrWontFix.FP; -import static org.sonar.server.issue.notification.FPOrWontFixNotification.FpOrWontFix.WONT_FIX; +import static org.sonar.server.issue.notification.FPOrAcceptedNotification.FpPrAccepted.FP; +import static org.sonar.server.issue.notification.FPOrAcceptedNotification.FpPrAccepted.ACCEPTED; import static org.sonar.server.issue.notification.IssuesChangesNotificationBuilderTesting.newRandomNotAHotspotRule; import static org.sonar.server.issue.notification.IssuesChangesNotificationBuilderTesting.newSecurityHotspotRule; import static org.sonar.server.issue.notification.IssuesChangesNotificationBuilderTesting.randomRuleTypeHotspotExcluded; @RunWith(DataProviderRunner.class) -public class FpOrWontFixEmailTemplateTest { +public class FpPrAcceptedEmailTemplateTest { private I18n i18n = mock(I18n.class); private EmailSettings emailSettings = mock(EmailSettings.class); - private FpOrWontFixEmailTemplate underTest = new FpOrWontFixEmailTemplate(i18n, emailSettings); + private FpOrAcceptedEmailTemplate underTest = new FpOrAcceptedEmailTemplate(i18n, emailSettings); @Test public void format_returns_null_on_Notification() { @@ -74,36 +74,36 @@ public class FpOrWontFixEmailTemplateTest { @Test public void format_sets_message_id_specific_to_fp() { - EmailMessage emailMessage = underTest.format(new FPOrWontFixNotification(mock(Change.class), Collections.emptySet(), FP)); + EmailMessage emailMessage = underTest.format(new FPOrAcceptedNotification(mock(Change.class), Collections.emptySet(), FP)); assertThat(emailMessage.getMessageId()).isEqualTo("fp-issue-changes"); } @Test public void format_sets_message_id_specific_to_wont_fix() { - EmailMessage emailMessage = underTest.format(new FPOrWontFixNotification(mock(Change.class), Collections.emptySet(), WONT_FIX)); + EmailMessage emailMessage = underTest.format(new FPOrAcceptedNotification(mock(Change.class), Collections.emptySet(), ACCEPTED)); - assertThat(emailMessage.getMessageId()).isEqualTo("wontfix-issue-changes"); + assertThat(emailMessage.getMessageId()).isEqualTo("accepted-issue-changes"); } @Test public void format_sets_subject_specific_to_fp() { - EmailMessage emailMessage = underTest.format(new FPOrWontFixNotification(mock(Change.class), Collections.emptySet(), FP)); + EmailMessage emailMessage = underTest.format(new FPOrAcceptedNotification(mock(Change.class), Collections.emptySet(), FP)); assertThat(emailMessage.getSubject()).isEqualTo("Issues marked as False Positive"); } @Test public void format_sets_subject_specific_to_wont_fix() { - EmailMessage emailMessage = underTest.format(new FPOrWontFixNotification(mock(Change.class), Collections.emptySet(), WONT_FIX)); + EmailMessage emailMessage = underTest.format(new FPOrAcceptedNotification(mock(Change.class), Collections.emptySet(), ACCEPTED)); - assertThat(emailMessage.getSubject()).isEqualTo("Issues marked as Won't Fix"); + assertThat(emailMessage.getSubject()).isEqualTo("Issues marked as Accepted"); } @Test public void format_sets_from_to_name_of_author_change_when_available() { UserChange change = new UserChange(new Random().nextLong(), new User(randomAlphabetic(5), randomAlphabetic(6), randomAlphabetic(7))); - EmailMessage emailMessage = underTest.format(new FPOrWontFixNotification(change, Collections.emptySet(), WONT_FIX)); + EmailMessage emailMessage = underTest.format(new FPOrAcceptedNotification(change, Collections.emptySet(), ACCEPTED)); assertThat(emailMessage.getFrom()).isEqualTo(change.getUser().getName().get()); } @@ -111,7 +111,7 @@ public class FpOrWontFixEmailTemplateTest { @Test public void format_sets_from_to_login_of_author_change_when_name_is_not_available() { UserChange change = new UserChange(new Random().nextLong(), new User(randomAlphabetic(5), randomAlphabetic(6), null)); - EmailMessage emailMessage = underTest.format(new FPOrWontFixNotification(change, Collections.emptySet(), WONT_FIX)); + EmailMessage emailMessage = underTest.format(new FPOrAcceptedNotification(change, Collections.emptySet(), ACCEPTED)); assertThat(emailMessage.getFrom()).isEqualTo(change.getUser().getLogin()); } @@ -119,7 +119,7 @@ public class FpOrWontFixEmailTemplateTest { @Test public void format_sets_from_to_null_when_analysisChange() { AnalysisChange change = new AnalysisChange(new Random().nextLong()); - EmailMessage emailMessage = underTest.format(new FPOrWontFixNotification(change, Collections.emptySet(), WONT_FIX)); + EmailMessage emailMessage = underTest.format(new FPOrAcceptedNotification(change, Collections.emptySet(), ACCEPTED)); assertThat(emailMessage.getFrom()).isNull(); } @@ -133,17 +133,17 @@ public class FpOrWontFixEmailTemplateTest { @Test @UseDataProvider("userOrAnalysisChange") public void formats_returns_html_message_with_only_footer_and_header_when_no_issue_for_Wont_fixs(Change change) { - formats_returns_html_message_with_only_footer_and_header_when_no_issue(change, WONT_FIX, "Won't Fix"); + formats_returns_html_message_with_only_footer_and_header_when_no_issue(change, ACCEPTED, "Accepted"); } - public void formats_returns_html_message_with_only_footer_and_header_when_no_issue(Change change, FpOrWontFix fpOrWontFix, String fpOrWontFixLabel) { + public void formats_returns_html_message_with_only_footer_and_header_when_no_issue(Change change, FpPrAccepted fpPrAccepted, String fpOrWontFixLabel) { String wordingNotification = randomAlphabetic(20); String host = randomAlphabetic(15); when(i18n.message(Locale.ENGLISH, "notification.dispatcher.NewFalsePositiveIssue", "notification.dispatcher.NewFalsePositiveIssue")) .thenReturn(wordingNotification); when(emailSettings.getServerBaseURL()).thenReturn(host); - EmailMessage emailMessage = underTest.format(new FPOrWontFixNotification(change, Collections.emptySet(), fpOrWontFix)); + EmailMessage emailMessage = underTest.format(new FPOrAcceptedNotification(change, Collections.emptySet(), fpPrAccepted)); String footerText = "You received this email because you are subscribed to \"" + wordingNotification + "\" notifications from SonarQube." + " Click here to edit your email preferences."; @@ -161,14 +161,14 @@ public class FpOrWontFixEmailTemplateTest { @Test @UseDataProvider("fpOrWontFixValuesByUserOrAnalysisChange") - public void formats_returns_html_message_for_single_issue_on_master(Change change, FpOrWontFix fpOrWontFix) { + public void formats_returns_html_message_for_single_issue_on_master(Change change, FpPrAccepted fpPrAccepted) { Project project = newProject("1"); String ruleName = randomAlphabetic(8); String host = randomAlphabetic(15); ChangedIssue changedIssue = newChangedIssue("key", project, ruleName, randomRuleTypeHotspotExcluded()); when(emailSettings.getServerBaseURL()).thenReturn(host); - EmailMessage emailMessage = underTest.format(new FPOrWontFixNotification(change, ImmutableSet.of(changedIssue), fpOrWontFix)); + EmailMessage emailMessage = underTest.format(new FPOrAcceptedNotification(change, ImmutableSet.of(changedIssue), fpPrAccepted)); HtmlFragmentAssert.assertThat(emailMessage.getMessage()) .hasParagraph().hasParagraph() // skip header @@ -181,14 +181,14 @@ public class FpOrWontFixEmailTemplateTest { @Test @UseDataProvider("fpOrWontFixValuesByUserOrAnalysisChange") - public void formats_returns_html_message_for_single_hotspot_on_master(Change change, FpOrWontFix fpOrWontFix) { + public void formats_returns_html_message_for_single_hotspot_on_master(Change change, FpPrAccepted fpPrAccepted) { Project project = newProject("1"); String ruleName = randomAlphabetic(8); String host = randomAlphabetic(15); ChangedIssue changedIssue = newChangedIssue("key", project, ruleName, SECURITY_HOTSPOT); when(emailSettings.getServerBaseURL()).thenReturn(host); - EmailMessage emailMessage = underTest.format(new FPOrWontFixNotification(change, ImmutableSet.of(changedIssue), fpOrWontFix)); + EmailMessage emailMessage = underTest.format(new FPOrAcceptedNotification(change, ImmutableSet.of(changedIssue), fpPrAccepted)); HtmlFragmentAssert.assertThat(emailMessage.getMessage()) .hasParagraph().hasParagraph() // skip header @@ -201,7 +201,7 @@ public class FpOrWontFixEmailTemplateTest { @Test @UseDataProvider("fpOrWontFixValuesByUserOrAnalysisChange") - public void formats_returns_html_message_for_single_issue_on_branch(Change change, FpOrWontFix fpOrWontFix) { + public void formats_returns_html_message_for_single_issue_on_branch(Change change, FpPrAccepted fpPrAccepted) { String branchName = randomAlphabetic(6); Project project = newBranch("1", branchName); String ruleName = randomAlphabetic(8); @@ -210,7 +210,7 @@ public class FpOrWontFixEmailTemplateTest { ChangedIssue changedIssue = newChangedIssue(key, project, ruleName, randomRuleTypeHotspotExcluded()); when(emailSettings.getServerBaseURL()).thenReturn(host); - EmailMessage emailMessage = underTest.format(new FPOrWontFixNotification(change, ImmutableSet.of(changedIssue), fpOrWontFix)); + EmailMessage emailMessage = underTest.format(new FPOrAcceptedNotification(change, ImmutableSet.of(changedIssue), fpPrAccepted)); HtmlFragmentAssert.assertThat(emailMessage.getMessage()) .hasParagraph().hasParagraph() // skip header @@ -224,7 +224,7 @@ public class FpOrWontFixEmailTemplateTest { @Test @UseDataProvider("fpOrWontFixValuesByUserOrAnalysisChange") - public void formats_returns_html_message_for_single_hotspot_on_branch(Change change, FpOrWontFix fpOrWontFix) { + public void formats_returns_html_message_for_single_hotspot_on_branch(Change change, FpPrAccepted fpPrAccepted) { String branchName = randomAlphabetic(6); Project project = newBranch("1", branchName); String ruleName = randomAlphabetic(8); @@ -233,7 +233,7 @@ public class FpOrWontFixEmailTemplateTest { ChangedIssue changedIssue = newChangedIssue(key, project, ruleName, SECURITY_HOTSPOT); when(emailSettings.getServerBaseURL()).thenReturn(host); - EmailMessage emailMessage = underTest.format(new FPOrWontFixNotification(change, ImmutableSet.of(changedIssue), fpOrWontFix)); + EmailMessage emailMessage = underTest.format(new FPOrAcceptedNotification(change, ImmutableSet.of(changedIssue), fpPrAccepted)); HtmlFragmentAssert.assertThat(emailMessage.getMessage()) .hasParagraph().hasParagraph() // skip header @@ -247,7 +247,7 @@ public class FpOrWontFixEmailTemplateTest { @Test @UseDataProvider("fpOrWontFixValuesByUserOrAnalysisChange") - public void formats_returns_html_message_for_multiple_issues_of_same_rule_on_same_project_on_master(Change change, FpOrWontFix fpOrWontFix) { + public void formats_returns_html_message_for_multiple_issues_of_same_rule_on_same_project_on_master(Change change, FpPrAccepted fpPrAccepted) { Project project = newProject("1"); String ruleName = randomAlphabetic(8); String host = randomAlphabetic(15); @@ -257,7 +257,7 @@ public class FpOrWontFixEmailTemplateTest { .collect(toList()); when(emailSettings.getServerBaseURL()).thenReturn(host); - EmailMessage emailMessage = underTest.format(new FPOrWontFixNotification(change, ImmutableSet.copyOf(changedIssues), fpOrWontFix)); + EmailMessage emailMessage = underTest.format(new FPOrAcceptedNotification(change, ImmutableSet.copyOf(changedIssues), fpPrAccepted)); String expectedHref = host + "/project/issues?id=" + project.getKey() + "&issues=" + changedIssues.stream().map(ChangedIssue::getKey).collect(joining("%2C")); @@ -273,7 +273,7 @@ public class FpOrWontFixEmailTemplateTest { @Test @UseDataProvider("fpOrWontFixValuesByUserOrAnalysisChange") - public void formats_returns_html_message_for_multiple_hotspots_of_same_rule_on_same_project_on_master(Change change, FpOrWontFix fpOrWontFix) { + public void formats_returns_html_message_for_multiple_hotspots_of_same_rule_on_same_project_on_master(Change change, FpPrAccepted fpPrAccepted) { Project project = newProject("1"); String ruleName = randomAlphabetic(8); String host = randomAlphabetic(15); @@ -283,7 +283,7 @@ public class FpOrWontFixEmailTemplateTest { .collect(toList()); when(emailSettings.getServerBaseURL()).thenReturn(host); - EmailMessage emailMessage = underTest.format(new FPOrWontFixNotification(change, ImmutableSet.copyOf(changedIssues), fpOrWontFix)); + EmailMessage emailMessage = underTest.format(new FPOrAcceptedNotification(change, ImmutableSet.copyOf(changedIssues), fpPrAccepted)); String expectedHref = host + "/project/issues?id=" + project.getKey() + "&issues=" + changedIssues.stream().map(ChangedIssue::getKey).collect(joining("%2C")); @@ -299,7 +299,7 @@ public class FpOrWontFixEmailTemplateTest { @Test @UseDataProvider("fpOrWontFixValuesByUserOrAnalysisChange") - public void formats_returns_html_message_for_multiple_issues_of_same_rule_on_same_project_on_branch(Change change, FpOrWontFix fpOrWontFix) { + public void formats_returns_html_message_for_multiple_issues_of_same_rule_on_same_project_on_branch(Change change, FpPrAccepted fpPrAccepted) { String branchName = randomAlphabetic(19); Project project = newBranch("1", branchName); String ruleName = randomAlphabetic(8); @@ -310,7 +310,7 @@ public class FpOrWontFixEmailTemplateTest { .collect(toList()); when(emailSettings.getServerBaseURL()).thenReturn(host); - EmailMessage emailMessage = underTest.format(new FPOrWontFixNotification(change, ImmutableSet.copyOf(changedIssues), fpOrWontFix)); + EmailMessage emailMessage = underTest.format(new FPOrAcceptedNotification(change, ImmutableSet.copyOf(changedIssues), fpPrAccepted)); String expectedHref = host + "/project/issues?id=" + project.getKey() + "&branch=" + branchName + "&issues=" + changedIssues.stream().map(ChangedIssue::getKey).collect(joining("%2C")); @@ -326,7 +326,7 @@ public class FpOrWontFixEmailTemplateTest { @Test @UseDataProvider("fpOrWontFixValuesByUserOrAnalysisChange") - public void formats_returns_html_message_for_multiple_hotspots_of_same_rule_on_same_project_on_branch(Change change, FpOrWontFix fpOrWontFix) { + public void formats_returns_html_message_for_multiple_hotspots_of_same_rule_on_same_project_on_branch(Change change, FpPrAccepted fpPrAccepted) { String branchName = randomAlphabetic(19); Project project = newBranch("1", branchName); String ruleName = randomAlphabetic(8); @@ -337,7 +337,7 @@ public class FpOrWontFixEmailTemplateTest { .collect(toList()); when(emailSettings.getServerBaseURL()).thenReturn(host); - EmailMessage emailMessage = underTest.format(new FPOrWontFixNotification(change, ImmutableSet.copyOf(changedIssues), fpOrWontFix)); + EmailMessage emailMessage = underTest.format(new FPOrAcceptedNotification(change, ImmutableSet.copyOf(changedIssues), fpPrAccepted)); String expectedHref = host + "/project/issues?id=" + project.getKey() + "&branch=" + branchName + "&issues=" + changedIssues.stream().map(ChangedIssue::getKey).collect(joining("%2C")); @@ -353,7 +353,7 @@ public class FpOrWontFixEmailTemplateTest { @Test @UseDataProvider("fpOrWontFixValuesByUserOrAnalysisChange") - public void formats_returns_html_message_with_projects_ordered_by_name(Change change, FpOrWontFix fpOrWontFix) { + public void formats_returns_html_message_with_projects_ordered_by_name(Change change, FpPrAccepted fpPrAccepted) { Project project1 = newProject("1"); Project project1Branch1 = newBranch("1", "a"); Project project1Branch2 = newBranch("1", "b"); @@ -367,7 +367,7 @@ public class FpOrWontFixEmailTemplateTest { Collections.shuffle(changedIssues); when(emailSettings.getServerBaseURL()).thenReturn(host); - EmailMessage emailMessage = underTest.format(new FPOrWontFixNotification(change, ImmutableSet.copyOf(changedIssues), fpOrWontFix)); + EmailMessage emailMessage = underTest.format(new FPOrAcceptedNotification(change, ImmutableSet.copyOf(changedIssues), fpPrAccepted)); HtmlFragmentAssert.assertThat(emailMessage.getMessage()) .hasParagraph().hasParagraph() // skip header @@ -389,7 +389,7 @@ public class FpOrWontFixEmailTemplateTest { @Test @UseDataProvider("fpOrWontFixValuesByUserOrAnalysisChange") - public void formats_returns_html_message_with_rules_ordered_by_name(Change change, FpOrWontFix fpOrWontFix) { + public void formats_returns_html_message_with_rules_ordered_by_name(Change change, FpPrAccepted fpPrAccepted) { Project project = newProject("1"); Rule rule1 = newRandomNotAHotspotRule("1"); Rule rule2 = newRandomNotAHotspotRule("a"); @@ -402,7 +402,7 @@ public class FpOrWontFixEmailTemplateTest { Collections.shuffle(changedIssues); when(emailSettings.getServerBaseURL()).thenReturn(host); - EmailMessage emailMessage = underTest.format(new FPOrWontFixNotification(change, ImmutableSet.copyOf(changedIssues), fpOrWontFix)); + EmailMessage emailMessage = underTest.format(new FPOrAcceptedNotification(change, ImmutableSet.copyOf(changedIssues), fpPrAccepted)); HtmlFragmentAssert.assertThat(emailMessage.getMessage()) .hasParagraph().hasParagraph() // skip header @@ -418,7 +418,7 @@ public class FpOrWontFixEmailTemplateTest { @Test @UseDataProvider("fpOrWontFixValuesByUserOrAnalysisChange") - public void formats_returns_html_message_with_multiple_links_by_rule_of_groups_of_up_to_40_issues(Change change, FpOrWontFix fpOrWontFix) { + public void formats_returns_html_message_with_multiple_links_by_rule_of_groups_of_up_to_40_issues(Change change, FpPrAccepted fpPrAccepted) { Project project1 = newProject("1"); Project project2 = newProject("V"); Project project2Branch = newBranch("V", "AB"); @@ -435,7 +435,7 @@ public class FpOrWontFixEmailTemplateTest { Collections.shuffle(changedIssues); when(emailSettings.getServerBaseURL()).thenReturn(host); - EmailMessage emailMessage = underTest.format(new FPOrWontFixNotification(change, ImmutableSet.copyOf(changedIssues), fpOrWontFix)); + EmailMessage emailMessage = underTest.format(new FPOrAcceptedNotification(change, ImmutableSet.copyOf(changedIssues), fpPrAccepted)); HtmlFragmentAssert.assertThat(emailMessage.getMessage()) .hasParagraph().hasParagraph() // skip header @@ -488,9 +488,9 @@ public class FpOrWontFixEmailTemplateTest { new Random().nextBoolean() ? null : randomAlphabetic(7))); return new Object[][] { {analysisChange, FP}, - {analysisChange, WONT_FIX}, + {analysisChange, ACCEPTED}, {userChange, FP}, - {userChange, WONT_FIX} + {userChange, ACCEPTED} }; } diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/IssuesChangesNotificationBuilderTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/IssuesChangesNotificationBuilderTest.java index 725166d8016..4d3b37af51d 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/IssuesChangesNotificationBuilderTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/IssuesChangesNotificationBuilderTest.java @@ -31,6 +31,7 @@ import org.junit.runner.RunWith; import org.sonar.api.rule.RuleKey; import org.sonar.api.rules.RuleType; import org.sonar.api.utils.System2; +import org.sonar.core.issue.status.IssueStatus; import org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.AnalysisChange; import org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue; import org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Project; @@ -50,7 +51,6 @@ public class IssuesChangesNotificationBuilderTest { .setRule(newRule("repository", "key", RuleType.CODE_SMELL, "name")) .setProject(new Project.Builder("uuid" + i).setKey("key").setProjectName("name").setBranchName("branch-name").build()) .setNewStatus("status") - .setNewResolution("resolution") .setAssignee(new User("uuid" + i, "login", "name")) .build()) .collect(Collectors.toSet()); @@ -76,7 +76,6 @@ public class IssuesChangesNotificationBuilderTest { .setRule(newRule("repository", "key", RuleType.CODE_SMELL, "name")) .setProject(new Project.Builder("uuid" + i).setKey("key").setProjectName("name").setBranchName("branch-name").build()) .setNewStatus("status") - .setNewResolution("resolution") .setAssignee(new User("uuid" + i, "login", "name")) .build()) .collect(Collectors.toSet()); @@ -341,12 +340,12 @@ public class IssuesChangesNotificationBuilderTest { .setRule(newRule("repository", "key", RuleType.CODE_SMELL, "name")) .setProject(new Project.Builder("uuid").setKey("key").setProjectName("name").setBranchName("branch-name").build()) .setNewStatus("status") - .setNewResolution("resolution") + .setNewIssueStatus(IssueStatus.ACCEPTED) .setAssignee(new User("uuid", "login", "name")) .build(); assertThat(changedIssue) - .hasToString("ChangedIssue{key='key', newStatus='status', newResolution='resolution', " + + .hasToString("ChangedIssue{key='key', newStatus='status', newIssueStatus='ACCEPTED', " + "assignee=User{uuid='uuid', login='login', name='name'}, " + "rule=Rule{key=repository:key, type=CODE_SMELL, name='name'}, " + "project=Project{uuid='uuid', key='key', projectName='name', branchName='branch-name'}}"); @@ -358,14 +357,12 @@ public class IssuesChangesNotificationBuilderTest { .setRule(newRule("repository", "key", RuleType.CODE_SMELL, "name")) .setProject(new Project.Builder("uuid").setKey("key").setProjectName("name").setBranchName("branch-name").build()) .setNewStatus("status") - .setNewResolution("resolution") .setAssignee(new User("uuid", "login", "name")) .build(); ChangedIssue changedIssue2 = new ChangedIssue.Builder("key") .setRule(newRule("repository", "key", RuleType.CODE_SMELL, "name")) .setProject(new Project.Builder("uuid").setKey("key").setProjectName("name").setBranchName("branch-name").build()) .setNewStatus("status") - .setNewResolution("resolution") .setAssignee(new User("uuid", "login", "name")) .build(); @@ -381,42 +378,30 @@ public class IssuesChangesNotificationBuilderTest { .setRule(newRule("repository", "key", RuleType.CODE_SMELL, "name")) .setProject(new Project.Builder("uuid").setKey("key").setProjectName("name").setBranchName("branch-name").build()) .setNewStatus("status") - .setNewResolution("resolution") .setAssignee(new User("uuid", "login", "name")) .build()}, {new ChangedIssue.Builder("key") .setRule(newRule("repository1", "key", RuleType.CODE_SMELL, "name")) .setProject(new Project.Builder("uuid").setKey("key").setProjectName("name").setBranchName("branch-name").build()) .setNewStatus("status") - .setNewResolution("resolution") .setAssignee(new User("uuid", "login", "name")) .build()}, {new ChangedIssue.Builder("key") .setRule(newRule("repository", "key", RuleType.CODE_SMELL, "name")) .setProject(new Project.Builder("uuid1").setKey("key").setProjectName("name").setBranchName("branch-name").build()) - .setNewStatus("status") - .setNewResolution("resolution") + .setNewStatus("status").setNewIssueStatus(IssueStatus.ACCEPTED) .setAssignee(new User("uuid", "login", "name")) .build()}, {new ChangedIssue.Builder("key") .setRule(newRule("repository", "key", RuleType.CODE_SMELL, "name")) .setProject(new Project.Builder("uuid").setKey("key").setProjectName("name").setBranchName("branch-name").build()) - .setNewStatus("status1") - .setNewResolution("resolution") - .setAssignee(new User("uuid", "login", "name")) - .build()}, - {new ChangedIssue.Builder("key") - .setRule(newRule("repository", "key", RuleType.CODE_SMELL, "name")) - .setProject(new Project.Builder("uuid").setKey("key").setProjectName("name").setBranchName("branch-name").build()) - .setNewStatus("status") - .setNewResolution("resolution1") + .setNewStatus("status").setNewIssueStatus(IssueStatus.FIXED) .setAssignee(new User("uuid", "login", "name")) .build()}, {new ChangedIssue.Builder("key") .setRule(newRule("repository", "key", RuleType.CODE_SMELL, "name")) .setProject(new Project.Builder("uuid").setKey("key").setProjectName("name").setBranchName("branch-name").build()) .setNewStatus("status") - .setNewResolution("resolution") .setAssignee(new User("uuid1", "login", "name")) .build()}, {null}, @@ -431,7 +416,6 @@ public class IssuesChangesNotificationBuilderTest { .setRule(newRule("repository", "key", RuleType.CODE_SMELL, "name")) .setProject(new Project.Builder("uuid").setKey("key").setProjectName("name").setBranchName("branch-name").build()) .setNewStatus("status") - .setNewResolution("resolution") .setAssignee(new User("uuid", "login", "name")) .build(); @@ -447,14 +431,12 @@ public class IssuesChangesNotificationBuilderTest { .setRule(rule) .setProject(project) .setNewStatus("status") - .setNewResolution("resolution") .setAssignee(user) .build(); assertThat(changedIssue.getKey()).isEqualTo("key"); assertThat(changedIssue.getNewStatus()).isEqualTo("status"); assertThat(changedIssue.getAssignee()).hasValue(user); - assertThat(changedIssue.getNewResolution()).hasValue("resolution"); assertThat(changedIssue.getProject()).isEqualTo(project); assertThat(changedIssue.getRule()).isEqualTo(rule); } diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/BulkChangeActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/BulkChangeActionIT.java index 2890bda1594..8a0953c6de7 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/BulkChangeActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/BulkChangeActionIT.java @@ -418,7 +418,6 @@ public class BulkChangeActionIT { ChangedIssue changedIssue = builder.getIssues().iterator().next(); assertThat(changedIssue.getKey()).isEqualTo(issue.getKey()); assertThat(changedIssue.getNewStatus()).isEqualTo(STATUS_CONFIRMED); - assertThat(changedIssue.getNewResolution()).isEmpty(); assertThat(changedIssue.getAssignee()).isEmpty(); assertThat(changedIssue.getRule()).isEqualTo(ruleOf(rule)); assertThat(changedIssue.getProject()).isEqualTo(projectBranchOf(db, branch)); @@ -485,7 +484,6 @@ public class BulkChangeActionIT { ChangedIssue changedIssue = builder.getIssues().iterator().next(); assertThat(changedIssue.getKey()).isEqualTo(issue3.getKey()); assertThat(changedIssue.getNewStatus()).isEqualTo(STATUS_OPEN); - assertThat(changedIssue.getNewResolution()).isEmpty(); assertThat(changedIssue.getAssignee()).isEmpty(); assertThat(changedIssue.getRule()).isEqualTo(ruleOf(rule)); assertThat(changedIssue.getProject()).isEqualTo(projectOf(project)); diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/IssueUpdaterIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/IssueUpdaterIT.java index 2ac0c3042a5..5ede61e2858 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/IssueUpdaterIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/IssueUpdaterIT.java @@ -123,7 +123,6 @@ public class IssueUpdaterIT { ChangedIssue changedIssue = builder.getIssues().iterator().next(); assertThat(changedIssue.getKey()).isEqualTo(issue.key()); assertThat(changedIssue.getNewStatus()).isEqualTo(issue.status()); - assertThat(changedIssue.getNewResolution()).isEmpty(); assertThat(changedIssue.getAssignee()).contains(userOf(assignee)); assertThat(changedIssue.getRule()).isEqualTo(ruleOf(rule)); assertThat(changedIssue.getProject()).isEqualTo(projectOf(project)); @@ -152,7 +151,6 @@ public class IssueUpdaterIT { ChangedIssue changedIssue = builder.getIssues().iterator().next(); assertThat(changedIssue.getKey()).isEqualTo(issue.key()); assertThat(changedIssue.getNewStatus()).isEqualTo(issue.status()); - assertThat(changedIssue.getNewResolution()).contains(RESOLUTION_FIXED); assertThat(changedIssue.getAssignee()).contains(userOf(assignee)); assertThat(changedIssue.getRule()).isEqualTo(ruleOf(rule)); assertThat(changedIssue.getProject()).isEqualTo(projectOf(project)); @@ -180,7 +178,6 @@ public class IssueUpdaterIT { ChangedIssue changedIssue = builder.getIssues().iterator().next(); assertThat(changedIssue.getKey()).isEqualTo(issue.key()); assertThat(changedIssue.getNewStatus()).isEqualTo(issue.status()); - assertThat(changedIssue.getNewResolution()).isEmpty(); assertThat(changedIssue.getAssignee()).isEmpty(); assertThat(changedIssue.getRule()).isEqualTo(ruleOf(rule)); assertThat(changedIssue.getProject()).isEqualTo(projectBranchOf(db, branch)); @@ -238,7 +235,6 @@ public class IssueUpdaterIT { ChangedIssue changedIssue = builder.getIssues().iterator().next(); assertThat(changedIssue.getKey()).isEqualTo(issue.key()); assertThat(changedIssue.getNewStatus()).isEqualTo(issue.status()); - assertThat(changedIssue.getNewResolution()).isEmpty(); assertThat(changedIssue.getAssignee()).contains(userOf(newAssignee)); assertThat(changedIssue.getRule()).isEqualTo(ruleOf(rule)); assertThat(changedIssue.getProject()).isEqualTo(projectOf(project)); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/BulkChangeAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/BulkChangeAction.java index 3d077b3324e..2b808158f3a 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/BulkChangeAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/BulkChangeAction.java @@ -47,6 +47,7 @@ import org.sonar.api.utils.System2; import org.sonar.api.web.UserRole; import org.sonar.core.issue.DefaultIssue; import org.sonar.core.issue.IssueChangeContext; +import org.sonar.core.issue.status.IssueStatus; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.component.BranchDto; @@ -334,7 +335,7 @@ public class BulkChangeAction implements IssuesWsAction { Optional assignee = Optional.ofNullable(issue.assignee()).map(userDtoByUuid::get); return new ChangedIssue.Builder(issue.key()) .setNewStatus(issue.status()) - .setNewResolution(issue.resolution()) + .setNewIssueStatus(IssueStatus.of(issue.status(), issue.resolution())) .setAssignee(assignee.map(u -> new User(u.getUuid(), u.getLogin(), u.getName())).orElse(null)) .setRule(new IssuesChangesNotificationBuilder.Rule(ruleDefinitionDto.getKey(), RuleType.valueOfNullable(ruleDefinitionDto.getType()), ruleDefinitionDto.getName())) .setProject(new Project.Builder(projectDto.uuid()) diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/IssueUpdater.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/IssueUpdater.java index 471c5071c3f..b07bcb0e61b 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/IssueUpdater.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/IssueUpdater.java @@ -28,6 +28,7 @@ import org.sonar.api.rule.RuleStatus; import org.sonar.api.rules.RuleType; import org.sonar.core.issue.DefaultIssue; import org.sonar.core.issue.IssueChangeContext; +import org.sonar.core.issue.status.IssueStatus; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.component.BranchDto; @@ -49,6 +50,7 @@ import org.sonar.server.notification.NotificationManager; import static com.google.common.base.Preconditions.checkState; import static java.util.Collections.singleton; import static java.util.Collections.singletonList; +import static java.util.Optional.ofNullable; import static org.apache.commons.lang.StringUtils.isNotEmpty; import static org.sonar.db.component.BranchType.PULL_REQUEST; @@ -120,15 +122,15 @@ public class IssueUpdater { return issueDto; } - Optional assignee = Optional.ofNullable(issue.assignee()) + Optional assignee = ofNullable(issue.assignee()) .map(assigneeUuid -> dbClient.userDao().selectByUuid(session, assigneeUuid)); - UserDto author = Optional.ofNullable(context.userUuid()) + UserDto author = ofNullable(context.userUuid()) .map(authorUuid -> dbClient.userDao().selectByUuid(session, authorUuid)) .orElseThrow(() -> new IllegalStateException("Can not find dto for change author " + context.userUuid())); IssuesChangesNotificationBuilder notificationBuilder = new IssuesChangesNotificationBuilder(singleton( new ChangedIssue.Builder(issue.key()) - .setNewResolution(issue.resolution()) .setNewStatus(issue.status()) + .setNewIssueStatus(IssueStatus.of(issue.status(), issue.resolution())) .setAssignee(assignee.map(assigneeDto -> new User(assigneeDto.getUuid(), assigneeDto.getLogin(), assigneeDto.getName())).orElse(null)) .setRule(new Rule(ruleDto.getKey(), RuleType.valueOfNullable(ruleDto.getType()), ruleDto.getName())) .setProject(new Project.Builder(project.uuid()) diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/notification/ws/DispatchersImplTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/notification/ws/DispatchersImplTest.java index b28319dcc35..6a080a5b8c1 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/notification/ws/DispatchersImplTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/notification/ws/DispatchersImplTest.java @@ -20,7 +20,7 @@ package org.sonar.server.notification.ws; import org.junit.Test; -import org.sonar.server.issue.notification.FPOrWontFixNotificationHandler; +import org.sonar.server.issue.notification.FPOrAcceptedNotificationHandler; import org.sonar.server.issue.notification.MyNewIssuesNotificationHandler; import org.sonar.server.issue.notification.NewIssuesNotificationHandler; import org.sonar.server.notification.NotificationChannel; @@ -43,7 +43,7 @@ public class DispatchersImplTest { NotificationDispatcherMetadata.create(QGChangeNotificationHandler.KEY) .setProperty(GLOBAL_NOTIFICATION, "true") .setProperty(PER_PROJECT_NOTIFICATION, "true"), - NotificationDispatcherMetadata.create(FPOrWontFixNotificationHandler.KEY) + NotificationDispatcherMetadata.create(FPOrAcceptedNotificationHandler.KEY) .setProperty(GLOBAL_NOTIFICATION, "false") .setProperty(PER_PROJECT_NOTIFICATION, "true") }, @@ -64,7 +64,7 @@ public class DispatchersImplTest { underTest.start(); assertThat(underTest.getProjectDispatchers()).containsExactly( - QGChangeNotificationHandler.KEY, FPOrWontFixNotificationHandler.KEY, MyNewIssuesNotificationHandler.KEY); + QGChangeNotificationHandler.KEY, FPOrAcceptedNotificationHandler.KEY, MyNewIssuesNotificationHandler.KEY); } } diff --git a/sonar-core/src/main/resources/org/sonar/l10n/core.properties b/sonar-core/src/main/resources/org/sonar/l10n/core.properties index 100d9b5eb50..df61d5598fa 100644 --- a/sonar-core/src/main/resources/org/sonar/l10n/core.properties +++ b/sonar-core/src/main/resources/org/sonar/l10n/core.properties @@ -2538,7 +2538,7 @@ notification.dispatcher.ChangesOnMyIssue=Changes in issues/hotspots assigned to notification.dispatcher.NewIssues=New issues notification.dispatcher.NewAlerts=Quality gate changes on all available projects notification.dispatcher.NewAlerts.project=Quality gate changes -notification.dispatcher.NewFalsePositiveIssue=Issues resolved as false positive or accept +notification.dispatcher.NewFalsePositiveIssue=Issues resolved as false positive or accepted notification.dispatcher.SQ-MyNewIssues=My new issues notification.dispatcher.CeReportTaskFailure=Background tasks in failure on my administered projects notification.dispatcher.CeReportTaskFailure.project=Background tasks in failure -- 2.39.5