]> source.dussan.org Git - sonarqube.git/commitdiff
[NO JIRA] Fix ComponentdbTester to support different main branch UUIDs
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Tue, 9 May 2023 15:19:14 +0000 (10:19 -0500)
committersonartech <sonartech@sonarsource.com>
Wed, 10 May 2023 20:05:28 +0000 (20:05 +0000)
server/sonar-ce-common/src/it/java/org/sonar/ce/queue/CeQueueImplIT.java
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/issue/SiblingsIssueMergerIT.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/PullRequestSourceBranchMergerTest.java
server/sonar-db-dao/src/it/java/org/sonar/db/purge/PurgeCommandsIT.java
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java
server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexFiltersTest.java

index 296cf5486295a36e6f4eb189085b60e157d9ecf3..0823582b04de0f9f581ef30c747ecbbd4414e8e1 100644 (file)
@@ -239,7 +239,7 @@ public class CeQueueImplIT {
 
   @Test
   public void massSubmit_populates_component_name_and_key_of_CeTask_if_project_and_branch_exists() {
-    ComponentDto project = insertComponent(ComponentTesting.newPrivateProjectDto("PROJECT_1"));
+    ComponentDto project = db.components().insertPublicProject(p -> p.setUuid("PROJECT_1").setBranchUuid("PROJECT_1")).getMainBranchComponent();
     ComponentDto branch1 = db.components().insertProjectBranch(project);
     ComponentDto branch2 = db.components().insertProjectBranch(project);
     CeTaskSubmit taskSubmit1 = createTaskSubmit(CeTaskTypes.REPORT, Component.fromDto(branch1.uuid(), project.uuid()), null);
index 9c38acb8216b37c886d9fe6df358cd8c96dfd3a4..a44ffda6cd1b9679486a0a2442c53452bcc4a4d9 100644 (file)
@@ -105,7 +105,7 @@ public class SiblingsIssueMergerIT {
     copier = new SiblingsIssueMerger(new SiblingsIssuesLoader(new SiblingComponentsWithOpenIssues(treeRootHolder, metadataHolder, dbClient), dbClient, componentIssuesLoader),
       tracker,
       issueLifecycle);
-    projectDto = db.components().insertPublicProject(p -> p.setKey(PROJECT_KEY).setUuid(PROJECT_UUID)).getMainBranchComponent();
+    projectDto = db.components().insertPublicProject(p -> p.setKey(PROJECT_KEY).setUuid(PROJECT_UUID).setBranchUuid(PROJECT_UUID)).getMainBranchComponent();
     branch1Dto = db.components().insertProjectBranch(projectDto, b -> b.setKey("myBranch1")
       .setBranchType(BranchType.PULL_REQUEST)
       .setMergeBranchUuid(projectDto.uuid()));
index 76da837df48e03ff15479fe55b2242744e2216f7..b8214e4fdec4c9e2cf1cfd30a815fa11b755d7e9 100644 (file)
@@ -88,7 +88,7 @@ public class PullRequestSourceBranchMergerTest {
       issueLifecycle,
       sourceBranchInputFactory);
 
-    ComponentDto projectDto = db.components().insertPublicProject(p -> p.setKey(PROJECT_KEY).setUuid(PROJECT_UUID)).getMainBranchComponent();
+    ComponentDto projectDto = db.components().insertPublicProject(p -> p.setKey(PROJECT_KEY).setUuid(PROJECT_UUID).setBranchUuid(PROJECT_UUID)).getMainBranchComponent();
     ComponentDto branch1Dto = db.components().insertProjectBranch(projectDto, b -> b.setKey("myBranch1")
       .setBranchType(BranchType.PULL_REQUEST)
       .setMergeBranchUuid(projectDto.uuid()));
index 1de9381e774c4a24028b4b2a65d0415202064311..2031f270006a06d097c00ae3f4ff573122a07393 100644 (file)
@@ -42,6 +42,7 @@ import org.sonar.db.ce.CeTaskMessageType;
 import org.sonar.db.component.BranchDto;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.component.ComponentTesting;
+import org.sonar.db.component.ProjectData;
 import org.sonar.db.component.SnapshotDto;
 import org.sonar.db.dialect.Dialect;
 import org.sonar.db.duplication.DuplicationUnitDto;
@@ -151,9 +152,8 @@ public class PurgeCommandsIT {
   }
 
   @Test
-  @UseDataProvider("projects")
-  public void deleteNonMainBranchComponentsByProjectUuid_shouldDeletesAllBranchesOfAProjectExceptMainBranch(ComponentDto project) {
-    dbTester.components().insertComponent(project);
+  public void deleteNonMainBranchComponentsByProjectUuid_shouldDeletesAllBranchesOfAProjectExceptMainBranch() {
+    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
     ComponentDto branch = dbTester.components().insertProjectBranch(project);
 
     ComponentDto directory1 = dbTester.components().insertComponent(ComponentTesting.newDirectory(project, "a"));
index 667b703230e856c59858c0975604832611350eba..88fe3d3428771e100a8e01a0f76b8eb93c717961 100644 (file)
@@ -21,6 +21,7 @@ package org.sonar.db.component;
 
 import java.util.Arrays;
 import java.util.List;
+import java.util.Optional;
 import java.util.function.Consumer;
 import javax.annotation.Nullable;
 import org.sonar.api.resources.Qualifiers;
@@ -478,10 +479,11 @@ public class ComponentDbTester {
   }
 
   @SafeVarargs
-  public final ComponentDto insertProjectBranch(ComponentDto project, Consumer<BranchDto>... dtoPopulators) {
-    BranchDto branchDto = ComponentTesting.newBranchDto(project.uuid(), BRANCH);
+  public final ComponentDto insertProjectBranch(ComponentDto mainBranchComponent, Consumer<BranchDto>... dtoPopulators) {
+    BranchDto mainBranch = dbClient.branchDao().selectByUuid(db.getSession(), mainBranchComponent.branchUuid()).orElseThrow(IllegalArgumentException::new);
+    BranchDto branchDto = ComponentTesting.newBranchDto(mainBranch.getProjectUuid(), BRANCH);
     Arrays.stream(dtoPopulators).forEach(dtoPopulator -> dtoPopulator.accept(branchDto));
-    return insertProjectBranch(project, branchDto);
+    return insertProjectBranch(mainBranchComponent, branchDto);
   }
 
   @SafeVarargs
index 93775cac98467515130cd045c92fa54592ba5846..fed30d63c1881dbd5b51392ffbeb8082d4b09584 100644 (file)
@@ -374,7 +374,7 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
   public void filter_by_created_after_by_project_branches() {
     Date now = new Date();
 
-    ComponentDto project1 = newPrivateProjectDto();
+    ComponentDto project1 = db.components().insertPrivateProject().getMainBranchComponent();
     IssueDoc project1Issue1 = newDocForProject(project1).setFuncCreationDate(addDays(now, -10));
     IssueDoc project1Issue2 = newDocForProject(project1).setFuncCreationDate(addDays(now, -20));
 
@@ -382,7 +382,7 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
     IssueDoc project1Branch1Issue1 = newDoc(project1Branch1, project1.uuid()).setFuncCreationDate(addDays(now, -10));
     IssueDoc project1Branch1Issue2 = newDoc(project1Branch1, project1.uuid()).setFuncCreationDate(addDays(now, -20));
 
-    ComponentDto project2 = newPrivateProjectDto();
+    ComponentDto project2 = db.components().insertPrivateProject().getMainBranchComponent();
 
     IssueDoc project2Issue1 = newDocForProject(project2).setFuncCreationDate(addDays(now, -15));
     IssueDoc project2Issue2 = newDocForProject(project2).setFuncCreationDate(addDays(now, -30));
@@ -441,7 +441,7 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
 
   @Test
   public void filter_by_new_code_reference_branches() {
-    ComponentDto project1 = newPrivateProjectDto();
+    ComponentDto project1 = db.components().insertPrivateProject().getMainBranchComponent();
     IssueDoc project1Issue1 = newDocForProject(project1).setIsNewCodeReference(true);
     IssueDoc project1Issue2 = newDocForProject(project1).setIsNewCodeReference(false);
 
@@ -449,7 +449,7 @@ public class IssueIndexFiltersTest extends IssueIndexTestCommon {
     IssueDoc project1Branch1Issue1 = newDoc(project1Branch1, project1.uuid()).setIsNewCodeReference(false);
     IssueDoc project1Branch1Issue2 = newDoc(project1Branch1, project1.uuid()).setIsNewCodeReference(true);
 
-    ComponentDto project2 = newPrivateProjectDto();
+    ComponentDto project2 = db.components().insertPrivateProject().getMainBranchComponent();
 
     IssueDoc project2Issue1 = newDocForProject(project2).setIsNewCodeReference(true);
     IssueDoc project2Issue2 = newDocForProject(project2).setIsNewCodeReference(false);