Search in sources :

Example 81 with TestComputationStepContext

use of org.sonar.ce.task.step.TestComputationStepContext in project sonarqube by SonarSource.

the class PersistEventsStepTest method persist_alert_events_on_root.

@Test
public void persist_alert_events_on_root() {
    when(system2.now()).thenReturn(NOW);
    treeRootHolder.setRoot(ROOT);
    Event alert = Event.createAlert("Failed", null, "Open issues > 0");
    when(eventRepository.getEvents(ROOT)).thenReturn(ImmutableList.of(alert));
    underTest.execute(new TestComputationStepContext());
    assertThat(dbTester.countRowsOfTable(dbTester.getSession(), "events")).isEqualTo(2);
    List<EventDto> eventDtos = dbTester.getDbClient().eventDao().selectByComponentUuid(dbTester.getSession(), ROOT.getUuid());
    assertThat(eventDtos).extracting(EventDto::getCategory).containsOnly(CATEGORY_ALERT, CATEGORY_VERSION);
    EventDto eventDto = eventDtos.stream().filter(t -> CATEGORY_ALERT.equals(t.getCategory())).findAny().get();
    assertThat(eventDto.getComponentUuid()).isEqualTo(ROOT.getUuid());
    assertThat(eventDto.getName()).isEqualTo(alert.getName());
    assertThat(eventDto.getDescription()).isEqualTo(alert.getDescription());
    assertThat(eventDto.getCategory()).isEqualTo(CATEGORY_ALERT);
    assertThat(eventDto.getData()).isNull();
    assertThat(eventDto.getDate()).isEqualTo(analysisMetadataHolder.getAnalysisDate());
    assertThat(eventDto.getCreatedAt()).isEqualTo(NOW);
}
Also used : EventDto(org.sonar.db.event.EventDto) Event(org.sonar.ce.task.projectanalysis.event.Event) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 82 with TestComputationStepContext

use of org.sonar.ce.task.step.TestComputationStepContext in project sonarqube by SonarSource.

the class PersistEventsStepTest method keep_one_event_by_version.

@Test
public void keep_one_event_by_version() {
    ComponentDto projectDto = dbTester.components().insertPublicProject();
    EventDto[] existingEvents = new EventDto[] { dbTester.events().insertEvent(newVersionEventDto(projectDto, 120_000_000L, "1.3-SNAPSHOT")), dbTester.events().insertEvent(newVersionEventDto(projectDto, 130_000_000L, "1.4")), dbTester.events().insertEvent(newVersionEventDto(projectDto, 140_000_000L, "1.5-SNAPSHOT")) };
    Component project = builder(PROJECT, 1).setUuid(projectDto.uuid()).setProjectVersion("1.5-SNAPSHOT").addChildren(builder(DIRECTORY, 2).setUuid("BCDE").addChildren(builder(DIRECTORY, 3).setUuid("Q").addChildren(builder(FILE, 4).setUuid("Z").build()).build()).build()).build();
    treeRootHolder.setRoot(project);
    underTest.execute(new TestComputationStepContext());
    assertThat(dbTester.countRowsOfTable(dbTester.getSession(), "events")).isEqualTo(3);
    List<EventDto> eventDtos = dbTester.getDbClient().eventDao().selectByComponentUuid(dbTester.getSession(), projectDto.uuid());
    assertThat(eventDtos).hasSize(3);
    assertThat(eventDtos).extracting(EventDto::getName).containsOnly("1.3-SNAPSHOT", "1.4", "1.5-SNAPSHOT");
    assertThat(eventDtos).extracting(EventDto::getUuid).contains(existingEvents[0].getUuid(), existingEvents[1].getUuid()).doesNotContain(existingEvents[2].getUuid());
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) EventDto(org.sonar.db.event.EventDto) Component(org.sonar.ce.task.projectanalysis.component.Component) ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 83 with TestComputationStepContext

use of org.sonar.ce.task.step.TestComputationStepContext in project sonarqube by SonarSource.

the class PersistLiveMeasuresStepTest method measures_on_new_code_period_are_persisted.

