Search in sources :

Example 16 with ProjectDto

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

the class AnalysisPropertiesDaoTest method selectProjectCountPerAnalysisPropertyValueInLastAnalysis_should_return_correct_values.

@Test
public void selectProjectCountPerAnalysisPropertyValueInLastAnalysis_should_return_correct_values() {
    final String analysisPropertyKey = "key";
    for (int i = 0; i < 7; i++) {
        final int index = i;
        ProjectDto project = dbTester.components().insertPrivateProjectDto();
        dbTester.components().insertSnapshot(project, s -> s.setLast(true).setUuid("uuid" + index));
    }
    underTest.insert(dbSession, new AnalysisPropertyDto().setKey(analysisPropertyKey).setValue("git").setAnalysisUuid("uuid0").setUuid("0"));
    underTest.insert(dbSession, new AnalysisPropertyDto().setKey(analysisPropertyKey).setValue("svn").setAnalysisUuid("uuid1").setUuid("1"));
    underTest.insert(dbSession, new AnalysisPropertyDto().setKey(analysisPropertyKey).setValue("undetected").setAnalysisUuid("uuid2").setUuid("2"));
    underTest.insert(dbSession, new AnalysisPropertyDto().setKey(analysisPropertyKey).setValue("undetected").setAnalysisUuid("uuid3").setUuid("3"));
    underTest.insert(dbSession, new AnalysisPropertyDto().setKey(analysisPropertyKey).setValue("git").setAnalysisUuid("uuid4").setUuid("4"));
    underTest.insert(dbSession, new AnalysisPropertyDto().setKey(analysisPropertyKey).setValue("git").setAnalysisUuid("uuid5").setUuid("5"));
    List<ProjectCountPerAnalysisPropertyValue> result = underTest.selectProjectCountPerAnalysisPropertyValueInLastAnalysis(dbSession, analysisPropertyKey);
    assertThat(result).extracting(ProjectCountPerAnalysisPropertyValue::getPropertyValue, ProjectCountPerAnalysisPropertyValue::getCount).containsExactlyInAnyOrder(tuple("git", 3L), tuple("svn", 1L), tuple("undetected", 2L));
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) Test(org.junit.Test)

Example 17 with ProjectDto

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

the class CeTaskMessageDaoTest method selectNonDismissedByUserAndTask_returns_non_dismissed_messages.

@Test
public void selectNonDismissedByUserAndTask_returns_non_dismissed_messages() {
    UserDto user = dbTester.users().insertUser();
    ProjectDto project = dbTester.components().insertPrivateProjectDto();
    dbTester.users().insertUserDismissedMessage(user, project, CeTaskMessageType.SUGGEST_DEVELOPER_EDITION_UPGRADE);
    String taskUuid = "17ae66e6-fe83-4c80-b704-4b04e9c5abe8";
    CeTaskMessageDto msg1 = insertMessage(taskUuid, 1, 1_222_333L);
    insertMessage(taskUuid, 2, 1_222_334L, CeTaskMessageType.SUGGEST_DEVELOPER_EDITION_UPGRADE);
    CeTaskMessageDto msg3 = insertMessage(taskUuid, 3, 1_222_335L);
    List<CeTaskMessageDto> messages = underTest.selectNonDismissedByUserAndTask(dbTester.getSession(), taskUuid, user.getUuid());
    assertThat(messages).hasSize(2);
    assertThat(messages).extracting(CeTaskMessageDto::getUuid).containsExactlyInAnyOrder(msg1.getUuid(), msg3.getUuid());
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) UserDto(org.sonar.db.user.UserDto) Test(org.junit.Test)

Example 18 with ProjectDto

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

the class PurgeCommandsTest method deleteProjectInPortfolios_deletes_branch_from_portfolios_if_root_is_branch.

@Test
public void deleteProjectInPortfolios_deletes_branch_from_portfolios_if_root_is_branch() {
    var portfolio1 = dbTester.components().insertPrivatePortfolioDto();
    ProjectDto project = dbTester.components().insertPrivateProjectDto();
    dbTester.components().addPortfolioProject(portfolio1, project);
    dbTester.components().addPortfolioProjectBranch(portfolio1, project, "projectBranch");
    dbTester.components().addPortfolioProjectBranch(portfolio1, project, "anotherBranch");
    PurgeCommands purgeCommands = new PurgeCommands(dbTester.getSession(), profiler, system2);
    purgeCommands.deleteProjectInPortfolios("projectBranch");
    assertThat(dbTester.getDbClient().portfolioDao().selectAllPortfolioProjects(dbTester.getSession())).extracting(PortfolioProjectDto::getPortfolioUuid, PortfolioProjectDto::getProjectUuid, PortfolioProjectDto::getBranchUuids).containsExactlyInAnyOrder(tuple(portfolio1.getUuid(), project.getUuid(), Set.of("anotherBranch")));
}
Also used : PortfolioProjectDto(org.sonar.db.portfolio.PortfolioProjectDto) ProjectDto(org.sonar.db.project.ProjectDto) Test(org.junit.Test)

Example 19 with ProjectDto

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

the class PurgeCommandsTest method deleteUserDismissedMessages_deletes_dismissed_warnings_on_project_for_all_users.

@Test
public void deleteUserDismissedMessages_deletes_dismissed_warnings_on_project_for_all_users() {
    UserDto user1 = dbTester.users().insertUser();
    UserDto user2 = dbTester.users().insertUser();
    ProjectDto project = dbTester.components().insertPrivateProjectDto();
    ProjectDto anotherProject = dbTester.components().insertPrivateProjectDto();
    dbTester.users().insertUserDismissedMessage(user1, project, CeTaskMessageType.SUGGEST_DEVELOPER_EDITION_UPGRADE);
    dbTester.users().insertUserDismissedMessage(user2, project, CeTaskMessageType.SUGGEST_DEVELOPER_EDITION_UPGRADE);
    dbTester.users().insertUserDismissedMessage(user1, anotherProject, CeTaskMessageType.SUGGEST_DEVELOPER_EDITION_UPGRADE);
    PurgeCommands purgeCommands = new PurgeCommands(dbTester.getSession(), profiler, system2);
    purgeCommands.deleteUserDismissedMessages(project.getUuid());
    assertThat(dbTester.countRowsOfTable("user_dismissed_messages")).isOne();
}
Also used : PortfolioProjectDto(org.sonar.db.portfolio.PortfolioProjectDto) ProjectDto(org.sonar.db.project.ProjectDto) UserDto(org.sonar.db.user.UserDto) Test(org.junit.Test)

Example 20 with ProjectDto

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

the class PortfolioDaoTest method selectAllDirectChildApplications.

@Test
public void selectAllDirectChildApplications() {
    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.selectApplicationReferenceUuids(session, p1.getUuid())).containsOnly(app1.getUuid());
    assertThat(portfolioDao.selectApplicationReferenceUuids(session, p2.getUuid())).containsOnly(app2.getUuid());
    assertThat(portfolioDao.selectApplicationReferenceUuids(session, p3.getUuid())).containsOnly(app3.getUuid());
}
Also used : ApplicationProjectDto(org.sonar.db.project.ApplicationProjectDto) 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