import org.sonar.db.component.BranchType;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ComponentTesting;
+import org.sonar.db.component.ProjectData;
import org.sonar.db.protobuf.DbProjectBranches;
import org.sonar.server.project.Project;
private final static Component MAIN = builder(Component.Type.PROJECT, 1, "PROJECT_KEY").setUuid("PROJECT_UUID").setName("p1").build();
private final static Component BRANCH1 = builder(Component.Type.PROJECT, 2, "BRANCH_KEY").setUuid("BRANCH_UUID").build();
private final static Component PR1 = builder(Component.Type.PROJECT, 3, "develop").setUuid("PR_UUID").build();
- private static final Project PROJECT = new Project(MAIN.getUuid(), MAIN.getKey(), MAIN.getName(), null, Collections.emptyList());
+ private static final Project PROJECT = new Project("PROJECT_UUID", MAIN.getKey(), MAIN.getName(), null, Collections.emptyList());
@Rule
public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule();
String pullRequestId = "pr-123";
// add project and branch in table PROJECTS
- ComponentDto mainComponent = ComponentTesting.newPrivateProjectDto(MAIN.getUuid()).setKey(MAIN.getKey());
+ ProjectData projectData = dbTester.components().insertPrivateProject(p -> p.setKey(MAIN.getKey()).setUuid(MAIN.getUuid()));
+ ComponentDto mainComponent = projectData.getMainBranchComponent();
ComponentDto component = ComponentTesting.newBranchComponent(mainComponent,
new BranchDto().setUuid(BRANCH1.getUuid()).setKey(BRANCH1.getKey()).setBranchType(PULL_REQUEST));
- dbTester.components().insertComponents(mainComponent, component);
+ dbTester.components().insertComponents(component);
// set project in metadata
treeRootHolder.setRoot(BRANCH1);
analysisMetadataHolder.setBranch(createBranch(PULL_REQUEST, false, pullRequestId, "mergeBanchUuid"));
- analysisMetadataHolder.setProject(Project.from(mainComponent));
+ analysisMetadataHolder.setProject(Project.from(projectData.getProjectDto()));
analysisMetadataHolder.setPullRequestKey(pullRequestId);
underTest.persist(dbTester.getSession());
assertThat(branchDto.get().getBranchType()).isEqualTo(PULL_REQUEST);
assertThat(branchDto.get().getKey()).isEqualTo(pullRequestId);
assertThat(branchDto.get().getMergeBranchUuid()).isEqualTo("mergeBanchUuid");
- assertThat(branchDto.get().getProjectUuid()).isEqualTo(MAIN.getUuid());
+ assertThat(branchDto.get().getProjectUuid()).isEqualTo(projectData.projectUuid());
assertThat(branchDto.get().getPullRequestData()).isEqualTo(DbProjectBranches.PullRequestData.newBuilder()
.setBranch(pullRequestId)
.setTarget("mergeBanchUuid")
analysisMetadataHolder.setBranch(branch);
ProjectData projectData = db.components().insertPublicProject();
- ComponentDto projectDto = projectData.getMainBranchComponent();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
when(project.getUuid()).thenReturn(projectData.projectUuid());
- branch1 = db.components().insertProjectBranch(projectDto, b -> b.setKey(BRANCH_KEY));
- ComponentDto pr1branch = db.components().insertProjectBranch(projectDto, b -> b.setKey(PR_KEY)
+ branch1 = db.components().insertProjectBranch(mainBranch, b -> b.setKey(BRANCH_KEY));
+ ComponentDto pr1branch = db.components().insertProjectBranch(mainBranch, b -> b.setKey(PR_KEY)
.setBranchType(BranchType.PULL_REQUEST)
.setPullRequestData(DbProjectBranches.PullRequestData.newBuilder().setBranch(BRANCH_KEY).build())
- .setMergeBranchUuid(projectDto.uuid()));
+ .setMergeBranchUuid(mainBranch.uuid()));
branch1File = ComponentTesting.newFileDto(branch1, null, "file").setUuid("branch1File");
pr1File = ComponentTesting.newFileDto(pr1branch, null, "file").setUuid("file1");
db.components().insertComponents(branch1File, pr1File);
private System2 system2 = new TestSystem2().setNow(NOW);
@Rule
- public DbTester db = DbTester.create(system2);
+ public DbTester db = DbTester.create(system2, true);
private DbSession dbSession = db.getSession();
private BranchDao underTest = new BranchDao(system2);
@Test
public void selectByProjectUuid() {
- ComponentDto project1 = db.components().insertPrivateProject().getMainBranchComponent();
- ComponentDto project2 = db.components().insertPrivateProject().getMainBranchComponent();
+ ProjectData projectData1 = db.components().insertPrivateProject();
+ ComponentDto mainBranch1 = projectData1.getMainBranchComponent();
+ ProjectData projectData2 = db.components().insertPrivateProject();
+ ComponentDto mainBranch2 = projectData2.getMainBranchComponent();
- ComponentDto branch1 = db.components().insertProjectBranch(project1);
- ComponentDto branch2 = db.components().insertProjectBranch(project1);
- ComponentDto branch3 = db.components().insertProjectBranch(project2);
- ComponentDto branch4 = db.components().insertProjectBranch(project2);
+ ComponentDto branch1 = db.components().insertProjectBranch(mainBranch1);
+ ComponentDto branch2 = db.components().insertProjectBranch(mainBranch1);
+ ComponentDto branch3 = db.components().insertProjectBranch(mainBranch2);
+ ComponentDto branch4 = db.components().insertProjectBranch(mainBranch2);
- assertThat(underTest.selectByProject(dbSession, new ProjectDto().setUuid(project1.uuid())))
+ assertThat(underTest.selectByProject(dbSession, new ProjectDto().setUuid(projectData1.projectUuid())))
.extracting(BranchDto::getUuid)
- .containsExactlyInAnyOrder(project1.uuid(), branch1.uuid(), branch2.uuid());
- assertThat(underTest.selectByProject(dbSession, new ProjectDto().setUuid(project2.uuid())))
+ .containsExactlyInAnyOrder(mainBranch1.uuid(), branch1.uuid(), branch2.uuid());
+ assertThat(underTest.selectByProject(dbSession, new ProjectDto().setUuid(projectData2.projectUuid())))
.extracting(BranchDto::getUuid)
- .containsExactlyInAnyOrder(project2.uuid(), branch3.uuid(), branch4.uuid());
+ .containsExactlyInAnyOrder(mainBranch2.uuid(), branch3.uuid(), branch4.uuid());
}
@Test
@Test
public void countPrAndBranchByProjectUuid() {
- ComponentDto project1 = db.components().insertPrivateProject().getMainBranchComponent();
+ ProjectData projectData1 = db.components().insertPrivateProject();
+ ComponentDto project1 = projectData1.getMainBranchComponent();
db.components().insertProjectBranch(project1, b -> b.setBranchType(BRANCH).setKey("p1-branch-1"));
db.components().insertProjectBranch(project1, b -> b.setBranchType(BRANCH).setKey("p1-branch-2"));
db.components().insertProjectBranch(project1, b -> b.setBranchType(PULL_REQUEST).setKey("p1-pr-1"));
db.components().insertProjectBranch(project1, b -> b.setBranchType(PULL_REQUEST).setKey("p1-pr-2"));
db.components().insertProjectBranch(project1, b -> b.setBranchType(PULL_REQUEST).setKey("p1-pr-3"));
- ComponentDto project2 = db.components().insertPrivateProject().getMainBranchComponent();
+ ProjectData projectData2 = db.components().insertPrivateProject();
+ ComponentDto project2 = projectData2.getMainBranchComponent();
db.components().insertProjectBranch(project2, b -> b.setBranchType(PULL_REQUEST).setKey("p2-pr-1"));
- ComponentDto project3 = db.components().insertPrivateProject().getMainBranchComponent();
+ ProjectData projectData3 = db.components().insertPrivateProject();
+ ComponentDto project3 = projectData3.getMainBranchComponent();
db.components().insertProjectBranch(project3, b -> b.setBranchType(BRANCH).setKey("p3-branch-1"));
MetricDto unanalyzedC = db.measures().insertMetric(m -> m.setKey("unanalyzed_c"));
.extracting(PrBranchAnalyzedLanguageCountByProjectDto::getProjectUuid, PrBranchAnalyzedLanguageCountByProjectDto::getBranch,
PrBranchAnalyzedLanguageCountByProjectDto::getPullRequest)
.containsExactlyInAnyOrder(
- tuple(project1.uuid(), 3L, 3L),
- tuple(project2.uuid(), 1L, 1L),
- tuple(project3.uuid(), 2L, 0L)
+ tuple(projectData1.projectUuid(), 3L, 3L),
+ tuple(projectData2.projectUuid(), 1L, 1L),
+ tuple(projectData3.projectUuid(), 2L, 0L)
);
}
assertThat(underTest.selectProjectUuidsWithIssuesNeedSync(db.getSession(),
Sets.newHashSet(project1Dto.getUuid(), project2Dto.getUuid(), project3Dto.getUuid(), project4Dto.getUuid())))
- .containsOnly(project1.uuid());
+ .containsOnly(project1Dto.getUuid());
}
@Test
@Test
public void selectBranchNeedingIssueSyncForProject() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- String uuid = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.BRANCH).setNeedIssueSync(true)).uuid();
- db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.BRANCH).setNeedIssueSync(false));
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ String uuid = db.components().insertProjectBranch(mainBranch, b -> b.setBranchType(BranchType.BRANCH).setNeedIssueSync(true)).uuid();
+ db.components().insertProjectBranch(mainBranch, b -> b.setBranchType(BranchType.BRANCH).setNeedIssueSync(false));
- assertThat(underTest.selectBranchNeedingIssueSyncForProject(dbSession, project.uuid()))
+ assertThat(underTest.selectBranchNeedingIssueSyncForProject(dbSession, projectData.projectUuid()))
.extracting(BranchDto::getUuid)
.containsExactly(uuid);
}
@Test
public void updateAllNeedIssueSync() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- String uuid1 = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.BRANCH).setNeedIssueSync(true)).uuid();
- String uuid2 = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.BRANCH).setNeedIssueSync(false)).uuid();
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ String uuid1 = db.components().insertProjectBranch(mainBranch, b -> b.setBranchType(BranchType.BRANCH).setNeedIssueSync(true)).uuid();
+ String uuid2 = db.components().insertProjectBranch(mainBranch, b -> b.setBranchType(BranchType.BRANCH).setNeedIssueSync(false)).uuid();
underTest.updateAllNeedIssueSync(dbSession);
@Test
public void updateAllNeedIssueSyncForProject() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- String uuid1 = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.BRANCH).setNeedIssueSync(true)).uuid();
- String uuid2 = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.BRANCH).setNeedIssueSync(false)).uuid();
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ String uuid1 = db.components().insertProjectBranch(mainBranch, b -> b.setBranchType(BranchType.BRANCH).setNeedIssueSync(true)).uuid();
+ String uuid2 = db.components().insertProjectBranch(mainBranch, b -> b.setBranchType(BranchType.BRANCH).setNeedIssueSync(false)).uuid();
- underTest.updateAllNeedIssueSyncForProject(dbSession, project.uuid());
+ underTest.updateAllNeedIssueSyncForProject(dbSession, projectData.projectUuid());
Optional<BranchDto> project1 = underTest.selectByUuid(dbSession, uuid1);
assertThat(project1).isPresent();
public void doAnyOfComponentsNeedIssueSync() {
assertThat(underTest.doAnyOfComponentsNeedIssueSync(dbSession, emptyList())).isFalse();
- ComponentDto project1 = db.components().insertPrivateProject().getMainBranchComponent();
- ComponentDto project2 = db.components().insertPrivateProject().getMainBranchComponent();
- ProjectDto projectDto = db.components().getProjectDtoByMainBranch(project1);
- db.components().insertProjectBranch(projectDto, b -> b.setBranchType(BranchType.BRANCH).setNeedIssueSync(true));
- BranchDto projectBranch1 = db.components().insertProjectBranch(projectDto, b -> b.setBranchType(BranchType.BRANCH).setNeedIssueSync(true));
- BranchDto projectBranch2 = db.components().insertProjectBranch(projectDto, b -> b.setBranchType(BranchType.BRANCH).setNeedIssueSync(false));
- db.components().insertProjectBranch(projectDto, b -> b.setBranchType(BranchType.BRANCH).setNeedIssueSync(false));
- BranchDto pullRequest1 = db.components().insertProjectBranch(projectDto, b -> b.setBranchType(BranchType.PULL_REQUEST).setNeedIssueSync(true));
- BranchDto pullRequest2 = db.components().insertProjectBranch(projectDto, b -> b.setBranchType(BranchType.PULL_REQUEST).setNeedIssueSync(false));
- db.components().insertProjectBranch(projectDto, b -> b.setBranchType(BranchType.PULL_REQUEST).setNeedIssueSync(true));
-
- assertThat(underTest.doAnyOfComponentsNeedIssueSync(dbSession, singletonList(project1.getKey()))).isTrue();
- assertThat(underTest.doAnyOfComponentsNeedIssueSync(dbSession, singletonList(project2.getKey()))).isFalse();
+ ProjectData projectData1 = db.components().insertPrivateProject();
+ ComponentDto project1 = projectData1.getMainBranchComponent();
+ ProjectData projectData2 = db.components().insertPrivateProject();
+ ComponentDto project2 = projectData2.getMainBranchComponent();
+ db.components().insertProjectBranch(projectData1.getProjectDto(), b -> b.setBranchType(BranchType.BRANCH).setNeedIssueSync(true));
+ BranchDto projectBranch1 = db.components().insertProjectBranch(projectData1.getProjectDto(), b -> b.setBranchType(BranchType.BRANCH).setNeedIssueSync(true));
+ BranchDto projectBranch2 = db.components().insertProjectBranch(projectData1.getProjectDto(), b -> b.setBranchType(BranchType.BRANCH).setNeedIssueSync(false));
+ db.components().insertProjectBranch(projectData1.getProjectDto(), b -> b.setBranchType(BranchType.BRANCH).setNeedIssueSync(false));
+ BranchDto pullRequest1 = db.components().insertProjectBranch(projectData1.getProjectDto(), b -> b.setBranchType(BranchType.PULL_REQUEST).setNeedIssueSync(true));
+ BranchDto pullRequest2 = db.components().insertProjectBranch(projectData1.getProjectDto(), b -> b.setBranchType(BranchType.PULL_REQUEST).setNeedIssueSync(false));
+ db.components().insertProjectBranch(projectData1.getProjectDto(), b -> b.setBranchType(BranchType.PULL_REQUEST).setNeedIssueSync(true));
+
+ assertThat(underTest.doAnyOfComponentsNeedIssueSync(dbSession, singletonList(projectData1.projectKey()))).isTrue();
+ assertThat(underTest.doAnyOfComponentsNeedIssueSync(dbSession, singletonList(projectData2.projectKey()))).isFalse();
}
@Test
db.components().addPortfolioProjectBranch(p1, proj1, "branch1");
db.components().addPortfolioProjectBranch(p2, proj1, "branch2");
- portfolioDao.addReference(session, "p1", "app1");
- portfolioDao.addReference(session, "p2", "app1");
+ portfolioDao.addReferenceBranch(session, "p1", "app1", "main1");
+ portfolioDao.addReferenceBranch(session, "p2", "app1", "main2");
portfolioDao.addReference(session, "p4", "p1");
portfolioDao.delete(session, p1);
portfolioDao.addReference(session, "portfolio1", "portfolio2");
portfolioDao.addReference(session, "portfolio2", "portfolio3");
- portfolioDao.addReference(session, "portfolio3", "app1");
+ portfolioDao.addReferenceBranch(session, "portfolio3", "app1", "main1");
assertThat(portfolioDao.selectAllReferencesToPortfolios(session))
.extracting(ReferenceDto::getSourceUuid, ReferenceDto::getTargetUuid, ReferenceDto::getBranchUuids)
db.components().insertPrivatePortfolioDto("portfolio1");
db.components().insertPrivatePortfolioDto("portfolio2");
db.components().insertPrivatePortfolioDto("portfolio3");
- ProjectDto app1 = db.components().insertPrivateApplication(p -> p.setKey("app1")).getProjectDto();
+ ProjectData appData1 = db.components().insertPrivateApplication(p -> p.setKey("app1"));
+ ProjectDto app1 = appData1.getProjectDto();
portfolioDao.addReference(session, "portfolio1", "portfolio2");
portfolioDao.addReference(session, "portfolio2", "portfolio3");
portfolioDao.addReferenceBranch(session, "portfolio3", app1.getUuid(), "branch1");
- portfolioDao.addReference(session, "portfolio2", app1.getUuid());
+ portfolioDao.addReferenceBranch(session, "portfolio2", app1.getUuid(), appData1.getMainBranchDto().getUuid());
assertThat(portfolioDao.selectAllReferencesToApplications(session))
.extracting(ReferenceDto::getSourceUuid, ReferenceDto::getTargetUuid, ReferenceDto::getTargetRootUuid, ReferenceDto::getBranchUuids)
.containsOnly(
tuple("portfolio3", app1.getUuid(), app1.getUuid(), singleton("branch1")),
- tuple("portfolio2", app1.getUuid(), app1.getUuid(), singleton(app1.getUuid())));
+ tuple("portfolio2", app1.getUuid(), app1.getUuid(), singleton(appData1.getMainBranchDto().getUuid())));
}
@Test
var p1 = db.components().insertPrivatePortfolioDto("portfolio1");
var p2 = db.components().insertPrivatePortfolioDto("portfolio2", p -> p.setRootUuid(p1.getUuid()).setParentUuid(p1.getUuid()));
var p3 = db.components().insertPrivatePortfolioDto("portfolio3", p -> p.setRootUuid(p1.getUuid()).setParentUuid(p1.getUuid()));
- ProjectDto app1 = db.components().insertPrivateApplication(p -> p.setKey("app1")).getProjectDto();
- ProjectDto app2 = db.components().insertPrivateApplication(p -> p.setKey("app2")).getProjectDto();
- ProjectDto app3 = db.components().insertPrivateApplication(p -> p.setKey("app3")).getProjectDto();
+ ProjectData appData1 = db.components().insertPrivateApplication(p -> p.setKey("app1"));
+ ProjectDto app1 = appData1.getProjectDto();
+ ProjectData appData2 = db.components().insertPrivateApplication(p -> p.setKey("app2"));
+ ProjectDto app2 = appData2.getProjectDto();
+ ProjectData appData3 = db.components().insertPrivateApplication(p -> p.setKey("app3"));
+ ProjectDto app3 = appData3.getProjectDto();
- portfolioDao.addReference(session, "portfolio1", app1.getUuid());
- portfolioDao.addReference(session, "portfolio2", app2.getUuid());
- portfolioDao.addReference(session, "portfolio3", app3.getUuid());
+ portfolioDao.addReferenceBranch(session, "portfolio1", app1.getUuid(), appData1.getMainBranchDto().getUuid());
+ portfolioDao.addReferenceBranch(session, "portfolio2", app2.getUuid(), appData2.getMainBranchDto().getUuid());
+ portfolioDao.addReferenceBranch(session, "portfolio3", app3.getUuid(), appData3.getMainBranchDto().getUuid());
assertThat(portfolioDao.selectApplicationReferenceUuids(session, p1.getUuid()))
.containsOnly(app1.getUuid());
var p1 = db.components().insertPrivatePortfolioDto("portfolio1");
var p2 = db.components().insertPrivatePortfolioDto("portfolio2", p -> p.setRootUuid(p1.getUuid()).setParentUuid(p1.getUuid()));
var p3 = db.components().insertPrivatePortfolioDto("portfolio3", p -> p.setRootUuid(p1.getUuid()).setParentUuid(p1.getUuid()));
- ProjectDto app1 = db.components().insertPrivateApplication(p -> p.setKey("app1")).getProjectDto();
- ProjectDto app2 = db.components().insertPrivateApplication(p -> p.setKey("app2")).getProjectDto();
- ProjectDto app3 = db.components().insertPrivateApplication(p -> p.setKey("app3")).getProjectDto();
+ ProjectData appData1 = db.components().insertPrivateApplication(p -> p.setKey("app1"));
+ ProjectDto app1 = appData1.getProjectDto();
+ ProjectData appData2 = db.components().insertPrivateApplication(p -> p.setKey("app2"));
+ ProjectDto app2 = appData2.getProjectDto();
+ ProjectData appData3 = db.components().insertPrivateApplication(p -> p.setKey("app3"));
+ ProjectDto app3 = appData3.getProjectDto();
- portfolioDao.addReference(session, "portfolio1", app1.getUuid());
- portfolioDao.addReference(session, "portfolio2", app2.getUuid());
- portfolioDao.addReference(session, "portfolio3", app3.getUuid());
+ portfolioDao.addReferenceBranch(session, "portfolio1", app1.getUuid(), appData1.getMainBranchDto().getUuid());
+ portfolioDao.addReferenceBranch(session, "portfolio2", app2.getUuid(), appData2.getMainBranchDto().getUuid());
+ portfolioDao.addReferenceBranch(session, "portfolio3", app3.getUuid(), appData3.getMainBranchDto().getUuid());
assertThat(portfolioDao.selectAllReferencesToApplicationsInHierarchy(session, p1.getUuid()))
.extracting(ReferenceDto::getTargetUuid)
@Test
public void selectAllApplicationProjectsBelongToTheSamePortfolio() {
var portfolio = db.components().insertPrivatePortfolioDto("portfolio1");
- var app1 = db.components().insertPrivateApplication(p -> p.setKey("app1")).getProjectDto();
- var app2 = db.components().insertPrivateApplication(p -> p.setKey("app2")).getProjectDto();
+ ProjectData appData1 = db.components().insertPrivateApplication(p -> p.setKey("app1"));
+ var app1 = appData1.getProjectDto();
+ ProjectData appData2 = db.components().insertPrivateApplication(p -> p.setKey("app2"));
+ var app2 = appData2.getProjectDto();
var project1 = db.components().insertPrivateProject(p -> p.setKey("project:one").setName("Projet Un")).getProjectDto();
var project2 = db.components().insertPrivateProject(p -> p.setKey("project:two").setName("Projet Deux")).getProjectDto();
db.components().addApplicationProject(app1, project1);
db.components().addApplicationProject(app2, project2);
- db.components().addPortfolioReference(portfolio, app1.getUuid());
- db.components().addPortfolioReference(portfolio, app2.getUuid());
+ db.components().addPortfolioApplicationBranch(portfolio.getUuid(), app1.getUuid(), appData1.getMainBranchDto().getUuid());
+ db.components().addPortfolioApplicationBranch(portfolio.getUuid(), app2.getUuid(), appData2.getMainBranchDto().getUuid());
assertThat(portfolioDao.selectAllApplicationProjects(session, portfolio.getRootUuid()))
.extracting(ApplicationProjectDto::getAppUuid, ApplicationProjectDto::getAppKey, ApplicationProjectDto::getProjectUuid)
@Test
public void add_and_select_references_by_uuid() {
assertThat(portfolioDao.selectPortfolioProjects(session, "portfolio1")).isEmpty();
- portfolioDao.addReference(session, "portfolio1", "app1");
- portfolioDao.addReference(session, "portfolio1", "app2");
- portfolioDao.addReference(session, "portfolio2", "app3");
+ portfolioDao.addReferenceBranch(session, "portfolio1", "app1", "main1");
+ portfolioDao.addReferenceBranch(session, "portfolio1", "app2", "main2");
+ portfolioDao.addReferenceBranch(session, "portfolio2", "app3", "main3");
db.commit();
assertThat(portfolioDao.selectReferenceUuids(session, "portfolio1")).containsExactlyInAnyOrder("app1", "app2");
assertThat(portfolioDao.selectReferenceUuids(session, "portfolio2")).containsExactlyInAnyOrder("app3");
@Test
public void select_reference_to_app_by_key() {
PortfolioDto portfolio = db.components().insertPrivatePortfolioDto("portfolio1");
- ProjectDto app1 = db.components().insertPrivateApplication(p -> p.setKey("app1")).getProjectDto();
- db.components().addPortfolioReference(portfolio, app1.getUuid());
+ ProjectData projectData = db.components().insertPrivateApplication(p -> p.setKey("app1"));
+ ProjectDto app1 = projectData.getProjectDto();
+ db.components().addPortfolioApplicationBranch(portfolio.getUuid(), app1.getUuid(), projectData.getMainBranchDto().getUuid());
assertThat(portfolioDao.selectReferenceToApp(db.getSession(), portfolio.getUuid(), app1.getKey()))
.get()
@Test
public void select_reference_to_app_with_branches() {
PortfolioDto portfolio = db.components().insertPrivatePortfolioDto("portfolio1");
- ProjectDto app = db.components().insertPrivateApplication(p -> p.setKey("app").setName("app")).getProjectDto();
+ ProjectData projectData = db.components().insertPrivateApplication(p -> p.setKey("app").setName("app"));
+ ProjectDto app = projectData.getProjectDto();
BranchDto branch1 = db.components().insertProjectBranch(app, b -> b.setExcludeFromPurge(true));
BranchDto branch2 = db.components().insertProjectBranch(app, b -> b.setExcludeFromPurge(true));
- db.components().addPortfolioReference(portfolio, app.getUuid());
+ db.components().addPortfolioApplicationBranch(portfolio.getUuid(), app.getUuid(), projectData.getMainBranchDto().getUuid());
db.components().addPortfolioApplicationBranch(portfolio.getUuid(), app.getUuid(), branch1.getUuid());
db.components().addPortfolioApplicationBranch(portfolio.getUuid(), app.getUuid(), branch2.getUuid());
assertThat(appFromDb.get())
.extracting(ReferenceDto::getTargetKey, ReferenceDto::getTargetName, ReferenceDto::getBranchUuids)
- .containsExactly("app", "app", Set.of(branch1.getUuid(), branch2.getUuid(), app.getUuid()));
+ .containsExactly("app", "app", Set.of(branch1.getUuid(), branch2.getUuid(), projectData.getMainBranchDto().getUuid()));
}
@Test
public void select_root_reference_to_app_main_branch() {
PortfolioDto portfolio1 = db.components().insertPrivatePortfolioDto("portfolio1");
- ProjectDto app1 = db.components().insertPrivateApplication(p -> p.setKey("app1")).getProjectDto();
- db.components().addPortfolioReference(portfolio1, app1.getUuid());
+ ProjectData appData1 = db.components().insertPrivateApplication(p -> p.setKey("app1"));
+ ProjectDto app1 = appData1.getProjectDto();
+ db.components().addPortfolioApplicationBranch(portfolio1.getUuid(), app1.getUuid(), appData1.getMainBranchDto().getUuid());
assertThat(portfolioDao.selectRootOfReferencersToMainBranch(db.getSession(), app1.getUuid()))
.extracting(PortfolioDto::getKey)
.containsExactly(portfolio1.getKey());
-
- PortfolioDto portfolio2 = db.components().insertPrivatePortfolioDto("portfolio2");
- ProjectDto app2 = db.components().insertPrivateApplication(p -> p.setKey("app2")).getProjectDto();
- db.components().addPortfolioApplicationBranch(portfolio2.getUuid(), app2.getUuid(), app2.getUuid());
-
- assertThat(portfolioDao.selectRootOfReferencersToMainBranch(db.getSession(), app2.getUuid()))
- .extracting(PortfolioDto::getKey)
- .containsExactly(portfolio2.getKey());
}
@Test
PortfolioDto portfolio1 = db.components().insertPrivatePortfolioDto("portfolio1");
PortfolioDto portfolio2 = db.components().insertPrivatePortfolioDto("portfolio2");
- ProjectDto app1 = db.components().insertPrivateApplication("app1").getProjectDto();
+ ProjectData appData1 = db.components().insertPrivateApplication("app1");
+ ProjectDto app1 = appData1.getProjectDto();
portfolioDao.addReference(session, "portfolio1", "portfolio2");
- portfolioDao.addReference(session, "portfolio1", app1.getUuid());
- portfolioDao.addReference(session, "portfolio2", app1.getUuid());
+ portfolioDao.addReferenceBranch(session, "portfolio1", app1.getUuid(), appData1.getMainBranchDto().getUuid());
+ portfolioDao.addReferenceBranch(session, "portfolio2", app1.getUuid(), appData1.getMainBranchDto().getUuid());
assertThat(portfolioDao.selectReferencers(session, portfolio2.getUuid()))
.extracting("uuid").containsOnly("portfolio1");
@Test
public void deleteReferenceBranch() {
PortfolioDto portfolio = db.components().insertPrivatePortfolioDto("portfolio1");
- ProjectDto app = db.components().insertPrivateApplication(p -> p.setKey("app").setName("app")).getProjectDto();
+ ProjectData appData = db.components().insertPrivateApplication(p -> p.setKey("app").setName("app"));
+ ProjectDto app = appData.getProjectDto();
BranchDto branch1 = db.components().insertProjectBranch(app, b -> b.setExcludeFromPurge(true));
BranchDto branch2 = db.components().insertProjectBranch(app, b -> b.setExcludeFromPurge(true));
- db.components().addPortfolioReference(portfolio, app.getUuid());
+ db.components().addPortfolioApplicationBranch(portfolio.getUuid(), app.getUuid(), appData.getMainBranchDto().getUuid());
db.components().addPortfolioApplicationBranch(portfolio.getUuid(), app.getUuid(), branch1.getUuid());
db.components().addPortfolioApplicationBranch(portfolio.getUuid(), app.getUuid(), branch2.getUuid());
assertThat(portfolioDao.selectReferenceToApp(db.getSession(), portfolio.getUuid(), app.getKey()))
.isPresent()
.map(ReferenceDto::getBranchUuids)
- .contains(Set.of(branch1.getUuid(), branch2.getUuid(), app.getUuid()));
+ .contains(Set.of(branch1.getUuid(), branch2.getUuid(), appData.getMainBranchDto().getUuid()));
portfolioDao.deleteReferenceBranch(db.getSession(), portfolio.getUuid(), app.getUuid(), branch1.getUuid());
assertThat(portfolioDao.selectReferenceToApp(db.getSession(), portfolio.getUuid(), app.getKey()))
.isPresent()
.map(ReferenceDto::getBranchUuids)
- .contains(Set.of(branch2.getUuid(), app.getUuid()));
+ .contains(Set.of(branch2.getUuid(), appData.getMainBranchDto().getUuid()));
}
public void addReference(DbSession dbSession, String portfolioUuid, String referenceUuid) {
PortfolioDto portfolio = mapper(dbSession).selectByUuid(referenceUuid);
if (portfolio == null) {
- mapper(dbSession).insertReference(uuidFactory.create(), portfolioUuid, referenceUuid, referenceUuid, system2.now());
+ throw new IllegalArgumentException("Reference must be a portfolio");
} else {
mapper(dbSession).insertReference(uuidFactory.create(), portfolioUuid, referenceUuid, null, system2.now());
}
select
case when exists
(
- select pb.project_uuid, pb.need_issue_sync from project_branches pb join components c on pb.project_uuid = c.branch_uuid
+ select pb.project_uuid, pb.need_issue_sync from project_branches pb
+ join components c on pb.uuid = c.branch_uuid
where c.kee in
<foreach collection="componentKeys" open="(" close=")" item="componentKey" separator=",">
#{componentKey,jdbcType=VARCHAR}
FROM portfolios c
INNER JOIN portfolio_references pr on pr.portfolio_uuid = c.uuid
INNER JOIN portfolios p on p.uuid = c.root_uuid
+ LEFT JOIN project_branches pb ON pr.branch_uuid = pb.uuid
where
pr.reference_uuid=#{referenceUuid,jdbcType=VARCHAR}
AND
(pr.branch_uuid is null
OR
- pr.branch_uuid=#{referenceUuid,jdbcType=VARCHAR}
+ pb.is_main = ${_true}
)
</select>
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;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
+import org.sonar.db.entity.EntityDto;
import org.sonar.db.portfolio.PortfolioDto;
import org.sonar.db.portfolio.PortfolioProjectDto;
import org.sonar.db.project.ProjectDto;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;
import static java.util.Arrays.asList;
+import static org.sonar.api.resources.Qualifiers.APP;
+import static org.sonar.api.resources.Qualifiers.SUBVIEW;
+import static org.sonar.api.resources.Qualifiers.VIEW;
import static org.sonar.db.component.BranchType.BRANCH;
import static org.sonar.db.portfolio.PortfolioDto.SelectionMode.NONE;
public ProjectData insertPrivateProject(Consumer<BranchDto> branchPopulator, Consumer<ComponentDto> componentDtoPopulator, Consumer<ProjectDto> projectDtoPopulator) {
return insertPrivateProjectWithCustomBranch(branchPopulator, componentDtoPopulator, projectDtoPopulator);
}
+
public final ComponentDto insertFile(BranchDto branch) {
ComponentDto projectComponent = getComponentDto(branch);
return insertComponent(ComponentTesting.newFileDto(projectComponent));
public void addPortfolioReference(String portfolioUuid, String... referencerUuids) {
for (String uuid : referencerUuids) {
- dbClient.portfolioDao().addReference(dbSession, portfolioUuid, uuid);
+ EntityDto entityDto = dbClient.entityDao().selectByUuid(dbSession, uuid)
+ .orElseThrow();
+ switch (entityDto.getQualifier()) {
+ case APP -> {
+ BranchDto appMainBranch = dbClient.branchDao().selectMainBranchByProjectUuid(dbSession, entityDto.getUuid())
+ .orElseThrow();
+ dbClient.portfolioDao().addReferenceBranch(dbSession, portfolioUuid, uuid, appMainBranch.getUuid());
+ }
+ case VIEW, SUBVIEW -> dbClient.portfolioDao().addReference(dbSession, portfolioUuid, uuid);
+ default -> throw new IllegalStateException("Unexpected value: " + entityDto.getQualifier());
+ }
}
db.commit();
}
this.tags = tags;
}
+ /**
+ * Should use {@link org.sonar.server.project.Project#fromProjectDtoWithTags(org.sonar.db.project.ProjectDto)} instead
+ */
+ @Deprecated
public static Project from(ComponentDto project) {
return new Project(project.uuid(), project.getKey(), project.name(), project.description(), emptyList());
}
// Add private project6 to private app2
db.components().addApplicationProject(app2, project6);
var copyProject6 = db.components().insertComponent(newProjectCopy(project6, app2));
- db.components().addPortfolioReference(portfolio, app2.getMainBranchComponent().uuid());
+ db.components().addPortfolioReference(portfolio, app2.getProjectDto().getUuid());
assertThat(underTest.keepAuthorizedComponents(UserRole.ADMIN, List.of(portfolio))).isEmpty();
assertThat(underTest.keepAuthorizedComponents(UserRole.USER, List.of(portfolio))).containsExactly(portfolio);
return this;
}
+
public UserSessionRule addPortfolioPermission(String portfolioPermission, PortfolioDto... portfolioDto) {
ensureAbstractMockUserSession().addPortfolioPermission(portfolioPermission, portfolioDto);
return this;
public class ComponentFinderIT {
@Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
+ public DbTester db = DbTester.create(System2.INSTANCE, true);
private final DbSession dbSession = db.getSession();
private final ComponentFinder underTest = TestComponentFinder.from(db);
@Rule
public UserSessionRule userSession = UserSessionRule.standalone();
@Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
+ public DbTester db = DbTester.create(System2.INSTANCE, true);
private final DbClient dbClient = db.getDbClient();
private final ResourceTypes defaultResourceTypes = new ResourceTypes(new ResourceTypeTree[]{DefaultResourceTypes.get()});
private final ResourceTypesRule resourceTypes = new ResourceTypesRule()
@Test
public void json_example() throws IOException {
- ProjectDto project = initJsonExampleComponents();
+ ProjectData project = initJsonExampleComponents();
logInWithBrowsePermission(project);
String response = ws.newRequest()
- .setParam(PARAM_COMPONENT, project.getKey())
+ .setParam(PARAM_COMPONENT, project.projectKey())
.execute()
.getInput();
db.components().insertComponent(directory);
db.components().insertComponent(newFileDto(projectMainBranch, directory, 10));
db.commit();
- logInWithBrowsePermission(projectData.getProjectDto());
+ logInWithBrowsePermission(projectData);
TreeWsResponse response = ws.newRequest()
.setParam(PARAM_STRATEGY, "children")
db.components().insertComponent(directory);
db.components().insertComponent(newFileDto(module, directory, 1));
db.commit();
- logInWithBrowsePermission(projectData.getProjectDto());
+ logInWithBrowsePermission(projectData);
TreeWsResponse response = ws.newRequest()
.setParam(PARAM_STRATEGY, "all")
db.components().insertComponent(newFileDto(projectMainBranch, 1));
db.components().insertComponent(newFileDto(projectMainBranch, 2));
db.commit();
- logInWithBrowsePermission(projectData.getProjectDto());
+ logInWithBrowsePermission(projectData);
TreeWsResponse response = ws.newRequest()
.setParam(PARAM_STRATEGY, "all")
db.components().insertComponent(directory);
db.components().insertComponent(newFileDto(mainBranch, directory, 3));
db.commit();
- logInWithBrowsePermission(projectData.getProjectDto());
+ logInWithBrowsePermission(projectData);
TreeWsResponse response = ws.newRequest()
.setParam(PARAM_STRATEGY, "leaves")
db.components().insertComponent(newFileDto(mainBranch, 2));
db.components().insertComponent(newDirectory(mainBranch, "path/directory/", "directory-uuid-1"));
db.commit();
- logInWithBrowsePermission(projectData.getProjectDto());
+ logInWithBrowsePermission(projectData);
TreeWsResponse response = ws.newRequest()
.setParam(PARAM_STRATEGY, "all")
ComponentDto techProjectBranch = db.components().insertComponent(newProjectCopy(projectBranch, applicationBranch)
.setKey(applicationBranch.getKey() + project.getKey()).setMainBranchProjectUuid(application.getUuid()));
- logInWithBrowsePermission(application);
+ logInWithBrowsePermission(applicationData);
userSession.addProjectBranchMapping(application.getUuid(), applicationBranch);
TreeWsResponse result = ws.newRequest()
@Test
public void response_is_empty_on_provisioned_projects() {
- ProjectDto project = db.components().insertPrivateProject("project-uuid").getProjectDto();
- logInWithBrowsePermission(project);
+ ProjectData projectData = db.components().insertPrivateProject("project-uuid");
+ ProjectDto project = projectData.getProjectDto();
+ logInWithBrowsePermission(projectData);
TreeWsResponse response = ws.newRequest()
.setParam(PARAM_COMPONENT, project.getKey()).executeProtobuf(TreeWsResponse.class);
ProjectData projectData = db.components().insertPrivateProject(p->p.setKey("file-key").setEnabled(false));
db.components().insertSnapshot(projectData.getMainBranchComponent());
- logInWithBrowsePermission(projectData.getProjectDto());
+ logInWithBrowsePermission(projectData);
TestRequest request = ws.newRequest()
.setParam(PARAM_COMPONENT, "file-key");
return newFileDto(moduleOrProject, null, i);
}
- private ProjectDto initJsonExampleComponents() throws IOException {
+ private ProjectData initJsonExampleComponents() throws IOException {
ProjectData projectData = db.components().insertPrivateProject(c -> c.setUuid("MY_PROJECT_ID")
.setDescription("MY_PROJECT_DESCRIPTION")
.setKey("MY_PROJECT_KEY")
.setCreatedAt(now));
}
db.commit();
- return projectData.getProjectDto();
+ return projectData;
}
@CheckForNull
return jsonElement == null ? null : jsonElement.getAsString();
}
- private void logInWithBrowsePermission(ProjectDto project) {
- userSession.logIn().addProjectPermission(UserRole.USER, project);
+ private void logInWithBrowsePermission(ProjectData project) {
+ userSession.logIn().addProjectPermission(UserRole.USER, project.getProjectDto())
+ .addProjectBranchMapping(project.projectUuid(), project.getMainBranchComponent());
}
@Test
ProjectData project = db.components().insertPrivateProject(p->p.setUuid("project-uuid").setBranchUuid("project-uuid"));
db.components().insertSnapshot(project.getMainBranchComponent());
db.commit();
- logInWithBrowsePermission(project.getProjectDto());
+ logInWithBrowsePermission(project);
TestRequest testRequest = ws.newRequest()
.setParam(PARAM_QUALIFIERS, "BRC")
import org.sonar.db.ce.CeQueueDto;
import org.sonar.db.ce.CeTaskTypes;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ProjectData;
import org.sonar.db.component.SnapshotDto;
import org.sonar.db.event.EventDto;
import org.sonar.server.es.EsTester;
.toArray(RuleType[]::new);
@Rule
- public DbTester db = DbTester.create();
+ public DbTester db = DbTester.create(true);
@Rule
public EsTester es = EsTester.create();
@Rule
@Test
public void json_example() {
- ComponentDto project = db.components().insertPrivateProject(p -> p.setName("My Project").setKey(KeyExamples.KEY_PROJECT_EXAMPLE_001)).getMainBranchComponent();
- userSession.addProjectPermission(USER, project);
- SnapshotDto analysis = insertAnalysis(project, 1_500_000_000_000L);
+ ProjectData projectData = db.components().insertPrivateProject(p -> p.setName("My Project").setKey(KeyExamples.KEY_PROJECT_EXAMPLE_001));
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ userSession.addProjectPermission(USER, projectData.getProjectDto());
+ SnapshotDto analysis = insertAnalysis(mainBranch, 1_500_000_000_000L);
EventDto e1 = db.events().insertEvent(newQualityGateEvent(analysis).setName("Failed").setDate(analysis.getCreatedAt()));
- IntStream.range(0, 15).forEach(x -> insertIssue(project, analysis));
+ IntStream.range(0, 15).forEach(x -> insertIssue(mainBranch, analysis));
issueIndexer.indexAllIssues();
when(server.getPublicRootUrl()).thenReturn("https://sonarcloud.io");
String result = ws.newRequest()
- .setParam(PARAM_PROJECTS, project.getKey())
+ .setParam(PARAM_PROJECTS, mainBranch.getKey())
.setParam(PARAM_FROM, formatDateTime(analysis.getCreatedAt() - 1_000L))
.execute().getInput();
@Test
public void events() {
when(server.getPublicRootUrl()).thenReturn("https://sonarcloud.io");
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- userSession.addProjectPermission(USER, project);
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ userSession.addProjectPermission(USER, projectData.getProjectDto());
String branchName = randomAlphanumeric(248);
- ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey(branchName));
- SnapshotDto projectAnalysis = insertAnalysis(project, 1_500_000_000_000L);
+ ComponentDto branch = db.components().insertProjectBranch(mainBranch, b -> b.setKey(branchName));
+ SnapshotDto projectAnalysis = insertAnalysis(mainBranch, 1_500_000_000_000L);
db.events().insertEvent(newQualityGateEvent(projectAnalysis).setDate(projectAnalysis.getCreatedAt()).setName("Passed"));
- insertIssue(project, projectAnalysis);
- insertIssue(project, projectAnalysis);
- SnapshotDto branchAnalysis = insertAnalysis(branch, project.uuid(), 1_501_000_000_000L);
+ insertIssue(mainBranch, projectAnalysis);
+ insertIssue(mainBranch, projectAnalysis);
+ SnapshotDto branchAnalysis = insertAnalysis(branch, mainBranch.uuid(), 1_501_000_000_000L);
db.events().insertEvent(newQualityGateEvent(branchAnalysis).setDate(branchAnalysis.getCreatedAt()).setName("Failed"));
insertIssue(branch, branchAnalysis);
issueIndexer.indexAllIssues();
SearchEventsWsResponse result = ws.newRequest()
- .setParam(PARAM_PROJECTS, project.getKey())
+ .setParam(PARAM_PROJECTS, mainBranch.getKey())
.setParam(PARAM_FROM, formatDateTime(1_499_000_000_000L))
.executeProtobuf(SearchEventsWsResponse.class);
assertThat(result.getEventsList())
.extracting(Event::getCategory, Event::getProject, Event::getMessage)
.containsOnly(
- tuple("QUALITY_GATE", project.getKey(), format("Quality Gate status of project '%s' changed to 'Passed'", project.name())),
- tuple("QUALITY_GATE", project.getKey(), format("Quality Gate status of project '%s' on branch '%s' changed to 'Failed'", project.name(), branchName)),
- tuple("NEW_ISSUES", project.getKey(), format("You have 2 new issues on project '%s'", project.name())),
- tuple("NEW_ISSUES", project.getKey(), format("You have 1 new issue on project '%s' on branch '%s'", project.name(), branchName)));
- verify(issueIndexSyncProgressChecker).checkIfAnyComponentsNeedIssueSync(any(), argThat(arg -> arg.contains(project.getKey())));
+ tuple("QUALITY_GATE", mainBranch.getKey(), format("Quality Gate status of project '%s' changed to 'Passed'", mainBranch.name())),
+ tuple("QUALITY_GATE", mainBranch.getKey(), format("Quality Gate status of project '%s' on branch '%s' changed to 'Failed'", mainBranch.name(), branchName)),
+ tuple("NEW_ISSUES", mainBranch.getKey(), format("You have 2 new issues on project '%s'", mainBranch.name())),
+ tuple("NEW_ISSUES", mainBranch.getKey(), format("You have 1 new issue on project '%s' on branch '%s'", mainBranch.name(), branchName)));
+ verify(issueIndexSyncProgressChecker).checkIfAnyComponentsNeedIssueSync(any(), argThat(arg -> arg.contains(mainBranch.getKey())));
}
@Test
public void does_not_return_old_events() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- userSession.addProjectPermission(USER, project);
- SnapshotDto analysis = insertAnalysis(project, 1_500_000_000_000L);
- insertIssue(project, analysis);
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ userSession.addProjectPermission(USER, projectData.getProjectDto());
+ SnapshotDto analysis = insertAnalysis(mainBranch, 1_500_000_000_000L);
+ insertIssue(mainBranch, analysis);
db.events().insertEvent(newQualityGateEvent(analysis).setDate(analysis.getCreatedAt()).setName("Passed"));
- SnapshotDto oldAnalysis = insertAnalysis(project, 1_400_000_000_000L);
- insertIssue(project, oldAnalysis);
+ SnapshotDto oldAnalysis = insertAnalysis(mainBranch, 1_400_000_000_000L);
+ insertIssue(mainBranch, oldAnalysis);
db.events().insertEvent(newQualityGateEvent(oldAnalysis).setDate(oldAnalysis.getCreatedAt()).setName("Failed"));
issueIndexer.indexAllIssues();
SearchEventsWsResponse result = ws.newRequest()
- .setParam(PARAM_PROJECTS, project.getKey())
+ .setParam(PARAM_PROJECTS, mainBranch.getKey())
.setParam(PARAM_FROM, formatDateTime(analysis.getCreatedAt() - 1450_000_000_000L))
.executeProtobuf(SearchEventsWsResponse.class);
@Test
public void does_not_return_events_of_project_for_which_the_current_user_has_no_browse_permission() {
- ComponentDto project1 = db.components().insertPrivateProject().getMainBranchComponent();
- userSession.addProjectPermission(UserRole.CODEVIEWER, project1);
- userSession.addProjectPermission(UserRole.ISSUE_ADMIN, project1);
+ ProjectData projectData1 = db.components().insertPrivateProject();
+ ComponentDto mainBranch1 = projectData1.getMainBranchComponent();
+ userSession.addProjectPermission(UserRole.CODEVIEWER, projectData1.getProjectDto());
+ userSession.addProjectPermission(UserRole.ISSUE_ADMIN, projectData1.getProjectDto());
- ComponentDto project2 = db.components().insertPrivateProject().getMainBranchComponent();
- userSession.addProjectPermission(USER, project2);
+ ProjectData projectData2 = db.components().insertPrivateProject();
+ ComponentDto mainBranch2 = projectData2.getMainBranchComponent();
+ userSession.addProjectPermission(USER, projectData2.getProjectDto());
- SnapshotDto a1 = insertAnalysis(project1, 1_500_000_000_000L);
+ SnapshotDto a1 = insertAnalysis(mainBranch1, 1_500_000_000_000L);
EventDto e1 = db.events().insertEvent(newQualityGateEvent(a1).setDate(a1.getCreatedAt()));
- insertIssue(project1, a1);
- SnapshotDto a2 = insertAnalysis(project2, 1_500_000_000_000L);
+ insertIssue(mainBranch1, a1);
+ SnapshotDto a2 = insertAnalysis(mainBranch2, 1_500_000_000_000L);
EventDto e2 = db.events().insertEvent(newQualityGateEvent(a2).setDate(a2.getCreatedAt()));
- insertIssue(project2, a2);
+ insertIssue(mainBranch2, a2);
issueIndexer.indexAllIssues();
String stringFrom = formatDateTime(a1.getCreatedAt() - 1_000L);
SearchEventsWsResponse result = ws.newRequest()
- .setParam(PARAM_PROJECTS, String.join(",", project1.getKey(), project2.getKey()))
+ .setParam(PARAM_PROJECTS, String.join(",", mainBranch1.getKey(), mainBranch2.getKey()))
.setParam(PARAM_FROM, String.join(",", stringFrom, stringFrom))
.executeProtobuf(SearchEventsWsResponse.class);
assertThat(result.getEventsList())
.extracting(Event::getCategory, Event::getProject)
.containsOnly(
- tuple("NEW_ISSUES", project2.getKey()),
- tuple(EventCategory.QUALITY_GATE.name(), project2.getKey()));
+ tuple("NEW_ISSUES", mainBranch2.getKey()),
+ tuple(EventCategory.QUALITY_GATE.name(), mainBranch2.getKey()));
}
@Test
import org.sonar.db.DbTester;
import org.sonar.db.component.BranchType;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ProjectData;
import org.sonar.db.issue.IssueChangeDto;
import org.sonar.db.issue.IssueDto;
+import org.sonar.db.project.ProjectDto;
import org.sonar.db.rule.RuleDto;
import org.sonar.db.user.UserDto;
import org.sonar.server.es.EsTester;
private System2 system2 = new TestSystem2().setNow(NOW);
@Rule
- public DbTester db = DbTester.create(system2);
+ public DbTester db = DbTester.create(system2, true);
@Rule
public EsTester es = EsTester.create();
@Rule
public void set_type() {
UserDto user = db.users().insertUser();
userSession.logIn(user);
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto project = projectData.getMainBranchComponent();
ComponentDto file = db.components().insertComponent(newFileDto(project));
- addUserProjectPermissions(user, project, USER, ISSUE_ADMIN);
+ addUserProjectPermissions(user, projectData, USER, ISSUE_ADMIN);
RuleDto rule = db.rules().insertIssueRule();
IssueDto issue = db.issues().insertIssue(rule, project, file, i -> i.setType(BUG)
.setStatus(STATUS_OPEN).setResolution(null));
public void set_severity() {
UserDto user = db.users().insertUser();
userSession.logIn(user);
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto project = projectData.getMainBranchComponent();
ComponentDto file = db.components().insertComponent(newFileDto(project));
- addUserProjectPermissions(user, project, USER, ISSUE_ADMIN);
+ addUserProjectPermissions(user, projectData, USER, ISSUE_ADMIN);
RuleDto rule = db.rules().insertIssueRule();
IssueDto issue = db.issues().insertIssue(rule, project, file, i -> i.setSeverity(MAJOR).setType(CODE_SMELL)
.setStatus(STATUS_OPEN).setResolution(null));
public void add_tags() {
UserDto user = db.users().insertUser();
userSession.logIn(user);
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto project = projectData.getMainBranchComponent();
ComponentDto file = db.components().insertComponent(newFileDto(project));
- addUserProjectPermissions(user, project, USER, ISSUE_ADMIN);
+ addUserProjectPermissions(user, projectData, USER, ISSUE_ADMIN);
RuleDto rule = db.rules().insertIssueRule();
IssueDto issue = db.issues().insertIssue(rule, project, file, i -> i.setTags(asList("tag1", "tag2"))
.setStatus(STATUS_OPEN).setResolution(null));
public void add_tags_when_issue_is_resolved_is_accepted() {
UserDto user = db.users().insertUser();
userSession.logIn(user);
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto project = projectData.getMainBranchComponent();
ComponentDto file = db.components().insertComponent(newFileDto(project));
- addUserProjectPermissions(user, project, USER, ISSUE_ADMIN);
+ addUserProjectPermissions(user, projectData, USER, ISSUE_ADMIN);
RuleDto rule = db.rules().insertIssueRule();
IssueDto issue = db.issues().insertIssue(rule, project, file, i -> i.setTags(asList("tag1", "tag2"))
.setStatus(STATUS_RESOLVED).setResolution(RESOLUTION_FALSE_POSITIVE));
public void remove_assignee() {
UserDto user = db.users().insertUser();
userSession.logIn(user);
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto project = projectData.getMainBranchComponent();
ComponentDto file = db.components().insertComponent(newFileDto(project));
- addUserProjectPermissions(user, project, USER, ISSUE_ADMIN);
+ addUserProjectPermissions(user, projectData, USER, ISSUE_ADMIN);
RuleDto rule = db.rules().insertIssueRule();
UserDto assignee = db.users().insertUser();
IssueDto issue = db.issues().insertIssue(rule, project, file, i -> i.setAssigneeUuid(assignee.getUuid())
public void bulk_change_with_comment() {
UserDto user = db.users().insertUser();
userSession.logIn(user);
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto project = projectData.getMainBranchComponent();
ComponentDto file = db.components().insertComponent(newFileDto(project));
- addUserProjectPermissions(user, project, USER, ISSUE_ADMIN);
+ addUserProjectPermissions(user, projectData, USER, ISSUE_ADMIN);
RuleDto rule = db.rules().insertIssueRule();
IssueDto issue = db.issues().insertIssue(rule, project, file, i -> i.setType(BUG)
.setStatus(STATUS_OPEN).setResolution(null));
public void bulk_change_many_issues() {
UserDto user = db.users().insertUser();
userSession.logIn(user);
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto project = projectData.getMainBranchComponent();
ComponentDto file = db.components().insertComponent(newFileDto(project));
- addUserProjectPermissions(user, project, USER, ISSUE_ADMIN);
+ addUserProjectPermissions(user, projectData, USER, ISSUE_ADMIN);
RuleDto rule = db.rules().insertIssueRule();
UserDto oldAssignee = db.users().insertUser();
UserDto userToAssign = db.users().insertUser();
public void send_notification() {
UserDto user = db.users().insertUser();
userSession.logIn(user);
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto project = projectData.getMainBranchComponent();
ComponentDto file = db.components().insertComponent(newFileDto(project));
- addUserProjectPermissions(user, project, USER, ISSUE_ADMIN);
+ addUserProjectPermissions(user, projectData, USER, ISSUE_ADMIN);
RuleDto rule = db.rules().insertIssueRule();
IssueDto issue = db.issues().insertIssue(rule, project, file, i -> i.setType(BUG)
.setStatus(STATUS_OPEN).setResolution(null));
public void should_ignore_hotspots() {
UserDto user = db.users().insertUser();
userSession.logIn(user);
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto project = projectData.getMainBranchComponent();
ComponentDto file = db.components().insertComponent(newFileDto(project));
- addUserProjectPermissions(user, project, USER, SECURITYHOTSPOT_ADMIN);
+ addUserProjectPermissions(user, projectData, USER, SECURITYHOTSPOT_ADMIN);
IssueDto issue = db.issues().insertHotspot(project, file);
BulkChangeWsResponse response = call(builder()
public void send_notification_on_branch() {
UserDto user = db.users().insertUser();
userSession.logIn(user);
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto project = projectData.getMainBranchComponent();
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("feature").setBranchType(BranchType.BRANCH));
- userSession.addProjectBranchMapping(project.uuid(), branch);
+ userSession.addProjectBranchMapping(projectData.projectUuid(), branch);
ComponentDto fileOnBranch = db.components().insertComponent(newFileDto(branch, project.uuid()));
- addUserProjectPermissions(user, project, USER, ISSUE_ADMIN);
+ addUserProjectPermissions(user, projectData, USER, ISSUE_ADMIN);
RuleDto rule = db.rules().insertIssueRule();
IssueDto issue = db.issues().insertIssue(rule, branch, fileOnBranch, i -> i.setType(BUG)
.setStatus(STATUS_OPEN).setResolution(null));
private void verifySendNoNotification(BranchType branchType) {
UserDto user = db.users().insertUser();
userSession.logIn(user);
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto project = projectData.getMainBranchComponent();
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("feature").setBranchType(branchType));
- userSession.addProjectBranchMapping(project.uuid(), branch);
+ userSession.addProjectBranchMapping(projectData.projectUuid(), branch);
ComponentDto fileOnBranch = db.components().insertComponent(newFileDto(branch, project.uuid()));
- addUserProjectPermissions(user, project, USER, ISSUE_ADMIN);
+ addUserProjectPermissions(user, projectData, USER, ISSUE_ADMIN);
RuleDto rule = db.rules().insertIssueRule();
IssueDto issue = db.issues().insertIssue(rule, branch, fileOnBranch, i -> i.setType(BUG)
.setStatus(STATUS_OPEN).setResolution(null));
public void send_notification_only_on_changed_issues() {
UserDto user = db.users().insertUser();
userSession.logIn(user);
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto project = projectData.getMainBranchComponent();
ComponentDto file = db.components().insertComponent(newFileDto(project));
- addUserProjectPermissions(user, project, USER, ISSUE_ADMIN);
+ addUserProjectPermissions(user, projectData, USER, ISSUE_ADMIN);
RuleDto rule = db.rules().insertIssueRule();
IssueDto issue1 = db.issues().insertIssue(rule, project, file, i -> i.setType(BUG)
.setStatus(STATUS_OPEN).setResolution(null));
public void ignore_the_issues_that_do_not_match_conditions() {
UserDto user = db.users().insertUser();
userSession.logIn(user);
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto project = projectData.getMainBranchComponent();
ComponentDto file1 = db.components().insertComponent(newFileDto(project));
ComponentDto file2 = db.components().insertComponent(newFileDto(project));
- addUserProjectPermissions(user, project, USER, ISSUE_ADMIN);
+ addUserProjectPermissions(user, projectData, USER, ISSUE_ADMIN);
RuleDto rule = db.rules().insertIssueRule();
IssueDto issue1 = db.issues().insertIssue(rule, project, file1, i -> i.setType(BUG)
.setStatus(STATUS_OPEN).setResolution(null));
public void ignore_issues_when_there_is_nothing_to_do() {
UserDto user = db.users().insertUser();
userSession.logIn(user);
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto project = projectData.getMainBranchComponent();
ComponentDto file1 = db.components().insertComponent(newFileDto(project));
ComponentDto file2 = db.components().insertComponent(newFileDto(project));
- addUserProjectPermissions(user, project, USER, ISSUE_ADMIN);
+ addUserProjectPermissions(user, projectData, USER, ISSUE_ADMIN);
RuleDto rule = db.rules().insertIssueRule();
IssueDto issue1 = db.issues().insertIssue(rule, project, file1, i -> i.setType(BUG).setSeverity(MINOR)
.setStatus(STATUS_OPEN).setResolution(null));
public void add_comment_only_on_changed_issues() {
UserDto user = db.users().insertUser();
userSession.logIn(user);
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto project = projectData.getMainBranchComponent();
ComponentDto file1 = db.components().insertComponent(newFileDto(project));
ComponentDto file2 = db.components().insertComponent(newFileDto(project));
- addUserProjectPermissions(user, project, USER, ISSUE_ADMIN);
+ addUserProjectPermissions(user, projectData, USER, ISSUE_ADMIN);
RuleDto rule = db.rules().insertIssueRule();
IssueDto issue1 = db.issues().insertIssue(rule, project, file1, i -> i.setType(BUG).setSeverity(MINOR)
.setStatus(STATUS_OPEN).setResolution(null));
public void ignore_external_issue() {
UserDto user = db.users().insertUser();
userSession.logIn(user);
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- addUserProjectPermissions(user, project, USER, ISSUE_ADMIN);
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+ addUserProjectPermissions(user, projectData, USER, ISSUE_ADMIN);
RuleDto rule = db.rules().insertIssueRule();
IssueDto issue = db.issues().insertIssue(rule, project, project, i -> i.setStatus(STATUS_OPEN).setResolution(null).setType(CODE_SMELL));
RuleDto externalRule = db.rules().insertIssueRule(r -> r.setIsExternal(true));
public void issues_on_which_user_has_not_browse_permission_are_ignored() {
UserDto user = db.users().insertUser();
userSession.logIn(user);
- ComponentDto project1 = db.components().insertPrivateProject().getMainBranchComponent();
- addUserProjectPermissions(user, project1, USER, ISSUE_ADMIN);
+ ProjectData projectData1 = db.components().insertPrivateProject();
+ ComponentDto project1 = projectData1.getMainBranchComponent();
+ addUserProjectPermissions(user, projectData1, USER, ISSUE_ADMIN);
ComponentDto project2 = db.components().insertPrivateProject().getMainBranchComponent();
RuleDto rule = db.rules().insertIssueRule();
IssueDto authorizedIssue = db.issues().insertIssue(rule, project1, project1, i -> i.setType(BUG)
public void does_not_update_type_when_no_issue_admin_permission() {
UserDto user = db.users().insertUser();
userSession.logIn(user);
- ComponentDto project1 = db.components().insertPrivateProject().getMainBranchComponent();
- addUserProjectPermissions(user, project1, USER, ISSUE_ADMIN);
- ComponentDto project2 = db.components().insertPrivateProject().getMainBranchComponent();
- addUserProjectPermissions(user, project2, USER);
+ ProjectData projectData1 = db.components().insertPrivateProject();
+ ComponentDto project1 = projectData1.getMainBranchComponent();
+ addUserProjectPermissions(user, projectData1, USER, ISSUE_ADMIN);
+ ProjectData projectData2 = db.components().insertPrivateProject();
+ ComponentDto project2 = projectData2.getMainBranchComponent();
+ addUserProjectPermissions(user, projectData2, USER);
RuleDto rule = db.rules().insertIssueRule();
IssueDto authorizedIssue1 = db.issues().insertIssue(rule, project1, project1, i -> i.setType(BUG)
.setStatus(STATUS_OPEN).setResolution(null));
public void does_not_update_severity_when_no_issue_admin_permission() {
UserDto user = db.users().insertUser();
userSession.logIn(user);
- ComponentDto project1 = db.components().insertPrivateProject().getMainBranchComponent();
- addUserProjectPermissions(user, project1, USER, ISSUE_ADMIN);
- ComponentDto project2 = db.components().insertPrivateProject().getMainBranchComponent();
- addUserProjectPermissions(user, project2, USER);
+ ProjectData projectData1 = db.components().insertPrivateProject();
+ ComponentDto project1 = projectData1.getMainBranchComponent();
+ addUserProjectPermissions(user, projectData1, USER, ISSUE_ADMIN);
+ ProjectData projectData2 = db.components().insertPrivateProject();
+ ComponentDto project2 = projectData2.getMainBranchComponent();
+ addUserProjectPermissions(user, projectData2, USER);
RuleDto rule = db.rules().insertIssueRule();
IssueDto authorizedIssue1 = db.issues().insertIssue(rule, project1, project1, i -> i.setSeverity(MAJOR)
.setStatus(STATUS_OPEN).setResolution(null).setType(CODE_SMELL));
public void fail_when_only_comment_action() {
UserDto user = db.users().insertUser();
userSession.logIn(user);
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- addUserProjectPermissions(user, project, USER);
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+ addUserProjectPermissions(user, projectData, USER);
RuleDto rule = db.rules().insertIssueRule();
IssueDto issue = db.issues().insertIssue(rule, project, project, i -> i.setType(BUG)
.setStatus(STATUS_OPEN).setResolution(null));
return request.executeProtobuf(BulkChangeWsResponse.class);
}
- private void addUserProjectPermissions(UserDto user, ComponentDto project, String... permissions) {
+ private void addUserProjectPermissions(UserDto user, ProjectData project, String... permissions) {
for (String permission : permissions) {
- db.users().insertProjectPermissionOnUser(user, permission, project);
- userSession.addProjectPermission(permission, project);
+ db.users().insertProjectPermissionOnUser(user, permission, project.getProjectDto());
+ userSession.addProjectPermission(permission, project.getProjectDto());
+ userSession.addProjectBranchMapping(project.projectUuid(), project.getMainBranchComponent());
}
}
private System2 system2 = mock(System2.class);
@Rule
- public DbTester db = DbTester.create(system2);
+ public DbTester db = DbTester.create(system2, true);
@Rule
public EsTester es = EsTester.create();
import org.sonar.api.utils.System2;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ProjectData;
import org.sonar.db.component.ResourceTypesRule;
import org.sonar.db.issue.IssueDto;
import org.sonar.db.rule.RuleDto;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.es.EsTester;
+import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.issue.index.IssueIndex;
import org.sonar.server.issue.index.IssueIndexSyncProgressChecker;
import org.sonar.server.issue.index.IssueIndexer;
@Rule
public UserSessionRule userSession = UserSessionRule.standalone();
@Rule
- public DbTester db = DbTester.create();
+ public DbTester db = DbTester.create(true);
@Rule
public EsTester es = EsTester.create();
@Test
public void search_tags() {
RuleDto rule = db.rules().insertIssueRule();
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- db.issues().insertIssue(rule, project, project, issue -> issue.setTags(asList("tag1", "tag2")));
- db.issues().insertIssue(rule, project, project, issue -> issue.setTags(asList("tag3", "tag4", "tag5")));
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ db.issues().insertIssue(rule, mainBranch, mainBranch, issue -> issue.setTags(asList("tag1", "tag2")));
+ db.issues().insertIssue(rule, mainBranch, mainBranch, issue -> issue.setTags(asList("tag3", "tag4", "tag5")));
indexIssues();
- permissionIndexer.allowOnlyAnyone(project);
+ permissionIndexer.allowOnlyAnyone(projectData.getProjectDto());
TagsResponse result = ws.newRequest().executeProtobuf(TagsResponse.class);
@Test
public void search_tags_ignores_hotspots() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
RuleDto issueRule = db.rules().insertIssueRule();
RuleDto hotspotRule = db.rules().insertHotspotRule();
Consumer<IssueDto> setTags = issue -> issue.setTags(asList("tag1", "tag2"));
- db.issues().insertIssue(issueRule, project, project, setTags);
- db.issues().insertHotspot(hotspotRule, project, project, setTags);
+ db.issues().insertIssue(issueRule, mainBranch, mainBranch, setTags);
+ db.issues().insertHotspot(hotspotRule, mainBranch, mainBranch, setTags);
indexIssues();
- permissionIndexer.allowOnlyAnyone(project);
+ permissionIndexer.allowOnlyAnyone(projectData.getProjectDto());
TestRequest testRequest = ws.newRequest();
assertThat(tagListOf(testRequest)).containsExactly("tag1", "tag2");
@Test
public void search_tags_by_query() {
RuleDto rule = db.rules().insertIssueRule();
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- db.issues().insertIssue(rule, project, project, issue -> issue.setTags(asList("tag1", "tag2")));
- db.issues().insertIssue(rule, project, project, issue -> issue.setTags(asList("tag12", "tag4", "tag5")));
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ db.issues().insertIssue(rule, mainBranch, mainBranch, issue -> issue.setTags(asList("tag1", "tag2")));
+ db.issues().insertIssue(rule, mainBranch, mainBranch, issue -> issue.setTags(asList("tag12", "tag4", "tag5")));
indexIssues();
- permissionIndexer.allowOnlyAnyone(project);
+ permissionIndexer.allowOnlyAnyone(projectData.getProjectDto());
assertThat(tagListOf(ws.newRequest().setParam("q", "ag1"))).containsExactly("tag1", "tag12");
}
public void search_tags_by_query_ignores_hotspots() {
RuleDto issueRule = db.rules().insertIssueRule();
RuleDto hotspotRule = db.rules().insertHotspotRule();
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- db.issues().insertIssue(issueRule, project, project, issue -> issue.setTags(asList("tag1", "tag2")));
- db.issues().insertHotspot(hotspotRule, project, project, issue -> issue.setTags(asList("tag1", "tag12", "tag4", "tag5")));
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ db.issues().insertIssue(issueRule, mainBranch, mainBranch, issue -> issue.setTags(asList("tag1", "tag2")));
+ db.issues().insertHotspot(hotspotRule, mainBranch, mainBranch, issue -> issue.setTags(asList("tag1", "tag12", "tag4", "tag5")));
indexIssues();
- permissionIndexer.allowOnlyAnyone(project);
+ permissionIndexer.allowOnlyAnyone(projectData.getProjectDto());
TestRequest testRequest = ws.newRequest();
assertThat(tagListOf(testRequest)).containsExactly("tag1", "tag2");
@Test
public void search_tags_by_project() {
RuleDto rule = db.rules().insertIssueRule();
- ComponentDto project1 = db.components().insertPrivateProject().getMainBranchComponent();
- ComponentDto project2 = db.components().insertPrivateProject().getMainBranchComponent();
- db.issues().insertIssue(rule, project1, project1, issue -> issue.setTags(singletonList("tag1")));
- db.issues().insertIssue(rule, project2, project2, issue -> issue.setTags(singletonList("tag2")));
+ ProjectData projectData1 = db.components().insertPrivateProject();
+ ComponentDto mainBranch1 = projectData1.getMainBranchComponent();
+ ProjectData projectData2 = db.components().insertPrivateProject();
+ ComponentDto mainBranch2 = projectData2.getMainBranchComponent();
+ db.issues().insertIssue(rule, mainBranch1, mainBranch1, issue -> issue.setTags(singletonList("tag1")));
+ db.issues().insertIssue(rule, mainBranch2, mainBranch2, issue -> issue.setTags(singletonList("tag2")));
indexIssues();
- permissionIndexer.allowOnlyAnyone(project1, project2);
+ permissionIndexer.allowOnlyAnyone(projectData1.getProjectDto(), projectData1.getProjectDto());
assertThat(tagListOf(ws.newRequest()
- .setParam("project", project1.getKey()))).containsExactly("tag1");
- verify(issueIndexSyncProgressChecker).checkIfComponentNeedIssueSync(any(), eq(project1.getKey()));
+ .setParam("project", mainBranch1.getKey()))).containsExactly("tag1");
+ verify(issueIndexSyncProgressChecker).checkIfComponentNeedIssueSync(any(), eq(mainBranch1.getKey()));
}
@Test
public void search_tags_by_branch_equals_main_branch() {
RuleDto rule = db.rules().insertIssueRule();
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("my_branch"));
- db.issues().insertIssue(rule, project, project, issue -> issue.setTags(asList("tag1", "tag2")));
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ ComponentDto branch = db.components().insertProjectBranch(mainBranch, b -> b.setKey("my_branch"));
+ db.issues().insertIssue(rule, mainBranch, mainBranch, issue -> issue.setTags(asList("tag1", "tag2")));
db.issues().insertIssue(rule, branch, branch, issue -> issue.setTags(asList("tag12", "tag4", "tag5")));
indexIssues();
- permissionIndexer.allowOnlyAnyone(project, branch);
+ permissionIndexer.allowOnlyAnyone(projectData.getProjectDto());
assertThat(tagListOf(ws.newRequest()
- .setParam("project", project.getKey())
- .setParam("branch", project.uuid()))).containsExactly("tag1", "tag2");
+ .setParam("project", mainBranch.getKey())
+ .setParam("branch", mainBranch.uuid()))).containsExactly("tag1", "tag2");
}
@Test
public void search_tags_by_branch() {
RuleDto rule = db.rules().insertIssueRule();
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("my_branch"));
- db.issues().insertIssue(rule, project, project, issue -> issue.setTags(asList("tag1", "tag2")));
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ ComponentDto branch = db.components().insertProjectBranch(mainBranch, b -> b.setKey("my_branch"));
+ db.issues().insertIssue(rule, mainBranch, mainBranch, issue -> issue.setTags(asList("tag1", "tag2")));
db.issues().insertIssue(rule, branch, branch, issue -> issue.setTags(asList("tag12", "tag4", "tag5")));
indexIssues();
- permissionIndexer.allowOnlyAnyone(project, branch);
+ permissionIndexer.allowOnlyAnyone(projectData.getProjectDto());
assertThat(tagListOf(ws.newRequest()
- .setParam("project", project.getKey())
+ .setParam("project", mainBranch.getKey())
.setParam("branch", "my_branch"))).containsExactly("tag12", "tag4", "tag5");
}
@Test
public void search_tags_by_branch_not_exist_fall_back_to_main_branch() {
RuleDto rule = db.rules().insertIssueRule();
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("my_branch"));
- db.issues().insertIssue(rule, project, project, issue -> issue.setTags(asList("tag1", "tag2")));
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ ComponentDto branch = db.components().insertProjectBranch(mainBranch, b -> b.setKey("my_branch"));
+ db.issues().insertIssue(rule, mainBranch, mainBranch, issue -> issue.setTags(asList("tag1", "tag2")));
db.issues().insertIssue(rule, branch, branch, issue -> issue.setTags(asList("tag12", "tag4", "tag5")));
indexIssues();
- permissionIndexer.allowOnlyAnyone(project, branch);
+ permissionIndexer.allowOnlyAnyone(projectData.getProjectDto());
assertThat(tagListOf(ws.newRequest()
- .setParam("project", project.getKey())
+ .setParam("project", mainBranch.getKey())
.setParam("branch", "not_exist"))).containsExactly("tag1", "tag2");
}
@Test
public void search_all_tags_by_query() {
RuleDto rule = db.rules().insertIssueRule();
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("my_branch"));
- db.issues().insertIssue(rule, project, project, issue -> issue.setTags(asList("tag1", "tag2")));
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ ComponentDto branch = db.components().insertProjectBranch(mainBranch, b -> b.setKey("my_branch"));
+ db.issues().insertIssue(rule, mainBranch, mainBranch, issue -> issue.setTags(asList("tag1", "tag2")));
db.issues().insertIssue(rule, branch, branch, issue -> issue.setTags(asList("tag12", "tag4", "tag5")));
indexIssues();
- permissionIndexer.allowOnlyAnyone(project, branch);
+ permissionIndexer.allowOnlyAnyone(projectData.getProjectDto());
assertThat(tagListOf(ws.newRequest()
.setParam("q", "tag1")
public void search_tags_by_project_ignores_hotspots() {
RuleDto issueRule = db.rules().insertIssueRule();
RuleDto hotspotRule = db.rules().insertHotspotRule();
- ComponentDto project1 = db.components().insertPrivateProject().getMainBranchComponent();
- ComponentDto project2 = db.components().insertPrivateProject().getMainBranchComponent();
+ ProjectData projectData1 = db.components().insertPrivateProject();
+ ComponentDto project1 = projectData1.getMainBranchComponent();
+ ProjectData projectData2 = db.components().insertPrivateProject();
+ ComponentDto project2 = projectData2.getMainBranchComponent();
db.issues().insertHotspot(hotspotRule, project1, project1, issue -> issue.setTags(singletonList("tag1")));
db.issues().insertIssue(issueRule, project1, project1, issue -> issue.setTags(singletonList("tag2")));
db.issues().insertHotspot(hotspotRule, project2, project2, issue -> issue.setTags(singletonList("tag3")));
db.issues().insertIssue(issueRule, project2, project2, issue -> issue.setTags(singletonList("tag4")));
indexIssues();
- permissionIndexer.allowOnlyAnyone(project1, project2);
+ permissionIndexer.allowOnlyAnyone(projectData1.getProjectDto(), projectData2.getProjectDto());
assertThat(tagListOf(ws.newRequest()
.setParam("project", project1.getKey()))).containsExactly("tag2");
@Test
public void search_tags_by_portfolio() {
ComponentDto portfolio = db.components().insertPrivatePortfolio();
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- db.components().insertComponent(newProjectCopy(project, portfolio));
- permissionIndexer.allowOnlyAnyone(project);
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ db.components().insertComponent(newProjectCopy(mainBranch, portfolio));
+ permissionIndexer.allowOnlyAnyone(projectData.getProjectDto());
RuleDto rule = db.rules().insertIssueRule();
- db.issues().insertIssue(rule, project, project, issue -> issue.setTags(singletonList("cwe")));
+ db.issues().insertIssue(rule, mainBranch, mainBranch, issue -> issue.setTags(singletonList("cwe")));
indexIssues();
viewIndexer.indexAll();
@Test
public void search_tags_by_portfolio_ignores_hotspots() {
ComponentDto portfolio = db.components().insertPrivatePortfolio();
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- db.components().insertComponent(newProjectCopy(project, portfolio));
- permissionIndexer.allowOnlyAnyone(project);
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ db.components().insertComponent(newProjectCopy(mainBranch, portfolio));
+ permissionIndexer.allowOnlyAnyone(projectData.getProjectDto());
RuleDto issueRule = db.rules().insertIssueRule();
RuleDto hotspotRule = db.rules().insertHotspotRule();
- db.issues().insertHotspot(hotspotRule, project, project, issue -> issue.setTags(singletonList("cwe")));
- db.issues().insertIssue(issueRule, project, project, issue -> issue.setTags(singletonList("foo")));
+ db.issues().insertHotspot(hotspotRule, mainBranch, mainBranch, issue -> issue.setTags(singletonList("cwe")));
+ db.issues().insertIssue(issueRule, mainBranch, mainBranch, issue -> issue.setTags(singletonList("foo")));
indexIssues();
viewIndexer.indexAll();
@Test
public void search_tags_by_application() {
- ComponentDto application = db.components().insertPrivateApplication().getMainBranchComponent();
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- db.components().insertComponent(newProjectCopy(project, application));
- permissionIndexer.allowOnlyAnyone(project);
+ ProjectData applicationData = db.components().insertPrivateApplication();
+ ComponentDto application = applicationData.getMainBranchComponent();
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ db.components().insertComponent(newProjectCopy(mainBranch, application));
+ permissionIndexer.allowOnlyAnyone(projectData.getProjectDto(), applicationData.getProjectDto());
RuleDto rule = db.rules().insertIssueRule();
- db.issues().insertIssue(rule, project, project, issue -> issue.setTags(singletonList("cwe")));
+ db.issues().insertIssue(rule, mainBranch, mainBranch, issue -> issue.setTags(singletonList("cwe")));
indexIssues();
viewIndexer.indexAll();
+
assertThat(tagListOf(ws.newRequest().setParam("project", application.getKey()))).containsExactly("cwe");
}
@Test
public void search_tags_by_application_ignores_hotspots() {
ComponentDto application = db.components().insertPrivateApplication().getMainBranchComponent();
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto project = projectData.getMainBranchComponent();
db.components().insertComponent(newProjectCopy(project, application));
- permissionIndexer.allowOnlyAnyone(project);
+ permissionIndexer.allowOnlyAnyone(projectData.getProjectDto());
RuleDto issueRule = db.rules().insertIssueRule();
RuleDto hotspotRule = db.rules().insertHotspotRule();
db.issues().insertIssue(issueRule, project, project, issue -> issue.setTags(singletonList("cwe")));
@Test
public void return_limited_size() {
RuleDto rule = db.rules().insertIssueRule();
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- db.issues().insertIssue(rule, project, project, issue -> issue.setTags(asList("tag1", "tag2")));
- db.issues().insertIssue(rule, project, project, issue -> issue.setTags(asList("tag3", "tag4", "tag5")));
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ db.issues().insertIssue(rule, mainBranch, mainBranch, issue -> issue.setTags(asList("tag1", "tag2")));
+ db.issues().insertIssue(rule, mainBranch, mainBranch, issue -> issue.setTags(asList("tag3", "tag4", "tag5")));
indexIssues();
- permissionIndexer.allowOnlyAnyone(project);
+ permissionIndexer.allowOnlyAnyone(projectData.getProjectDto());
TagsResponse result = ws.newRequest()
.setParam("ps", "2")
@Test
public void do_not_return_issues_without_permission() {
RuleDto rule = db.rules().insertIssueRule();
- ComponentDto project1 = db.components().insertPrivateProject().getMainBranchComponent();
- ComponentDto project2 = db.components().insertPrivateProject().getMainBranchComponent();
- db.issues().insertIssue(rule, project1, project1, issue -> issue.setTags(asList("tag1", "tag2")));
- db.issues().insertIssue(rule, project2, project2, issue -> issue.setTags(asList("tag3", "tag4", "tag5")));
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch1 = projectData.getMainBranchComponent();
+ ComponentDto mainBranch2 = db.components().insertPrivateProject().getMainBranchComponent();
+ db.issues().insertIssue(rule, mainBranch1, mainBranch1, issue -> issue.setTags(asList("tag1", "tag2")));
+ db.issues().insertIssue(rule, mainBranch2, mainBranch2, issue -> issue.setTags(asList("tag3", "tag4", "tag5")));
indexIssues();
// Project 2 is not visible to current user
- permissionIndexer.allowOnlyAnyone(project1);
+ permissionIndexer.allowOnlyAnyone(projectData.getProjectDto());
TagsResponse result = ws.newRequest().executeProtobuf(TagsResponse.class);
@Test
public void fail_when_project_parameter_does_not_match_a_project() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- ComponentDto file = db.components().insertComponent(newFileDto(project));
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ ComponentDto file = db.components().insertComponent(newFileDto(mainBranch));
indexIssues();
- permissionIndexer.allowOnlyAnyone(project, project);
+ permissionIndexer.allowOnlyAnyone(projectData.getProjectDto());
assertThatThrownBy(() -> {
ws.newRequest()
.setParam("project", file.getKey())
.execute();
})
- .isInstanceOf(IllegalArgumentException.class)
- .hasMessage(format("Component '%s' must be a project", file.getKey()));
+ .isInstanceOf(NotFoundException.class)
+ .hasMessage(format("Component '%s' not found", file.getKey()));
}
@Test
public void json_example() {
RuleDto rule = db.rules().insertIssueRule();
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- db.issues().insertIssue(rule, project, project, issue -> issue.setTags(asList("convention", "security")));
- db.issues().insertIssue(rule, project, project, issue -> issue.setTags(singletonList("cwe")));
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ db.issues().insertIssue(rule, mainBranch, mainBranch, issue -> issue.setTags(asList("convention", "security")));
+ db.issues().insertIssue(rule, mainBranch, mainBranch, issue -> issue.setTags(singletonList("cwe")));
indexIssues();
- permissionIndexer.allowOnlyAnyone(project);
+ permissionIndexer.allowOnlyAnyone(projectData.getProjectDto());
String result = ws.newRequest().execute().getInput();
@Rule
public UserSessionRule userSession = UserSessionRule.standalone().logIn();
@Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
+ public DbTester db = DbTester.create(System2.INSTANCE, true);
private final I18nRule i18n = new I18nRule();
@Test
public void json_example() {
- ComponentDto project = db.components().insertPrivateProject(p -> p.setKey("MY_PROJECT")
- .setName("My Project")).getMainBranchComponent();
- userSession.addProjectPermission(USER, project);
- SnapshotDto analysis = db.components().insertSnapshot(project, s -> s.setPeriodDate(parseDateTime("2016-01-11T10:49:50+0100").getTime())
+ ProjectData projectData = db.components().insertPrivateProject(p -> p.setKey("MY_PROJECT")
+ .setName("My Project"));
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ addProjectPermission(projectData);
+ SnapshotDto analysis = db.components().insertSnapshot(mainBranch, s -> s.setPeriodDate(parseDateTime("2016-01-11T10:49:50+0100").getTime())
.setPeriodMode("previous_version")
.setPeriodParam("1.0-SNAPSHOT"));
- ComponentDto file1 = db.components().insertComponent(newFileDto(project)
+ ComponentDto file1 = db.components().insertComponent(newFileDto(mainBranch)
.setUuid("AVIwDXE-bJbJqrw6wFv5")
.setKey("com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown/impl/ElementImpl.java")
.setName("ElementImpl.java")
.setLanguage("java")
.setQualifier(FILE)
.setPath("src/main/java/com/sonarsource/markdown/impl/ElementImpl.java"));
- ComponentDto file2 = db.components().insertComponent(newFileDto(project)
+ ComponentDto file2 = db.components().insertComponent(newFileDto(mainBranch)
.setUuid("AVIwDXE_bJbJqrw6wFwJ")
.setKey("com.sonarsource:java-markdown:src/test/java/com/sonarsource/markdown/impl/ElementImplTest.java")
.setName("ElementImplTest.java")
.setLanguage("java")
.setQualifier(UNIT_TEST_FILE)
.setPath("src/test/java/com/sonarsource/markdown/impl/ElementImplTest.java"));
- ComponentDto dir = db.components().insertComponent(newDirectory(project, "src/main/java/com/sonarsource/markdown/impl")
+ ComponentDto dir = db.components().insertComponent(newDirectory(mainBranch, "src/main/java/com/sonarsource/markdown/impl")
.setUuid("AVIwDXE-bJbJqrw6wFv8")
.setKey("com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown/impl")
.setQualifier(DIRECTORY));
MetricDto complexity = insertComplexityMetric();
db.measures().insertLiveMeasure(file1, complexity, m -> m.setValue(12.0d));
db.measures().insertLiveMeasure(dir, complexity, m -> m.setValue(35.0d));
- db.measures().insertLiveMeasure(project, complexity, m -> m.setValue(42.0d));
+ db.measures().insertLiveMeasure(mainBranch, complexity, m -> m.setValue(42.0d));
MetricDto ncloc = insertNclocMetric();
db.measures().insertLiveMeasure(file1, ncloc, m -> m.setValue(114.0d));
db.measures().insertLiveMeasure(dir, ncloc, m -> m.setValue(217.0d));
- db.measures().insertLiveMeasure(project, ncloc, m -> m.setValue(1984.0d));
+ db.measures().insertLiveMeasure(mainBranch, ncloc, m -> m.setValue(1984.0d));
MetricDto newViolations = insertNewViolationsMetric();
db.measures().insertLiveMeasure(file1, newViolations, m -> m.setValue(25.0d));
db.measures().insertLiveMeasure(dir, newViolations, m -> m.setValue(25.0d));
- db.measures().insertLiveMeasure(project, newViolations, m -> m.setValue(255.0d));
+ db.measures().insertLiveMeasure(mainBranch, newViolations, m -> m.setValue(255.0d));
db.commit();
String response = ws.newRequest()
- .setParam(PARAM_COMPONENT, project.getKey())
+ .setParam(PARAM_COMPONENT, mainBranch.getKey())
.setParam(PARAM_METRIC_KEYS, "ncloc, complexity, new_violations")
.setParam(PARAM_ADDITIONAL_FIELDS, "metrics,period")
.execute()
assertJson(response).isSimilarTo(getClass().getResource("component_tree-example.json"));
}
+ private UserSessionRule addProjectPermission(ProjectData projectData) {
+ return userSession.addProjectPermission(USER, projectData.getProjectDto())
+ .addProjectBranchMapping(projectData.projectUuid(), projectData.getMainBranchComponent());
+ }
+
@Test
public void empty_response() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- userSession.addProjectPermission(USER, project);
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ addProjectPermission(projectData);
ComponentTreeWsResponse response = ws.newRequest()
- .setParam(PARAM_COMPONENT, project.getKey())
+ .setParam(PARAM_COMPONENT, mainBranch.getKey())
.setParam(PARAM_METRIC_KEYS, "ncloc, complexity")
.executeProtobuf(ComponentTreeWsResponse.class);
- assertThat(response.getBaseComponent().getKey()).isEqualTo(project.getKey());
+ assertThat(response.getBaseComponent().getKey()).isEqualTo(mainBranch.getKey());
assertThat(response.getComponentsList()).isEmpty();
assertThat(response.getMetrics().getMetricsList()).isEmpty();
assertThat(response.hasPeriod()).isFalse();
@Test
public void load_measures_and_periods() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
+ ComponentDto mainBranch = db.components().insertPrivateProject().getMainBranchComponent();
SnapshotDto projectSnapshot = dbClient.snapshotDao().insert(dbSession,
- newAnalysis(project)
+ newAnalysis(mainBranch)
.setPeriodDate(System.currentTimeMillis())
.setPeriodMode("last_version")
.setPeriodDate(System.currentTimeMillis()));
- userSession.anonymous().addProjectPermission(USER, project);
- ComponentDto directory = newDirectory(project, "directory-uuid", "path/to/directory").setName("directory-1");
+ userSession.anonymous().addProjectPermission(USER, mainBranch);
+ ComponentDto directory = newDirectory(mainBranch, "directory-uuid", "path/to/directory").setName("directory-1");
db.components().insertComponent(directory);
ComponentDto file = newFileDto(directory, null, "file-uuid").setName("file-1");
db.components().insertComponent(file);
db.measures().insertLiveMeasure(directory, coverage, m -> m.setValue(15.5d));
ComponentTreeWsResponse response = ws.newRequest()
- .setParam(PARAM_COMPONENT, project.getKey())
+ .setParam(PARAM_COMPONENT, mainBranch.getKey())
.setParam(PARAM_METRIC_KEYS, "ncloc,coverage")
.setParam(PARAM_ADDITIONAL_FIELDS, ADDITIONAL_PERIOD)
.executeProtobuf(ComponentTreeWsResponse.class);
@Test
public void load_measures_with_best_value() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- SnapshotDto projectSnapshot = db.components().insertSnapshot(project);
- userSession.anonymous().addProjectPermission(USER, project);
- ComponentDto directory = newDirectory(project, "directory-uuid", "path/to/directory").setName("directory-1");
+ ComponentDto mainBranch = db.components().insertPrivateProject().getMainBranchComponent();
+ SnapshotDto projectSnapshot = db.components().insertSnapshot(mainBranch);
+ userSession.anonymous().addProjectPermission(USER, mainBranch);
+ ComponentDto directory = newDirectory(mainBranch, "directory-uuid", "path/to/directory").setName("directory-1");
db.components().insertComponent(directory);
ComponentDto file = newFileDto(directory, null, "file-uuid").setName("file-1");
db.components().insertComponent(file);
db.measures().insertLiveMeasure(directory, coverage, m -> m.setValue(42.0d));
ComponentTreeWsResponse response = ws.newRequest()
- .setParam(PARAM_COMPONENT, project.getKey())
+ .setParam(PARAM_COMPONENT, mainBranch.getKey())
.setParam(PARAM_METRIC_KEYS, "ncloc,coverage,new_violations")
.setParam(PARAM_ADDITIONAL_FIELDS, "metrics")
.executeProtobuf(ComponentTreeWsResponse.class);
@Test
public void return_is_best_value_on_leak_measures() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- db.components().insertSnapshot(project);
- userSession.anonymous().addProjectPermission(USER, project);
- ComponentDto file = newFileDto(project);
+ ComponentDto mainBranch = db.components().insertPrivateProject().getMainBranchComponent();
+ db.components().insertSnapshot(mainBranch);
+ userSession.anonymous().addProjectPermission(USER, mainBranch);
+ ComponentDto file = newFileDto(mainBranch);
db.components().insertComponent(file);
MetricDto matchingBestValue = db.measures().insertMetric(m -> m
db.measures().insertLiveMeasure(file, noBestValue, m -> m.setData((String) null).setValue(42.0d));
ComponentTreeWsResponse response = ws.newRequest()
- .setParam(PARAM_COMPONENT, project.getKey())
+ .setParam(PARAM_COMPONENT, mainBranch.getKey())
.setParam(PARAM_METRIC_KEYS, "new_lines,new_lines_2,new_violations")
.executeProtobuf(ComponentTreeWsResponse.class);
@Test
public void use_best_value_for_rating() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- userSession.anonymous().addProjectPermission(USER, project);
- SnapshotDto projectSnapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(project)
+ ComponentDto mainBranch = db.components().insertPrivateProject().getMainBranchComponent();
+ userSession.anonymous().addProjectPermission(USER, mainBranch);
+ SnapshotDto projectSnapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(mainBranch)
.setPeriodDate(parseDateTime("2016-01-11T10:49:50+0100").getTime())
.setPeriodMode("previous_version")
.setPeriodParam("1.0-SNAPSHOT"));
- ComponentDto directory = newDirectory(project, "directory-uuid", "path/to/directory").setName("directory-1");
+ ComponentDto directory = newDirectory(mainBranch, "directory-uuid", "path/to/directory").setName("directory-1");
db.components().insertComponent(directory);
ComponentDto file = newFileDto(directory, null, "file-uuid").setName("file-1");
db.components().insertComponent(file);
db.measures().insertLiveMeasure(directory, metric, m -> m.setValue(2d));
ComponentTreeWsResponse response = ws.newRequest()
- .setParam(PARAM_COMPONENT, project.getKey())
+ .setParam(PARAM_COMPONENT, mainBranch.getKey())
.setParam(PARAM_METRIC_KEYS, NEW_SECURITY_RATING_KEY)
.setParam(PARAM_ADDITIONAL_FIELDS, "metrics")
.executeProtobuf(ComponentTreeWsResponse.class);
@Test
public void load_measures_multi_sort_with_metric_key_and_paginated() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- userSession.addProjectPermission(USER, project);
- SnapshotDto projectSnapshot = db.components().insertSnapshot(project);
- ComponentDto file9 = db.components().insertComponent(newFileDto(project, null, "file-uuid-9").setName("file-1").setKey("file-9-key"));
- ComponentDto file8 = db.components().insertComponent(newFileDto(project, null, "file-uuid-8").setName("file-1").setKey("file-8-key"));
- ComponentDto file7 = db.components().insertComponent(newFileDto(project, null, "file-uuid-7").setName("file-1").setKey("file-7-key"));
- ComponentDto file6 = db.components().insertComponent(newFileDto(project, null, "file-uuid-6").setName("file-1").setKey("file-6-key"));
- ComponentDto file5 = db.components().insertComponent(newFileDto(project, null, "file-uuid-5").setName("file-1").setKey("file-5-key"));
- ComponentDto file4 = db.components().insertComponent(newFileDto(project, null, "file-uuid-4").setName("file-1").setKey("file-4-key"));
- ComponentDto file3 = db.components().insertComponent(newFileDto(project, null, "file-uuid-3").setName("file-1").setKey("file-3-key"));
- ComponentDto file2 = db.components().insertComponent(newFileDto(project, null, "file-uuid-2").setName("file-1").setKey("file-2-key"));
- ComponentDto file1 = db.components().insertComponent(newFileDto(project, null, "file-uuid-1").setName("file-1").setKey("file-1-key"));
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ addProjectPermission(projectData);
+ SnapshotDto projectSnapshot = db.components().insertSnapshot(mainBranch);
+ ComponentDto file9 = db.components().insertComponent(newFileDto(mainBranch, null, "file-uuid-9").setName("file-1").setKey("file-9-key"));
+ ComponentDto file8 = db.components().insertComponent(newFileDto(mainBranch, null, "file-uuid-8").setName("file-1").setKey("file-8-key"));
+ ComponentDto file7 = db.components().insertComponent(newFileDto(mainBranch, null, "file-uuid-7").setName("file-1").setKey("file-7-key"));
+ ComponentDto file6 = db.components().insertComponent(newFileDto(mainBranch, null, "file-uuid-6").setName("file-1").setKey("file-6-key"));
+ ComponentDto file5 = db.components().insertComponent(newFileDto(mainBranch, null, "file-uuid-5").setName("file-1").setKey("file-5-key"));
+ ComponentDto file4 = db.components().insertComponent(newFileDto(mainBranch, null, "file-uuid-4").setName("file-1").setKey("file-4-key"));
+ ComponentDto file3 = db.components().insertComponent(newFileDto(mainBranch, null, "file-uuid-3").setName("file-1").setKey("file-3-key"));
+ ComponentDto file2 = db.components().insertComponent(newFileDto(mainBranch, null, "file-uuid-2").setName("file-1").setKey("file-2-key"));
+ ComponentDto file1 = db.components().insertComponent(newFileDto(mainBranch, null, "file-uuid-1").setName("file-1").setKey("file-1-key"));
MetricDto coverage = insertCoverageMetric();
db.commit();
db.measures().insertLiveMeasure(file1, coverage, m -> m.setValue(1.0d));
db.measures().insertLiveMeasure(file9, coverage, m -> m.setValue(9.0d));
ComponentTreeWsResponse response = ws.newRequest()
- .setParam(PARAM_COMPONENT, project.getKey())
+ .setParam(PARAM_COMPONENT, mainBranch.getKey())
.setParam(SORT, NAME_SORT + ", " + METRIC_SORT)
.setParam(PARAM_METRIC_SORT, "coverage")
.setParam(PARAM_METRIC_KEYS, "coverage")
@Test
public void sort_by_metric_value() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- userSession.addProjectPermission(USER, project);
- SnapshotDto projectSnapshot = db.components().insertSnapshot(project);
- ComponentDto file4 = db.components().insertComponent(newFileDto(project, null, "file-uuid-4").setKey("file-4-key"));
- ComponentDto file3 = db.components().insertComponent(newFileDto(project, null, "file-uuid-3").setKey("file-3-key"));
- ComponentDto file1 = db.components().insertComponent(newFileDto(project, null, "file-uuid-1").setKey("file-1-key"));
- ComponentDto file2 = db.components().insertComponent(newFileDto(project, null, "file-uuid-2").setKey("file-2-key"));
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ addProjectPermission(projectData);
+ SnapshotDto projectSnapshot = db.components().insertSnapshot(mainBranch);
+ ComponentDto file4 = db.components().insertComponent(newFileDto(mainBranch, null, "file-uuid-4").setKey("file-4-key"));
+ ComponentDto file3 = db.components().insertComponent(newFileDto(mainBranch, null, "file-uuid-3").setKey("file-3-key"));
+ ComponentDto file1 = db.components().insertComponent(newFileDto(mainBranch, null, "file-uuid-1").setKey("file-1-key"));
+ ComponentDto file2 = db.components().insertComponent(newFileDto(mainBranch, null, "file-uuid-2").setKey("file-2-key"));
MetricDto ncloc = newMetricDto().setKey("ncloc").setValueType(INT.name()).setDirection(1);
dbClient.metricDao().insert(dbSession, ncloc);
db.commit();
db.measures().insertLiveMeasure(file3, ncloc, m -> m.setValue(3.0d));
ComponentTreeWsResponse response = ws.newRequest()
- .setParam(PARAM_COMPONENT, project.getKey())
+ .setParam(PARAM_COMPONENT, mainBranch.getKey())
.setParam(SORT, METRIC_SORT)
.setParam(PARAM_METRIC_SORT, "ncloc")
.setParam(PARAM_METRIC_KEYS, "ncloc")
@Test
public void remove_components_without_measure_on_the_metric_sort() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- userSession.addProjectPermission(USER, project);
- SnapshotDto projectSnapshot = db.components().insertSnapshot(project);
- ComponentDto file1 = newFileDto(project, null, "file-uuid-1").setKey("file-1-key");
- ComponentDto file2 = newFileDto(project, null, "file-uuid-2").setKey("file-2-key");
- ComponentDto file3 = newFileDto(project, null, "file-uuid-3").setKey("file-3-key");
- ComponentDto file4 = newFileDto(project, null, "file-uuid-4").setKey("file-4-key");
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ addProjectPermission(projectData);
+ SnapshotDto projectSnapshot = db.components().insertSnapshot(mainBranch);
+ ComponentDto file1 = newFileDto(mainBranch, null, "file-uuid-1").setKey("file-1-key");
+ ComponentDto file2 = newFileDto(mainBranch, null, "file-uuid-2").setKey("file-2-key");
+ ComponentDto file3 = newFileDto(mainBranch, null, "file-uuid-3").setKey("file-3-key");
+ ComponentDto file4 = newFileDto(mainBranch, null, "file-uuid-4").setKey("file-4-key");
db.components().insertComponent(file1);
db.components().insertComponent(file2);
db.components().insertComponent(file3);
db.commit();
ComponentTreeWsResponse response = ws.newRequest()
- .setParam(PARAM_COMPONENT, project.getKey())
+ .setParam(PARAM_COMPONENT, mainBranch.getKey())
.setParam(SORT, METRIC_SORT)
.setParam(PARAM_METRIC_SORT, "ncloc")
.setParam(PARAM_METRIC_KEYS, "ncloc")
@Test
public void sort_by_metric_period() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- userSession.addProjectPermission(USER, project);
- SnapshotDto projectSnapshot = db.components().insertSnapshot(project);
- ComponentDto file3 = db.components().insertComponent(newFileDto(project, null, "file-uuid-3").setKey("file-3-key"));
- ComponentDto file1 = db.components().insertComponent(newFileDto(project, null, "file-uuid-1").setKey("file-1-key"));
- ComponentDto file2 = db.components().insertComponent(newFileDto(project, null, "file-uuid-2").setKey("file-2-key"));
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ addProjectPermission(projectData);
+ SnapshotDto projectSnapshot = db.components().insertSnapshot(mainBranch);
+ ComponentDto file3 = db.components().insertComponent(newFileDto(mainBranch, null, "file-uuid-3").setKey("file-3-key"));
+ ComponentDto file1 = db.components().insertComponent(newFileDto(mainBranch, null, "file-uuid-1").setKey("file-1-key"));
+ ComponentDto file2 = db.components().insertComponent(newFileDto(mainBranch, null, "file-uuid-2").setKey("file-2-key"));
MetricDto ncloc = newMetricDto().setKey("ncloc").setValueType(INT.name()).setDirection(1);
dbClient.metricDao().insert(dbSession, ncloc);
db.commit();
db.measures().insertLiveMeasure(file3, ncloc, m -> m.setValue(3.0d));
ComponentTreeWsResponse response = ws.newRequest()
- .setParam(PARAM_COMPONENT, project.getKey())
+ .setParam(PARAM_COMPONENT, mainBranch.getKey())
.setParam(SORT, METRIC_PERIOD_SORT)
.setParam(PARAM_METRIC_SORT, "ncloc")
.setParam(PARAM_METRIC_KEYS, "ncloc")
@Test
public void remove_components_without_measure_on_the_metric_period_sort() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- userSession.addProjectPermission(USER, project);
- SnapshotDto projectSnapshot = db.components().insertSnapshot(project);
- ComponentDto file4 = db.components().insertComponent(newFileDto(project, null, "file-uuid-4").setKey("file-4-key"));
- ComponentDto file3 = db.components().insertComponent(newFileDto(project, null, "file-uuid-3").setKey("file-3-key"));
- ComponentDto file2 = db.components().insertComponent(newFileDto(project, null, "file-uuid-2").setKey("file-2-key"));
- ComponentDto file1 = db.components().insertComponent(newFileDto(project, null, "file-uuid-1").setKey("file-1-key"));
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ addProjectPermission(projectData);
+ SnapshotDto projectSnapshot = db.components().insertSnapshot(mainBranch);
+ ComponentDto file4 = db.components().insertComponent(newFileDto(mainBranch, null, "file-uuid-4").setKey("file-4-key"));
+ ComponentDto file3 = db.components().insertComponent(newFileDto(mainBranch, null, "file-uuid-3").setKey("file-3-key"));
+ ComponentDto file2 = db.components().insertComponent(newFileDto(mainBranch, null, "file-uuid-2").setKey("file-2-key"));
+ ComponentDto file1 = db.components().insertComponent(newFileDto(mainBranch, null, "file-uuid-1").setKey("file-1-key"));
MetricDto ncloc = newMetricDto().setKey("new_ncloc").setValueType(INT.name()).setDirection(1);
dbClient.metricDao().insert(dbSession, ncloc);
db.measures().insertLiveMeasure(file1, ncloc, m -> m.setData((String) null).setValue(1.0d));
db.commit();
ComponentTreeWsResponse response = ws.newRequest()
- .setParam(PARAM_COMPONENT, project.getKey())
+ .setParam(PARAM_COMPONENT, mainBranch.getKey())
.setParam(SORT, METRIC_PERIOD_SORT + "," + NAME_SORT)
.setParam(PARAM_METRIC_SORT, "new_ncloc")
.setParam(PARAM_METRIC_KEYS, "new_ncloc")
@Test
public void load_measures_when_no_leave_qualifier() {
resourceTypes.setLeavesQualifiers();
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- userSession.addProjectPermission(USER, project);
- db.components().insertSnapshot(project);
- db.components().insertComponent(newFileDto(project));
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ addProjectPermission(projectData);
+ db.components().insertSnapshot(mainBranch);
+ db.components().insertComponent(newFileDto(mainBranch));
insertNclocMetric();
ComponentTreeWsResponse result = ws.newRequest()
- .setParam(PARAM_COMPONENT, project.getKey())
+ .setParam(PARAM_COMPONENT, mainBranch.getKey())
.setParam(PARAM_STRATEGY, LEAVES_STRATEGY)
.setParam(PARAM_METRIC_KEYS, "ncloc")
.executeProtobuf(ComponentTreeWsResponse.class);
- assertThat(result.getBaseComponent().getKey()).isEqualTo(project.getKey());
+ assertThat(result.getBaseComponent().getKey()).isEqualTo(mainBranch.getKey());
assertThat(result.getComponentsCount()).isZero();
}
@Test
public void branch() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- userSession.addProjectPermission(USER, project);
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ addProjectPermission(projectData);
String branchName = "my-branch";
- ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey(branchName));
- userSession.addProjectBranchMapping(project.uuid(), branch);
+ ComponentDto branch = db.components().insertProjectBranch(mainBranch, b -> b.setKey(branchName));
+ userSession.addProjectBranchMapping(projectData.getProjectDto().getUuid(), branch);
db.components().insertSnapshot(branch);
- ComponentDto file = db.components().insertComponent(newFileDto(branch, project.uuid()));
+ ComponentDto file = db.components().insertComponent(newFileDto(branch, mainBranch.uuid()));
MetricDto complexity = db.measures().insertMetric(m -> m.setValueType(INT.name()));
LiveMeasureDto measure = db.measures().insertLiveMeasure(file, complexity, m -> m.setValue(12.0d));
@Test
public void dont_show_branch_if_main_branch() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- userSession.addProjectPermission(USER, project);
- ComponentDto file = db.components().insertComponent(newFileDto(project));
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ addProjectPermission(projectData);
+ ComponentDto file = db.components().insertComponent(newFileDto(mainBranch));
MetricDto complexity = db.measures().insertMetric(m -> m.setValueType(INT.name()));
ComponentTreeWsResponse response = ws.newRequest()
@Test
public void pull_request() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- userSession.addProjectPermission(USER, project);
- ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("pr-123").setBranchType(PULL_REQUEST));
- userSession.addProjectBranchMapping(project.uuid(), branch);
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ addProjectPermission(projectData);
+ ComponentDto branch = db.components().insertProjectBranch(mainBranch, b -> b.setKey("pr-123").setBranchType(PULL_REQUEST));
+ userSession.addProjectBranchMapping(projectData.projectUuid(), branch);
SnapshotDto analysis = db.components().insertSnapshot(branch);
- ComponentDto file = db.components().insertComponent(newFileDto(branch, project.uuid()).setMainBranchProjectUuid(project.uuid()));
+ ComponentDto file = db.components().insertComponent(newFileDto(branch, mainBranch.uuid()).setMainBranchProjectUuid(mainBranch.uuid()));
MetricDto complexity = db.measures().insertMetric(m -> m.setValueType(INT.name()));
LiveMeasureDto measure = db.measures().insertLiveMeasure(file, complexity, m -> m.setValue(12.0d));
@Test
public void fix_pull_request_new_issue_count_metrics() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- userSession.addProjectPermission(USER, project);
- ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("pr-123").setBranchType(PULL_REQUEST));
- userSession.addProjectBranchMapping(project.uuid(), branch);
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ addProjectPermission(projectData);
+ ComponentDto branch = db.components().insertProjectBranch(mainBranch, b -> b.setKey("pr-123").setBranchType(PULL_REQUEST));
+ userSession.addProjectBranchMapping(projectData.projectUuid(), branch);
SnapshotDto analysis = db.components().insertSnapshot(branch);
- ComponentDto file = db.components().insertComponent(newFileDto(branch, project.uuid()));
+ ComponentDto file = db.components().insertComponent(newFileDto(branch, mainBranch.uuid()));
MetricDto bug = db.measures().insertMetric(m -> m.setValueType(INT.name()).setKey(CoreMetrics.BUGS_KEY));
MetricDto newBug = db.measures().insertMetric(m -> m.setValueType(INT.name()).setKey(CoreMetrics.NEW_BUGS_KEY));
@Test
public void new_issue_count_measures_are_not_transformed_if_they_dont_exist_in_pr() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- userSession.addProjectPermission(USER, project);
- ComponentDto pr = db.components().insertProjectBranch(project, b -> b.setKey("pr").setBranchType(PULL_REQUEST));
- userSession.addProjectBranchMapping(project.uuid(), pr);
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ addProjectPermission(projectData);
+ ComponentDto pr = db.components().insertProjectBranch(mainBranch, b -> b.setKey("pr").setBranchType(PULL_REQUEST));
+ userSession.addProjectBranchMapping(projectData.projectUuid(), pr);
SnapshotDto analysis = db.components().insertSnapshot(pr);
- ComponentDto file = db.components().insertComponent(newFileDto(pr, project.uuid()));
+ ComponentDto file = db.components().insertComponent(newFileDto(pr, mainBranch.uuid()));
MetricDto bug = db.measures().insertMetric(m -> m.setValueType(INT.name()).setKey(CoreMetrics.BUGS_KEY));
MetricDto newBug = db.measures().insertMetric(m -> m.setValueType(INT.name()).setKey(CoreMetrics.NEW_BUGS_KEY));
@Test
public void metric_without_a_domain() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- userSession.addProjectPermission(USER, project);
- SnapshotDto analysis = db.getDbClient().snapshotDao().insert(dbSession, newAnalysis(project));
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ addProjectPermission(projectData);
+ SnapshotDto analysis = db.getDbClient().snapshotDao().insert(dbSession, newAnalysis(mainBranch));
MetricDto metricWithoutDomain = db.measures().insertMetric(m -> m
.setValueType(Metric.ValueType.INT.name())
.setDomain(null));
- db.measures().insertLiveMeasure(project, metricWithoutDomain);
+ db.measures().insertLiveMeasure(mainBranch, metricWithoutDomain);
ComponentTreeWsResponse result = ws.newRequest()
- .setParam(PARAM_COMPONENT, project.getKey())
+ .setParam(PARAM_COMPONENT, mainBranch.getKey())
.setParam(PARAM_METRIC_KEYS, metricWithoutDomain.getKey())
.setParam(PARAM_ADDITIONAL_FIELDS, "metrics")
.executeProtobuf(ComponentTreeWsResponse.class);
@Test
public void project_reference_from_portfolio() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- userSession.addProjectPermission(USER, project);
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ addProjectPermission(projectData);
ComponentDto view = db.components().insertPrivatePortfolio();
userSession.addProjectPermission(USER, view);
SnapshotDto viewAnalysis = db.components().insertSnapshot(view);
- ComponentDto projectCopy = db.components().insertComponent(newProjectCopy(project, view));
+ ComponentDto projectCopy = db.components().insertComponent(newProjectCopy(mainBranch, view));
MetricDto ncloc = insertNclocMetric();
db.measures().insertLiveMeasure(projectCopy, ncloc, m -> m.setValue(5d));
assertThat(result.getComponentsList())
.extracting(Component::getKey, Component::getRefKey)
- .containsExactlyInAnyOrder(tuple(projectCopy.getKey(), project.getKey()));
+ .containsExactlyInAnyOrder(tuple(projectCopy.getKey(), mainBranch.getKey()));
}
@Test
ComponentDto applicationBranch = db.components().insertProjectBranch(application, a -> a.setKey(branchName), a -> a.setUuid("custom-uuid"));
userSession.addProjectBranchMapping(applicationData.projectUuid(), applicationBranch);
ProjectData projectData = db.components().insertPrivateProject(p -> p.setKey("project-key"));
- ComponentDto project = projectData.getMainBranchComponent();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
- ComponentDto projectBranch = db.components().insertProjectBranch(project, b -> b.setKey("project-branch"));
+ ComponentDto projectBranch = db.components().insertProjectBranch(mainBranch, b -> b.setKey("project-branch"));
userSession.addProjectBranchMapping(projectData.projectUuid(), projectBranch);
ComponentDto techProjectBranch = db.components().insertComponent(newProjectCopy(projectBranch, applicationBranch)
.setKey(applicationBranch.getKey() + branchName + projectBranch.getKey()));
.containsExactlyInAnyOrder(applicationBranch.getKey(), branchName);
assertThat(result.getComponentsList())
.extracting(Component::getKey, Component::getBranch, Component::getRefKey)
- .containsExactlyInAnyOrder(tuple(techProjectBranch.getKey(), "project-branch", project.getKey()));
+ .containsExactlyInAnyOrder(tuple(techProjectBranch.getKey(), "project-branch", mainBranch.getKey()));
}
@Test
public void fail_when_metric_keys_parameter_is_empty() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- db.components().insertSnapshot(project);
+ ComponentDto mainBranch = db.components().insertPrivateProject().getMainBranchComponent();
+ db.components().insertSnapshot(mainBranch);
assertThatThrownBy(() -> {
ws.newRequest()
- .setParam(PARAM_COMPONENT, project.getKey())
+ .setParam(PARAM_COMPONENT, mainBranch.getKey())
.setParam(PARAM_METRIC_KEYS, "")
.executeProtobuf(ComponentTreeWsResponse.class);
})
@Test
public void fail_when_a_metric_is_not_found() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- userSession.addProjectPermission(USER, project);
- db.components().insertSnapshot(project);
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ addProjectPermission(projectData);
+ db.components().insertSnapshot(mainBranch);
insertNclocMetric();
insertNewViolationsMetric();
assertThatThrownBy(() -> {
ws.newRequest()
- .setParam(PARAM_COMPONENT, project.getKey())
+ .setParam(PARAM_COMPONENT, mainBranch.getKey())
.setParam(PARAM_METRIC_KEYS, "ncloc, new_violations, unknown-metric, another-unknown-metric").executeProtobuf(ComponentTreeWsResponse.class);
})
.isInstanceOf(NotFoundException.class)
@Test
public void fail_when_using_DISTRIB_metrics() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- userSession.addProjectPermission(USER, project);
- db.components().insertSnapshot(project);
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ addProjectPermission(projectData);
+ db.components().insertSnapshot(mainBranch);
dbClient.metricDao().insert(dbSession, newMetricDto().setKey("distrib1").setValueType(DISTRIB.name()));
dbClient.metricDao().insert(dbSession, newMetricDto().setKey("distrib2").setValueType(DISTRIB.name()));
db.commit();
assertThatThrownBy(() -> {
ws.newRequest()
- .setParam(PARAM_COMPONENT, project.getKey())
+ .setParam(PARAM_COMPONENT, mainBranch.getKey())
.setParam(PARAM_METRIC_KEYS, "distrib1,distrib2")
.execute();
})
@Test
public void fail_when_using_DATA_metrics() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- userSession.addProjectPermission(USER, project);
- db.components().insertSnapshot(project);
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ addProjectPermission(projectData);
+ db.components().insertSnapshot(mainBranch);
dbClient.metricDao().insert(dbSession, newMetricDto().setKey("data1").setValueType(DISTRIB.name()));
dbClient.metricDao().insert(dbSession, newMetricDto().setKey("data2").setValueType(DISTRIB.name()));
assertThatThrownBy(() -> {
ws.newRequest()
- .setParam(PARAM_COMPONENT, project.getKey())
+ .setParam(PARAM_COMPONENT, mainBranch.getKey())
.setParam(PARAM_METRIC_KEYS, "data1,data2")
.execute();
})
@Test
public void fail_when_setting_more_than_15_metric_keys() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- db.components().insertSnapshot(project);
+ ComponentDto mainBranch = db.components().insertPrivateProject().getMainBranchComponent();
+ db.components().insertSnapshot(mainBranch);
List<String> metrics = IntStream.range(0, 20)
.mapToObj(i -> "metric" + i)
.collect(MoreCollectors.toList());
assertThatThrownBy(() -> {
ws.newRequest()
- .setParam(PARAM_COMPONENT, project.getKey())
+ .setParam(PARAM_COMPONENT, mainBranch.getKey())
.setParam(PARAM_METRIC_KEYS, Joiner.on(",").join(metrics))
.execute();
})
@Test
public void fail_when_search_query_have_less_than_3_characters() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- db.components().insertSnapshot(project);
+ ComponentDto mainBranch = db.components().insertPrivateProject().getMainBranchComponent();
+ db.components().insertSnapshot(mainBranch);
insertNclocMetric();
insertNewViolationsMetric();
assertThatThrownBy(() -> {
ws.newRequest()
- .setParam(PARAM_COMPONENT, project.getKey())
+ .setParam(PARAM_COMPONENT, mainBranch.getKey())
.setParam(PARAM_METRIC_KEYS, "ncloc, new_violations")
.setParam(Param.TEXT_QUERY, "fi")
.executeProtobuf(ComponentTreeWsResponse.class);
@Test
public void fail_when_insufficient_privileges() {
userSession.logIn();
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- db.components().insertSnapshot(project);
+ ComponentDto mainBranch = db.components().insertPrivateProject().getMainBranchComponent();
+ db.components().insertSnapshot(mainBranch);
var request = ws.newRequest()
- .setParam(PARAM_COMPONENT, project.getKey())
+ .setParam(PARAM_COMPONENT, mainBranch.getKey())
.setParam(PARAM_METRIC_KEYS, "ncloc");
assertThatThrownBy(() -> request.executeProtobuf(ComponentTreeWsResponse.class))
.isInstanceOf(ForbiddenException.class);
@Test
public void fail_when_sort_by_metric_and_no_metric_sort_provided() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- db.components().insertSnapshot(project);
+ ComponentDto mainBranch = db.components().insertPrivateProject().getMainBranchComponent();
+ db.components().insertSnapshot(mainBranch);
assertThatThrownBy(() -> {
ws.newRequest()
- .setParam(PARAM_COMPONENT, project.getKey())
+ .setParam(PARAM_COMPONENT, mainBranch.getKey())
.setParam(PARAM_METRIC_KEYS, "ncloc")
// PARAM_METRIC_SORT is not set
.setParam(SORT, METRIC_SORT)
@Test
public void fail_when_sort_by_metric_and_not_in_the_list_of_metric_keys() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- db.components().insertSnapshot(project);
+ ComponentDto mainBranch = db.components().insertPrivateProject().getMainBranchComponent();
+ db.components().insertSnapshot(mainBranch);
assertThatThrownBy(() -> {
ws.newRequest()
- .setParam(PARAM_COMPONENT, project.getKey())
+ .setParam(PARAM_COMPONENT, mainBranch.getKey())
.setParam(PARAM_METRIC_KEYS, "ncloc,violations")
.setParam(PARAM_METRIC_SORT, "complexity")
.setParam(SORT, METRIC_SORT)
@Test
public void fail_when_sort_by_metric_period_and_no_metric_period_sort_provided() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- db.components().insertSnapshot(project);
+ ComponentDto mainBranch = db.components().insertPrivateProject().getMainBranchComponent();
+ db.components().insertSnapshot(mainBranch);
assertThatThrownBy(() -> {
ws.newRequest()
- .setParam(PARAM_COMPONENT, project.getKey())
+ .setParam(PARAM_COMPONENT, mainBranch.getKey())
.setParam(PARAM_METRIC_KEYS, "ncloc")
.setParam(PARAM_METRIC_SORT, "ncloc")
// PARAM_METRIC_PERIOD_SORT_IS_NOT_SET
@Test
public void fail_when_paging_parameter_is_too_big() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- db.components().insertSnapshot(project);
+ ComponentDto mainBranch = db.components().insertPrivateProject().getMainBranchComponent();
+ db.components().insertSnapshot(mainBranch);
insertNclocMetric();
assertThatThrownBy(() -> {
ws.newRequest()
- .setParam(PARAM_COMPONENT, project.getKey())
+ .setParam(PARAM_COMPONENT, mainBranch.getKey())
.setParam(PARAM_METRIC_KEYS, "ncloc")
.setParam(Param.PAGE_SIZE, "2540")
.execute();
@Test
public void fail_when_with_measures_only_and_no_metric_sort() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- db.components().insertSnapshot(project);
+ ComponentDto mainBranch = db.components().insertPrivateProject().getMainBranchComponent();
+ db.components().insertSnapshot(mainBranch);
insertNclocMetric();
assertThatThrownBy(() -> {
ws.newRequest()
- .setParam(PARAM_COMPONENT, project.getKey())
+ .setParam(PARAM_COMPONENT, mainBranch.getKey())
.setParam(PARAM_METRIC_KEYS, "ncloc")
.setParam(PARAM_METRIC_SORT_FILTER, WITH_MEASURES_ONLY_METRIC_SORT_FILTER)
.executeProtobuf(ComponentTreeWsResponse.class);
@Test
public void fail_when_component_is_removed() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- db.components().insertSnapshot(project);
- ComponentDto file = db.components().insertComponent(newFileDto(project).setKey("file-key").setEnabled(false));
- userSession.anonymous().addProjectPermission(USER, project);
+ ComponentDto mainBranch = db.components().insertPrivateProject().getMainBranchComponent();
+ db.components().insertSnapshot(mainBranch);
+ ComponentDto file = db.components().insertComponent(newFileDto(mainBranch).setKey("file-key").setEnabled(false));
+ userSession.anonymous().addProjectPermission(USER, mainBranch);
insertNclocMetric();
assertThatThrownBy(() -> {
@Test
public void fail_if_branch_does_not_exist() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- ComponentDto file = db.components().insertComponent(newFileDto(project));
- userSession.addProjectPermission(USER, project);
- db.components().insertProjectBranch(project, b -> b.setKey("my_branch"));
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ ComponentDto file = db.components().insertComponent(newFileDto(mainBranch));
+ addProjectPermission(projectData);
+ db.components().insertProjectBranch(mainBranch, b -> b.setKey("my_branch"));
assertThatThrownBy(() -> {
ws.newRequest()
}
@Test
- public void doHandle_whenPassingUnexpectedQualifier_shouldThrowException(){
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- userSession.addProjectPermission(USER, project);
- ComponentDto file = db.components().insertComponent(newFileDto(project));
+ public void doHandle_whenPassingUnexpectedQualifier_shouldThrowException() {
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ addProjectPermission(projectData);
+ ComponentDto file = db.components().insertComponent(newFileDto(mainBranch));
MetricDto complexity = db.measures().insertMetric(m -> m.setValueType(INT.name()));
TestRequest testRequest = ws.newRequest()
.setParam(PARAM_QUALIFIERS, "BRC")
.setParam(PARAM_METRIC_KEYS, complexity.getKey());
- assertThatThrownBy(()->testRequest.execute()).isInstanceOf(IllegalArgumentException.class)
+ assertThatThrownBy(() -> testRequest.execute()).isInstanceOf(IllegalArgumentException.class)
.hasMessage("Value of parameter 'qualifiers' (BRC) must be one of: [UTS, FIL, DIR, TRK]");
}
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.component.BranchDto;
+import org.sonar.db.component.ProjectData;
import org.sonar.db.component.SnapshotDto;
import org.sonar.db.event.EventDto;
import org.sonar.db.project.ProjectDto;
@Rule
public UserSessionRule userSession = UserSessionRule.standalone();
@Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
+ public DbTester db = DbTester.create(System2.INSTANCE, true);
private DbClient dbClient = db.getDbClient();
private DbSession dbSession = db.getSession();
@Test
public void create_2_version_events_on_same_project() {
- ProjectDto project = db.components().insertPrivateProject().getProjectDto();
+ ProjectData projectData = db.components().insertPrivateProject();
+ ProjectDto project = projectData.getProjectDto();
SnapshotDto firstAnalysis = db.components().insertSnapshot(project);
SnapshotDto secondAnalysis = db.components().insertSnapshot(project);
db.commit();
call(VERSION.name(), "5.6.3", firstAnalysis.getUuid());
call(VERSION.name(), "6.3", secondAnalysis.getUuid());
- List<EventDto> events = dbClient.eventDao().selectByComponentUuid(dbSession, project.getUuid());
+ List<EventDto> events = dbClient.eventDao().selectByComponentUuid(dbSession, projectData.getMainBranchComponent().uuid());
assertThat(events).hasSize(2);
}
import org.sonar.db.event.EventPurgeData;
import org.sonar.db.newcodeperiod.NewCodePeriodDto;
import org.sonar.db.newcodeperiod.NewCodePeriodType;
+import org.sonar.db.project.ProjectDto;
import org.sonar.server.component.TestComponentFinder;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
@Rule
public UserSessionRule userSession = UserSessionRule.standalone();
@Rule
- public DbTester db = DbTester.create();
+ public DbTester db = DbTester.create(true);
@Rule
public LogTester logTester = new LogTester();
@DataProvider
public static Object[][] changedBranches() {
- return new Object[][] {
+ return new Object[][]{
{null, "newbranch"},
{"newbranch", "anotherbranch"},
{"newbranch", null},
@Test
public void json_example() {
- ComponentDto project = db.components().insertComponent(ComponentTesting.newPrivateProjectDto().setKey(KEY_PROJECT_EXAMPLE_001));
+ ProjectData projectData = db.components().insertPrivateProject(c -> c.setKey(KEY_PROJECT_EXAMPLE_001));
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
- userSession.addProjectPermission(UserRole.USER, project);
- SnapshotDto a1 = db.components().insertSnapshot(newAnalysis(project)
+ addProjectPermission(projectData);
+ SnapshotDto a1 = db.components().insertSnapshot(newAnalysis(mainBranch)
.setUuid("A1")
.setCreatedAt(parseDateTime("2016-12-11T17:12:45+0100").getTime())
.setProjectVersion("1.2")
.setBuildString("1.2.0.322")
.setRevision("bfe36592eb7f9f2708b5d358b5b5f33ed535c8cf"));
- SnapshotDto a2 = db.components().insertSnapshot(newAnalysis(project)
+ SnapshotDto a2 = db.components().insertSnapshot(newAnalysis(mainBranch)
.setUuid("A2")
.setCreatedAt(parseDateTime("2016-12-12T17:12:45+0100").getTime())
.setProjectVersion("1.2.1")
.setBuildString("1.2.1.423")
.setRevision("be6c75b85da526349c44e3978374c95e0b80a96d"));
- SnapshotDto a3 = db.components().insertSnapshot(newAnalysis(project)
+ SnapshotDto a3 = db.components().insertSnapshot(newAnalysis(mainBranch)
.setUuid("P1")
.setCreatedAt(parseDateTime("2015-11-11T10:00:00+0100").getTime())
.setProjectVersion("1.2")
.setKey(CorePropertyDefinitions.SONAR_ANALYSIS_DETECTEDCI)
.setValue("Jenkins")
.setCreatedAt(1L));
- BranchDto branchDto = newMainBranchDto(project, project.uuid());
- db.getDbClient().branchDao().insert(db.getSession(), branchDto);
+
db.newCodePeriods().insert(new NewCodePeriodDto()
- .setProjectUuid(project.uuid())
- .setBranchUuid(branchDto.getUuid())
+ .setProjectUuid(projectData.getProjectDto().getUuid())
+ .setBranchUuid(mainBranch.uuid())
.setType(NewCodePeriodType.SPECIFIC_ANALYSIS)
.setValue(a1.getUuid()));
db.commit();
.setData("{stillFailing: true, status: \"ERROR\"}")
.setCategory(CATEGORY_ALERT)
.setDescription(""));
- EventComponentChangeDto changeDto1 = generateEventComponentChange(eventDto, FAILED_QUALITY_GATE, "My project", "app1", "master", project.uuid());
+ EventComponentChangeDto changeDto1 = generateEventComponentChange(eventDto, FAILED_QUALITY_GATE, "My project", "app1", "master", mainBranch.uuid());
EventComponentChangeDto changeDto2 = generateEventComponentChange(eventDto, FAILED_QUALITY_GATE, "Another project", "app2", "master", uuidFactoryFast.create());
- insertEventComponentChanges(project, a3, changeDto1, changeDto2);
+ insertEventComponentChanges(mainBranch, a3, changeDto1, changeDto2);
String result = ws.newRequest()
.setParam(PARAM_PROJECT, KEY_PROJECT_EXAMPLE_001)
assertJson(result).isSimilarTo(getClass().getResource("search-example.json"));
}
+ private void addProjectPermission(ProjectData projectData) {
+ userSession.addProjectPermission(UserRole.USER, projectData.getProjectDto())
+ .addProjectBranchMapping(projectData.getProjectDto().getUuid(), projectData.getMainBranchComponent());
+ }
+
@Test
public void return_analyses_ordered_by_analysis_date() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- userSession.addProjectPermission(UserRole.USER, project);
- db.components().insertSnapshot(newAnalysis(project).setUuid("A1").setCreatedAt(1_000_000L));
- db.components().insertSnapshot(newAnalysis(project).setUuid("A2").setCreatedAt(2_000_000L));
- db.components().insertSnapshot(newAnalysis(project).setUuid("A3").setCreatedAt(3_000_000L));
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ addProjectPermission(projectData);
+ db.components().insertSnapshot(newAnalysis(mainBranch).setUuid("A1").setCreatedAt(1_000_000L));
+ db.components().insertSnapshot(newAnalysis(mainBranch).setUuid("A2").setCreatedAt(2_000_000L));
+ db.components().insertSnapshot(newAnalysis(mainBranch).setUuid("A3").setCreatedAt(3_000_000L));
- List<Analysis> result = call(project.getKey()).getAnalysesList();
+ List<Analysis> result = call(mainBranch.getKey()).getAnalysesList();
assertThat(result).hasSize(3);
assertThat(result).extracting(Analysis::getKey, a -> parseDateTime(a.getDate()).getTime()).containsExactly(
@Test
public void return_only_processed_analyses() {
- ComponentDto project = db.components().insertPrivateProject(c -> c.setKey("P1")).getMainBranchComponent();
- userSession.addProjectPermission(UserRole.USER, project);
- db.components().insertSnapshot(newAnalysis(project).setUuid("A1"));
- db.components().insertSnapshot(newAnalysis(project).setUuid("A2").setStatus(SnapshotDto.STATUS_UNPROCESSED));
+ ProjectData projectData = db.components().insertPrivateProject(c -> c.setKey("P1"));
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ addProjectPermission(projectData);
+ db.components().insertSnapshot(newAnalysis(mainBranch).setUuid("A1"));
+ db.components().insertSnapshot(newAnalysis(mainBranch).setUuid("A2").setStatus(SnapshotDto.STATUS_UNPROCESSED));
List<Analysis> result = call("P1").getAnalysesList();
@Test
public void return_events() {
- ComponentDto project = db.components().insertPrivateProject(c -> c.setKey("P1")).getMainBranchComponent();
- userSession.addProjectPermission(UserRole.USER, project);
- SnapshotDto a1 = db.components().insertSnapshot(newAnalysis(project).setUuid("A1"));
+ ProjectData projectData = db.components().insertPrivateProject(c -> c.setKey("P1"));
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ addProjectPermission(projectData);
+ SnapshotDto a1 = db.components().insertSnapshot(newAnalysis(mainBranch).setUuid("A1"));
SnapshotDto a42 = db.components().insertSnapshot(newAnalysis(ComponentTesting.newPrivateProjectDto()).setUuid("A42"));
EventDto e1 = db.events().insertEvent(newEvent(a1).setUuid("E1").setName("N1").setCategory(QUALITY_GATE.getLabel()).setDescription("D1"));
EventDto e2 = db.events().insertEvent(newEvent(a1).setUuid("E2").setName("N2").setCategory(VERSION.getLabel()).setDescription("D2"));
@Test
public void return_analyses_of_application() {
- ComponentDto application = db.components().insertPublicApplication().getMainBranchComponent();
- userSession.registerApplication(toProjectDto(application, 1L));
- SnapshotDto firstAnalysis = db.components().insertSnapshot(newAnalysis(application).setCreatedAt(1_000_000L));
- SnapshotDto secondAnalysis = db.components().insertSnapshot(newAnalysis(application).setCreatedAt(2_000_000L));
- SnapshotDto thirdAnalysis = db.components().insertSnapshot(newAnalysis(application).setCreatedAt(3_000_000L));
+ ProjectData appData = db.components().insertPublicApplication();
+ ComponentDto appMainBranch = appData.getMainBranchComponent();
+ registerApplication(appData);
+ SnapshotDto firstAnalysis = db.components().insertSnapshot(newAnalysis(appMainBranch).setCreatedAt(1_000_000L));
+ SnapshotDto secondAnalysis = db.components().insertSnapshot(newAnalysis(appMainBranch).setCreatedAt(2_000_000L));
+ SnapshotDto thirdAnalysis = db.components().insertSnapshot(newAnalysis(appMainBranch).setCreatedAt(3_000_000L));
- List<Analysis> result = call(application.getKey()).getAnalysesList();
+ List<Analysis> result = call(appMainBranch.getKey()).getAnalysesList();
assertThat(result)
.hasSize(3)
@Test
public void return_definition_change_events_on_application_analyses() {
- ComponentDto application = db.components().insertPublicApplication().getMainBranchComponent();
- userSession.registerApplication(toProjectDto(application, 1L));
- SnapshotDto firstAnalysis = db.components().insertSnapshot(newAnalysis(application).setCreatedAt(1_000_000L));
+ ProjectData appData = db.components().insertPublicApplication();
+ ComponentDto mainBranch = appData.getMainBranchComponent();
+ registerApplication(appData);
+ SnapshotDto firstAnalysis = db.components().insertSnapshot(newAnalysis(mainBranch).setCreatedAt(1_000_000L));
EventDto event = db.events().insertEvent(newEvent(firstAnalysis).setName("").setUuid("E11").setCategory(DEFINITION_CHANGE.getLabel()));
EventComponentChangeDto changeDto1 = generateEventComponentChange(event, ADDED, "My project", "app1", "master", uuidFactoryFast.create());
EventComponentChangeDto changeDto2 = generateEventComponentChange(event, REMOVED, "Another project", "app2", "master", uuidFactoryFast.create());
- insertEventComponentChanges(application, firstAnalysis, changeDto1, changeDto2);
+ insertEventComponentChanges(mainBranch, firstAnalysis, changeDto1, changeDto2);
- List<Analysis> result = call(application.getKey()).getAnalysesList();
+ List<Analysis> result = call(mainBranch.getKey()).getAnalysesList();
assertThat(result).hasSize(1);
List<Event> events = result.get(0).getEventsList();
@Test
@UseDataProvider("changedBranches")
public void application_definition_change_with_branch(@Nullable String oldBranch, @Nullable String newBranch) {
- ComponentDto application = db.components().insertPublicApplication().getMainBranchComponent();
- userSession.registerApplication(toProjectDto(application, 1L));
- SnapshotDto firstAnalysis = db.components().insertSnapshot(newAnalysis(application).setCreatedAt(1_000_000L));
+ ProjectData appData = db.components().insertPublicApplication();
+ ComponentDto appMainBranch = appData.getMainBranchComponent();
+ registerApplication(appData);
+ SnapshotDto firstAnalysis = db.components().insertSnapshot(newAnalysis(appMainBranch).setCreatedAt(1_000_000L));
EventDto event = db.events().insertEvent(newEvent(firstAnalysis).setName("").setUuid("E11").setCategory(DEFINITION_CHANGE.getLabel()));
EventComponentChangeDto changeDto1 = generateEventComponentChange(event, REMOVED, "My project", "app1", oldBranch, uuidFactoryFast.create());
EventComponentChangeDto changeDto2 = generateEventComponentChange(event, ADDED, "My project", "app1", newBranch, changeDto1.getComponentUuid());
- insertEventComponentChanges(application, firstAnalysis, changeDto1, changeDto2);
+ insertEventComponentChanges(appMainBranch, firstAnalysis, changeDto1, changeDto2);
- List<Analysis> result = call(application.getKey()).getAnalysesList();
+ List<Analysis> result = call(appMainBranch.getKey()).getAnalysesList();
assertThat(result).hasSize(1);
List<Event> events = result.get(0).getEventsList();
@Test
public void incorrect_eventcomponentchange_two_identical_changes_added_on_same_project() {
- ComponentDto application = db.components().insertPublicApplication().getMainBranchComponent();
- userSession.registerApplication(toProjectDto(application, 1L));
- SnapshotDto firstAnalysis = db.components().insertSnapshot(newAnalysis(application).setCreatedAt(1_000_000L));
+ ProjectData appData = db.components().insertPublicApplication();
+ ComponentDto appMainBranch = appData.getMainBranchComponent();
+ registerApplication(appData);
+ SnapshotDto firstAnalysis = db.components().insertSnapshot(newAnalysis(appMainBranch).setCreatedAt(1_000_000L));
EventDto event = db.events().insertEvent(newEvent(firstAnalysis).setName("").setUuid("E11").setCategory(DEFINITION_CHANGE.getLabel()));
EventComponentChangeDto changeDto1 = generateEventComponentChange(event, ADDED, "My project", "app1", "master", uuidFactoryFast.create());
EventComponentChangeDto changeDto2 = generateEventComponentChange(event, ADDED, "My project", "app1", "master", uuidFactoryFast.create());
- EventPurgeData eventPurgeData = new EventPurgeData(application.uuid(), firstAnalysis.getUuid());
+ EventPurgeData eventPurgeData = new EventPurgeData(appMainBranch.uuid(), firstAnalysis.getUuid());
db.getDbClient().eventComponentChangeDao().insert(db.getSession(), changeDto1, eventPurgeData);
db.getDbClient().eventComponentChangeDao().insert(db.getSession(), changeDto2, eventPurgeData);
db.getSession().commit();
- List<Analysis> result = call(application.getKey()).getAnalysesList();
+ List<Analysis> result = call(appMainBranch.getKey()).getAnalysesList();
assertThat(result).hasSize(1);
List<Event> events = result.get(0).getEventsList();
@Test
public void incorrect_eventcomponentchange_incorrect_category() {
- ComponentDto application = db.components().insertPublicApplication().getMainBranchComponent();
- userSession.registerApplication(toProjectDto(application, 1L));
- SnapshotDto firstAnalysis = db.components().insertSnapshot(newAnalysis(application).setCreatedAt(1_000_000L));
+ ProjectData appData = db.components().insertPublicApplication();
+ ComponentDto appMainBranch = appData.getMainBranchComponent();
+ registerApplication(appData);
+ SnapshotDto firstAnalysis = db.components().insertSnapshot(newAnalysis(appMainBranch).setCreatedAt(1_000_000L));
EventDto event = db.events().insertEvent(newEvent(firstAnalysis).setName("").setUuid("E11").setCategory(DEFINITION_CHANGE.getLabel()));
EventComponentChangeDto changeDto1 = generateEventComponentChange(event, FAILED_QUALITY_GATE, "My project", "app1", "master", uuidFactoryFast.create());
- EventPurgeData eventPurgeData = new EventPurgeData(application.uuid(), firstAnalysis.getUuid());
+ EventPurgeData eventPurgeData = new EventPurgeData(appMainBranch.uuid(), firstAnalysis.getUuid());
db.getDbClient().eventComponentChangeDao().insert(db.getSession(), changeDto1, eventPurgeData);
db.getSession().commit();
- List<Analysis> result = call(application.getKey()).getAnalysesList();
+ List<Analysis> result = call(appMainBranch.getKey()).getAnalysesList();
assertThat(result).hasSize(1);
List<Event> events = result.get(0).getEventsList();
@Test
public void incorrect_eventcomponentchange_three_component_changes_on_same_project() {
- ComponentDto application = db.components().insertPublicApplication().getMainBranchComponent();
- userSession.registerApplication(toProjectDto(application, 1L));
- SnapshotDto firstAnalysis = db.components().insertSnapshot(newAnalysis(application).setCreatedAt(1_000_000L));
+ ProjectData appData = db.components().insertPublicApplication();
+ ComponentDto appMainBranch = appData.getMainBranchComponent();
+ registerApplication(appData);
+ SnapshotDto firstAnalysis = db.components().insertSnapshot(newAnalysis(appMainBranch).setCreatedAt(1_000_000L));
EventDto event = db.events().insertEvent(newEvent(firstAnalysis).setName("").setUuid("E11").setCategory(DEFINITION_CHANGE.getLabel()));
EventComponentChangeDto changeDto1 = generateEventComponentChange(event, ADDED, "My project", "app1", "master", uuidFactoryFast.create());
EventComponentChangeDto changeDto2 = generateEventComponentChange(event, REMOVED, "Another project", "app1", "", uuidFactoryFast.create());
EventComponentChangeDto changeDto3 = generateEventComponentChange(event, REMOVED, "Another project", "app1", "", uuidFactoryFast.create());
- EventPurgeData eventPurgeData = new EventPurgeData(application.uuid(), firstAnalysis.getUuid());
+ EventPurgeData eventPurgeData = new EventPurgeData(appMainBranch.uuid(), firstAnalysis.getUuid());
db.getDbClient().eventComponentChangeDao().insert(db.getSession(), changeDto1, eventPurgeData);
db.getDbClient().eventComponentChangeDao().insert(db.getSession(), changeDto2, eventPurgeData);
db.getDbClient().eventComponentChangeDao().insert(db.getSession(), changeDto3, eventPurgeData);
db.getSession().commit();
- List<Analysis> result = call(application.getKey()).getAnalysesList();
+ List<Analysis> result = call(appMainBranch.getKey()).getAnalysesList();
assertThat(result).hasSize(1);
List<Event> events = result.get(0).getEventsList();
format("Too many changes on same project (3) for eventComponentChange uuids : %s,%s,%s", changeDto1.getUuid(), changeDto2.getUuid(), changeDto3.getUuid()));
}
+ private void registerApplication(ProjectData appData) {
+ userSession.registerApplication(appData.getProjectDto())
+ .addProjectBranchMapping(appData.projectUuid(), appData.getMainBranchComponent());
+ }
+
@Test
public void incorrect_quality_gate_information() {
- ComponentDto application = db.components().insertPublicApplication().getMainBranchComponent();
- userSession.registerApplication(toProjectDto(application, 1L));
- SnapshotDto firstAnalysis = db.components().insertSnapshot(newAnalysis(application).setCreatedAt(1_000_000L));
+ ProjectData appData = db.components().insertPublicApplication();
+ ComponentDto appMainBranch = appData.getMainBranchComponent();
+ registerApplication(appData);
+ SnapshotDto firstAnalysis = db.components().insertSnapshot(newAnalysis(appMainBranch).setCreatedAt(1_000_000L));
EventDto event = db.events().insertEvent(
newEvent(firstAnalysis)
.setName("")
.setCategory(CATEGORY_ALERT)
.setData("UNPARSEABLE JSON")); // Error in Data
EventComponentChangeDto changeDto1 = generateEventComponentChange(event, FAILED_QUALITY_GATE, "My project", "app1", "master", uuidFactoryFast.create());
- EventPurgeData eventPurgeData = new EventPurgeData(application.uuid(), firstAnalysis.getUuid());
+ EventPurgeData eventPurgeData = new EventPurgeData(appMainBranch.uuid(), firstAnalysis.getUuid());
db.getDbClient().eventComponentChangeDao().insert(db.getSession(), changeDto1, eventPurgeData);
db.getSession().commit();
- List<Analysis> result = call(application.getKey()).getAnalysesList();
+ List<Analysis> result = call(appMainBranch.getKey()).getAnalysesList();
assertThat(result).hasSize(1);
List<Event> events = result.get(0).getEventsList();
@Test
public void paginate_analyses() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- userSession.addProjectPermission(UserRole.USER, project);
- IntStream.rangeClosed(1, 9).forEach(i -> db.components().insertSnapshot(newAnalysis(project).setCreatedAt(1_000_000L * i).setUuid("A" + i)));
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ addProjectPermission(projectData);
+ IntStream.rangeClosed(1, 9).forEach(i -> db.components().insertSnapshot(newAnalysis(mainBranch).setCreatedAt(1_000_000L * i).setUuid("A" + i)));
SearchResponse result = call(SearchRequest.builder()
- .setProject(project.getKey())
+ .setProject(mainBranch.getKey())
.setPage(2)
.setPageSize(3)
.build());
@Test
public void filter_by_category() {
- ComponentDto project = db.components().insertPrivateProject(c -> c.setKey("P1")).getMainBranchComponent();
- userSession.addProjectPermission(UserRole.USER, project);
- SnapshotDto a1 = db.components().insertSnapshot(newAnalysis(project).setUuid("A1"));
- SnapshotDto a2 = db.components().insertSnapshot(newAnalysis(project).setUuid("A2"));
- SnapshotDto a42 = db.components().insertSnapshot(newAnalysis(project).setUuid("A42"));
+ ProjectData projectData = db.components().insertPrivateProject(c -> c.setKey("P1"));
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ addProjectPermission(projectData);
+ SnapshotDto a1 = db.components().insertSnapshot(newAnalysis(mainBranch).setUuid("A1"));
+ SnapshotDto a2 = db.components().insertSnapshot(newAnalysis(mainBranch).setUuid("A2"));
+ SnapshotDto a42 = db.components().insertSnapshot(newAnalysis(mainBranch).setUuid("A42"));
db.events().insertEvent(newEvent(a1).setUuid("E11").setCategory(VERSION.getLabel()));
db.events().insertEvent(newEvent(a1).setUuid("E12").setCategory(QUALITY_GATE.getLabel()));
db.events().insertEvent(newEvent(a2).setUuid("E21").setCategory(QUALITY_GATE.getLabel()));
@Test
public void paginate_with_filter_on_category() {
- ComponentDto project = db.components().insertPrivateProject(c -> c.setKey("P1")).getMainBranchComponent();
- userSession.addProjectPermission(UserRole.USER, project);
- SnapshotDto a1 = db.components().insertSnapshot(newAnalysis(project).setUuid("A1").setCreatedAt(1_000_000L));
- SnapshotDto a2 = db.components().insertSnapshot(newAnalysis(project).setUuid("A2").setCreatedAt(2_000_000L));
- SnapshotDto a3 = db.components().insertSnapshot(newAnalysis(project).setUuid("A3").setCreatedAt(3_000_000L));
- SnapshotDto a42 = db.components().insertSnapshot(newAnalysis(project).setUuid("A42"));
+ ProjectData projectData = db.components().insertPrivateProject(c -> c.setKey("P1"));
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ addProjectPermission(projectData);
+ SnapshotDto a1 = db.components().insertSnapshot(newAnalysis(mainBranch).setUuid("A1").setCreatedAt(1_000_000L));
+ SnapshotDto a2 = db.components().insertSnapshot(newAnalysis(mainBranch).setUuid("A2").setCreatedAt(2_000_000L));
+ SnapshotDto a3 = db.components().insertSnapshot(newAnalysis(mainBranch).setUuid("A3").setCreatedAt(3_000_000L));
+ SnapshotDto a42 = db.components().insertSnapshot(newAnalysis(mainBranch).setUuid("A42"));
db.events().insertEvent(newEvent(a1).setUuid("E11").setCategory(VERSION.getLabel()));
db.events().insertEvent(newEvent(a1).setUuid("E12").setCategory(QUALITY_GATE.getLabel()));
db.events().insertEvent(newEvent(a2).setUuid("E21").setCategory(QUALITY_GATE.getLabel()));
@Test
public void filter_from_date() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- userSession.addProjectPermission(UserRole.USER, project);
- SnapshotDto a1 = db.components().insertSnapshot(newAnalysis(project).setUuid("a1").setCreatedAt(1_000_000_000L));
- SnapshotDto a2 = db.components().insertSnapshot(newAnalysis(project).setUuid("a2").setCreatedAt(2_000_000_000L));
- SnapshotDto a3 = db.components().insertSnapshot(newAnalysis(project).setUuid("a3").setCreatedAt(3_000_000_000L));
- SnapshotDto a4 = db.components().insertSnapshot(newAnalysis(project).setUuid("a4").setCreatedAt(4_000_000_000L));
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ addProjectPermission(projectData);
+ SnapshotDto a1 = db.components().insertSnapshot(newAnalysis(mainBranch).setUuid("a1").setCreatedAt(1_000_000_000L));
+ SnapshotDto a2 = db.components().insertSnapshot(newAnalysis(mainBranch).setUuid("a2").setCreatedAt(2_000_000_000L));
+ SnapshotDto a3 = db.components().insertSnapshot(newAnalysis(mainBranch).setUuid("a3").setCreatedAt(3_000_000_000L));
+ SnapshotDto a4 = db.components().insertSnapshot(newAnalysis(mainBranch).setUuid("a4").setCreatedAt(4_000_000_000L));
SearchResponse result = call(SearchRequest.builder()
- .setProject(project.getKey())
+ .setProject(mainBranch.getKey())
.setFrom(formatDateTime(2_000_000_000L))
.build());
@Test
public void filter_to_date() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- userSession.addProjectPermission(UserRole.USER, project);
- SnapshotDto a1 = db.components().insertSnapshot(newAnalysis(project).setUuid("a1").setCreatedAt(1_000_000_000L));
- SnapshotDto a2 = db.components().insertSnapshot(newAnalysis(project).setUuid("a2").setCreatedAt(2_000_000_000L));
- SnapshotDto a3 = db.components().insertSnapshot(newAnalysis(project).setUuid("a3").setCreatedAt(3_000_000_000L));
- SnapshotDto a4 = db.components().insertSnapshot(newAnalysis(project).setUuid("a4").setCreatedAt(4_000_000_000L));
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ addProjectPermission(projectData);
+ SnapshotDto a1 = db.components().insertSnapshot(newAnalysis(mainBranch).setUuid("a1").setCreatedAt(1_000_000_000L));
+ SnapshotDto a2 = db.components().insertSnapshot(newAnalysis(mainBranch).setUuid("a2").setCreatedAt(2_000_000_000L));
+ SnapshotDto a3 = db.components().insertSnapshot(newAnalysis(mainBranch).setUuid("a3").setCreatedAt(3_000_000_000L));
+ SnapshotDto a4 = db.components().insertSnapshot(newAnalysis(mainBranch).setUuid("a4").setCreatedAt(4_000_000_000L));
SearchResponse result = call(SearchRequest.builder()
- .setProject(project.getKey())
+ .setProject(mainBranch.getKey())
.setTo(formatDateTime(2_000_000_000L))
.build());
@Test
public void filter_by_dates_using_datetime_format() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- userSession.addProjectPermission(UserRole.USER, project);
- SnapshotDto a1 = db.components().insertSnapshot(newAnalysis(project).setUuid("a1").setCreatedAt(1_000_000_000L));
- SnapshotDto a2 = db.components().insertSnapshot(newAnalysis(project).setUuid("a2").setCreatedAt(2_000_000_000L));
- SnapshotDto a3 = db.components().insertSnapshot(newAnalysis(project).setUuid("a3").setCreatedAt(3_000_000_000L));
- SnapshotDto a4 = db.components().insertSnapshot(newAnalysis(project).setUuid("a4").setCreatedAt(4_000_000_000L));
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ addProjectPermission(projectData);
+ SnapshotDto a1 = db.components().insertSnapshot(newAnalysis(mainBranch).setUuid("a1").setCreatedAt(1_000_000_000L));
+ SnapshotDto a2 = db.components().insertSnapshot(newAnalysis(mainBranch).setUuid("a2").setCreatedAt(2_000_000_000L));
+ SnapshotDto a3 = db.components().insertSnapshot(newAnalysis(mainBranch).setUuid("a3").setCreatedAt(3_000_000_000L));
+ SnapshotDto a4 = db.components().insertSnapshot(newAnalysis(mainBranch).setUuid("a4").setCreatedAt(4_000_000_000L));
SearchResponse result = call(SearchRequest.builder()
- .setProject(project.getKey())
+ .setProject(mainBranch.getKey())
.setFrom(formatDateTime(2_000_000_000L))
.setTo(formatDateTime(3_000_000_000L))
.build());
@Test
public void filter_by_dates_using_date_format() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- userSession.addProjectPermission(UserRole.USER, project);
- SnapshotDto a1 = db.components().insertSnapshot(newAnalysis(project).setUuid("a1").setCreatedAt(1_000_000_000L));
- SnapshotDto a2 = db.components().insertSnapshot(newAnalysis(project).setUuid("a2").setCreatedAt(2_000_000_000L));
- SnapshotDto a3 = db.components().insertSnapshot(newAnalysis(project).setUuid("a3").setCreatedAt(3_000_000_000L));
- SnapshotDto a4 = db.components().insertSnapshot(newAnalysis(project).setUuid("a4").setCreatedAt(4_000_000_000L));
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ addProjectPermission(projectData);
+ SnapshotDto a1 = db.components().insertSnapshot(newAnalysis(mainBranch).setUuid("a1").setCreatedAt(1_000_000_000L));
+ SnapshotDto a2 = db.components().insertSnapshot(newAnalysis(mainBranch).setUuid("a2").setCreatedAt(2_000_000_000L));
+ SnapshotDto a3 = db.components().insertSnapshot(newAnalysis(mainBranch).setUuid("a3").setCreatedAt(3_000_000_000L));
+ SnapshotDto a4 = db.components().insertSnapshot(newAnalysis(mainBranch).setUuid("a4").setCreatedAt(4_000_000_000L));
SearchResponse result = call(SearchRequest.builder()
- .setProject(project.getKey())
+ .setProject(mainBranch.getKey())
.setFrom(formatDate(new Date(2_000_000_000L)))
.setTo(formatDate(new Date(3_000_000_000L)))
.build());
@Test
public void branch() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- userSession.addProjectPermission(UserRole.USER, project);
- ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("my_branch"));
- userSession.addProjectBranchMapping(project.uuid(), branch);
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ addProjectPermission(projectData);
+ ComponentDto branch = db.components().insertProjectBranch(mainBranch, b -> b.setKey("my_branch"));
+ userSession.addProjectBranchMapping(projectData.projectUuid(), branch);
SnapshotDto analysis = db.components().insertSnapshot(newAnalysis(branch));
EventDto event = db.events().insertEvent(newEvent(analysis).setCategory(QUALITY_GATE.getLabel()));
List<Analysis> result = call(SearchRequest.builder()
- .setProject(project.getKey())
+ .setProject(mainBranch.getKey())
.setBranch("my_branch")
.build())
- .getAnalysesList();
+ .getAnalysesList();
assertThat(result).extracting(Analysis::getKey).containsExactlyInAnyOrder(analysis.getUuid());
assertThat(result.get(0).getEventsList()).extracting(Event::getKey).containsExactlyInAnyOrder(event.getUuid());
@Test
public void empty_response() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- userSession.addProjectPermission(UserRole.USER, project);
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ addProjectPermission(projectData);
- SearchResponse result = call(project.getKey());
+ SearchResponse result = call(mainBranch.getKey());
assertThat(result.hasPaging()).isTrue();
assertThat(result.getPaging()).extracting(Paging::getPageIndex, Paging::getPageSize, Paging::getTotal).containsExactly(1, 100, 0);
@Test
public void populates_projectVersion_and_buildString() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- userSession.addProjectPermission(UserRole.USER, project);
- SnapshotDto[] analyses = new SnapshotDto[] {
- db.components().insertSnapshot(newAnalysis(project).setProjectVersion(null).setBuildString(null)),
- db.components().insertSnapshot(newAnalysis(project).setProjectVersion("a").setBuildString(null)),
- db.components().insertSnapshot(newAnalysis(project).setProjectVersion(null).setBuildString("b")),
- db.components().insertSnapshot(newAnalysis(project).setProjectVersion("c").setBuildString("d"))
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ addProjectPermission(projectData);
+ SnapshotDto[] analyses = new SnapshotDto[]{
+ db.components().insertSnapshot(newAnalysis(mainBranch).setProjectVersion(null).setBuildString(null)),
+ db.components().insertSnapshot(newAnalysis(mainBranch).setProjectVersion("a").setBuildString(null)),
+ db.components().insertSnapshot(newAnalysis(mainBranch).setProjectVersion(null).setBuildString("b")),
+ db.components().insertSnapshot(newAnalysis(mainBranch).setProjectVersion("c").setBuildString("d"))
};
- SearchResponse result = call(project.getKey());
+ SearchResponse result = call(mainBranch.getKey());
assertThat(result.getAnalysesList())
.extracting(Analysis::getKey, Analysis::getProjectVersion, Analysis::getBuildString)
@Test
public void fail_if_not_enough_permissions() {
userSession.anonymous();
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
- var projectDbKey = project.getKey();
+ var projectDbKey = mainBranch.getKey();
assertThatThrownBy(() -> call(projectDbKey))
.isInstanceOf(ForbiddenException.class);
}
@Test
public void fail_if_not_enough_permissions_on_applications_projects() {
- ComponentDto application = db.components().insertPrivateApplication().getMainBranchComponent();
- ComponentDto project1 = db.components().insertPrivateProject().getMainBranchComponent();
- ComponentDto project2 = db.components().insertPrivateProject().getMainBranchComponent();
+ ProjectDto application = db.components().insertPrivateApplication().getProjectDto();
+ ProjectDto project1 = db.components().insertPrivateProject().getProjectDto();
+ ProjectDto project2 = db.components().insertPrivateProject().getProjectDto();
userSession.logIn()
- .registerApplication(
- toProjectDto(application, 1L),
- toProjectDto(project1, 1L),
- toProjectDto(project2, 1L))
+ .registerApplication(application)
+ .registerProjects(project1, project2)
.addProjectPermission(UserRole.USER, application, project1);
var projectDbKey = application.getKey();
public void fail_if_branch_does_not_exist() {
ProjectData projectData = db.components().insertPrivateProject();
ComponentDto mainBranch = projectData.getMainBranchComponent();
- userSession.addProjectPermission(UserRole.USER, projectData.getProjectDto());
+ addProjectPermission(projectData);
db.components().insertProjectBranch(mainBranch, b -> b.setKey("my_branch"));
var searchRequest = SearchRequest.builder()
import org.sonar.db.DbTester;
import org.sonar.db.component.BranchType;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ProjectData;
import org.sonar.db.component.SnapshotDto;
import org.sonar.db.metric.MetricDto;
import org.sonar.db.permission.GlobalPermission;
@Rule
public UserSessionRule userSession = UserSessionRule.standalone();
@Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
+ public DbTester db = DbTester.create(System2.INSTANCE, true);
private final DbClient dbClient = db.getDbClient();
private final DbSession dbSession = db.getSession();
@Test
public void test_json_example() throws IOException {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- userSession.addProjectPermission(UserRole.USER, project);
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ userSession.addProjectPermission(UserRole.USER, projectData.getProjectDto());
MetricDto gateDetailsMetric = insertGateDetailMetric();
- SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(project)
+ SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(mainBranch)
.setPeriodMode("last_version")
.setPeriodParam("2015-12-07")
.setPeriodDate(956789123987L));
dbClient.measureDao().insert(dbSession,
- newMeasureDto(gateDetailsMetric, project, snapshot)
+ newMeasureDto(gateDetailsMetric, mainBranch, snapshot)
.setData(IOUtils.toString(getClass().getResource("ProjectStatusActionIT/measure_data.json"), StandardCharsets.UTF_8)));
dbSession.commit();
@Test
public void return_past_status_when_project_is_referenced_by_past_analysis_id() throws IOException {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- SnapshotDto pastAnalysis = dbClient.snapshotDao().insert(dbSession, newAnalysis(project)
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ SnapshotDto pastAnalysis = dbClient.snapshotDao().insert(dbSession, newAnalysis(mainBranch)
.setLast(false)
.setPeriodMode("last_version")
.setPeriodParam("2015-12-07")
.setPeriodDate(956789123987L));
- SnapshotDto lastAnalysis = dbClient.snapshotDao().insert(dbSession, newAnalysis(project)
+ SnapshotDto lastAnalysis = dbClient.snapshotDao().insert(dbSession, newAnalysis(mainBranch)
.setLast(true)
.setPeriodMode("last_version")
.setPeriodParam("2016-12-07")
.setPeriodDate(1_500L));
MetricDto gateDetailsMetric = insertGateDetailMetric();
dbClient.measureDao().insert(dbSession,
- newMeasureDto(gateDetailsMetric, project, pastAnalysis)
+ newMeasureDto(gateDetailsMetric, mainBranch, pastAnalysis)
.setData(IOUtils.toString(getClass().getResource("ProjectStatusActionIT/measure_data.json"))));
dbClient.measureDao().insert(dbSession,
- newMeasureDto(gateDetailsMetric, project, lastAnalysis)
+ newMeasureDto(gateDetailsMetric, mainBranch, lastAnalysis)
.setData("not_used"));
dbSession.commit();
- userSession.addProjectPermission(UserRole.USER, project);
+ userSession.addProjectPermission(UserRole.USER, projectData.getProjectDto());
String response = ws.newRequest()
.setParam(PARAM_ANALYSIS_ID, pastAnalysis.getUuid())
@Test
public void return_live_status_when_project_is_referenced_by_its_id() throws IOException {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- dbClient.snapshotDao().insert(dbSession, newAnalysis(project)
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ dbClient.snapshotDao().insert(dbSession, newAnalysis(mainBranch)
.setPeriodMode("last_version")
.setPeriodParam("2015-12-07")
.setPeriodDate(956789123987L));
MetricDto gateDetailsMetric = insertGateDetailMetric();
dbClient.liveMeasureDao().insert(dbSession,
- newLiveMeasure(project, gateDetailsMetric)
+ newLiveMeasure(mainBranch, gateDetailsMetric)
.setData(IOUtils.toString(getClass().getResource("ProjectStatusActionIT/measure_data.json"))));
dbSession.commit();
- userSession.addProjectPermission(UserRole.USER, project);
+ userSession.addProjectPermission(UserRole.USER, projectData.getProjectDto());
String response = ws.newRequest()
- .setParam(PARAM_PROJECT_ID, project.uuid())
+ .setParam(PARAM_PROJECT_ID, projectData.projectUuid())
.execute().getInput();
assertJson(response).isSimilarTo(getClass().getResource("project_status-example.json"));
@Test
public void return_past_status_when_branch_is_referenced_by_past_analysis_id() throws IOException {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- ComponentDto branch = db.components().insertProjectBranch(project);
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ ComponentDto branch = db.components().insertProjectBranch(mainBranch);
SnapshotDto pastAnalysis = dbClient.snapshotDao().insert(dbSession, newAnalysis(branch)
.setLast(false)
.setPeriodMode("last_version")
newMeasureDto(gateDetailsMetric, branch, lastAnalysis)
.setData("not_used"));
dbSession.commit();
- userSession.addProjectPermission(UserRole.USER, project);
+ userSession.addProjectPermission(UserRole.USER, projectData.getProjectDto());
String response = ws.newRequest()
.setParam(PARAM_ANALYSIS_ID, pastAnalysis.getUuid())
@Test
public void return_live_status_when_project_is_referenced_by_its_key() throws IOException {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto project = projectData.getMainBranchComponent();
dbClient.snapshotDao().insert(dbSession, newAnalysis(project)
.setPeriodMode("last_version")
.setPeriodParam("2015-12-07")
newLiveMeasure(project, gateDetailsMetric)
.setData(IOUtils.toString(getClass().getResource("ProjectStatusActionIT/measure_data.json"))));
dbSession.commit();
- userSession.addProjectPermission(UserRole.USER, project);
+ userSession.addProjectPermission(UserRole.USER, projectData.getProjectDto());
String response = ws.newRequest()
.setParam(PARAM_PROJECT_KEY, project.getKey())
@Test
public void return_live_status_when_branch_is_referenced_by_its_key() throws IOException {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
String branchName = randomAlphanumeric(248);
- ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey(branchName));
+ ComponentDto branch = db.components().insertProjectBranch(mainBranch, b -> b.setKey(branchName));
dbClient.snapshotDao().insert(dbSession, newAnalysis(branch)
.setPeriodMode("last_version")
newLiveMeasure(branch, gateDetailsMetric)
.setData(IOUtils.toString(getClass().getResource("ProjectStatusActionIT/measure_data.json"))));
dbSession.commit();
- userSession.addProjectPermission(UserRole.USER, project);
+ userSession.addProjectPermission(UserRole.USER, projectData.getProjectDto());
String response = ws.newRequest()
- .setParam(PARAM_PROJECT_KEY, project.getKey())
+ .setParam(PARAM_PROJECT_KEY, mainBranch.getKey())
.setParam(PARAM_BRANCH, branchName)
.execute().getInput();
@Test
public void return_live_status_when_pull_request_is_referenced_by_its_key() throws IOException {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
String pullRequestKey = RandomStringUtils.randomAlphanumeric(100);
- ComponentDto pr = db.components().insertProjectBranch(project, branch -> branch.setBranchType(BranchType.PULL_REQUEST)
+ ComponentDto pr = db.components().insertProjectBranch(mainBranch, branch -> branch.setBranchType(BranchType.PULL_REQUEST)
.setKey(pullRequestKey));
dbClient.snapshotDao().insert(dbSession, newAnalysis(pr)
newLiveMeasure(pr, gateDetailsMetric)
.setData(IOUtils.toString(getClass().getResource("ProjectStatusActionIT/measure_data.json"))));
dbSession.commit();
- userSession.addProjectPermission(UserRole.USER, project);
+ userSession.addProjectPermission(UserRole.USER, projectData.getProjectDto());
String response = ws.newRequest()
- .setParam(PARAM_PROJECT_KEY, project.getKey())
+ .setParam(PARAM_PROJECT_KEY, mainBranch.getKey())
.setParam(PARAM_PULL_REQUEST, pullRequestKey)
.execute().getInput();
@Test
public void return_undefined_status_if_specified_analysis_is_not_found() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(project));
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(mainBranch));
dbSession.commit();
- userSession.addProjectPermission(UserRole.USER, project);
+ userSession.addProjectPermission(UserRole.USER, projectData.getProjectDto());
ProjectStatusResponse result = ws.newRequest()
.setParam(PARAM_ANALYSIS_ID, snapshot.getUuid())
@Test
public void return_undefined_status_if_project_is_not_analyzed() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- userSession.addProjectPermission(UserRole.USER, project);
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ userSession.addProjectPermission(UserRole.USER, projectData.getProjectDto());
ProjectStatusResponse result = ws.newRequest()
- .setParam(PARAM_PROJECT_ID, project.uuid())
+ .setParam(PARAM_PROJECT_ID, projectData.projectUuid())
.executeProtobuf(ProjectStatusResponse.class);
assertThat(result.getProjectStatus().getStatus()).isEqualTo(Status.NONE);
@Test
public void project_administrator_is_allowed_to_get_project_status() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(project));
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(mainBranch));
dbSession.commit();
- userSession.addProjectPermission(UserRole.ADMIN, project);
+ userSession.addProjectPermission(UserRole.ADMIN, projectData.getProjectDto());
ws.newRequest()
.setParam(PARAM_ANALYSIS_ID, snapshot.getUuid())
@Test
public void project_user_is_allowed_to_get_project_status() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(project));
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(mainBranch));
dbSession.commit();
- userSession.addProjectPermission(UserRole.USER, project);
+ userSession.addProjectPermission(UserRole.USER, projectData.getProjectDto());
ws.newRequest()
.setParam(PARAM_ANALYSIS_ID, snapshot.getUuid())
@Test
public void check_cayc_compliant_flag() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
var qg = db.qualityGates().insertBuiltInQualityGate();
db.qualityGates().setDefaultQualityGate(qg);
- when(qualityGateCaycChecker.checkCaycCompliantFromProject(any(DbSession.class), eq(project.uuid()))).thenReturn(COMPLIANT);
- SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(project));
+ when(qualityGateCaycChecker.checkCaycCompliantFromProject(any(DbSession.class), eq(projectData.projectUuid()))).thenReturn(COMPLIANT);
+ SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(mainBranch));
dbSession.commit();
- userSession.addProjectPermission(UserRole.USER, project);
+ userSession.addProjectPermission(UserRole.USER, projectData.getProjectDto());
ProjectStatusResponse result = ws.newRequest()
.setParam(PARAM_ANALYSIS_ID, snapshot.getUuid())
@Test
public void user_with_project_scan_permission_is_allowed_to_get_project_status() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(project));
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(mainBranch));
dbSession.commit();
- userSession.addProjectPermission(UserRole.SCAN, project);
+ userSession.addProjectPermission(UserRole.SCAN, projectData.getProjectDto());
var response = ws.newRequest()
.setParam(PARAM_ANALYSIS_ID, snapshot.getUuid()).execute();
@Test
public void user_with_global_scan_permission_is_allowed_to_get_project_status() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(project));
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(mainBranch));
dbSession.commit();
userSession.addPermission(GlobalPermission.SCAN);
@Test
public void fail_if_insufficient_privileges() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(project));
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(mainBranch));
dbSession.commit();
userSession.logIn();
@Test
public void fail_when_using_branch_uuid() {
- ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
- userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
- ComponentDto branch = db.components().insertProjectBranch(project);
+ ProjectData projectData = db.components().insertPublicProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ userSession.logIn().addProjectPermission(UserRole.ADMIN, projectData.getProjectDto());
+ ComponentDto branch = db.components().insertProjectBranch(mainBranch);
SnapshotDto snapshot = db.components().insertSnapshot(branch);
assertThatThrownBy(() -> ws.newRequest()
import org.sonar.db.audit.NoOpAuditPersister;
import org.sonar.db.component.BranchDao;
import org.sonar.db.component.BranchDto;
+import org.sonar.db.component.ProjectData;
import org.sonar.db.project.ProjectDao;
import org.sonar.db.project.ProjectDto;
import org.sonar.db.scannercache.ScannerAnalysisCacheDao;
@Rule
public UserSessionRule userSession = UserSessionRule.standalone();
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
+ public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
private final ScannerAnalysisCacheDao dao = new ScannerAnalysisCacheDao();
private final ProjectDao projectDao = new ProjectDao(System2.INSTANCE, new NoOpAuditPersister());
@Test
public void get_data_for_project() throws IOException {
- ProjectDto project1 = dbTester.components().insertPrivateProject().getProjectDto();
- BranchDto branch = dbTester.components().insertProjectBranch(project1);
- ProjectDto project2 = dbTester.components().insertPrivateProject().getProjectDto();
+ ProjectData projectData = dbTester.components().insertPrivateProject();
+ BranchDto branch = dbTester.components().insertProjectBranch(projectData.getProjectDto());
+ ProjectData projectData2 = dbTester.components().insertPrivateProject();
- dao.insert(dbTester.getSession(), project1.getUuid(), stringToCompressedInputStream("test data1"));
+ dao.insert(dbTester.getSession(), projectData.getMainBranchDto().getUuid(), stringToCompressedInputStream("test data1"));
dao.insert(dbTester.getSession(), branch.getUuid(), stringToCompressedInputStream("test data2"));
- dao.insert(dbTester.getSession(), project2.getUuid(), stringToCompressedInputStream("test data3"));
+ dao.insert(dbTester.getSession(), projectData2.getMainBranchComponent().uuid(), stringToCompressedInputStream("test data3"));
- userSession.logIn().addProjectPermission(SCAN, project1);
+ userSession.logIn().addProjectPermission(SCAN, projectData.getProjectDto());
TestResponse response = wsTester.newRequest()
- .setParam("project", project1.getKey())
+ .setParam("project", projectData.projectKey())
.setHeader("Accept-Encoding", "gzip")
.execute();
@Test
public void get_uncompressed_data_for_project() throws IOException {
- ProjectDto project1 = dbTester.components().insertPrivateProject().getProjectDto();
+ ProjectData projectData = dbTester.components().insertPrivateProject();
+ ProjectDto project1 = projectData.getProjectDto();
- dao.insert(dbTester.getSession(), project1.getUuid(), stringToCompressedInputStream("test data1"));
+ dao.insert(dbTester.getSession(), projectData.getMainBranchDto().getUuid(), stringToCompressedInputStream("test data1"));
userSession.logIn().addProjectPermission(SCAN, project1);
import org.sonar.db.DbClient;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ProjectData;
import org.sonar.db.user.UserDto;
import org.sonar.server.issue.AvatarResolverImpl;
import org.sonar.server.permission.PermissionService;
@Rule
public UserSessionRule userSessionRule = UserSessionRule.standalone();
@Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
+ public DbTester db = DbTester.create(System2.INSTANCE, true);
private final DbClient dbClient = db.getDbClient();
@UseDataProvider("allEditions")
public void return_homepage_when_set_to_a_project(EditionProvider.Edition edition) {
setPlatformEdition(edition);
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- UserDto user = db.users().insertUser(u -> u.setHomepageType("PROJECT").setHomepageParameter(project.uuid()));
- userSessionRule.logIn(user).addProjectPermission(USER, project);
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ UserDto user = db.users().insertUser(u -> u.setHomepageType("PROJECT").setHomepageParameter(mainBranch.uuid()));
+ userSessionRule.logIn(user).addProjectPermission(USER, projectData.getProjectDto());
CurrentWsResponse response = call();
assertThat(response.getHomepage())
.extracting(CurrentWsResponse.Homepage::getType, CurrentWsResponse.Homepage::getComponent)
- .containsExactly(CurrentWsResponse.HomepageType.PROJECT, project.getKey());
+ .containsExactly(CurrentWsResponse.HomepageType.PROJECT, mainBranch.getKey());
}
@Test
@Test
public void return_homepage_when_set_to_a_branch() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto project = projectData.getMainBranchComponent();
String branchName = randomAlphanumeric(248);
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey(branchName));
UserDto user = db.users().insertUser(u -> u.setHomepageType("PROJECT").setHomepageParameter(branch.uuid()));
- userSessionRule.logIn(user).addProjectPermission(USER, project);
+ userSessionRule.logIn(user).addProjectPermission(USER, projectData.getProjectDto());
CurrentWsResponse response = call();
public UserSessionRule userSession = UserSessionRule.standalone();
@Rule
- public DbTester db = DbTester.create();
+ public DbTester db = DbTester.create(true);
private final DbClient dbClient = db.getDbClient();
private final WsActionTester ws = new WsActionTester(new SetHomepageAction(userSession, dbClient, TestComponentFinder.from(db)));
@Test
public void set_project_homepage() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
+ ComponentDto mainBranch = db.components().insertPrivateProject().getMainBranchComponent();
UserDto user = db.users().insertUser();
userSession.logIn(user);
ws.newRequest()
.setMethod("POST")
.setParam(PARAM_TYPE, "PROJECT")
- .setParam("component", project.getKey())
+ .setParam("component", mainBranch.getKey())
.execute();
UserDto actual = db.getDbClient().userDao().selectByLogin(db.getSession(), user.getLogin());
assertThat(actual).isNotNull();
assertThat(actual.getHomepageType()).isEqualTo("PROJECT");
- assertThat(actual.getHomepageParameter()).isEqualTo(project.uuid());
+ assertThat(actual.getHomepageParameter()).isEqualTo(mainBranch.uuid());
}
@Test
public void set_branch_homepage() {
- ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
+ ComponentDto mainBranch = db.components().insertPublicProject().getMainBranchComponent();
String branchName = randomAlphanumeric(248);
- ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey(branchName));
+ ComponentDto branch = db.components().insertProjectBranch(mainBranch, b -> b.setKey(branchName));
UserDto user = db.users().insertUser();
userSession.logIn(user);
return Stream.empty();
}
- List<String> projectUuids = analyses.stream().map(SnapshotDto::getComponentUuid).collect(toList());
- Map<String, BranchDto> branchesByUuids = dbClient.branchDao().selectByUuids(dbSession, projectUuids).stream().collect(uniqueIndex(BranchDto::getUuid));
+ List<String> branchUuids = analyses.stream().map(SnapshotDto::getComponentUuid).collect(toList());
+ Map<String, BranchDto> branchesByUuids = dbClient.branchDao().selectByUuids(dbSession, branchUuids).stream().collect(uniqueIndex(BranchDto::getUuid));
return Stream.concat(
computeQualityGateChangeEvents(dbSession, projectsByUuid, branchesByUuids, analyses),
import java.util.Set;
import javax.annotation.Nullable;
import org.sonar.api.resources.Qualifiers;
-import org.sonar.api.resources.Scopes;
import org.sonar.api.server.ws.Change;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.component.BranchDto;
-import org.sonar.db.component.ComponentDto;
+import org.sonar.db.entity.EntityDto;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.issue.index.IssueIndex;
import org.sonar.server.issue.index.IssueIndexSyncProgressChecker;
import org.sonar.server.issue.index.IssueQuery;
import org.sonarqube.ws.Issues;
-import static com.google.common.base.Preconditions.checkArgument;
import static org.sonar.api.server.ws.WebService.Param.PAGE_SIZE;
import static org.sonar.api.server.ws.WebService.Param.TEXT_QUERY;
import static org.sonar.server.issue.index.IssueQueryFactory.ISSUE_TYPE_NAMES;
private final ComponentFinder componentFinder;
public TagsAction(IssueIndex issueIndex,
- IssueIndexSyncProgressChecker issueIndexSyncProgressChecker, DbClient dbClient,
- ComponentFinder componentFinder) {
+ IssueIndexSyncProgressChecker issueIndexSyncProgressChecker, DbClient dbClient,
+ ComponentFinder componentFinder) {
this.issueIndex = issueIndex;
this.issueIndexSyncProgressChecker = issueIndexSyncProgressChecker;
this.dbClient = dbClient;
boolean all = request.mandatoryParamAsBoolean(PARAM_ALL);
checkIfAnyComponentsNeedIssueSync(dbSession, projectKey);
- Optional<ComponentDto> project = getProject(dbSession, projectKey);
- Optional<BranchDto> branch = project.flatMap(p -> dbClient.branchDao().selectByBranchKey(dbSession, p.uuid(), branchKey));
- List<String> tags = searchTags(project.orElse(null), branch.orElse(null), request, all);
+ Optional<EntityDto> entity = getProject(dbSession, projectKey);
+ Optional<BranchDto> branch = entity.flatMap(p -> dbClient.branchDao().selectByBranchKey(dbSession, p.getUuid(), branchKey));
+ List<String> tags = searchTags(entity.orElse(null), branch.orElse(null), request, all, dbSession);
Issues.TagsResponse.Builder tagsResponseBuilder = Issues.TagsResponse.newBuilder();
tags.forEach(tagsResponseBuilder::addTags);
}
}
- private Optional<ComponentDto> getProject(DbSession dbSession, @Nullable String projectKey) {
- if (projectKey == null) {
+ private Optional<EntityDto> getProject(DbSession dbSession, @Nullable String entityKey) {
+ if (entityKey == null) {
return Optional.empty();
}
- ComponentDto project = componentFinder.getByKey(dbSession, projectKey);
- checkArgument(project.scope().equals(Scopes.PROJECT), "Component '%s' must be a project", projectKey);
- return Optional.of(project);
+ EntityDto entity = componentFinder.getEntityByKey(dbSession, entityKey);
+ return Optional.of(entity);
}
private void checkIfAnyComponentsNeedIssueSync(DbSession session, @Nullable String projectKey) {
}
}
- private List<String> searchTags(@Nullable ComponentDto project, @Nullable BranchDto branch, Request request, boolean all) {
+ private List<String> searchTags(@Nullable EntityDto entity, @Nullable BranchDto branch, Request request, boolean all, DbSession dbSession) {
IssueQuery.Builder issueQueryBuilder = IssueQuery.builder()
.types(ISSUE_TYPE_NAMES);
- if (project != null) {
- switch (project.qualifier()) {
- case Qualifiers.PROJECT:
- issueQueryBuilder.projectUuids(Set.of(project.uuid()));
- break;
- case Qualifiers.APP, Qualifiers.VIEW:
- issueQueryBuilder.viewUuids(Set.of(project.uuid()));
- break;
- default:
- throw new IllegalArgumentException(String.format("Component of type '%s' is not supported", project.qualifier()));
+ if (entity != null) {
+ switch (entity.getQualifier()) {
+ case Qualifiers.PROJECT -> issueQueryBuilder.projectUuids(Set.of(entity.getUuid()));
+ case Qualifiers.VIEW, Qualifiers.APP -> issueQueryBuilder.viewUuids(Set.of(entity.getUuid()));
+ default ->
+ throw new IllegalArgumentException(String.format("Entity of type '%s' is not supported", entity.getQualifier()));
}
- if (branch != null && !project.uuid().equals(branch.getUuid())) {
+ if (branch != null && !branch.isMain()) {
issueQueryBuilder.branchUuid(branch.getUuid());
issueQueryBuilder.mainBranch(false);
+ } else if (Qualifiers.APP.equals(entity.getQualifier())) {
+ dbClient.branchDao().selectMainBranchByProjectUuid(dbSession, entity.getUuid())
+ .ifPresent(b -> issueQueryBuilder.branchUuid(b.getUuid()));
}
}
if (all) {
case PROJECT:
checkArgument(isNotBlank(componentParameter), PARAMETER_REQUIRED, type.name(), PARAM_COMPONENT);
ProjectDto projectDto = componentFinder.getProjectByKey(dbSession, componentParameter);
- if (branchParameter != null) {
- return componentFinder.getBranchOrPullRequest(dbSession, projectDto, branchParameter, null).getUuid();
- } else {
- return projectDto.getUuid();
- }
+ return componentFinder.getBranchOrPullRequest(dbSession, projectDto, branchParameter, null).getUuid();
case PORTFOLIO, APPLICATION:
checkArgument(isNotBlank(componentParameter), PARAMETER_REQUIRED, type.name(), PARAM_COMPONENT);
return componentFinder.getByKey(dbSession, componentParameter).uuid();