Search in sources :

Example 76 with BranchDto

use of org.sonar.db.component.BranchDto in project sonarqube by SonarSource.

the class ExportBranchesStepTest method setUp.

@Before
public void setUp() {
    Date createdAt = new Date();
    ComponentDto projectDto = dbTester.components().insertPublicProject(PROJECT).setCreatedAt(createdAt);
    for (BranchDto branch : branches) {
        createdAt = DateUtils.addMinutes(createdAt, 10);
        dbTester.components().insertProjectBranch(PROJECT, branch).setCreatedAt(createdAt);
    }
    dbTester.commit();
    when(projectHolder.projectDto()).thenReturn(dbTester.components().getProjectDto(projectDto));
}
Also used : BranchDto(org.sonar.db.component.BranchDto) ComponentDto(org.sonar.db.component.ComponentDto) Date(java.util.Date) Before(org.junit.Before)

Example 77 with BranchDto

use of org.sonar.db.component.BranchDto in project sonarqube by SonarSource.

the class ExportIssuesChangelogStepTest method setUp.

@Before
public void setUp() {
    ComponentDto projectDto = dbTester.components().insertPublicProject(p -> p.setUuid(PROJECT_UUID));
    when(projectHolder.projectDto()).thenReturn(dbTester.components().getProjectDto(projectDto));
    when(projectHolder.branches()).thenReturn(newArrayList(new BranchDto().setBranchType(BranchType.BRANCH).setKey("master").setProjectUuid(PROJECT_UUID).setUuid(PROJECT_UUID)));
    insertIssue(PROJECT_UUID, ISSUE_OPEN_UUID, STATUS_OPEN);
    insertIssue(PROJECT_UUID, ISSUE_CONFIRMED_UUID, STATUS_CONFIRMED);
    insertIssue(PROJECT_UUID, ISSUE_REOPENED_UUID, STATUS_REOPENED);
    insertIssue(PROJECT_UUID, ISSUE_RESOLVED_UUID, STATUS_RESOLVED);
    insertIssue(PROJECT_UUID, ISSUE_CLOSED_UUID, STATUS_CLOSED);
}
Also used : BranchDto(org.sonar.db.component.BranchDto) ComponentDto(org.sonar.db.component.ComponentDto) Before(org.junit.Before)

Example 78 with BranchDto

use of org.sonar.db.component.BranchDto in project sonarqube by SonarSource.

the class PurgeCommandsTest method deleteNewCodePeriodsByRootUuid_deletes_branch_new_code_periods.

@Test
public void deleteNewCodePeriodsByRootUuid_deletes_branch_new_code_periods() {
    ComponentDto project = dbTester.components().insertPrivateProject();
    BranchDto branch = newBranchDto(project);
    dbTester.components().insertProjectBranch(project, branch);
    // global settings
    dbTester.newCodePeriods().insert(NewCodePeriodType.PREVIOUS_VERSION, null);
    // project settings
    dbTester.newCodePeriods().insert(project.uuid(), NewCodePeriodType.NUMBER_OF_DAYS, "20");
    // branch settings
    dbTester.newCodePeriods().insert(project.uuid(), branch.getUuid(), NewCodePeriodType.NUMBER_OF_DAYS, "1");
    PurgeCommands purgeCommands = new PurgeCommands(dbTester.getSession(), profiler, system2);
    purgeCommands.deleteNewCodePeriods(branch.getUuid());
    // should delete branch settings only
    assertThat(dbTester.countRowsOfTable("new_code_periods")).isEqualTo(2);
}
Also used : BranchDto(org.sonar.db.component.BranchDto) ComponentTesting.newBranchDto(org.sonar.db.component.ComponentTesting.newBranchDto) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 79 with BranchDto

use of org.sonar.db.component.BranchDto in project sonarqube by SonarSource.

the class PortfolioDaoTest method select_root_reference_to_app_with_branches.

@Test
public void select_root_reference_to_app_with_branches() {
    PortfolioDto portfolio = db.components().insertPrivatePortfolioDto("portfolio1");
    ProjectDto app = db.components().insertPrivateApplicationDto(p -> p.setDbKey("app").setName("app"));
    BranchDto branch = db.components().insertProjectBranch(app, b -> b.setExcludeFromPurge(true));
    db.components().addPortfolioApplicationBranch(portfolio.getUuid(), app.getUuid(), branch.getUuid());
    assertThat(portfolioDao.selectRootOfReferencersToAppBranch(db.getSession(), app.getUuid(), branch.getKey())).extracting(PortfolioDto::getKey).containsExactly(portfolio.getKey());
}
Also used : ApplicationProjectDto(org.sonar.db.project.ApplicationProjectDto) ProjectDto(org.sonar.db.project.ProjectDto) BranchDto(org.sonar.db.component.BranchDto) Test(org.junit.Test)

Example 80 with BranchDto

use of org.sonar.db.component.BranchDto in project sonarqube by SonarSource.

the class PortfolioDaoTest method deleteReferenceBranch.

@Test
public void deleteReferenceBranch() {
    PortfolioDto portfolio = db.components().insertPrivatePortfolioDto("portfolio1");
    ProjectDto app = db.components().insertPrivateApplicationDto(p -> p.setDbKey("app").setName("app"));
    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(), 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()));
    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()));
}
Also used : ApplicationProjectDto(org.sonar.db.project.ApplicationProjectDto) ProjectDto(org.sonar.db.project.ProjectDto) BranchDto(org.sonar.db.component.BranchDto) Test(org.junit.Test)

Aggregations

BranchDto (org.sonar.db.component.BranchDto)111 Test (org.junit.Test)62 ComponentDto (org.sonar.db.component.ComponentDto)52 ProjectDto (org.sonar.db.project.ProjectDto)42 DbSession (org.sonar.db.DbSession)31 SnapshotDto (org.sonar.db.component.SnapshotDto)22 List (java.util.List)15 ComponentTesting.newBranchDto (org.sonar.db.component.ComponentTesting.newBranchDto)13 DbClient (org.sonar.db.DbClient)12 MetricDto (org.sonar.db.metric.MetricDto)12 Map (java.util.Map)9 Optional (java.util.Optional)9 Nullable (javax.annotation.Nullable)9 WebService (org.sonar.api.server.ws.WebService)9 System2 (org.sonar.api.utils.System2)9 NotFoundException (org.sonar.server.exceptions.NotFoundException)9 Collection (java.util.Collection)8 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)8 Rule (org.junit.Rule)8 Request (org.sonar.api.server.ws.Request)8