Search in sources :

Example 21 with ProjectDto

use of org.sonar.db.project.ProjectDto in project sonarqube by SonarSource.

the class PortfolioDaoTest method add_and_delete_selected_branches.

@Test
public void add_and_delete_selected_branches() {
    PortfolioDto portfolio1 = db.components().insertPrivatePortfolioDto("portfolio1");
    ProjectDto project1 = db.components().insertPrivateProjectDto("project1");
    db.components().addPortfolioProject(portfolio1, project1);
    assertThat(db.countRowsOfTable(db.getSession(), "portfolio_proj_branches")).isZero();
    assertThat(portfolioDao.selectPortfolioProjectOrFail(db.getSession(), portfolio1.getUuid(), project1.getUuid()).getBranchUuids()).isEmpty();
    db.components().addPortfolioProjectBranch(portfolio1, project1, "branch1");
    assertThat(db.countRowsOfTable(db.getSession(), "portfolio_proj_branches")).isOne();
    PortfolioProjectDto portfolioProject = portfolioDao.selectPortfolioProjectOrFail(db.getSession(), portfolio1.getUuid(), project1.getUuid());
    assertThat(portfolioProject.getBranchUuids()).containsOnly("branch1");
    portfolioDao.deleteBranch(db.getSession(), portfolio1.getUuid(), project1.getUuid(), "branch1");
    assertThat(db.countRowsOfTable(db.getSession(), "portfolio_proj_branches")).isZero();
    assertThat(portfolioDao.selectPortfolioProjectOrFail(db.getSession(), portfolio1.getUuid(), project1.getUuid()).getBranchUuids()).isEmpty();
}
Also used : ApplicationProjectDto(org.sonar.db.project.ApplicationProjectDto) ProjectDto(org.sonar.db.project.ProjectDto) Test(org.junit.Test)

Example 22 with ProjectDto

use of org.sonar.db.project.ProjectDto in project sonarqube by SonarSource.

the class PortfolioDaoTest method select_reference_to_app_by_key.

@Test
public void select_reference_to_app_by_key() {
    PortfolioDto portfolio = db.components().insertPrivatePortfolioDto("portfolio1");
    ProjectDto app1 = db.components().insertPrivateApplicationDto(p -> p.setDbKey("app1"));
    db.components().addPortfolioReference(portfolio, app1.getUuid());
    assertThat(portfolioDao.selectReferenceToApp(db.getSession(), portfolio.getUuid(), app1.getKey())).get().extracting(ReferenceDto::getTargetUuid).isEqualTo(app1.getUuid());
    assertThat(portfolioDao.selectReference(db.getSession(), portfolio.getUuid(), app1.getKey())).extracting(ReferenceDto::getTargetUuid).isEqualTo(app1.getUuid());
    assertThat(portfolioDao.selectReferenceToPortfolio(db.getSession(), portfolio.getUuid(), app1.getKey())).isEmpty();
}
Also used : ApplicationProjectDto(org.sonar.db.project.ApplicationProjectDto) ProjectDto(org.sonar.db.project.ProjectDto) Test(org.junit.Test)

Example 23 with ProjectDto

use of org.sonar.db.project.ProjectDto in project sonarqube by SonarSource.

the class PortfolioDaoTest method selectAllReferencesToApplicationsInHierarchy.

@Test
public void selectAllReferencesToApplicationsInHierarchy() {
    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().insertPrivateApplicationDto(p -> p.setDbKey("app1"));
    ProjectDto app2 = db.components().insertPrivateApplicationDto(p -> p.setDbKey("app2"));
    ProjectDto app3 = db.components().insertPrivateApplicationDto(p -> p.setDbKey("app3"));
    portfolioDao.addReference(session, "portfolio1", app1.getUuid());
    portfolioDao.addReference(session, "portfolio2", app2.getUuid());
    portfolioDao.addReference(session, "portfolio3", app3.getUuid());
    assertThat(portfolioDao.selectAllReferencesToApplicationsInHierarchy(session, p1.getUuid())).extracting(ReferenceDto::getTargetUuid).containsExactlyInAnyOrder(app1.getUuid(), app2.getUuid(), app3.getUuid());
}
Also used : ApplicationProjectDto(org.sonar.db.project.ApplicationProjectDto) ProjectDto(org.sonar.db.project.ProjectDto) Test(org.junit.Test)

Example 24 with ProjectDto

use of org.sonar.db.project.ProjectDto in project sonarqube by SonarSource.

the class PortfolioDaoTest method select_reference_to_app_with_branches.

@Test
public void select_reference_to_app_with_branches() {
    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());
    var appFromDb = portfolioDao.selectReferenceToApp(db.getSession(), portfolio.getUuid(), app.getKey());
    assertThat(appFromDb).isPresent();
    assertThat(appFromDb.get()).extracting(ReferenceDto::getTargetKey, ReferenceDto::getTargetName, ReferenceDto::getBranchUuids).containsExactly("app", "app", Set.of(branch1.getUuid(), 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)

Example 25 with ProjectDto

use of org.sonar.db.project.ProjectDto in project sonarqube by SonarSource.

the class WebhookDaoTest method cleanWebhooksOfAProject.

@Test
public void cleanWebhooksOfAProject() {
    ProjectDto projectDto = componentDbTester.insertPrivateProjectDto();
    webhookDbTester.insertWebhook(projectDto);
    webhookDbTester.insertWebhook(projectDto);
    webhookDbTester.insertWebhook(projectDto);
    webhookDbTester.insertWebhook(projectDto);
    underTest.deleteByProject(dbSession, projectDto);
    Optional<WebhookDto> reloaded = underTest.selectByUuid(dbSession, projectDto.getUuid());
    assertThat(reloaded).isEmpty();
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) Test(org.junit.Test)

Aggregations

ProjectDto (org.sonar.db.project.ProjectDto)283 Test (org.junit.Test)215 DbSession (org.sonar.db.DbSession)49 BranchDto (org.sonar.db.component.BranchDto)42 UserDto (org.sonar.db.user.UserDto)39 AlmSettingDto (org.sonar.db.alm.setting.AlmSettingDto)38 QProfileDto (org.sonar.db.qualityprofile.QProfileDto)31 SnapshotDto (org.sonar.db.component.SnapshotDto)27 QualityGateDto (org.sonar.db.qualitygate.QualityGateDto)26 ComponentDto (org.sonar.db.component.ComponentDto)23 ComponentTesting.newPrivateProjectDto (org.sonar.db.component.ComponentTesting.newPrivateProjectDto)20 NotFoundException (org.sonar.server.exceptions.NotFoundException)17 WebhookDto (org.sonar.db.webhook.WebhookDto)15 ApplicationProjectDto (org.sonar.db.project.ApplicationProjectDto)14 WebService (org.sonar.api.server.ws.WebService)13 DbClient (org.sonar.db.DbClient)12 PortfolioProjectDto (org.sonar.db.portfolio.PortfolioProjectDto)12 TestRequest (org.sonar.server.ws.TestRequest)11 TestResponse (org.sonar.server.ws.TestResponse)10 Projects (org.sonarqube.ws.Projects)10