Search in sources :

Example 71 with BranchDto

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

the class IgnoreOrphanBranchStepTest method execute_on_already_indexed_branch.

@Test
public void execute_on_already_indexed_branch() {
    BranchDto branchDto = new BranchDto().setBranchType(BRANCH).setKey("branchName").setUuid(BRANCH_UUID).setProjectUuid("project_uuid").setNeedIssueSync(false);
    dbClient.branchDao().insert(dbTester.getSession(), branchDto);
    dbTester.commit();
    underTest.execute(() -> null);
    Optional<BranchDto> branch = dbClient.branchDao().selectByUuid(dbTester.getSession(), BRANCH_UUID);
    assertThat(branch.get().isNeedIssueSync()).isFalse();
    assertThat(branch.get().isExcludeFromPurge()).isFalse();
}
Also used : BranchDto(org.sonar.db.component.BranchDto) Test(org.junit.Test)

Example 72 with BranchDto

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

the class IndexIssuesStepTest method execute.

@Test
public void execute() {
    BranchDto branchDto = new BranchDto().setBranchType(BRANCH).setKey("branchName").setUuid(BRANCH_UUID).setProjectUuid("project_uuid").setNeedIssueSync(true);
    dbClient.branchDao().insert(dbTester.getSession(), branchDto);
    dbTester.commit();
    underTest.execute(() -> null);
    verify(issueIndexer, times(1)).indexOnAnalysis(BRANCH_UUID);
    Optional<BranchDto> branch = dbClient.branchDao().selectByUuid(dbTester.getSession(), BRANCH_UUID);
    assertThat(branch.get().isNeedIssueSync()).isFalse();
}
Also used : BranchDto(org.sonar.db.component.BranchDto) Test(org.junit.Test)

Example 73 with BranchDto

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

the class ExportLiveMeasuresStepTest method do_not_export_measures_on_disabled_projects.

@Test
public void do_not_export_measures_on_disabled_projects() {
    ComponentDto project = createProject(false);
    componentRepository.register(1, project.uuid(), false);
    MetricDto metric = dbTester.measures().insertMetric(m -> m.setValueType(INT.name()));
    dbTester.measures().insertLiveMeasure(project, metric, m -> m.setValue(4711.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).isEmpty();
}
Also used : 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 74 with BranchDto

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

the class ExportLiveMeasuresStepTest method test_null_exported_fields.

@Test
public void test_null_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(null).setData((String) null).setVariation(null));
    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::hasDoubleValue, ProjectDump.LiveMeasure::getTextValue, ProjectDump.LiveMeasure::hasVariation).containsOnly(tuple(false, "", false));
    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) 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 75 with BranchDto

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

the class ExportLiveMeasuresStepTest method do_not_export_measures_on_disabled_metrics.

@Test
public void do_not_export_measures_on_disabled_metrics() {
    ComponentDto project = createProject(true);
    componentRepository.register(1, project.uuid(), false);
    MetricDto metric = dbTester.measures().insertMetric(m -> m.setValueType(INT.name()).setEnabled(false));
    dbTester.measures().insertLiveMeasure(project, metric, m -> m.setValue(4711.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).isEmpty();
}
Also used : 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)

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