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);
}
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());
}
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);
}
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);
}
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);
}
Aggregations