]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-11989 Send notification when doing bulk changes on Security Hotspots
authorJulien HENRY <julien.henry@sonarsource.com>
Tue, 21 May 2019 13:40:33 +0000 (15:40 +0200)
committerSonarTech <sonartech@sonarsource.com>
Wed, 22 May 2019 18:21:16 +0000 (20:21 +0200)
server/sonar-server/src/main/java/org/sonar/server/issue/ws/BulkChangeAction.java
server/sonar-server/src/test/java/org/sonar/server/issue/ws/BulkChangeActionTest.java

index 4b4bba89e88a9d74ae46d903524a31a256f3b72f..d4662b0a5c34196a18993158c6a55758d9da2ecc 100644 (file)
@@ -267,7 +267,6 @@ public class BulkChangeAction implements IssuesWsAction {
       return;
     }
     Set<ChangedIssue> changedIssues = issues.stream()
-      .filter(issue -> issue.type() != RuleType.SECURITY_HOTSPOT)
       // should not happen but filter it out anyway to avoid NPE in oldestUpdateDate call below
       .filter(issue -> issue.updateDate() != null)
       .map(issue -> toNotification(bulkChangeData, userDtoByUuid, issue))
index 127e87d2530ede65e6d059957999c07bdd805b19..edcfca9ce0f1539cb2bbeefe7549a371b4cc700d 100644 (file)
@@ -74,15 +74,16 @@ import static java.util.Objects.requireNonNull;
 import static java.util.Optional.ofNullable;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.tuple;
-import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.verifyZeroInteractions;
+import static org.sonar.api.issue.DefaultTransitions.SET_AS_IN_REVIEW;
 import static org.sonar.api.issue.Issue.RESOLUTION_FIXED;
 import static org.sonar.api.issue.Issue.STATUS_CLOSED;
 import static org.sonar.api.issue.Issue.STATUS_CONFIRMED;
+import static org.sonar.api.issue.Issue.STATUS_IN_REVIEW;
 import static org.sonar.api.issue.Issue.STATUS_OPEN;
+import static org.sonar.api.issue.Issue.STATUS_TO_REVIEW;
 import static org.sonar.api.rule.Severity.MAJOR;
 import static org.sonar.api.rule.Severity.MINOR;
 import static org.sonar.api.rules.RuleType.BUG;
@@ -90,6 +91,7 @@ import static org.sonar.api.rules.RuleType.CODE_SMELL;
 import static org.sonar.api.rules.RuleType.SECURITY_HOTSPOT;
 import static org.sonar.api.rules.RuleType.VULNERABILITY;
 import static org.sonar.api.web.UserRole.ISSUE_ADMIN;
+import static org.sonar.api.web.UserRole.SECURITYHOTSPOT_ADMIN;
 import static org.sonar.api.web.UserRole.USER;
 import static org.sonar.db.component.ComponentTesting.newFileDto;
 import static org.sonar.db.issue.IssueChangeDto.TYPE_COMMENT;
@@ -333,24 +335,34 @@ public class BulkChangeActionTest {
   }
 
   @Test
-  public void hotspots_are_ignored_and_no_notification_is_sent() {
+  public void send_notification_on_hotspots() {
     UserDto user = db.users().insertUser();
     userSession.logIn(user);
     ComponentDto project = db.components().insertMainBranch();
     ComponentDto file = db.components().insertComponent(newFileDto(project));
-    addUserProjectPermissions(user, project, USER, ISSUE_ADMIN);
+    addUserProjectPermissions(user, project, USER, SECURITYHOTSPOT_ADMIN);
     RuleDefinitionDto rule = db.rules().insert();
     IssueDto issue = db.issues().insert(rule, project, file, i -> i.setType(SECURITY_HOTSPOT)
-      .setStatus(STATUS_OPEN).setResolution(null));
+      .setStatus(STATUS_TO_REVIEW).setResolution(null));
 
     BulkChangeWsResponse response = call(builder()
       .setIssues(singletonList(issue.getKey()))
-      .setDoTransition("resetastoreview")
+      .setDoTransition(SET_AS_IN_REVIEW)
       .setSendNotifications(true)
       .build());
 
-    checkResponse(response, 1, 0, 1, 0);
-    verify(notificationManager, never()).scheduleForSending(any());
+    checkResponse(response, 1, 1, 0, 0);
+    verify(notificationManager).scheduleForSending(issueChangeNotificationCaptor.capture());
+    IssuesChangesNotificationBuilder builder = issuesChangesSerializer.from(issueChangeNotificationCaptor.getValue());
+    assertThat(builder.getIssues()).hasSize(1);
+    ChangedIssue changedIssue = builder.getIssues().iterator().next();
+    assertThat(changedIssue.getKey()).isEqualTo(issue.getKey());
+    assertThat(changedIssue.getNewStatus()).isEqualTo(STATUS_IN_REVIEW);
+    assertThat(changedIssue.getNewResolution()).isEmpty();
+    assertThat(changedIssue.getAssignee()).isEmpty();
+    assertThat(changedIssue.getRule()).isEqualTo(ruleOf(rule));
+    assertThat(builder.getChange()).isEqualTo(new UserChange(NOW, userOf(user)));
+    verifyPostProcessorCalled(file);
   }
 
   @Test