Search in sources :

Example 6 with ProjectDto

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

the class ExportIssuesStepTest method setUp.

@Before
public void setUp() {
    ProjectDto project = createProject();
    when(projectHolder.projectDto()).thenReturn(project);
    when(projectHolder.branches()).thenReturn(newArrayList(new BranchDto().setBranchType(BranchType.BRANCH).setKey("master").setProjectUuid(SOME_PROJECT_UUID).setUuid(SOME_PROJECT_UUID)));
    // adds a random number of Rules to db and repository so that READY_RULE_KEY does always get id=ref=1
    for (int i = 0; i < new Random().nextInt(150); i++) {
        RuleKey ruleKey = RuleKey.of("repo_" + i, "key_" + i);
        RuleDto ruleDto = insertRule(ruleKey.toString());
        ruleRepository.register(ruleDto.getUuid(), ruleKey);
    }
    this.readyRuleDto = insertRule(READY_RULE_KEY);
    componentRepository.register(12, SOME_PROJECT_UUID, false);
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) BranchDto(org.sonar.db.component.BranchDto) Random(java.util.Random) RuleKey(org.sonar.api.rule.RuleKey) RuleDto(org.sonar.db.rule.RuleDto) Before(org.junit.Before)

Example 7 with ProjectDto

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

the class ExportLiveMeasuresStepTest method export_zero_measures.

@Test
public void export_zero_measures() {
    when(projectHolder.branches()).thenReturn(newArrayList());
    when(projectHolder.projectDto()).thenReturn(new ProjectDto().setUuid("does not exist"));
    underTest.execute(new TestComputationStepContext());
    assertThat(dumpWriter.getWrittenMessagesOf(DumpElement.LIVE_MEASURES)).isEmpty();
    assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("0 live measures exported");
    assertThat(metricRepository.getRefByUuid()).isEmpty();
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 8 with ProjectDto

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

the class BranchDaoTest method selectProjectUuidsWithIssuesNeedSync.

@Test
public void selectProjectUuidsWithIssuesNeedSync() {
    ComponentDto project1 = db.components().insertPrivateProject();
    ComponentDto project2 = db.components().insertPrivateProject();
    ComponentDto project3 = db.components().insertPrivateProject();
    ComponentDto project4 = db.components().insertPrivateProject();
    ProjectDto project1Dto = db.components().getProjectDto(project1);
    ProjectDto project2Dto = db.components().getProjectDto(project2);
    ProjectDto project3Dto = db.components().getProjectDto(project3);
    ProjectDto project4Dto = db.components().getProjectDto(project4);
    BranchDto branch1 = db.components().insertProjectBranch(project1Dto, branchDto -> branchDto.setNeedIssueSync(true));
    BranchDto branch2 = db.components().insertProjectBranch(project1Dto, branchDto -> branchDto.setNeedIssueSync(false));
    BranchDto branch3 = db.components().insertProjectBranch(project2Dto);
    assertThat(underTest.selectProjectUuidsWithIssuesNeedSync(db.getSession(), Sets.newHashSet(project1Dto.getUuid(), project2Dto.getUuid(), project3Dto.getUuid(), project4Dto.getUuid()))).containsOnly(project1.uuid());
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) Test(org.junit.Test)

Example 9 with ProjectDto

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

the class BranchDaoTest method selectByBranchKeys.

@Test
public void selectByBranchKeys() {
    ProjectDto project1 = db.components().insertPrivateProjectDto();
    ProjectDto project2 = db.components().insertPrivateProjectDto();
    ProjectDto project3 = db.components().insertPrivateProjectDto();
    BranchDto branch1 = db.components().insertProjectBranch(project1, b -> b.setKey("branch1"));
    BranchDto branch2 = db.components().insertProjectBranch(project2, b -> b.setKey("branch2"));
    BranchDto branch3 = db.components().insertProjectBranch(project3, b -> b.setKey("branch3"));
    Map<String, String> branchKeysByProjectUuid = new HashMap<>();
    branchKeysByProjectUuid.put(project1.getUuid(), "branch1");
    branchKeysByProjectUuid.put(project2.getUuid(), "branch2");
    branchKeysByProjectUuid.put(project3.getUuid(), "nonexisting");
    List<BranchDto> branchDtos = underTest.selectByBranchKeys(dbSession, branchKeysByProjectUuid);
    assertThat(branchDtos).hasSize(2);
    assertThat(branchDtos).extracting(BranchDto::getUuid).containsExactlyInAnyOrder(branch1.getUuid(), branch2.getUuid());
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 10 with ProjectDto

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

the class BranchDaoTest method selectByProjectUuid.

@Test
public void selectByProjectUuid() {
    ComponentDto project1 = db.components().insertPrivateProject();
    ComponentDto project2 = db.components().insertPrivateProject();
    ComponentDto branch1 = db.components().insertProjectBranch(project1);
    ComponentDto branch2 = db.components().insertProjectBranch(project1);
    ComponentDto branch3 = db.components().insertProjectBranch(project2);
    ComponentDto branch4 = db.components().insertProjectBranch(project2);
    assertThat(underTest.selectByProject(dbSession, new ProjectDto().setUuid(project1.uuid()))).extracting(BranchDto::getUuid).containsExactlyInAnyOrder(project1.uuid(), branch1.uuid(), branch2.uuid());
    assertThat(underTest.selectByProject(dbSession, new ProjectDto().setUuid(project2.uuid()))).extracting(BranchDto::getUuid).containsExactlyInAnyOrder(project2.uuid(), branch3.uuid(), branch4.uuid());
}
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