@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);
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()));
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()));
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;
}
@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"));
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;
}
@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
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));
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));
@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);
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);