Search in sources :

Example 11 with BranchDto

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

the class ExportLiveMeasuresStepTest method test_exported_fields.

@Test
public void test_exported_fields() {
    ComponentDto project = createProject(true);
    componentRepository.register(1, project.uuid(), false);
    MetricDto metric = dbTester.measures().insertMetric(m -> m.setValueType(INT.name()));
    dbTester.measures().insertLiveMeasure(project, metric, m -> m.setProjectUuid(project.uuid()).setValue(4711.0d).setData("test").setVariation(7.0d));
    when(projectHolder.projectDto()).thenReturn(dbTester.components().getProjectDto(project));
    when(projectHolder.branches()).thenReturn(newArrayList(new BranchDto().setProjectUuid(project.uuid()).setUuid(project.uuid()).setKey("master").setBranchType(BranchType.BRANCH)));
    underTest.execute(new TestComputationStepContext());
    List<ProjectDump.LiveMeasure> exportedMeasures = dumpWriter.getWrittenMessagesOf(DumpElement.LIVE_MEASURES);
    assertThat(exportedMeasures).hasSize(1);
    assertThat(exportedMeasures).extracting(ProjectDump.LiveMeasure::getComponentRef, ProjectDump.LiveMeasure::getMetricRef, m -> m.getDoubleValue().getValue(), ProjectDump.LiveMeasure::getTextValue, m -> m.getVariation().getValue()).containsOnly(tuple(1L, 0, 4711.0d, "test", 7.0d));
    assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("1 live measures exported");
    assertThat(metricRepository.getRefByUuid()).containsOnlyKeys(metric.getUuid());
}
Also used : ProjectDump(com.sonarsource.governance.projectdump.protobuf.ProjectDump) BranchDto(org.sonar.db.component.BranchDto) DbTester(org.sonar.db.DbTester) BranchType(org.sonar.db.component.BranchType) System2(org.sonar.api.utils.System2) Assertions.tuple(org.assertj.core.api.Assertions.tuple) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ComponentRepositoryImpl(org.sonar.ce.task.projectexport.component.ComponentRepositoryImpl) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) List(java.util.List) ComponentDto(org.sonar.db.component.ComponentDto) Rule(org.junit.Rule) LogTester(org.sonar.api.utils.log.LogTester) MetricDto(org.sonar.db.metric.MetricDto) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) INT(org.sonar.api.measures.Metric.ValueType.INT) ProjectDump(com.sonarsource.governance.projectdump.protobuf.ProjectDump) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) ProjectDto(org.sonar.db.project.ProjectDto) LoggerLevel(org.sonar.api.utils.log.LoggerLevel) Mockito.mock(org.mockito.Mockito.mock) MetricDto(org.sonar.db.metric.MetricDto) BranchDto(org.sonar.db.component.BranchDto) ComponentDto(org.sonar.db.component.ComponentDto) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 12 with BranchDto

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

the class CeActivityDaoTest method hasAnyFailedOrCancelledIssueSyncTask.

@Test
public void hasAnyFailedOrCancelledIssueSyncTask() {
    assertThat(underTest.hasAnyFailedOrCancelledIssueSyncTask(db.getSession())).isFalse();
    insert("TASK_1", REPORT, MAINCOMPONENT_1, SUCCESS);
    insert("TASK_2", REPORT, MAINCOMPONENT_1, FAILED);
    ProjectDto projectDto1 = db.components().insertPrivateProjectDto(branchDto -> branchDto.setNeedIssueSync(false), c -> {
    }, p -> {
    });
    insert("TASK_3", CeTaskTypes.BRANCH_ISSUE_SYNC, projectDto1.getUuid(), projectDto1.getUuid(), SUCCESS);
    ProjectDto projectDto2 = db.components().insertPrivateProjectDto(branchDto -> branchDto.setNeedIssueSync(false), c -> {
    }, p -> {
    });
    insert("TASK_4", CeTaskTypes.BRANCH_ISSUE_SYNC, projectDto2.getUuid(), projectDto2.getUuid(), SUCCESS);
    assertThat(underTest.hasAnyFailedOrCancelledIssueSyncTask(db.getSession())).isFalse();
    ProjectDto projectDto3 = db.components().insertPrivateProjectDto(branchDto -> branchDto.setNeedIssueSync(false), c -> {
    }, p -> {
    });
    insert("TASK_5", CeTaskTypes.BRANCH_ISSUE_SYNC, projectDto3.getUuid(), projectDto3.getUuid(), SUCCESS);
    BranchDto projectBranch1 = db.components().insertProjectBranch(projectDto3, branchDto -> branchDto.setNeedIssueSync(true));
    insert("TASK_6", CeTaskTypes.BRANCH_ISSUE_SYNC, projectBranch1.getUuid(), projectDto3.getUuid(), FAILED);
    BranchDto projectBranch2 = db.components().insertProjectBranch(projectDto3, branchDto -> branchDto.setNeedIssueSync(true));
    insert("TASK_7", CeTaskTypes.BRANCH_ISSUE_SYNC, projectBranch2.getUuid(), projectDto3.getUuid(), CANCELED);
    // failed task and project branch still exists and need sync
    assertThat(underTest.hasAnyFailedOrCancelledIssueSyncTask(db.getSession())).isTrue();
    // assume branch has been re-analysed
    db.getDbClient().branchDao().updateNeedIssueSync(db.getSession(), projectBranch1.getUuid(), false);
    // assume branch has been re-analysed
    db.getDbClient().branchDao().updateNeedIssueSync(db.getSession(), projectBranch2.getUuid(), false);
    assertThat(underTest.hasAnyFailedOrCancelledIssueSyncTask(db.getSession())).isFalse();
    // assume branch has been deleted
    db.getDbClient().purgeDao().deleteBranch(db.getSession(), projectBranch1.getUuid());
    db.getDbClient().purgeDao().deleteBranch(db.getSession(), projectBranch2.getUuid());
    // associated branch does not exist, so there is no failures - either it has been deleted or purged or reanalysed
    assertThat(underTest.hasAnyFailedOrCancelledIssueSyncTask(db.getSession())).isFalse();
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) BranchDto(org.sonar.db.component.BranchDto) Test(org.junit.Test)

Example 13 with BranchDto

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

the class PurgeCommandsTest method deleteNewCodePeriodsByRootUuid_should_not_delete_any_if_root_uuid_is_null.

@Test
public void deleteNewCodePeriodsByRootUuid_should_not_delete_any_if_root_uuid_is_null() {
    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(null);
    // should delete branch and project settings only
    assertThat(dbTester.countRowsOfTable("new_code_periods")).isEqualTo(3);
}
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 14 with BranchDto

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

the class PurgeCommandsTest method deleteNewCodePeriodsByRootUuid_deletes_project_new_code_periods.

@Test
public void deleteNewCodePeriodsByRootUuid_deletes_project_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(project.uuid());
    // should delete branch and project settings only
    assertThat(dbTester.countRowsOfTable("new_code_periods")).isOne();
}
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 15 with BranchDto

use of org.sonar.db.component.BranchDto 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)

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