@Test
public void measures_on_new_code_period_are_persisted() {
    prepareProject();
    measureRepository.addRawMeasure(REF_1, INT_METRIC.getKey(), newMeasureBuilder().setVariation(42.0).createNoValue());
    TestComputationStepContext context = new TestComputationStepContext();
    step().execute(context);
    LiveMeasureDto persistedMeasure = selectMeasure("project-uuid", INT_METRIC).get();
    assertThat(persistedMeasure.getValue()).isNull();
    assertThat(persistedMeasure.getVariation()).isEqualTo(42.0);
    verifyStatistics(context, 1);
}
Also used : LiveMeasureDto(org.sonar.db.measure.LiveMeasureDto) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 84 with TestComputationStepContext

use of org.sonar.ce.task.step.TestComputationStepContext in project sonarqube by SonarSource.

the class PersistLiveMeasuresStepTest method do_not_persist_file_measures_with_best_value.

@Test
public void do_not_persist_file_measures_with_best_value() {
    prepareProject();
    // measure to be deleted because new value matches the metric best value
    LiveMeasureDto oldMeasure = insertMeasure("file-uuid", "project-uuid", INT_METRIC);
    db.commit();
    // project measure with metric best value -> persist with value 0
    measureRepository.addRawMeasure(REF_1, METRIC_WITH_BEST_VALUE.getKey(), newMeasureBuilder().create(0));
    // file measure with metric best value -> do not persist
    measureRepository.addRawMeasure(REF_4, METRIC_WITH_BEST_VALUE.getKey(), newMeasureBuilder().create(0));
    TestComputationStepContext context = new TestComputationStepContext();
    step().execute(context);
    assertThatMeasureDoesNotExist(oldMeasure);
    assertThatMeasureHasValue("project-uuid", METRIC_WITH_BEST_VALUE, 0);
    verifyStatistics(context, 1);
}
Also used : LiveMeasureDto(org.sonar.db.measure.LiveMeasureDto) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 85 with TestComputationStepContext

use of org.sonar.ce.task.step.TestComputationStepContext in project sonarqube by SonarSource.

the class PersistLiveMeasuresStepTest method measures_without_value_are_not_persisted.

@Test
public void measures_without_value_are_not_persisted() {
    prepareProject();
    measureRepository.addRawMeasure(REF_1, STRING_METRIC.getKey(), newMeasureBuilder().createNoValue());
    measureRepository.addRawMeasure(REF_1, INT_METRIC.getKey(), newMeasureBuilder().createNoValue());
    TestComputationStepContext context = new TestComputationStepContext();
    step().execute(context);
    assertThatMeasureIsNotPersisted("project-uuid", STRING_METRIC);
    assertThatMeasureIsNotPersisted("project-uuid", INT_METRIC);
    verifyStatistics(context, 0);
}
Also used : TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Aggregations

TestComputationStepContext (org.sonar.ce.task.step.TestComputationStepContext)458 Test (org.junit.Test)431 ComponentDto (org.sonar.db.component.ComponentDto)91 ProjectDump (com.sonarsource.governance.projectdump.protobuf.ProjectDump)38 Component (org.sonar.ce.task.projectanalysis.component.Component)38 SnapshotDto (org.sonar.db.component.SnapshotDto)31 Date (java.util.Date)30 ReportComponent (org.sonar.ce.task.projectanalysis.component.ReportComponent)28 ComputationStep (org.sonar.ce.task.step.ComputationStep)24 RuleDefinitionDto (org.sonar.db.rule.RuleDefinitionDto)17 FileSourceDto (org.sonar.db.source.FileSourceDto)15 BaseStepTest (org.sonar.ce.task.projectanalysis.step.BaseStepTest)14 Project (org.sonar.server.project.Project)14 TextBlock (org.sonar.ce.task.projectanalysis.duplication.TextBlock)13 QualityProfile (org.sonar.server.qualityprofile.QualityProfile)13 Notification (org.sonar.api.notifications.Notification)12 DefaultIssue (org.sonar.core.issue.DefaultIssue)12 MeasureComputer (org.sonar.api.ce.measure.MeasureComputer)11 IssueDto (org.sonar.db.issue.IssueDto)11 IssuesChangesNotification (org.sonar.server.issue.notification.IssuesChangesNotification)11