]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-18944 Fix PushEvent population on issues
authorJacek Poreda <jacek.poreda@sonarsource.com>
Tue, 6 Jun 2023 08:30:03 +0000 (10:30 +0200)
committersonartech <sonartech@sonarsource.com>
Tue, 6 Jun 2023 20:03:10 +0000 (20:03 +0000)
server/sonar-webserver-pushapi/src/main/java/org/sonar/server/pushapi/issues/IssueChangeEventServiceImpl.java
server/sonar-webserver-pushapi/src/test/java/org/sonar/server/pushapi/issues/IssueChangeEventServiceImplTest.java

index 835909e02890109926540a114179acff2336631e..eade0b95a1d22dd2f702f4e3fae74e19c9845013 100644 (file)
@@ -79,7 +79,7 @@ public class IssueChangeEventServiceImpl implements IssueChangeEventService {
     IssueChangedEvent event = new IssueChangedEvent(projectKey, new Issue[]{changedIssue},
       resolved, severity, type);
 
-    persistEvent(event, issue.projectUuid());
+    persistEvent(event, branch.getProjectUuid());
   }
 
   @Override
@@ -106,7 +106,8 @@ public class IssueChangeEventServiceImpl implements IssueChangeEventService {
       IssueChangedEvent event = getIssueChangedEvent(projectKey, issuesInProject, issueChanges);
 
       if (event != null) {
-        persistEvent(event, entry.getValue().branchUuid());
+        BranchDto branchDto = branchesByProjectUuid.get(entry.getKey());
+        persistEvent(event, branchDto.getProjectUuid());
       }
     }
   }
index b3ebcac7130de800369d7512b71111a21d3d76c9..9f01bc411cdb375d06a9fa9c7c57b8e35883937e 100644 (file)
@@ -63,7 +63,7 @@ public class IssueChangeEventServiceImplTest {
   public final IssueChangeEventServiceImpl underTest = new IssueChangeEventServiceImpl(db.getDbClient());
 
   @Test
-  public void distributeIssueChangeEvent_singleIssueChange_severityChange() {
+  public void distributeIssueChangeEvent_whenSingleIssueChange_shouldChangeSeverity() {
     ComponentDto componentDto = db.components().insertPublicProject().getMainBranchComponent();
     ProjectDto project = db.getDbClient().projectDao().selectByUuid(db.getSession(), componentDto.uuid()).get();
     BranchDto branch = db.getDbClient().branchDao().selectByUuid(db.getSession(), project.getUuid()).get();
@@ -74,7 +74,7 @@ public class IssueChangeEventServiceImplTest {
   }
 
   @Test
-  public void distributeIssueChangeEvent_singleIssueChange_typeChange() {
+  public void distributeIssueChangeEvent_whenSingleIssueChange_shouldChangeType() {
     ComponentDto componentDto = db.components().insertPublicProject().getMainBranchComponent();
     ProjectDto project = db.getDbClient().projectDao().selectByUuid(db.getSession(), componentDto.uuid()).get();
     BranchDto branch = db.getDbClient().branchDao().selectByUuid(db.getSession(), project.getUuid()).get();
@@ -85,7 +85,7 @@ public class IssueChangeEventServiceImplTest {
   }
 
   @Test
-  public void distributeIssueChangeEvent_singleIssueChange_transitionChanges() {
+  public void distributeIssueChangeEvent_whenSingleIssueChange_shouldExecuteTransitionChanges() {
     ComponentDto componentDto = db.components().insertPublicProject().getMainBranchComponent();
     ProjectDto project = db.getDbClient().projectDao().selectByUuid(db.getSession(), componentDto.uuid()).get();
     BranchDto branch = db.getDbClient().branchDao().selectByUuid(db.getSession(), project.getUuid()).get();
@@ -103,7 +103,18 @@ public class IssueChangeEventServiceImplTest {
   }
 
   @Test
-  public void distributeIssueChangeEvent_singleIssueChange_severalChanges() {
+  public void distributeIssueChangeEvent_whenSingleIssueChangeOnABranch_shouldChangeSeverity() {
+    ComponentDto componentDto = db.components().insertPublicProject().getMainBranchComponent();
+    ProjectDto project = db.getDbClient().projectDao().selectByUuid(db.getSession(), componentDto.uuid()).get();
+    BranchDto featureBranch = db.components().insertProjectBranch(project, b -> b.setKey("feature1"));
+    ComponentDto branchComponent = db.components().insertFile(featureBranch);
+    RuleDto rule = db.rules().insert();
+    IssueDto issue = db.issues().insert(rule, project, branchComponent, i -> i.setSeverity(MAJOR.name()));
+    assertPushEventIsPersisted(project, featureBranch, issue, BLOCKER.name(), null, null, null, 1);
+  }
+
+  @Test
+  public void distributeIssueChangeEvent_whenSingleIssueChange_shouldExecuteSeveralChanges() {
     ComponentDto componentDto = db.components().insertPublicProject().getMainBranchComponent();
     ProjectDto project = db.getDbClient().projectDao().selectByUuid(db.getSession(), componentDto.uuid()).get();
     BranchDto branch = db.getDbClient().branchDao().selectByUuid(db.getSession(), project.getUuid()).get();
@@ -114,7 +125,7 @@ public class IssueChangeEventServiceImplTest {
   }
 
   @Test
-  public void distributeIssueChangeEvent_bulkIssueChange() {
+  public void distributeIssueChangeEvent_whenBulkIssueChange_shouldDistributesEvents() {
     RuleDto rule = db.rules().insert();
 
     ComponentDto componentDto1 = db.components().insertPublicProject().getMainBranchComponent();
@@ -185,7 +196,7 @@ public class IssueChangeEventServiceImplTest {
   }
 
   @Test
-  public void doNotDistributeIssueChangeEvent_forPullRequestIssues() {
+  public void distributeIssueChangeEvent_whenPullRequestIssues_shouldNotDistributeEvents() {
     RuleDto rule = db.rules().insert();
 
     ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();