aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-webserver-pushapi
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2023-06-16 14:48:59 -0500
committersonartech <sonartech@sonarsource.com>2023-06-29 20:05:14 +0000
commit114a4deec2e278438cb9db6666b9bc8dfc46ab2c (patch)
tree046a3509a9af9f2e3b4052200078f01cb18ce698 /server/sonar-webserver-pushapi
parent63fc7d901eaacd42e9a40099906c38ae2aa779d4 (diff)
downloadsonarqube-114a4deec2e278438cb9db6666b9bc8dfc46ab2c.tar.gz
sonarqube-114a4deec2e278438cb9db6666b9bc8dfc46ab2c.zip
SONAR-19558 Refactor 'issues', 'issue_changes', Components and view indexes
Diffstat (limited to 'server/sonar-webserver-pushapi')
-rw-r--r--server/sonar-webserver-pushapi/src/test/java/org/sonar/server/pushapi/issues/IssueChangeEventServiceImplTest.java90
1 files changed, 43 insertions, 47 deletions
diff --git a/server/sonar-webserver-pushapi/src/test/java/org/sonar/server/pushapi/issues/IssueChangeEventServiceImplTest.java b/server/sonar-webserver-pushapi/src/test/java/org/sonar/server/pushapi/issues/IssueChangeEventServiceImplTest.java
index 9f01bc411cd..05b3efeb779 100644
--- a/server/sonar-webserver-pushapi/src/test/java/org/sonar/server/pushapi/issues/IssueChangeEventServiceImplTest.java
+++ b/server/sonar-webserver-pushapi/src/test/java/org/sonar/server/pushapi/issues/IssueChangeEventServiceImplTest.java
@@ -35,6 +35,7 @@ import org.sonar.db.DbTester;
import org.sonar.db.component.BranchDto;
import org.sonar.db.component.BranchType;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ProjectData;
import org.sonar.db.issue.IssueDto;
import org.sonar.db.project.ProjectDto;
import org.sonar.db.pushevent.PushEventDto;
@@ -58,90 +59,86 @@ import static org.sonarqube.ws.Common.Severity.MAJOR;
public class IssueChangeEventServiceImplTest {
@Rule
- public DbTester db = DbTester.create();
+ public DbTester db = DbTester.create(true);
public final IssueChangeEventServiceImpl underTest = new IssueChangeEventServiceImpl(db.getDbClient());
@Test
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();
+ ProjectData projectData = db.components().insertPublicProject();
RuleDto rule = db.rules().insert();
- IssueDto issue = db.issues().insert(rule, project, componentDto, i -> i.setSeverity(MAJOR.name()));
+ IssueDto issue = db.issues().insert(rule, projectData.getMainBranchDto(), projectData.getMainBranchComponent(), i -> i.setSeverity(MAJOR.name()));
- assertPushEventIsPersisted(project, branch, issue, BLOCKER.name(), null, null, null, 1);
+ assertPushEventIsPersisted(projectData.getProjectDto(), projectData.getMainBranchDto(), issue, BLOCKER.name(), null, null, null, 1);
}
@Test
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();
+ ProjectData projectData = db.components().insertPublicProject();
RuleDto rule = db.rules().insert();
- IssueDto issue = db.issues().insert(rule, project, componentDto, i -> i.setSeverity(MAJOR.name()));
+ IssueDto issue = db.issues().insert(rule, projectData.getMainBranchDto(), projectData.getMainBranchComponent(), i -> i.setSeverity(MAJOR.name()));
- assertPushEventIsPersisted(project, branch, issue, null, Common.RuleType.BUG.name(), null, null, 1);
+ assertPushEventIsPersisted(projectData.getProjectDto(), projectData.getMainBranchDto(), issue, null, Common.RuleType.BUG.name(), null, null, 1);
}
@Test
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();
+ ProjectData projectData = db.components().insertPublicProject();
+ ProjectDto project = projectData.getProjectDto();
+ BranchDto mainBranch = projectData.getMainBranchDto();
RuleDto rule = db.rules().insert();
- IssueDto issue = db.issues().insert(rule, project, componentDto, i -> i.setSeverity(MAJOR.name()));
-
- assertPushEventIsPersisted(project, branch, issue, null, null, WONT_FIX, true, 1);
- assertPushEventIsPersisted(project, branch, issue, null, null, REOPEN, false, 2);
- assertPushEventIsPersisted(project, branch, issue, null, null, FALSE_POSITIVE, true, 3);
- assertPushEventIsPersisted(project, branch, issue, null, null, REOPEN, false, 4);
- assertPushEventIsPersisted(project, branch, issue, null, null, RESOLVE, false, 5);
- assertPushEventIsPersisted(project, branch, issue, null, null, REOPEN, false, 6);
- assertNoIssueDistribution(project, branch, issue, null, null, CONFIRM, 7);
- assertNoIssueDistribution(project, branch, issue, null, null, UNCONFIRM, 8);
+ IssueDto issue = db.issues().insert(rule, mainBranch, projectData.getMainBranchComponent(), i -> i.setSeverity(MAJOR.name()));
+
+ assertPushEventIsPersisted(project, mainBranch, issue, null, null, WONT_FIX, true, 1);
+ assertPushEventIsPersisted(project, mainBranch, issue, null, null, REOPEN, false, 2);
+ assertPushEventIsPersisted(project, mainBranch, issue, null, null, FALSE_POSITIVE, true, 3);
+ assertPushEventIsPersisted(project, mainBranch, issue, null, null, REOPEN, false, 4);
+ assertPushEventIsPersisted(project, mainBranch, issue, null, null, RESOLVE, false, 5);
+ assertPushEventIsPersisted(project, mainBranch, issue, null, null, REOPEN, false, 6);
+ assertNoIssueDistribution(project, mainBranch, issue, null, null, CONFIRM, 7);
+ assertNoIssueDistribution(project, mainBranch, issue, null, null, UNCONFIRM, 8);
}
@Test
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"));
+ ProjectData projectData = db.components().insertPublicProject();
+ BranchDto featureBranch = db.components().insertProjectBranch(projectData.getProjectDto(), 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);
+ IssueDto issue = db.issues().insert(rule, featureBranch, branchComponent, i -> i.setSeverity(MAJOR.name()));
+ assertPushEventIsPersisted(projectData.getProjectDto(), 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();
+ ProjectData projectData = db.components().insertPublicProject();
RuleDto rule = db.rules().insert();
- IssueDto issue = db.issues().insert(rule, project, componentDto, i -> i.setSeverity(MAJOR.name()));
+ IssueDto issue = db.issues().insert(rule, projectData.getMainBranchDto(), projectData.getMainBranchComponent(), i -> i.setSeverity(MAJOR.name()));
- assertPushEventIsPersisted(project, branch, issue, BLOCKER.name(), Common.RuleType.BUG.name(), WONT_FIX, true, 1);
+ assertPushEventIsPersisted(projectData.getProjectDto(), projectData.getMainBranchDto(), issue, BLOCKER.name(), Common.RuleType.BUG.name(), WONT_FIX, true, 1);
}
@Test
public void distributeIssueChangeEvent_whenBulkIssueChange_shouldDistributesEvents() {
RuleDto rule = db.rules().insert();
- ComponentDto componentDto1 = db.components().insertPublicProject().getMainBranchComponent();
- ProjectDto project1 = db.getDbClient().projectDao().selectByUuid(db.getSession(), componentDto1.uuid()).get();
- BranchDto branch1 = db.getDbClient().branchDao().selectByUuid(db.getSession(), project1.getUuid()).get();
- IssueDto issue1 = db.issues().insert(rule, project1, componentDto1, i -> i.setSeverity(MAJOR.name()).setType(RuleType.BUG));
+ ProjectData projectData1 = db.components().insertPublicProject();
+ ProjectDto project1 = projectData1.getProjectDto();
+ BranchDto branch1 = projectData1.getMainBranchDto();
+ ComponentDto componentDto1 = projectData1.getMainBranchComponent();
+ IssueDto issue1 = db.issues().insert(rule, branch1, componentDto1, i -> i.setSeverity(MAJOR.name()).setType(RuleType.BUG));
- ComponentDto componentDto2 = db.components().insertPublicProject().getMainBranchComponent();
- ProjectDto project2 = db.getDbClient().projectDao().selectByUuid(db.getSession(), componentDto2.uuid()).get();
- BranchDto branch2 = db.getDbClient().branchDao().selectByUuid(db.getSession(), project2.getUuid()).get();
- IssueDto issue2 = db.issues().insert(rule, project2, componentDto2, i -> i.setSeverity(MAJOR.name()).setType(RuleType.BUG));
+ ProjectData projectData2 = db.components().insertPublicProject();
+ ProjectDto project2 = projectData2.getProjectDto();
+ BranchDto branch2 = projectData2.getMainBranchDto();
+ ComponentDto componentDto2 = projectData2.getMainBranchComponent();
+ IssueDto issue2 = db.issues().insert(rule, branch2, componentDto2, i -> i.setSeverity(MAJOR.name()).setType(RuleType.BUG));
- ComponentDto componentDto3 = db.components().insertPublicProject().getMainBranchComponent();
- ProjectDto project3 = db.getDbClient().projectDao().selectByUuid(db.getSession(), componentDto3.uuid()).get();
- BranchDto branch3 = db.getDbClient().branchDao().selectByUuid(db.getSession(), project3.getUuid()).get();
- IssueDto issue3 = db.issues().insert(rule, project3, componentDto3, i -> i.setSeverity(MAJOR.name()).setType(RuleType.BUG));
+ ProjectData projectData3 = db.components().insertPublicProject();
+ ProjectDto project3 = projectData3.getProjectDto();
+ BranchDto branch3 = projectData3.getMainBranchDto();
+ ComponentDto componentDto3 = projectData3.getMainBranchComponent();
+ IssueDto issue3 = db.issues().insert(rule, branch3, componentDto3, i -> i.setSeverity(MAJOR.name()).setType(RuleType.BUG));
DefaultIssue defaultIssue1 = issue1.toDefaultIssue().setCurrentChangeWithoutAddChange(new FieldDiffs()
.setDiff("resolution", null, null)
@@ -256,7 +253,6 @@ public class IssueChangeEventServiceImplTest {
if (resolved != null) {
assertThat(payload).contains("\"resolved\":" + resolved);
}
-
}
}